util
Class EnsureProperties

java.lang.Object
  extended by java.util.Dictionary<K,V>
      extended by java.util.Hashtable<Object,Object>
          extended by java.util.Properties
              extended by util.EnsureProperties
All Implemented Interfaces:
Serializable, Cloneable, Map<Object,Object>

public class EnsureProperties
extends Properties

An extension to the classical Properties object. This class circumvents the clumsy implementation of assigning non-defined keys default values in the parent class with an other implemntation. If the method ensurePropertySet(java.lang.String, java.lang.String) is called prior to a querry for a certain key the default value is returned unless the key was not present in the original Properties.

Additionally a direct construction of the properties from a file is allowed. Note that an IllegalArgumentException is thrown if the properties cannot be constructed from the given file name.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class java.util.Properties
defaults
 
Constructor Summary
EnsureProperties()
          Calls the superclass-constructor.
EnsureProperties(File infile)
          Reads the properties from the given file.
EnsureProperties(Properties def)
          Calls the superclass-constructor.
 
Method Summary
static Properties augment(Properties which, Properties by)
          Augments the first argumental properties with all the properties found in the second argument.
 boolean ensurePropertySet(String key, String def)
          Ensures that a property with the specified key is present in the properties.
 
Methods inherited from class java.util.Properties
getProperty, getProperty, list, list, load, load, loadFromXML, propertyNames, save, setProperty, store, store, storeToXML, storeToXML, stringPropertyNames
 
Methods inherited from class java.util.Hashtable
clear, clone, contains, containsKey, containsValue, elements, entrySet, equals, get, hashCode, isEmpty, keys, keySet, put, putAll, rehash, remove, size, toString, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

EnsureProperties

public EnsureProperties()
Calls the superclass-constructor.


EnsureProperties

public EnsureProperties(Properties def)
Calls the superclass-constructor.


EnsureProperties

public EnsureProperties(File infile)
Reads the properties from the given file. If an IOException occurs during the reading phase, an IllegalArgumentException is thrown.

Method Detail

ensurePropertySet

public boolean ensurePropertySet(String key,
                                 String def)
Ensures that a property with the specified key is present in the properties. If the specified key is not found the default value is mapped to the key in the underlying properties.
Note that we do not utilize the default properties object linked to this properties but merely add the key and its value to the propeties. This allows ascii-representation of formerly undefined keys in properties files.

Parameters:
key - The key to ensure is mapped to a value in the properties.
def - The default value to add if the key is not mapped.
Returns:
True if the key was already present, false otherwise.

augment

public static Properties augment(Properties which,
                                 Properties by)
Augments the first argumental properties with all the properties found in the second argument. Returns the augmented properties. Useful for constructors that require construction with a single properties object.