cgl.narada.util
Interface Configuration

All Known Implementing Classes:
ConfigurationParamsReader

public interface Configuration

Configuration interface.


Method Summary
 void addProperty(String key, Object value)
          Add a property to the configuration.
 void clearProperty(String key)
          Clear a property in the configuration.
 boolean containsKey(String key)
          Check if the configuration contains the key.
 boolean getBoolean(String key)
          Get a boolean associated with the given configuration key.
 boolean getBoolean(String key, boolean defaultValue)
          Get a boolean associated with the given configuration key.
 Boolean getBoolean(String key, Boolean defaultValue)
          Get a boolean associated with the given configuration key.
 byte getByte(String key)
          Get a byte associated with the given configuration key.
 byte getByte(String key, byte defaultValue)
          Get a byte associated with the given configuration key.
 Byte getByte(String key, Byte defaultValue)
          Get a byte associated with the given configuration key.
 double getDouble(String key)
          Get a double associated with the given configuration key.
 double getDouble(String key, double defaultValue)
          Get a double associated with the given configuration key.
 Double getDouble(String key, Double defaultValue)
          Get a double associated with the given configuration key.
 float getFloat(String key)
          Get a float associated with the given configuration key.
 float getFloat(String key, float defaultValue)
          Get a float associated with the given configuration key.
 Float getFloat(String key, Float defaultValue)
          Get a float associated with the given configuration key.
 int getInt(String key)
          Get a int associated with the given configuration key.
 int getInt(String key, int defaultValue)
          Get a int associated with the given configuration key.
 Integer getInteger(String key, Integer defaultValue)
          Get a int associated with the given configuration key.
 Iterator getKeys()
          Get the list of the keys contained in the configuration repository.
 Iterator getKeys(String prefix)
          Get the list of the keys contained in the configuration repository that match the specified prefix.
 long getLong(String key)
          Get a long associated with the given configuration key.
 long getLong(String key, long defaultValue)
          Get a long associated with the given configuration key.
 Long getLong(String key, Long defaultValue)
          Get a long associated with the given configuration key.
 Properties getProperties(String key)
          Get a list of properties associated with the given configuration key.
 String getProperty(String key)
          Gets a property from the configuration.
 short getShort(String key)
          Get a short associated with the given configuration key.
 short getShort(String key, short defaultValue)
          Get a short associated with the given configuration key.
 Short getShort(String key, Short defaultValue)
          Get a short associated with the given configuration key.
 String getString(String key)
          Get a string associated with the given configuration key.
 String getString(String key, String defaultValue)
          Get a string associated with the given configuration key.
 String[] getStringArray(String key)
          Get an array of strings associated with the given configuration key.
 Vector getVector(String key)
          Get a Vector of strings associated with the given configuration key.
 Vector getVector(String key, Vector defaultValue)
          Get a Vector of strings associated with the given configuration key.
 boolean isEmpty()
          Check if the configuration is empty.
 void setProperty(String key, Object value)
          Set a property, this will replace any previously set values.
 Configuration subset(String prefix)
          Create an Configuration object that is a subset of this one.
 

Method Detail

subset

Configuration subset(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

boolean isEmpty()
Check if the configuration is empty.

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

containsKey

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

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

addProperty

void addProperty(String key,
                 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 Vector like the following: ["file", "classpath"]

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

setProperty

void setProperty(String key,
                 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

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

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

getProperty

String getProperty(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

Iterator getKeys(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

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

Returns:
An Iterator.

getProperties

Properties getProperties(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.
IllegalArgumentException - if one of the tokens is malformed (does not contain an equals sign).

getBoolean

boolean getBoolean(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.
ClassCastException - is thrown if the key maps to an object that is not a Boolean.

getBoolean

boolean getBoolean(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:
ClassCastException - is thrown if the key maps to an object that is not a Boolean.

getBoolean

Boolean getBoolean(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 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

byte getByte(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.
ClassCastException - is thrown if the key maps to an object that is not a Byte.
NumberFormatException - is thrown if the value mapped by the key has not a valid number format.

getByte

byte getByte(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:
ClassCastException - is thrown if the key maps to an object that is not a Byte.
NumberFormatException - is thrown if the value mapped by the key has not a valid number format.

getByte

Byte getByte(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 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.
NumberFormatException - is thrown if the value mapped by the key has not a valid number format.

getDouble

double getDouble(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.
ClassCastException - is thrown if the key maps to an object that is not a Double.
NumberFormatException - is thrown if the value mapped by the key has not a valid number format.

getDouble

double getDouble(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:
ClassCastException - is thrown if the key maps to an object that is not a Double.
NumberFormatException - is thrown if the value mapped by the key has not a valid number format.

getDouble

Double getDouble(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 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.
NumberFormatException - is thrown if the value mapped by the key has not a valid number format.

getFloat

float getFloat(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.
ClassCastException - is thrown if the key maps to an object that is not a Float.
NumberFormatException - is thrown if the value mapped by the key has not a valid number format.

getFloat

float getFloat(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:
ClassCastException - is thrown if the key maps to an object that is not a Float.
NumberFormatException - is thrown if the value mapped by the key has not a valid number format.

getFloat

Float getFloat(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 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.
NumberFormatException - is thrown if the value mapped by the key has not a valid number format.

getInt

int getInt(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.
ClassCastException - is thrown if the key maps to an object that is not a Integer.
NumberFormatException - is thrown if the value mapped by the key has not a valid number format.

getInt

int getInt(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:
ClassCastException - is thrown if the key maps to an object that is not a Integer.
NumberFormatException - is thrown if the value mapped by the key has not a valid number format.

getInteger

Integer getInteger(String key,
                   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:
ClassCastException - is thrown if the key maps to an object that is not a Integer.
NumberFormatException - is thrown if the value mapped by the key has not a valid number format.

getLong

long getLong(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.
ClassCastException - is thrown if the key maps to an object that is not a Long.
NumberFormatException - is thrown if the value mapped by the key has not a valid number format.

getLong

long getLong(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:
ClassCastException - is thrown if the key maps to an object that is not a Long.
NumberFormatException - is thrown if the value mapped by the key has not a valid number format.

getLong

Long getLong(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 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.
NumberFormatException - is thrown if the value mapped by the key has not a valid number format.

getShort

short getShort(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.
ClassCastException - is thrown if the key maps to an object that is not a Short.
NumberFormatException - is thrown if the value mapped by the key has not a valid number format.

getShort

short getShort(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:
ClassCastException - is thrown if the key maps to an object that is not a Short.
NumberFormatException - is thrown if the value mapped by the key has not a valid number format.

getShort

Short getShort(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 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.
NumberFormatException - is thrown if the value mapped by the key has not a valid number format.

getString

String getString(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

String getString(String key,
                 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:
ClassCastException - is thrown if the key maps to an object that is not a String.

getStringArray

String[] getStringArray(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 of Strings.

getVector

Vector getVector(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

Vector getVector(String key,
                 Vector defaultValue)
Get a Vector of strings associated with the given configuration key.

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


For comments and suggestions please send e-mail to The NaradaBrokering Project