org.apache.java.util
Class Configurations

java.lang.Object
  |
  +--org.apache.java.util.Configurations

public class Configurations
extends java.lang.Object

This class is used to encapsulate properties and addresses the need for a flexible, portable and fast configurations repository.

While properties are just considered as strings, configurations have methods to return different types such as int and long.

Performance is needed to avoid the use of properties only at startup to fill variables: configurations encapsulate properties in the sense that objects retrieved by parsing property strings are stored for faster reuse. This allows a program to use configurations instead of global variables in a central repository, that, if updated, will reflect instantly the changes throughout the whole application.

The behavior of this class is syntax indipendent because it's only an encapsulator. This allows greater flexibility throught the use of syntax abstraction and faster transition between different configuration syntax.

Version:
$Revision: 1.23 $ $Date: 2000/04/29 01:26:55 $

Field Summary
private  Configurations defaults
          Default configurations repository.
private  ConfigurationsRepository repository
          Configuration repository.
 
Constructor Summary
Configurations()
          Creates an empty configuration repository with no default values.
Configurations(Configurations defaults)
          Creates an empty configuration repository with the specified defaults.
Configurations(ConfigurationsRepository properties)
          Creates a configuration repository encapsulating the given properties with no default values.
Configurations(ConfigurationsRepository properties, Configurations defaults)
          Merge the given properties object as configurations.
 
Method Summary
 boolean getBoolean(java.lang.String key)
          Get a boolean associated with the given configuration key.
 boolean getBoolean(java.lang.String key, boolean defaultValue)
          Get a boolean associated with the given configuration key.
 java.lang.Boolean getBoolean(java.lang.String key, java.lang.Boolean defaultValue)
          Get a boolean associated with the given configuration key.
 byte getByte(java.lang.String key)
          Get a byte associated with the given configuration key.
 byte getByte(java.lang.String key, byte defaultValue)
          Get a byte associated with the given configuration key.
 java.lang.Byte getByte(java.lang.String key, java.lang.Byte defaultValue)
          Get a byte associated with the given configuration key.
 double getDouble(java.lang.String key)
          Get a double associated with the given configuration key.
 double getDouble(java.lang.String key, double defaultValue)
          Get a double associated with the given configuration key.
 java.lang.Double getDouble(java.lang.String key, java.lang.Double defaultValue)
          Get a double associated with the given configuration key.
 float getFloat(java.lang.String key)
          Get a float associated with the given configuration key.
 float getFloat(java.lang.String key, float defaultValue)
          Get a float associated with the given configuration key.
 java.lang.Float getFloat(java.lang.String key, java.lang.Float defaultValue)
          Get a float associated with the given configuration key.
 int getInteger(java.lang.String key)
          Get a int associated with the given configuration key.
 int getInteger(java.lang.String key, int defaultValue)
          Get a int associated with the given configuration key.
 java.lang.Integer getInteger(java.lang.String key, java.lang.Integer defaultValue)
          Get a int associated with the given configuration key.
 java.util.Enumeration getKeys()
          Get the list of the keys contained in the configuration repository.
 java.util.Enumeration getKeys(java.lang.String prefix)
          Get the list of the keys contained in the configuration repository that match the specified prefix.
 java.util.Enumeration getList(java.lang.String key)
          Get a list of strings associated with the given configuration key.
 long getLong(java.lang.String key)
          Get a long associated with the given configuration key.
 long getLong(java.lang.String key, long defaultValue)
          Get a long associated with the given configuration key.
 java.lang.Long getLong(java.lang.String key, java.lang.Long defaultValue)
          Get a long associated with the given configuration key.
 java.util.Properties getProperties(java.lang.String key)
          Get a list of properties associated with the given configuration key.
 java.util.Properties getProperties(java.lang.String key, java.util.Properties defaults)
          Get a list of properties associated with the given configuration key.
 java.util.Hashtable getRepository()
          Get encapsulated configuration repository.
 short getShort(java.lang.String key)
          Get a short associated with the given configuration key.
 short getShort(java.lang.String key, short defaultValue)
          Get a short associated with the given configuration key.
 java.lang.Short getShort(java.lang.String key, java.lang.Short defaultValue)
          Get a short associated with the given configuration key.
 java.lang.String getString(java.lang.String key)
          Get a string associated with the given configuration key.
 java.lang.String getString(java.lang.String key, java.lang.String defaultValue)
          Get a string associated with the given configuration key.
 java.lang.String[] getStringArray(java.lang.String key)
          Get an array of strings associated with the given configuration key.
 java.util.Vector getVector(java.lang.String key)
          Get a Vector of strings associated with the given configuration key.
 java.util.Vector getVector(java.lang.String key, java.util.Vector defaultValue)
          Get a Vector of strings associated with the given configuration key.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

defaults

private Configurations defaults
Default configurations repository.

repository

private ConfigurationsRepository repository
Configuration repository.
Constructor Detail

Configurations

public Configurations()
Creates an empty configuration repository with no default values.

Configurations

public Configurations(ConfigurationsRepository properties)
Creates a configuration repository encapsulating the given properties with no default values.
Parameters:
properties - the properties to encapsulate.

Configurations

public Configurations(Configurations defaults)
Creates an empty configuration repository with the specified defaults.
Parameters:
defaults - the default values repository.

Configurations

public Configurations(ConfigurationsRepository properties,
                      Configurations defaults)
Merge the given properties object as configurations.
Parameters:
properties - the properties file to merge
Method Detail

getRepository

public java.util.Hashtable getRepository()
Get encapsulated configuration repository.

getKeys

public java.util.Enumeration getKeys()
Get the list of the keys contained in the configuration repository.

getKeys

public java.util.Enumeration getKeys(java.lang.String prefix)
Get the list of the keys contained in the configuration repository that match the specified prefix.
Parameters:
prefix - the prefix to test against
Returns:
an Enumeration of keys that match the prefix

getString

public java.lang.String getString(java.lang.String key)
Get a string associated with the given configuration key.
Parameters:
key - the configuration key.
Returns:
the associated string.
Throws:
ClassCastException - is thrown if the key maps to an object that is not a String.

getString

public java.lang.String getString(java.lang.String key,
                                  java.lang.String defaultValue)
Get a string associated with the given configuration key.
Parameters:
key - the configuration key.
defaultValue - the default value.
Returns:
the associated string if key is found, default value otherwise.
Throws:
ClassCastException - is thrown if the key maps to an object that is not a String.

getProperties

public java.util.Properties getProperties(java.lang.String key)
Get a list of properties associated with the given configuration key.
Parameters:
key - the configuration key.
Returns:
the associated properties if key is found
Throws:
ClassCastException - is thrown if the key maps to an object that is not a String/Vector
java.lang.IllegalArgumentException - if one of the tokens is malformed (does not contain an equals sign)

getProperties

public java.util.Properties getProperties(java.lang.String key,
                                          java.util.Properties defaults)
Get a list of properties associated with the given configuration key.
Parameters:
key - the configuration key.
Returns:
the associated properties if key is found
Throws:
ClassCastException - is thrown if the key maps to an object that is not a String/Vector
java.lang.IllegalArgumentException - if one of the tokens is malformed (does not contain an equals sign)

getStringArray

public java.lang.String[] getStringArray(java.lang.String key)
Get an array of strings associated with the given configuration key.
Parameters:
key - the configuration key.
Returns:
the associated string array if key is found,
Throws:
ClassCastException - is thrown if the key maps to an object that is not a String/Vector

getList

public java.util.Enumeration getList(java.lang.String key)
Get a list of strings associated with the given configuration key.
Parameters:
key - the configuration key.
Returns:
the associated list.
Throws:
ClassCastException - is thrown if the key maps to an object that is not a Vector.

getVector

public java.util.Vector getVector(java.lang.String key)
Get a Vector of strings associated with the given configuration key.
Parameters:
key - the configuration key.
Returns:
the associated Vector.
Throws:
ClassCastException - is thrown if the key maps to an object that is not a Vector.

getVector

public java.util.Vector getVector(java.lang.String key,
                                  java.util.Vector defaultValue)
Get a Vector of strings associated with the given configuration key.
Parameters:
key - the configuration key.
defaultValue - the defaul value.
Returns:
the associated Vector.
Throws:
ClassCastException - is thrown if the key maps to an object that is not a Vector.

getBoolean

public boolean getBoolean(java.lang.String key)
Get a boolean associated with the given configuration key.
Parameters:
key - the configuration key.
Returns:
the associated boolean.
Throws:
java.util.NoSuchElementException - is thrown if the key doesn't map to an existing object.
ClassCastException - is thrown if the key maps to an object that is not a Boolean.

getBoolean

public boolean getBoolean(java.lang.String key,
                          boolean defaultValue)
Get a boolean associated with the given configuration key.
Parameters:
key - the configuration key.
defaultValue - the defaul value.
Returns:
the associated boolean.
Throws:
ClassCastException - is thrown if the key maps to an object that is not a Boolean.

getBoolean

public java.lang.Boolean getBoolean(java.lang.String key,
                                    java.lang.Boolean defaultValue)
Get a boolean associated with the given configuration key.
Parameters:
key - the configuration key.
defaultValue - the defaul value.
Returns:
the associated boolean if key is found and has valid format, default value otherwise.
Throws:
ClassCastException - is thrown if the key maps to an object that is not a Boolean.

getByte

public byte getByte(java.lang.String key)
Get a byte associated with the given configuration key.
Parameters:
key - the configuration key.
Returns:
the associated byte.
Throws:
java.util.NoSuchElementException - is thrown if the key doesn't map to an existing object.
ClassCastException - is thrown if the key maps to an object that is not a Byte.
java.lang.NumberFormatException - is thrown if the value mapped by the key has not a valid number format.

getByte

public byte getByte(java.lang.String key,
                    byte defaultValue)
Get a byte associated with the given configuration key.
Parameters:
key - the configuration key.
defaultValue - the defaul value.
Returns:
the associated byte.
Throws:
ClassCastException - is thrown if the key maps to an object that is not a Byte.
java.lang.NumberFormatException - is thrown if the value mapped by the key has not a valid number format.

getByte

public java.lang.Byte getByte(java.lang.String key,
                              java.lang.Byte defaultValue)
Get a byte associated with the given configuration key.
Parameters:
key - the configuration key.
defaultValue - the defaul value.
Returns:
the associated byte if key is found and has valid format, default value otherwise.
Throws:
ClassCastException - is thrown if the key maps to an object that is not a Byte.
java.lang.NumberFormatException - is thrown if the value mapped by the key has not a valid number format.

getShort

public short getShort(java.lang.String key)
Get a short associated with the given configuration key.
Parameters:
key - the configuration key.
Returns:
the associated short.
Throws:
java.util.NoSuchElementException - is thrown if the key doesn't map to an existing object.
ClassCastException - is thrown if the key maps to an object that is not a Short.
java.lang.NumberFormatException - is thrown if the value mapped by the key has not a valid number format.

getShort

public short getShort(java.lang.String key,
                      short defaultValue)
Get a short associated with the given configuration key.
Parameters:
key - the configuration key.
defaultValue - the defaul value.
Returns:
the associated short.
Throws:
ClassCastException - is thrown if the key maps to an object that is not a Short.
java.lang.NumberFormatException - is thrown if the value mapped by the key has not a valid number format.

getShort

public java.lang.Short getShort(java.lang.String key,
                                java.lang.Short defaultValue)
Get a short associated with the given configuration key.
Parameters:
key - the configuration key.
defaultValue - the defaul value.
Returns:
the associated short if key is found and has valid format, default value otherwise.
Throws:
ClassCastException - is thrown if the key maps to an object that is not a Short.
java.lang.NumberFormatException - is thrown if the value mapped by the key has not a valid number format.

getInteger

public int getInteger(java.lang.String key)
Get a int associated with the given configuration key.
Parameters:
key - the configuration key.
Returns:
the associated int.
Throws:
java.util.NoSuchElementException - is thrown if the key doesn't map to an existing object.
ClassCastException - is thrown if the key maps to an object that is not a Integer.
java.lang.NumberFormatException - is thrown if the value mapped by the key has not a valid number format.

getInteger

public int getInteger(java.lang.String key,
                      int defaultValue)
Get a int associated with the given configuration key.
Parameters:
key - the configuration key.
defaultValue - the defaul value.
Returns:
the associated int.
Throws:
ClassCastException - is thrown if the key maps to an object that is not a Integer.
java.lang.NumberFormatException - is thrown if the value mapped by the key has not a valid number format.

getInteger

public java.lang.Integer getInteger(java.lang.String key,
                                    java.lang.Integer defaultValue)
Get a int associated with the given configuration key.
Parameters:
key - the configuration key.
defaultValue - the defaul value.
Returns:
the associated int if key is found and has valid format, default value otherwise.
Throws:
ClassCastException - is thrown if the key maps to an object that is not a Integer.
java.lang.NumberFormatException - is thrown if the value mapped by the key has not a valid number format.

getLong

public long getLong(java.lang.String key)
Get a long associated with the given configuration key.
Parameters:
key - the configuration key.
Returns:
the associated long.
Throws:
java.util.NoSuchElementException - is thrown if the key doesn't map to an existing object.
ClassCastException - is thrown if the key maps to an object that is not a Long.
java.lang.NumberFormatException - is thrown if the value mapped by the key has not a valid number format.

getLong

public long getLong(java.lang.String key,
                    long defaultValue)
Get a long associated with the given configuration key.
Parameters:
key - the configuration key.
defaultValue - the defaul value.
Returns:
the associated long.
Throws:
ClassCastException - is thrown if the key maps to an object that is not a Long.
java.lang.NumberFormatException - is thrown if the value mapped by the key has not a valid number format.

getLong

public java.lang.Long getLong(java.lang.String key,
                              java.lang.Long defaultValue)
Get a long associated with the given configuration key.
Parameters:
key - the configuration key.
defaultValue - the defaul value.
Returns:
the associated long if key is found and has valid format, default value otherwise.
Throws:
ClassCastException - is thrown if the key maps to an object that is not a Long.
java.lang.NumberFormatException - is thrown if the value mapped by the key has not a valid number format.

getFloat

public float getFloat(java.lang.String key)
Get a float associated with the given configuration key.
Parameters:
key - the configuration key.
Returns:
the associated float.
Throws:
java.util.NoSuchElementException - is thrown if the key doesn't map to an existing object.
ClassCastException - is thrown if the key maps to an object that is not a Float.
java.lang.NumberFormatException - is thrown if the value mapped by the key has not a valid number format.

getFloat

public float getFloat(java.lang.String key,
                      float defaultValue)
Get a float associated with the given configuration key.
Parameters:
key - the configuration key.
defaultValue - the defaul value.
Returns:
the associated float.
Throws:
ClassCastException - is thrown if the key maps to an object that is not a Float.
java.lang.NumberFormatException - is thrown if the value mapped by the key has not a valid number format.

getFloat

public java.lang.Float getFloat(java.lang.String key,
                                java.lang.Float defaultValue)
Get a float associated with the given configuration key.
Parameters:
key - the configuration key.
defaultValue - the defaul value.
Returns:
the associated float if key is found and has valid format, default value otherwise.
Throws:
ClassCastException - is thrown if the key maps to an object that is not a Float.
java.lang.NumberFormatException - is thrown if the value mapped by the key has not a valid number format.

getDouble

public double getDouble(java.lang.String key)
Get a double associated with the given configuration key.
Parameters:
key - the configuration key.
Returns:
the associated double.
Throws:
java.util.NoSuchElementException - is thrown if the key doesn't map to an existing object.
ClassCastException - is thrown if the key maps to an object that is not a Double.
java.lang.NumberFormatException - is thrown if the value mapped by the key has not a valid number format.

getDouble

public double getDouble(java.lang.String key,
                        double defaultValue)
Get a double associated with the given configuration key.
Parameters:
key - the configuration key.
defaultValue - the defaul value.
Returns:
the associated double.
Throws:
ClassCastException - is thrown if the key maps to an object that is not a Double.
java.lang.NumberFormatException - is thrown if the value mapped by the key has not a valid number format.

getDouble

public java.lang.Double getDouble(java.lang.String key,
                                  java.lang.Double defaultValue)
Get a double associated with the given configuration key.
Parameters:
key - the configuration key.
defaultValue - the defaul value.
Returns:
the associated double if key is found and has valid format, default value otherwise.
Throws:
ClassCastException - is thrown if the key maps to an object that is not a Double.
java.lang.NumberFormatException - is thrown if the value mapped by the key has not a valid number format.