Commons.Collections
Class ExtendedProperties

Field Summary
string basePath
         Base path of the configuration file used to create this ExtendedProperties object.
string file
         The file connected to this repository (holding comments and such). * @serial
string fileSeparator
         File separator.
string include
         This is the name of the property that can point to other properties file for including other properties files.
bool isInitialized
         Has this configuration been intialized.
System.Collections.ArrayList keysAsListed
         These are the keys in the order they listed in the configuration file. This is useful when you wish to perform operations with configuration information in a particular order.

Constructor Summary
ExtendedProperties()
         Creates an empty extended properties object.
ExtendedProperties(string file)
         Creates and loads the extended properties from the specified file. *
ExtendedProperties(string file, string defaultFile)
         Creates and loads the extended properties from the specified file. *

Property Summary
string Include
System.Collections.IEnumerator Keys

Properties inherited from class System.Collections.Hashtable
comparer, Count, hcp, IsFixedSize, IsReadOnly, IsSynchronized, Item, SyncRoot, Values

Method Summary
void AddProperty(string key, object token)
         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"] *
void ClearProperty(string key)
         Clear a property in the configuration. *
void Combine(Commons.Collections.ExtendedProperties c)
         Combines an existing Hashtable with this Hashtable. * Warning: It will overwrite previous entries without warning. *
Commons.Collections.ExtendedProperties ConvertProperties(Commons.Collections.ExtendedProperties p)
         Convert a standard properties class into a configuration class. *
bool GetBoolean(string key, bool defaultValue)
         Get a boolean associated with the given configuration key. *
bool GetBoolean(string key)
         Get a boolean associated with the given configuration key. *
byte GetByte(string key, byte defaultValue)
         Get a byte associated with the given configuration key. *
sbyte GetByte(string key, sbyte defaultValue)
         Get a byte associated with the given configuration key. *
sbyte GetByte(string key)
         Get a byte 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)
         Get a double 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)
         Get a float associated with the given configuration key. *
int GetInt(string name, int def)
         The purpose of this method is to get the configuration resource with the given name as an integer, or a default value. *
int GetInt(string name)
         The purpose of this method is to get the configuration resource with the given name as an integer. *
int GetInteger(string key, int defaultValue)
         Get a int associated with the given configuration key. *
int GetInteger(string key)
         Get a int associated with the given configuration key. *
System.Collections.IEnumerator GetKeys(string prefix)
         Get the list of the keys contained in the configuration repository that match the specified prefix. *
long GetLong(string key, long defaultValue)
         Get a long associated with the given configuration key. *
long GetLong(string key)
         Get a long associated with the given configuration key. *
System.Collections.Hashtable GetProperties(string key, System.Collections.Hashtable defaults)
         Get a list of properties associated with the given configuration key. *
System.Collections.Hashtable GetProperties(string key)
         Get a list of properties associated with the given configuration key. *
object GetProperty(string key)
         Gets a property from the configuration. *
short GetShort(string key, short defaultValue)
         Get a short associated with the given configuration key. *
short GetShort(string key)
         Get a short associated with the given configuration key. *
string GetString(string key, string defaultValue)
         Get a string associated with the given configuration key. *
string GetString(string key)
         Get a string associated with the given configuration key. *
string[] GetStringArray(string key)
         Get an array of strings associated with the given configuration key. *
System.Collections.ArrayList GetVector(string key, System.Collections.ArrayList defaultValue)
         Get a Vector of strings associated with the given configuration key. *
System.Collections.ArrayList GetVector(string key)
         Get a Vector of strings associated with the given configuration key. *
bool IsInitialized()
         Indicate to client code whether property resources have been initialized or not.
void Load(System.IO.Stream input, string enc)
         Load the properties from the given input stream and using the specified encoding. *
void Load(System.IO.Stream input)
         Load the properties from the given input stream. *
void Save(System.IO.TextWriter output, string Header)
         Save the properties to the given outputstream.
void SetProperty(string key, object value_Renamed)
         Set a property, this will replace any previously set values. Set values is implicitly a call to clearProperty(key), addProperty(key,value).
Commons.Collections.ExtendedProperties Subset(string prefix)
         Create an ExtendedProperties object that is a subset of this one. Take into account duplicate keys by using the setProperty() in ExtendedProperties. *
string TestBoolean(string value_Renamed)
         Test whether the string represent by value maps to a boolean value or not. We will allow
true
,
on
, and
yes
for a
true
boolean value, and
false
,
off
, and
no
for
false
boolean values. Case of value to test for boolean status is ignored. *
string ToString()
         Display the configuration for debugging purposes.

Methods inherited from class System.Collections.Hashtable
Add, Clear, Clone, Contains, ContainsKey, ContainsValue, CopyTo, GetEnumerator, GetHash, GetObjectData, IEnumerable.GetEnumerator, KeyEquals, OnDeserialization, Remove

Methods inherited from class System.Object
Equals, Finalize, GetHashCode, GetType, MemberwiseClone


Field Detail

basePath

protected internal string basePath

Base path of the configuration file used to create this ExtendedProperties object.


file

protected internal string file

The file connected to this repository (holding comments and such). * @serial


fileSeparator

protected internal string fileSeparator

File separator.


include

protected internal string include

This is the name of the property that can point to other properties file for including other properties files.


isInitialized

protected internal bool isInitialized

Has this configuration been intialized.


keysAsListed

protected internal System.Collections.ArrayList keysAsListed

These are the keys in the order they listed in the configuration file. This is useful when you wish to perform operations with configuration information in a particular order.

Constructor Detail

ExtendedProperties

public ExtendedProperties()

Creates an empty extended properties object.


ExtendedProperties

public ExtendedProperties(string file)

Creates and loads the extended properties from the specified file. *

Parameters:
file - A String.
Throws:
- IOException.

ExtendedProperties

public ExtendedProperties(string file,
                          string defaultFile)

Creates and loads the extended properties from the specified file. *

Parameters:
file - A String.
Throws:
- IOException.
Property Detail

Include

public string Include


Keys

public System.Collections.IEnumerator Keys

Method Detail

AddProperty

public void AddProperty(string key,
                        object token)

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:
String - key
String - value

ClearProperty

public void ClearProperty(string key)

Clear a property in the configuration. *

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

Combine

public void Combine(Commons.Collections.ExtendedProperties c)

Combines an existing Hashtable with this Hashtable. * Warning: It will overwrite previous entries without warning. *

Parameters:
- ExtendedProperties

ConvertProperties

public Commons.Collections.ExtendedProperties ConvertProperties(Commons.Collections.ExtendedProperties p)

Convert a standard properties class into a configuration class. *

Parameters:
p - properties object to convert into a ExtendedProperties object. *
Returns:
ExtendedProperties configuration created from the properties object.

GetBoolean

public bool GetBoolean(string key,
                       bool 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.

GetBoolean

public bool 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.

GetByte

public 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.

GetByte

public sbyte GetByte(string key,
                     sbyte 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

public sbyte 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.

GetDouble

public 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.

GetDouble

public 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.

GetFloat

public 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.

GetFloat

public 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.

GetInt

public int GetInt(string name,
                  int def)

The purpose of this method is to get the configuration resource with the given name as an integer, or a default value. *

Parameters:
name - The resource name
def - The default value of the resource.
Returns:
The value of the resource as an integer.

GetInt

public int GetInt(string name)

The purpose of this method is to get the configuration resource with the given name as an integer. *

Parameters:
name - The resource name.
Returns:
The value of the resource as an integer.

GetInteger

public int GetInteger(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 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.

GetInteger

public int GetInteger(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.

GetKeys

public System.Collections.IEnumerator 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.

GetLong

public 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.

GetLong

public 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.

GetProperties

public System.Collections.Hashtable GetProperties(string key,
                                                  System.Collections.Hashtable 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.
- IllegalArgumentException if one of the tokens is malformed (does not contain an equals sign).

GetProperties

public System.Collections.Hashtable 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).

GetProperty

public object 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

GetShort

public 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.

GetShort

public 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.

GetString

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

GetString

public 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.

GetStringArray

public 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.

GetVector

public System.Collections.ArrayList GetVector(string key,
                                              System.Collections.ArrayList 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.

GetVector

public System.Collections.ArrayList 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.

IsInitialized

public bool IsInitialized()

Indicate to client code whether property resources have been initialized or not.


Load

public void Load(System.IO.Stream input,
                 string enc)

Load the properties from the given input stream and using the specified encoding. *

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

Load

public void Load(System.IO.Stream input)

Load the properties from the given input stream. *

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

Save

public void Save(System.IO.TextWriter output,
                 string Header)

Save the properties to the given outputstream.

Parameters:
output - An OutputStream.
header - A String.
Throws:
- IOException.

SetProperty

public void SetProperty(string key,
                        object value_Renamed)

Set a property, this will replace any previously set values. Set values is implicitly a call to clearProperty(key), addProperty(key,value).

Parameters:
String - key
String - value

Subset

public Commons.Collections.ExtendedProperties Subset(string prefix)

Create an ExtendedProperties object that is a subset of this one. Take into account duplicate keys by using the setProperty() in ExtendedProperties. *

Parameters:
String - prefix

TestBoolean

public string TestBoolean(string value_Renamed)

Test whether the string represent by value maps to a boolean value or not. We will allow

true
,
on
, and
yes
for a
true
boolean value, and
false
,
off
, and
no
for
false
boolean values. Case of value to test for boolean status is ignored. *

Parameters:
String - The value to test for boolean state.
Returns:
true
or
false
if the supplied text maps to a boolean value, or
null
otherwise.

ToString

public string ToString()

Display the configuration for debugging purposes.