org.fuin:xmlcfg4j

XML based configuration for Java

License

License

Categories

Categories

cfg4j Application Layer Libs Configuration
GroupId

GroupId

org.fuin
ArtifactId

ArtifactId

xmlcfg4j
Last Version

Last Version

0.2.0
Release Date

Release Date

Type

Type

jar
Description

Description

XML based configuration for Java
Project URL

Project URL

https://github.com/fuinorg/xmlcfg4j/
Project Organization

Project Organization

fuin.org (Germany)
Source Code Management

Source Code Management

https://github.com/fuinorg/xmlcfg4j/

Download xmlcfg4j

How to add to project

<!-- https://jarcasting.com/artifacts/org.fuin/xmlcfg4j/ -->
<dependency>
    <groupId>org.fuin</groupId>
    <artifactId>xmlcfg4j</artifactId>
    <version>0.2.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.fuin/xmlcfg4j/
implementation 'org.fuin:xmlcfg4j:0.2.0'
// https://jarcasting.com/artifacts/org.fuin/xmlcfg4j/
implementation ("org.fuin:xmlcfg4j:0.2.0")
'org.fuin:xmlcfg4j:jar:0.2.0'
<dependency org="org.fuin" name="xmlcfg4j" rev="0.2.0">
  <artifact name="xmlcfg4j" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.fuin', module='xmlcfg4j', version='0.2.0')
)
libraryDependencies += "org.fuin" % "xmlcfg4j" % "0.2.0"
[org.fuin/xmlcfg4j "0.2.0"]

Dependencies

compile (4)

Group / Artifact Type Version
org.fuin : utils4j jar 0.10.0
com.google.code.findbugs : jsr305 jar 3.0.2
javax.validation : validation-api jar 2.0.1.Final
org.apache.commons : commons-lang3 jar 3.7

test (8)

Group / Artifact Type Version
junit : junit jar 4.12
org.assertj : assertj-core jar 3.10.0
nl.jqno.equalsverifier : equalsverifier jar 2.4.6
xmlunit : xmlunit jar 1.6
com.googlecode.openpojo : openpojo jar 0.7.3
commons-io : commons-io jar 2.6
org.glassfish.web : javax.el jar 2.2.6
org.hibernate : hibernate-validator jar 6.0.10.Final

Project Modules

There are no modules declared in this project.

xmlcfg4j

XML based configuration for Java.

Build Status Coverage Status Maven Central LGPLv3 License Java Development Kit 1.8

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>
org.fuin

fuin.org

Versions

Version
0.2.0
0.1.0