cgl.narada.wsinfra.util
Class ConfigurationParamsReader

java.lang.Object
  extended by cgl.narada.wsinfra.util.ConfigurationParamsReader
All Implemented Interfaces:
Configuration

public class ConfigurationParamsReader
extends Object
implements Configuration

Responsible for loading the configuration parameters specified in a configuration file.


Field Summary
protected  Configuration defaults
           
 String DELIMITER
           
 String FILE_SEPARATOR
           
protected  Hashtable store
           
 
Constructor Summary
ConfigurationParamsReader()
           
ConfigurationParamsReader(Configuration defaults)
           
ConfigurationParamsReader(String file)
           
 
Method Summary
 void addProperty(String key, Object token)
          Add a property to the configuration.
protected  void addPropertyDirect(String key, Object obj)
           
 void clearProperty(String key)
          Clear a property in the configuration.
 boolean containsKey(String key)
          Check if the configuration contains the key.
 String getBasePath()
           
 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(Properties _defaults)
          Returns all the properties that have been read from the specified configuration file
 Properties getProperties(String key)
          Get a list of properties associated with the given configuration key.
 Properties getProperties(String key, Properties defaults)
           
 String getProperty(String key)
          Gets a property from the configuration.
 InputStream getPropertyStream(String resourceName)
           
 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 load(InputStream input)
          Load the properties from the given input stream.
 void load(InputStream input, String enc)
          Load the properties from the given input stream and using the specified encoding.
 void load(String file)
          Load the properties from the given file
protected  List processString(String token)
           
 void setBasePath(String path)
           
 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.
 String testBoolean(String value)
          Map true , on , yes to true; false , off , no to false.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FILE_SEPARATOR

public final String FILE_SEPARATOR
See Also:
Constant Field Values

DELIMITER

public final String DELIMITER
See Also:
Constant Field Values

defaults

protected Configuration defaults

store

protected Hashtable store
Constructor Detail

ConfigurationParamsReader

public ConfigurationParamsReader()

ConfigurationParamsReader

public ConfigurationParamsReader(String file)

ConfigurationParamsReader

public ConfigurationParamsReader(Configuration defaults)
Method Detail

load

public void load(String file)
          throws IOException
Load the properties from the given file

Parameters:
file - The properties file to load
Throws:
IOException

load

public void load(InputStream input)
          throws IOException
Load the properties from the given input stream.

Parameters:
input - An InputStream on the properties file
Throws:
IOException

load

public void load(InputStream input,
                 String enc)
          throws IOException
Load the properties from the given input stream and using the specified encoding.

Parameters:
input - An InputStream.
enc - An encoding.
Throws:
IOException

getPropertyStream

public InputStream getPropertyStream(String resourceName)
                              throws IOException
Parameters:
resourceName - The file name with which to get InputStream
Returns:
An InputStream
Throws:
IOException

addProperty

public void addProperty(String key,
                        Object token)
Description copied from interface: Configuration
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"]

Specified by:
addProperty in interface Configuration
Parameters:
key - The Key to add the property to.
token - The Value to add.
See Also:
Configuration

processString

protected List processString(String token)
Parameters:
token - A String token
Returns:
A List of Strings

addPropertyDirect

protected void addPropertyDirect(String key,
                                 Object obj)
Parameters:
key - key to use for mapping
obj - object to store

testBoolean

public String testBoolean(String value)
Map true , on , yes to true; false , off , no to false.

Parameters:
value - The value to test for boolean state.
Returns:
String of true, false or null

subset

public Configuration subset(String prefix)
Description copied from interface: Configuration
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.

Specified by:
subset in interface Configuration
Parameters:
prefix - The prefix used to select the properties.
See Also:
Configuration

isEmpty

public boolean isEmpty()
Description copied from interface: Configuration
Check if the configuration is empty.

Specified by:
isEmpty in interface Configuration
Returns:
true is the configuration contains no key/value pair, false otherwise
See Also:
Configuration.isEmpty()

containsKey

public boolean containsKey(String key)
Description copied from interface: Configuration
Check if the configuration contains the key.

Specified by:
containsKey in interface Configuration
Returns:
true is the configuration contains a value for this key, false otherwise
See Also:
Configuration

setProperty

public void setProperty(String key,
                        Object value)
Description copied from interface: Configuration
Set a property, this will replace any previously set values. Set values is implicitly a call to clearProperty(key), addProperty(key,value).

Specified by:
setProperty in interface Configuration
Parameters:
key - The key of the property to change
value - The new value
See Also:
Configuration

clearProperty

public void clearProperty(String key)
Description copied from interface: Configuration
Clear a property in the configuration.

Specified by:
clearProperty in interface Configuration
Parameters:
key - the key to remove along with corresponding value.
See Also:
Configuration

getKeys

public Iterator getKeys()
Description copied from interface: Configuration
Get the list of the keys contained in the configuration repository.

Specified by:
getKeys in interface Configuration
Returns:
An Iterator.
See Also:
Configuration

getKeys

public Iterator getKeys(String prefix)
Description copied from interface: Configuration
Get the list of the keys contained in the configuration repository that match the specified prefix.

Specified by:
getKeys in interface Configuration
Parameters:
prefix - The prefix to test against.
Returns:
An Iterator of keys that match the prefix.
See Also:
Configuration

getProperties

public Properties getProperties(Properties _defaults)
Returns all the properties that have been read from the specified configuration file


getProperties

public Properties getProperties(String key)
Description copied from interface: Configuration
Get a list of properties associated with the given configuration key.

Specified by:
getProperties in interface Configuration
Parameters:
key - The configuration key.
Returns:
The associated properties if key is found.
See Also:
Configuration, getProperties(String, Properties)

getProperties

public Properties getProperties(String key,
                                Properties defaults)
See Also:
Configuration

getProperty

public String getProperty(String key)
Description copied from interface: Configuration
Gets a property from the configuration.

Specified by:
getProperty in interface 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
See Also:
Configuration

getBoolean

public boolean getBoolean(String key)
Description copied from interface: Configuration
Get a boolean associated with the given configuration key.

Specified by:
getBoolean in interface Configuration
Parameters:
key - The configuration key.
Returns:
The associated boolean.
See Also:
Configuration

getBoolean

public boolean getBoolean(String key,
                          boolean defaultValue)
Description copied from interface: Configuration
Get a boolean associated with the given configuration key.

Specified by:
getBoolean in interface Configuration
Parameters:
key - The configuration key.
defaultValue - The default value.
Returns:
The associated boolean.
See Also:
Configuration

getBoolean

public Boolean getBoolean(String key,
                          Boolean defaultValue)
Description copied from interface: Configuration
Get a boolean associated with the given configuration key.

Specified by:
getBoolean in interface Configuration
Parameters:
key - The configuration key.
defaultValue - The default value.
Returns:
The associated boolean if key is found and has valid format, default value otherwise.
See Also:
Configuration

getByte

public byte getByte(String key)
Description copied from interface: Configuration
Get a byte associated with the given configuration key.

Specified by:
getByte in interface Configuration
Parameters:
key - The configuration key.
Returns:
The associated byte.
See Also:
Configuration

getByte

public byte getByte(String key,
                    byte defaultValue)
Description copied from interface: Configuration
Get a byte associated with the given configuration key.

Specified by:
getByte in interface Configuration
Parameters:
key - The configuration key.
defaultValue - The default value.
Returns:
The associated byte.
See Also:
Configuration

getByte

public Byte getByte(String key,
                    Byte defaultValue)
Description copied from interface: Configuration
Get a byte associated with the given configuration key.

Specified by:
getByte in interface Configuration
Parameters:
key - The configuration key.
defaultValue - The default value.
Returns:
The associated byte if key is found and has valid format, default value otherwise.
See Also:
Configuration

getDouble

public double getDouble(String key)
Description copied from interface: Configuration
Get a double associated with the given configuration key.

Specified by:
getDouble in interface Configuration
Parameters:
key - The configuration key.
Returns:
The associated double.
See Also:
Configuration

getDouble

public double getDouble(String key,
                        double defaultValue)
Description copied from interface: Configuration
Get a double associated with the given configuration key.

Specified by:
getDouble in interface Configuration
Parameters:
key - The configuration key.
defaultValue - The default value.
Returns:
The associated double.
See Also:
Configuration

getDouble

public Double getDouble(String key,
                        Double defaultValue)
Description copied from interface: Configuration
Get a double associated with the given configuration key.

Specified by:
getDouble in interface Configuration
Parameters:
key - The configuration key.
defaultValue - The default value.
Returns:
The associated double if key is found and has valid format, default value otherwise.
See Also:
Configuration

getFloat

public float getFloat(String key)
Description copied from interface: Configuration
Get a float associated with the given configuration key.

Specified by:
getFloat in interface Configuration
Parameters:
key - The configuration key.
Returns:
The associated float.
See Also:
Configuration

getFloat

public float getFloat(String key,
                      float defaultValue)
Description copied from interface: Configuration
Get a float associated with the given configuration key.

Specified by:
getFloat in interface Configuration
Parameters:
key - The configuration key.
defaultValue - The default value.
Returns:
The associated float.
See Also:
Configuration

getFloat

public Float getFloat(String key,
                      Float defaultValue)
Description copied from interface: Configuration
Get a float associated with the given configuration key.

Specified by:
getFloat in interface Configuration
Parameters:
key - The configuration key.
defaultValue - The default value.
Returns:
The associated float if key is found and has valid format, default value otherwise.
See Also:
Configuration

getInt

public int getInt(String key)
Description copied from interface: Configuration
Get a int associated with the given configuration key.

Specified by:
getInt in interface Configuration
Parameters:
key - The configuration key.
Returns:
The associated int.
See Also:
Configuration

getInt

public int getInt(String key,
                  int defaultValue)
Description copied from interface: Configuration
Get a int associated with the given configuration key.

Specified by:
getInt in interface Configuration
Parameters:
key - The configuration key.
defaultValue - The default value.
Returns:
The associated int.
See Also:
Configuration

getInteger

public Integer getInteger(String key,
                          Integer defaultValue)
Description copied from interface: Configuration
Get a int associated with the given configuration key.

Specified by:
getInteger in interface Configuration
Parameters:
key - The configuration key.
defaultValue - The default value.
Returns:
The associated int if key is found and has valid format, default value otherwise.
See Also:
Configuration

getLong

public long getLong(String key)
Description copied from interface: Configuration
Get a long associated with the given configuration key.

Specified by:
getLong in interface Configuration
Parameters:
key - The configuration key.
Returns:
The associated long.
See Also:
Configuration

getLong

public long getLong(String key,
                    long defaultValue)
Description copied from interface: Configuration
Get a long associated with the given configuration key.

Specified by:
getLong in interface Configuration
Parameters:
key - The configuration key.
defaultValue - The default value.
Returns:
The associated long.
See Also:
Configuration

getLong

public Long getLong(String key,
                    Long defaultValue)
Description copied from interface: Configuration
Get a long associated with the given configuration key.

Specified by:
getLong in interface Configuration
Parameters:
key - The configuration key.
defaultValue - The default value.
Returns:
The associated long if key is found and has valid format, default value otherwise.
See Also:
Configuration

getShort

public short getShort(String key)
Description copied from interface: Configuration
Get a short associated with the given configuration key.

Specified by:
getShort in interface Configuration
Parameters:
key - The configuration key.
Returns:
The associated short.
See Also:
Configuration

getShort

public short getShort(String key,
                      short defaultValue)
Description copied from interface: Configuration
Get a short associated with the given configuration key.

Specified by:
getShort in interface Configuration
Parameters:
key - The configuration key.
defaultValue - The default value.
Returns:
The associated short.
See Also:
Configuration

getShort

public Short getShort(String key,
                      Short defaultValue)
Description copied from interface: Configuration
Get a short associated with the given configuration key.

Specified by:
getShort in interface Configuration
Parameters:
key - The configuration key.
defaultValue - The default value.
Returns:
The associated short if key is found and has valid format, default value otherwise.
See Also:
Configuration

getString

public String getString(String key)
Description copied from interface: Configuration
Get a string associated with the given configuration key.

Specified by:
getString in interface Configuration
Parameters:
key - The configuration key.
Returns:
The associated string.
See Also:
Configuration

getString

public String getString(String key,
                        String defaultValue)
Description copied from interface: Configuration
Get a string associated with the given configuration key.

Specified by:
getString in interface Configuration
Parameters:
key - The configuration key.
defaultValue - The default value.
Returns:
The associated string if key is found and has valid format, default value otherwise.
See Also:
Configuration

getStringArray

public String[] getStringArray(String key)
Description copied from interface: Configuration
Get an array of strings associated with the given configuration key.

Specified by:
getStringArray in interface Configuration
Parameters:
key - The configuration key.
Returns:
The associated string array if key is found.
See Also:
Configuration

getVector

public Vector getVector(String key)
Description copied from interface: Configuration
Get a Vector of strings associated with the given configuration key.

Specified by:
getVector in interface Configuration
Parameters:
key - The configuration key.
Returns:
The associated Vector.
See Also:
Configuration

getVector

public Vector getVector(String key,
                        Vector defaultValue)
Description copied from interface: Configuration
Get a Vector of strings associated with the given configuration key.

Specified by:
getVector in interface Configuration
Parameters:
key - The configuration key.
defaultValue - The default value.
Returns:
The associated Vector.
See Also:
Configuration

getBasePath

public String getBasePath()

setBasePath

public void setBasePath(String path)


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