org.apache.commons.configuration
Interface Configuration

All Known Implementing Classes:
AbstractConfiguration, ClassPropertiesConfiguration, CompositeConfiguration, JNDIConfiguration, PropertiesConfiguration

public interface Configuration

Configuration interface. The general idea here is to make something that will work like our extended properties and be compatible with the preferences API if at all possible.

Version:
$Id: Configuration.java,v 1.2 2003/12/24 14:28:22 epugh Exp $
Author:
Jason van Zyl, Martin Poeschl

Method Summary
 void addProperty(java.lang.String key, java.lang.Object value)
          Add a property to the configuration.
 void clearProperty(java.lang.String key)
          Clear a property in the configuration.
 boolean containsKey(java.lang.String key)
          Check if the configuration contains the key.
 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 getInt(java.lang.String key)
          Get a int associated with the given configuration key.
 int getInt(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.Iterator getKeys()
          Get the list of the keys contained in the configuration repository.
 java.util.Iterator getKeys(java.lang.String prefix)
          Get the list of the keys contained in the configuration repository that match the specified prefix.
 java.util.List getList(java.lang.String key)
          Get a List of strings associated with the given configuration key.
 java.util.List getList(java.lang.String key, java.util.List defaultValue)
          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.lang.Object getProperty(java.lang.String key)
          Gets a property from the configuration.
 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.
 boolean isEmpty()
          Check if the configuration is empty.
 void setProperty(java.lang.String key, java.lang.Object value)
          Set a property, this will replace any previously set values.
 Configuration subset(java.lang.String prefix)
          Create an Configuration object that is a subset of this one.
 

Method Detail

subset

public Configuration subset(java.lang.String prefix)
Create an Configuration object that is a subset of this one. The new Configuration object contains every key from the current Configuration that starts with prefix. The prefix is removed from the keys in the subset.

Parameters:
prefix - The prefix used to select the properties.

isEmpty

public boolean isEmpty()
Check if the configuration is empty.

Returns:
true is the configuration contains no key/value pair, false otherwise

containsKey

public boolean containsKey(java.lang.String key)
Check if the configuration contains the key.

Returns:
true is the configuration contains a value for this key, false otherwise

addProperty

public void addProperty(java.lang.String key,
                        java.lang.Object value)
Add a property to the configuration. If it already exists then the value stated here will be added to the configuration entry. For example, if resource.loader = file is already present in the configuration and you addProperty("resource.loader", "classpath") Then you will end up with a List like the following: ["file", "classpath"]

Parameters:
key - The Key to add the property to.

setProperty

public void setProperty(java.lang.String key,
                        java.lang.Object value)
Set a property, this will replace any previously set values. Set values is implicitly a call to clearProperty(key), addProperty(key,value).

Parameters:
key - The key of the property to change
value - The new value

clearProperty

public void clearProperty(java.lang.String key)
Clear a property in the configuration.

Parameters:
key - the key to remove along with corresponding value.

getProperty

public java.lang.Object getProperty(java.lang.String key)
Gets a property from the configuration.

Parameters:
key - property to retrieve
Returns:
value as object. Will return user value if exists, if not then default value if exists, otherwise null

getKeys

public java.util.Iterator 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 Iterator of keys that match the prefix.

getKeys

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

Returns:
An Iterator.

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:
java.lang.ClassCastException - is thrown if the key maps to an object that is not a String/List.
java.lang.IllegalArgumentException - if one of the tokens is malformed (does not contain an equals sign).

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:
NoSuchElementException - is thrown if the key doesn't map to an existing object.
java.lang.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 default value.
Returns:
The associated boolean.
Throws:
java.lang.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 default value.
Returns:
The associated boolean if key is found and has valid format, default value otherwise.
Throws:
java.lang.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:
NoSuchElementException - is thrown if the key doesn't map to an existing object.
java.lang.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 default value.
Returns:
The associated byte.
Throws:
java.lang.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 default value.
Returns:
The associated byte if key is found and has valid format, default value otherwise.
Throws:
java.lang.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.

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:
NoSuchElementException - is thrown if the key doesn't map to an existing object.
java.lang.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 default value.
Returns:
The associated double.
Throws:
java.lang.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 default value.
Returns:
The associated double if key is found and has valid format, default value otherwise.
Throws:
java.lang.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.

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:
NoSuchElementException - is thrown if the key doesn't map to an existing object.
java.lang.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 default value.
Returns:
The associated float.
Throws:
java.lang.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 default value.
Returns:
The associated float if key is found and has valid format, default value otherwise.
Throws:
java.lang.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.

getInt

public int getInt(java.lang.String key)
Get a int associated with the given configuration key.

Parameters:
key - The configuration key.
Returns:
The associated int.
Throws:
NoSuchElementException - is thrown if the key doesn't map to an existing object.
java.lang.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.

getInt

public int getInt(java.lang.String key,
                  int defaultValue)
Get a int associated with the given configuration key.

Parameters:
key - The configuration key.
defaultValue - The default value.
Returns:
The associated int.
Throws:
java.lang.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 default value.
Returns:
The associated int if key is found and has valid format, default value otherwise.
Throws:
java.lang.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:
NoSuchElementException - is thrown if the key doesn't map to an existing object.
java.lang.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 default value.
Returns:
The associated long.
Throws:
java.lang.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 default value.
Returns:
The associated long if key is found and has valid format, default value otherwise.
Throws:
java.lang.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.

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:
NoSuchElementException - is thrown if the key doesn't map to an existing object.
java.lang.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 default value.
Returns:
The associated short.
Throws:
java.lang.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 default value.
Returns:
The associated short if key is found and has valid format, default value otherwise.
Throws:
java.lang.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.
NoSuchElementException - is thrown if the key doesn't map to an existing object.

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:
java.lang.ClassCastException - is thrown if the key maps to an object that is not a String.
NoSuchElementException - is thrown if the key doesn't map to an existing object.

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 and has valid format, default value otherwise.
Throws:
java.lang.ClassCastException - is thrown if the key maps to an object that is not a String.

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:
java.lang.ClassCastException - is thrown if the key maps to an object that is not a String/List of Strings.

getList

public java.util.List 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:
java.lang.ClassCastException - is thrown if the key maps to an object that is not a List.

getList

public java.util.List getList(java.lang.String key,
                              java.util.List defaultValue)
Get a List of strings associated with the given configuration key.

Parameters:
key - The configuration key.
defaultValue - The default value.
Returns:
The associated List.
Throws:
java.lang.ClassCastException - is thrown if the key maps to an object that is not a List.