XProperties 1.0.3

at.spardat.properties
Class XProperties

java.lang.Object
  extended byat.spardat.properties.XProperties
All Implemented Interfaces:
java.io.Serializable

public class XProperties
extends java.lang.Object
implements java.io.Serializable

Root Class for accessing Properties. XProperties instances are the primary way to access properties. The properties are loaded automatically on first access. Use the static methods to get a concrete XProperties instance. The properties shall be defined in "packages" similary to java classes. Each XProperties instance is initialized with a package name. If you definie a property named "at.spardat.sample.a=0", you shall instantiate a XProperties instance by calling node=XProperties.getNode(Sample.class) and access the property by calling node.get("a")

See Also:
Serialized Form

Constructor Summary
protected XProperties(java.lang.String value)
          TODO KDM: hier pruefen ob richtig initialisiert wurde XProperties constructor.
 
Method Summary
 java.lang.String get(java.lang.String key)
          Access to the property with the name "basename+key".
 java.lang.String get(java.lang.String key, java.lang.String defaultValue)
          Access to the property with the name "basename+key".
static java.util.Iterator getAllKeys()
          Liefert alle vorhandenen PropertyKeys
 java.lang.String getBaseName()
           
 boolean getBoolean(java.lang.String key)
          Access to the property with the name "basename+key".
 boolean getBoolean(java.lang.String key, boolean defaultValue)
          Access to the property with the name "basename+key".
 java.util.Date getDate(java.lang.String key)
          Access to the property with the name "basename+key".
 java.util.Date getDate(java.lang.String key, java.util.Date defaultValue)
          Access to the property with the name "basename+key".
 double getDouble(java.lang.String key)
          Access to the property with the name "basename+key".
 double getDouble(java.lang.String key, double defaultValue)
          Access to the property with the name "basename+key".
 float getFloat(java.lang.String key)
          Access to the property with the name "basename+key".
 float getFloat(java.lang.String key, float defaultValue)
          Access to the property with the name "basename+key".
 java.util.Iterator getGroupProperties(java.lang.String propertyName)
          Tries to find subnodes of this XProperties node which start with name propertyName and a number starting with "1" (e.g. at.spardat.sample.group1).
 java.util.Iterator getGroupProperties(java.lang.String propertyName, int start)
          Tries to find subnodes of this XProperties node which start with name propertyName and a number starting with start (e.g. at.spardat.sample.group1).
 int getInt(java.lang.String key)
          Access to the property with the name "basename+key".
 int getInt(java.lang.String key, int defaultValue)
          Access to the property with the name "basename+key".
 java.util.Iterator getKeys()
          Returns an Iterator to iterate over the names of the properties which are defined on this node.
 long getLong(java.lang.String key)
          Access to the property with the name "basename+key".
 long getLong(java.lang.String key, long defaultValue)
          Access to the property with the name "basename+key".
protected  java.lang.String getMustProperty(java.lang.String key)
          Internal method to access a raw property value
static XProperties getNode(java.lang.Class clazz)
          get the preferences node for the package of the given class
static XProperties getNodeOfPackage(java.lang.String packageName)
          get the preferences node for the given package This method should not be used extensivly as it breaks some sort of encapsulation.
protected  java.lang.String getProperty(java.lang.String key)
          Internal method to access a raw property value
static java.lang.String getPropertyMeta(java.lang.String prop)
          Liefert zum übergebenen PropertyKey die diesbezüglich konfigurierten Informationen.
static XProperties getRoot()
          get the root preferences node (no associated package)
 XProperties getSubNode(java.lang.String node)
          Get a new XProperties instance for a subnode of this node.
 java.util.Date getTime(java.lang.String key)
          Access to the property with the name "basename+key".
 java.util.Date getTime(java.lang.String key, java.util.Date defaultValue)
          Access to the property with the name "basename+key".
static XProperties userNodeForPackage(java.lang.Class clazz)
          Deprecated. for compatibility to Preferences API
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XProperties

protected XProperties(java.lang.String value)
TODO KDM: hier pruefen ob richtig initialisiert wurde XProperties constructor. Access only through class methods.

Parameters:
value - basename this instance shall refer to
Method Detail

getNode

public static XProperties getNode(java.lang.Class clazz)
get the preferences node for the package of the given class

Parameters:
clazz - The class where the packagename defines the base name for property access
Returns:
a XProperties instance which referes to the properties of the package of the given class

getSubNode

public XProperties getSubNode(java.lang.String node)
Get a new XProperties instance for a subnode of this node.

Parameters:
node - the name of the subnode
Returns:
a new XProperties instance which referes to the subnode

getRoot

public static XProperties getRoot()
get the root preferences node (no associated package)

Returns:
root node of the preferences

getNodeOfPackage

public static XProperties getNodeOfPackage(java.lang.String packageName)
get the preferences node for the given package This method should not be used extensivly as it breaks some sort of encapsulation. This may lead to debugging sessions in case a package is refactored. The getNode() package shall be prefered for access to properties. Static methods in some class of the target package shall be provided to access the properties of another package!!

Parameters:
packageName - name of the package the XProperties shall refer to
Returns:
XProperties instance which referes to the properties of the given package

userNodeForPackage

public static XProperties userNodeForPackage(java.lang.Class clazz)
Deprecated. for compatibility to Preferences API

Parameters:
clazz - The class where the packagename defines the base name for property access
Returns:
a XProperties instance which referes to the properties of the package of the given class
See Also:
getNode(java.lang.Class)

getBaseName

public java.lang.String getBaseName()
Returns:
the name of the package this object references to

getProperty

protected java.lang.String getProperty(java.lang.String key)
Internal method to access a raw property value

Parameters:
key - the key of this property without the basename
Returns:
The found property or null if no property was found

getMustProperty

protected java.lang.String getMustProperty(java.lang.String key)
                                    throws PropertyUnknownException
Internal method to access a raw property value

Parameters:
key - the key of this property without the basename
Returns:
The found property
Throws:
PropertyUnknownException - if no property with the given name was found

get

public java.lang.String get(java.lang.String key,
                            java.lang.String defaultValue)
Access to the property with the name "basename+key". If no property was found the defaultvalue is returned.

Parameters:
key - the name of the property
defaultValue - the defaultvalue if no property is defined
Returns:
the property value

getInt

public int getInt(java.lang.String key,
                  int defaultValue)
Access to the property with the name "basename+key". If no property was found the defaultvalue is returned. The found property value is converted to an int value.

Parameters:
key - the name of the property
defaultValue - the defaultvalue if no property is defined
Returns:
the property value
Throws:
java.lang.NumberFormatException - if the property may not be converted to an int

getFloat

public float getFloat(java.lang.String key,
                      float defaultValue)
Access to the property with the name "basename+key". If no property was found the defaultvalue is returned. The found property value is converted to an float value.

Parameters:
key - the name of the property
defaultValue - the defaultvalue if no property is defined
Returns:
the property value
Throws:
java.lang.NumberFormatException - if the property may not be converted to an float

getDouble

public double getDouble(java.lang.String key,
                        double defaultValue)
Access to the property with the name "basename+key". If no property was found the defaultvalue is returned. The found property value is converted to an double value.

Parameters:
key - the name of the property
defaultValue - the defaultvalue if no property is defined
Returns:
the property value
Throws:
java.lang.NumberFormatException - if the property may not be converted to an double

getLong

public long getLong(java.lang.String key,
                    long defaultValue)
Access to the property with the name "basename+key". If no property was found the defaultvalue is returned. The found property value is converted to an long value.

Parameters:
key - the name of the property
defaultValue - the defaultvalue if no property is defined
Returns:
the property value
Throws:
java.lang.NumberFormatException - if the property may not be converted to an long

getBoolean

public boolean getBoolean(java.lang.String key,
                          boolean defaultValue)
Access to the property with the name "basename+key". If no property was found the defaultvalue is returned. The found property value is converted to an boolean value.

Parameters:
key - the name of the property
defaultValue - the defaultvalue if no property is defined
Returns:
the property value

getDate

public java.util.Date getDate(java.lang.String key,
                              java.util.Date defaultValue)
                       throws java.text.ParseException
Access to the property with the name "basename+key". If no property was found the defaultvalue is returned. The found property value is converted to an java.util.Date by using the formating pattern "DD.MM.YYYY".

Parameters:
key - the name of the property
defaultValue - the defaultvalue if no property is defined
Returns:
the property value
Throws:
java.text.ParseException - if the conversion fails

getTime

public java.util.Date getTime(java.lang.String key,
                              java.util.Date defaultValue)
                       throws java.text.ParseException
Access to the property with the name "basename+key". If no property was found the defaultvalue is returned. The found property value is converted to an java.util.Date by using the formating pattern "HH:MM:SS".

Parameters:
key - the name of the property
defaultValue - the defaultvalue if no property is defined
Returns:
the property value
Throws:
java.text.ParseException - if the conversion fails

get

public java.lang.String get(java.lang.String key)
                     throws PropertyUnknownException
Access to the property with the name "basename+key". If no property an exception is thrown.

Parameters:
key - the name of the property
Returns:
the property value
Throws:
PropertyUnknownException - if no property was found.

getInt

public int getInt(java.lang.String key)
           throws PropertyUnknownException
Access to the property with the name "basename+key". If no property an exception is thrown.

Parameters:
key - the name of the property
Returns:
the property value
Throws:
PropertyUnknownException - if no property was found.
java.lang.NumberFormatException - if the property conversion to int fails

getFloat

public float getFloat(java.lang.String key)
               throws PropertyUnknownException
Access to the property with the name "basename+key". If no property an exception is thrown.

Parameters:
key - the name of the property
Returns:
the property value
Throws:
PropertyUnknownException - if no property was found.
java.lang.NumberFormatException - if the property conversion to float fails

getDouble

public double getDouble(java.lang.String key)
                 throws PropertyUnknownException
Access to the property with the name "basename+key". If no property an exception is thrown.

Parameters:
key - the name of the property
Returns:
the property value
Throws:
PropertyUnknownException - if no property was found.
java.lang.NumberFormatException - if the property conversion to double fails

getLong

public long getLong(java.lang.String key)
             throws PropertyUnknownException
Access to the property with the name "basename+key". If no property an exception is thrown.

Parameters:
key - the name of the property
Returns:
the property value
Throws:
PropertyUnknownException - if no property was found.
java.lang.NumberFormatException - if the property conversion to long fails

getBoolean

public boolean getBoolean(java.lang.String key)
                   throws PropertyUnknownException
Access to the property with the name "basename+key". If no property an exception is thrown.

Parameters:
key - the name of the property
Returns:
the property value
Throws:
PropertyUnknownException - if no property was found.
java.lang.NumberFormatException - if the property conversion to boolean fails

getDate

public java.util.Date getDate(java.lang.String key)
                       throws PropertyUnknownException,
                              java.text.ParseException
Access to the property with the name "basename+key". If no property an exception is thrown. The property is converted to a "java.util.Date" by using the formating pattern "DD.MM.YYYY".

Parameters:
key - the name of the property
Returns:
the property value
Throws:
PropertyUnknownException - if no property was found.
java.text.ParseException - if the property conversion fails

getTime

public java.util.Date getTime(java.lang.String key)
                       throws PropertyUnknownException,
                              java.text.ParseException
Access to the property with the name "basename+key". If no property an exception is thrown. The property is converted to a "java.util.Date" by using the formating pattern "HH:MM:SS".

Parameters:
key - the name of the property
Returns:
the property value
Throws:
PropertyUnknownException - if no property was found.
java.text.ParseException - if the property conversion fails

getKeys

public java.util.Iterator getKeys()
Returns an Iterator to iterate over the names of the properties which are defined on this node. Note: This does not include any subnodes which are defined on this node!

Returns:
an Iterator with String elements representing the names of defined properties

getGroupProperties

public java.util.Iterator getGroupProperties(java.lang.String propertyName)
Tries to find subnodes of this XProperties node which start with name propertyName and a number starting with "1" (e.g. at.spardat.sample.group1). The returned Iterator contains an XProperties instance for each found subnode.

Parameters:
propertyName - the basename of the subnode without the counter
Returns:
an iterator containing a number of XProperties instance for each found group element
See Also:
for a sample

getGroupProperties

public java.util.Iterator getGroupProperties(java.lang.String propertyName,
                                             int start)
Tries to find subnodes of this XProperties node which start with name propertyName and a number starting with start (e.g. at.spardat.sample.group1). The returned Iterator contains an XProperties instance for each found subnode.

Parameters:
propertyName - the basename of the subnode without the counter
start - the start number for the counter
Returns:
an iterator containing a number of XProperties instance for each found group element
See Also:
for a sample

getPropertyMeta

public static java.lang.String getPropertyMeta(java.lang.String prop)
Liefert zum übergebenen PropertyKey die diesbezüglich konfigurierten Informationen.

Parameters:
prop -
Returns:

getAllKeys

public static java.util.Iterator getAllKeys()
Liefert alle vorhandenen PropertyKeys

Returns:

XProperties 1.0.3