Universität Duisburg-Essen
Startseite Arbeitsgruppe Informationsysteme

Property maps

Property maps are an extension to the map implementations in the Java API.

The abstract class de.unidu.is.util.PropertyMap implements the interface java.util.Map and adds methods for setting and getting values as strings, ints, longs, doubles and booleans.

Values can reference other values. Similar to other programming languages as well as Ant, a value with the key foo.bar can be referenced (i.e., inserted) as ${foo.bar}. E.g., with the following content of a property map


	  foo.a=42
	  foo.b=Hello ${foo.a}
	

the value for the key foo.b is "Hello 42".

The property map can be configured (in the constructor) to contain more than one value for a key. Internally, a java.util.List is then used for storing the values. In this case, the getXYZ methods return the first value only; setXYZ add values to the map. The complete list of values for a key can always be retrieved by getAll(Object).

The class de.unidu.is.util.DelegatedPropertyMap extends PropertyMap and delegates all methods inherited from java.util.Map to another map. Its direct sub-class de.unidu.is.util.HashPropertyMap employs a java.util.HashMap. A second map ("initial map") can be specified to a DelegatedPropertyMap constructor whose key/value pairs are copied to the "delegate" map.

The abstract class de.unidu.is.util.StreamPropertyMap can load and save property maps from/into streams (including streams created from URLs). The format is the same as in the example above. The class de.unidu.is.util.FilePropertyMap can be used together from files (which can be specified by their URL as well). In both cases, the entries from the initial map are not saved.

The class de.unidu.is.util.Config can be used together with a file "conf/config" on the classpath (it can also be included in a JAR), the standard configuration file which is loaded automatically if needed.