xmlcfg4j
XML based configuration for Java.
Description
This library provides base classes for JAXB based configurations. The configuration itself is always implemented in another (specific) project. There is also an XSD schema available: xmlcfg4j.xsd
Variable
A variable tag defines simply a key and a value.
<variable name="abc" value="def" />
The tag may reference other variables.
<variable name="a" value="1" />
<variable name="b" value="${a}/2" />
<variable name="c" value="${b}/3" />
The final values of the variables are: a="1" / b="1/2" / c="1/2/3".
AbstractElement
The class AbstractElement is mainly a container for variables.
You will need to extend it in your project that has a JAXB based XML configuration:
@XmlRootElement(name = "my-element")
public class MyElement extends AbstractElement {
}
Then you can use it like this:
<my-element>
<variable name="a" value="1" />
<variable name="b" value="${a}/2" />
</my-element>
AbstractNamedElement
The class AbstractNamedElement adds only a unique name to the AbstractElement.
You will need to extend it in your project that has a JAXB based XML configuration:
@XmlRootElement(name = "my-named-element")
public class MyNamedElement extends AbstractNamedElement {
}
Then you can use it like this:
<my-named-element name="AnyName">
<variable name="a" value="1" />
<variable name="b" value="${a}/2" />
</my-named-element>
Inherit and override variables
If you create elements that contain other elements, it's easy to support inheritance of variables and also override them.
<?xml version="1.0" encoding="UTF-8"?>
<test:parent xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.fuin.org/xmlcfg4j" xmlns:test="http://www.fuin.org/xmlcfg4j/test">
<variable name="root" value="/var/tmp" />
<variable name="path" value="${root}/example" />
<!-- Read a file from the classpath and replace variables contained in it. -->
<variable name="res" url="classpath:header.txt" encoding="utf-8" />
<!-- Use escaped characters. -->
<variable name="escapes" value="\r\n\t" />
<test:child>
<!-- Inherits variable "root" -->
<!-- Inherits variable "res" -->
<!-- Inherits variable "escapes" -->
<!-- Overrides variable "path" = "/var/tmp/example/child" -->
<variable name="path" value="${path}/child" />
</test:child>
</test:parent>
See ParentChildTest for an example on how to use it.
Building this project
Checkout the source code from the repository and use the following commands inside the project's directory to build the project.
Linux:
$ ./mvnw clean install
Windows:
C:\Users\YourUser> mvnw.cmd clean install
Snapshots
Snapshots can be found on the OSS Sonatype Snapshots Repository.
Add the following to your .m2/settings.xml to enable snapshots in your Maven build:
<repository>
<id>sonatype.oss.snapshots</id>
<name>Sonatype OSS Snapshot Repository</name>
<url>http://oss.sonatype.org/content/repositories/snapshots</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>