EAF 7.4 Util

com.lutris.util
Class Config

java.lang.Object
  extended by com.lutris.util.KeywordValueTable
      extended by com.lutris.util.Config
All Implemented Interfaces:
java.io.Serializable

public class Config
extends KeywordValueTable

Config is essentially a KeywordValueTable used for recursive storage of data derived from a config file. The contents is initialized but ConfigFile.

Version:
$Revision: 1.8 $
Author:
John Marco, Shawn McMurdo
See Also:
ConfigFile, KeywordValueTable, Serialized Form

Constructor Summary
Config()
          Default constructor for an empty Config.
Config(org.enhydra.util.ConfigFileInterface configFile)
          Constructor that associates this Config with a given ConfigFile.
Config(KeywordValueTable kvt)
          Constructor that takes a KeywordValueTable as initialization.
Config(KeywordValueTable kvt, org.enhydra.util.ConfigFileInterface configFile)
          Constructor that takes a KeywordValueTable and a ConfigFile as initialization.
 
Method Summary
 java.util.Hashtable allConfigParams(java.lang.String prefix)
          Returns the hashtable containing names and values of all config parameters Names are in the form name-level-0_name-level-1_name-level-2...
 int containsCount(java.lang.String key)
          Returns the number of data elements for a given key, or -1 if the key is not found.
 boolean containsKey(java.lang.String key)
          Returns true if the specified key is found, false otherwise.
 boolean getBoolean(java.lang.String key)
          Returns a single boolean value associated with a given key.
 boolean getBoolean(java.lang.String key, boolean defaultValue)
          Returns a single boolean value associated with a given key.
 boolean[] getBooleans(java.lang.String key)
          Returns all boolean values associated with a given key.
 boolean[] getBooleans(java.lang.String key, boolean[] defaultValue)
          Returns all boolean values associated with a given key.
 Config getClonedConfig()
          Returnes cloned Config object.
 Config getConfig(java.lang.String keyword)
          Get the value of a section as a Config object.
 org.enhydra.util.ConfigFileInterface getConfigFile()
          Gets the ConfigFile associated with this object.
 java.lang.Object getDataSource(java.lang.String key)
          Returns a DataSource value associated with a given key.
 java.lang.Object getDataSource(java.lang.String key, java.lang.Object defaultValue)
          Returns a single DataSource value associated with a given key.
 double getDouble(java.lang.String key)
          Returns a single double value associated with a given key.
 double getDouble(java.lang.String key, double defaultValue)
          Returns a single double value associated with a given key.
 double[] getDoubles(java.lang.String key)
          Returns all double values associated with a given key.
 double[] getDoubles(java.lang.String key, double[] defaultValue)
          Returns all double values associated with a given key.
 int getInt(java.lang.String key)
          Returns a single integer value associated with a given key.
 int getInt(java.lang.String key, int defaultValue)
          Returns a single integer value associated with a given key.
 int[] getInts(java.lang.String key)
          Returns all integer values associated with a given key.
 int[] getInts(java.lang.String key, int[] defaultValue)
          Returns all integer values associated with a given key.
 long getLong(java.lang.String key)
          Returns a single long integer value associated with a given key.
 long getLong(java.lang.String key, long defaultValue)
          Returns a single long integer value associated with a given key.
 long[] getLongs(java.lang.String key)
          Returns all long integer values associated with a given key.
 long[] getLongs(java.lang.String key, long[] defaultValue)
          Returns all long integer values associated with a given key.
 KeywordValueTable getSection(java.lang.String keyword)
          Gets the value of a section as a KeywordValueTable object.
 java.lang.String getString(java.lang.String key)
          Returns a single String value associated with a given key.
 java.lang.String getString(java.lang.String key, java.lang.String defaultValue)
          Returns a single String value associated with a given key.
 java.lang.String[] getStrings(java.lang.String key)
          Returns all String values associated with a given key.
 java.lang.String[] getStrings(java.lang.String key, java.lang.String[] defaultValue)
          Returns all String values associated with a given key.
 void importConfig(Config config)
          Imorts and synchronizes to, all parameters (key-value pairs) according to given Config object parameters.
 boolean isArray(java.lang.String key)
          Is the key is an array, or a single value.
protected  KeywordValueTable newSection()
          Allocates a new section.
 void setConfigFile(org.enhydra.util.ConfigFileInterface configFile)
          Sets the ConfigFile associated with this object.
 
Methods inherited from class com.lutris.util.KeywordValueTable
get, get, keys, leafKeys, remove, set, setDefault, toHtml, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Config

public Config()
Default constructor for an empty Config.


Config

public Config(KeywordValueTable kvt)
Constructor that takes a KeywordValueTable as initialization.

Parameters:
kvt - KeywordValueTable with which to initialize Config

Config

public Config(KeywordValueTable kvt,
              org.enhydra.util.ConfigFileInterface configFile)
Constructor that takes a KeywordValueTable and a ConfigFile as initialization. The ConfigFile is associated with this Config object.

Parameters:
kvt - KeywordValueTable with which to initialize Config
configFile - ConfigFile to associate this Config object with

Config

public Config(org.enhydra.util.ConfigFileInterface configFile)
Constructor that associates this Config with a given ConfigFile.

Parameters:
configFile - ConfigFile to associate this object with
Method Detail

getClonedConfig

public Config getClonedConfig()
                       throws com.lutris.util.KeywordValueException
Returnes cloned Config object. The cloned and original objects have exatly same key value pairs, but free of any common object references. Only reference which is same for both objects (the original, and it's clone) is reference to associated ConfigFile object (private argument of Config class).

Returns:
A cloned Config object.
Throws:
KeywordValueException

allConfigParams

public java.util.Hashtable allConfigParams(java.lang.String prefix)
                                    throws com.lutris.util.KeywordValueException
Returns the hashtable containing names and values of all config parameters Names are in the form name-level-0_name-level-1_name-level-2...

Parameters:
prefix - - previous level name
Returns:
hashtable of all config parameters
Throws:
com.lutris.util.KeywordValueException

importConfig

public void importConfig(Config config)
                  throws com.lutris.util.KeywordValueException
Imorts and synchronizes to, all parameters (key-value pairs) according to given Config object parameters. All parameters which do not exist in imported Config object will be removed.

Parameters:
config - Config object which has key-value pairs for importing.
Throws:
KeywordValueException

newSection

protected KeywordValueTable newSection()
Allocates a new section. The overrides the default method to allocate a section that is of class Config.

Overrides:
newSection in class KeywordValueTable
Returns:
A reference to a new section.
See Also:
KeywordValueTable.newSection()

getConfigFile

public org.enhydra.util.ConfigFileInterface getConfigFile()
Gets the ConfigFile associated with this object.

Returns:
the associated ConfigFile, null if there is no config file associated with this object.

setConfigFile

public void setConfigFile(org.enhydra.util.ConfigFileInterface configFile)
Sets the ConfigFile associated with this object. For use by ConfigFile only, anyone else please use the appropriate constructor

Parameters:
configFile - ConfigFile object associated with this object

getConfig

public Config getConfig(java.lang.String keyword)
                 throws com.lutris.util.KeywordValueException
Get the value of a section as a Config object.

Parameters:
keyword - The keyword of the field. This can be a simple keyword or a recursive, dot-seperated keyword path.
Returns:
A reference to the section object or null if not found.
Throws:
KeywordValueException - If the keyword is not syntactically legal or a non-leaf element of the keyword is not a section or the value object is not a KeywordValueTable.
See Also:
KeywordValueTable.getSection(java.lang.String)

getSection

public KeywordValueTable getSection(java.lang.String keyword)
                             throws com.lutris.util.KeywordValueException
Gets the value of a section as a KeywordValueTable object. This method overrides the KeywordValueTable.getSection in order to insure that Config.getSection() always returns a Config object even if a KeywordValueTable was inserted into the Config as a section.

Overrides:
getSection in class KeywordValueTable
Parameters:
keyword - The keyword of the field. This can be a simple keyword or a recursive, dot-seperated keyword path.
Returns:
A reference to the section object or null if not found.
Throws:
KeywordValueException - If the keyword is not syntactically legal or a non-leaf element of the keyword is not a section or the value object is not a KeywordValueTable.
See Also:
KeywordValueTable.getSection(java.lang.String)

containsKey

public boolean containsKey(java.lang.String key)
Returns true if the specified key is found, false otherwise.

Overrides:
containsKey in class KeywordValueTable
Parameters:
key - The key whose existence is to be tested.
Returns:
true if the key was found, otherwise false.

containsCount

public int containsCount(java.lang.String key)
                  throws com.lutris.util.ConfigException
Returns the number of data elements for a given key, or -1 if the key is not found.

Parameters:
key - The key to search for.
Returns:
The number of entries for the given key, or -1 if the key is not found.
Throws:
ConfigException

isArray

public boolean isArray(java.lang.String key)
                throws com.lutris.util.ConfigException
Is the key is an array, or a single value. If this returns true, you should use getStrings() (or if you know the type of the data, you can use, for example, getInts()). If this returns false, you shoud use getString() (or if you know the type of the data, you can use, for example, getInt()).

Parameters:
key - The key to search for.
Returns:
True if the key is an array, false if it is a single value.
Throws:
ConfigException - If the key is not found.

getLong

public long getLong(java.lang.String key)
             throws com.lutris.util.ConfigException
Returns a single long integer value associated with a given key. If the key is associated with more than one element, or the retrieved element cannot be converted to a long integer then a ConfigException exception is thrown.

Parameters:
key - The key to use to search for the configuration entry.
Returns:
The long integer value associated with the given key.
Throws:
ConfigException - Thrown if the requested entry does not exist or elements are not in the requested format.
See Also:
ConfigException

getLong

public long getLong(java.lang.String key,
                    long defaultValue)
             throws com.lutris.util.ConfigException
Returns a single long integer value associated with a given key. If the key is associated with more than one element then a ConfigException error is thrown with reason set to COUNT. If the retrieved element cannot be converted to a long integer then a ConfigException error is thrown with reason set to FORMAT.

Parameters:
key - The key to use to search for the configuration entry.
defaultValue - The default value to use if the requested entry does not exist.
Returns:
The long integer value associated with the given key.
Throws:
ConfigException - Thrown if there was not exactly one requested element, or if the element is of the wrong data type or format.
See Also:
ConfigException

getLongs

public long[] getLongs(java.lang.String key)
                throws com.lutris.util.ConfigException
Returns all long integer values associated with a given key. If any of the elements associated with the key cannot be converted to a long integer then a ConfigException error is thrown.

Parameters:
key - The key to use to search for the configuration entry.
Returns:
An array of longs containing the list of long values from the configuration input stream.
Throws:
ConfigException - Thrown if the requested entry does not exist or elements are not in the requested format.
See Also:
ConfigException

getLongs

public long[] getLongs(java.lang.String key,
                       long[] defaultValue)
                throws com.lutris.util.ConfigException
Returns all long integer values associated with a given key. If any of the elements associated with the key cannot be converted to a long integer then a ConfigException error is thrown.

Parameters:
key - The key to use to search for the configuration entry.
defaultValue - The default value to use if the requested entry does not exist.
Returns:
An array of longs containing the list of long values from the configuration input stream.
Throws:
ConfigException - Thrown if the requested entries are of the wrong data type or format.
See Also:
ConfigException

getInt

public int getInt(java.lang.String key)
           throws com.lutris.util.ConfigException
Returns a single integer value associated with a given key. If the key is associated with more than one element, or the retrieved element cannot be converted to a integer then a ConfigException exception is thrown.

Parameters:
key - The key to use to search for the configuration entry.
Returns:
The integer value associated with the given key.
Throws:
ConfigException - Thrown if the requested entry does not exist or elements are not in the requested format.
See Also:
ConfigException

getInt

public int getInt(java.lang.String key,
                  int defaultValue)
           throws com.lutris.util.ConfigException
Returns a single integer value associated with a given key. If the key is associated with more than one element, or the retrieved element cannot be converted to a integer then a ConfigException exception is thrown.

Parameters:
key - The key to use to search for the configuration entry.
defaultValue - The default value to use if the requested entry does not exist.
Returns:
The integer value associated with the given key.
Throws:
ConfigException - Thrown if there was not exactly one requested element, or if the element is of the wrong data type or format.
See Also:
ConfigException

getInts

public int[] getInts(java.lang.String key)
              throws com.lutris.util.ConfigException
Returns all integer values associated with a given key. If any of the elements associated with the key cannot be converted to a integer then a ConfigException error is thrown.

Parameters:
key - The key to use to search for the configuration entry.
Returns:
An array of integers containing the list of integer values from the configuration input stream.
Throws:
ConfigException - Thrown if the requested entry does not exist or elements are not in the requested format.
See Also:
ConfigException

getInts

public int[] getInts(java.lang.String key,
                     int[] defaultValue)
              throws com.lutris.util.ConfigException
Returns all integer values associated with a given key. If any of the elements associated with the key cannot be converted to a integer then a ConfigException error is thrown.

Parameters:
key - The key to use to search for the configuration entry.
defaultValue - The default value to use if the requested entry does not exist.
Returns:
An array of integers containing the list of integer values from the configuration input stream.
Throws:
ConfigException - Thrown if the requested entries are of the wrong data type or format.
See Also:
ConfigException

getString

public java.lang.String getString(java.lang.String key)
                           throws com.lutris.util.ConfigException
Returns a single String value associated with a given key. If the key is associated with more than one element, or the retrieved element cannot be converted to a String then a ConfigException exception is thrown.

Overrides:
getString in class KeywordValueTable
Parameters:
key - The key to use to search for the configuration entry.
Returns:
The string value associated with the given key.
Throws:
ConfigException - Thrown if the requested entry does not exist or elements are not in the requested format.
See Also:
ConfigException

getString

public java.lang.String getString(java.lang.String key,
                                  java.lang.String defaultValue)
                           throws com.lutris.util.ConfigException
Returns a single String value associated with a given key. If the key is associated with more than one element, or the retrieved element cannot be converted to a String then a ConfigException exception is thrown.

Overrides:
getString in class KeywordValueTable
Parameters:
key - The key to use to search for the configuration entry.
defaultValue - The default value to use if the requested entry does not exist.
Returns:
The string value associated with the given key.
Throws:
ConfigException - Thrown if there was not exactly one requested element, or if the element is of the wrong data type or format.
See Also:
ConfigException

getStrings

public java.lang.String[] getStrings(java.lang.String key)
                              throws com.lutris.util.ConfigException
Returns all String values associated with a given key. If any of the elements associated with the key cannot be converted to a String then a ConfigException error is thrown.

Parameters:
key - The key to use to search for the configuration entry.
Returns:
An array of strings containing the list of string values from the configuration input stream.
Throws:
ConfigException - Thrown if the requested entry does not exist or elements are not in the requested format.
See Also:
ConfigException

getStrings

public java.lang.String[] getStrings(java.lang.String key,
                                     java.lang.String[] defaultValue)
                              throws com.lutris.util.ConfigException
Returns all String values associated with a given key. If any of the elements associated with the key cannot be converted to a String then a ConfigException error is thrown.

Parameters:
key - The key to use to search for the configuration entry.
defaultValue - The default value to use if the requested entry does not exist.
Returns:
An array of strings containing the list of string values from the configuration input stream.
Throws:
ConfigException - Thrown if the requested entries are of the wrong data type or format.
See Also:
ConfigException

getBoolean

public boolean getBoolean(java.lang.String key)
                   throws com.lutris.util.ConfigException
Returns a single boolean value associated with a given key. If the key is associated with more than one element, or the retrieved element cannot be converted to a boolean then a ConfigException exception is thrown.

Parameters:
key - The key to use to search for the configuration entry.
Returns:
The boolean value associated with the given key.
Throws:
ConfigException - Thrown if the requested entry does not exist or elements are not in the requested format.
See Also:
ConfigException

getBoolean

public boolean getBoolean(java.lang.String key,
                          boolean defaultValue)
                   throws com.lutris.util.ConfigException
Returns a single boolean value associated with a given key. If the key is associated with more than one element, or the retrieved element cannot be converted to a boolean then a ConfigException exception is thrown.

Parameters:
key - The key to use to search for the configuration entry.
defaultValue - The default value to use if the requested entry does not exist.
Returns:
The boolean value associated with the given key.
Throws:
ConfigException - Thrown if there was not exactly one requested element, or if the element is of the wrong data type or format.
See Also:
ConfigException

getBooleans

public boolean[] getBooleans(java.lang.String key)
                      throws com.lutris.util.ConfigException
Returns all boolean values associated with a given key. If any of the elements associated with the key cannot be converted to a boolean then a ConfigException error is thrown.

Parameters:
key - The key to use to search for the configuration entry.
Returns:
An array of booleans containing the list of boolean values from the configuration input stream.
Throws:
ConfigException - Thrown if the requested entry does not exist or elements are not in the requested format.
See Also:
ConfigException

getBooleans

public boolean[] getBooleans(java.lang.String key,
                             boolean[] defaultValue)
                      throws com.lutris.util.ConfigException
Returns all boolean values associated with a given key. If any of the elements associated with the key cannot be converted to a boolean then a ConfigException error is thrown.

Parameters:
key - The key to use to search for the configuration entry.
defaultValue - The default value to use if the requested entry does not exist.
Returns:
An array of booleans containing the list of boolean values from the configuration input stream.
Throws:
ConfigException - Thrown if the requested entries are of the wrong data type or format.
See Also:
ConfigException

getDouble

public double getDouble(java.lang.String key)
                 throws com.lutris.util.ConfigException
Returns a single double value associated with a given key. If the key is associated with more than one element, or the retrieved element cannot be converted to a double then a ConfigException exception is thrown.

Parameters:
key - The key to use to search for the configuration entry.
Returns:
The double value associated with the given key.
Throws:
ConfigException - Thrown if the requested entry does not exist or elements are not in the requested format.
See Also:
ConfigException

getDouble

public double getDouble(java.lang.String key,
                        double defaultValue)
                 throws com.lutris.util.ConfigException
Returns a single double value associated with a given key. If the key is associated with more than one element, or the retrieved element cannot be converted to a double then a ConfigException exception is thrown.

Parameters:
key - The key to use to search for the configuration entry.
defaultValue - The default value to use if the requested entry does not exist.
Returns:
The double value associated with the given key.
Throws:
ConfigException - Thrown if there was not exactly one requested element, or if the element is of the wrong data type or format.
See Also:
ConfigException

getDoubles

public double[] getDoubles(java.lang.String key)
                    throws com.lutris.util.ConfigException
Returns all double values associated with a given key. If any of the elements associated with the key cannot be converted to a double then a ConfigException error is thrown.

Parameters:
key - The key to use to search for the configuration entry.
Returns:
An array of doubles containing the list of double values from the configuration input stream.
Throws:
ConfigException - Thrown if the requested entry does not exist or elements are not in the requested format.
See Also:
ConfigException

getDoubles

public double[] getDoubles(java.lang.String key,
                           double[] defaultValue)
                    throws com.lutris.util.ConfigException
Returns all double values associated with a given key. If any of the elements associated with the key cannot be converted to a double then a ConfigException error is thrown.

Parameters:
key - The key to use to search for the configuration entry.
defaultValue - The default value to use if the requested entry does not exist.
Returns:
An array of doubles containing the list of double values from the configuration input stream.
Throws:
ConfigException - Thrown if the requested entries are of the wrong data type or format.
See Also:
ConfigException

getDataSource

public java.lang.Object getDataSource(java.lang.String key)
                               throws com.lutris.util.ConfigException
Returns a DataSource value associated with a given key.

Parameters:
key - The key to use to search for the configuration entry.
Returns:
The DataSource value associated with the given key.
Throws:
ConfigException - Thrown if the requested entry does not exist or elements are not in the requested format.
See Also:
ConfigException

getDataSource

public java.lang.Object getDataSource(java.lang.String key,
                                      java.lang.Object defaultValue)
                               throws com.lutris.util.ConfigException
Returns a single DataSource value associated with a given key. If the key is associated with more than one element, or the retrieved element cannot be converted to a String then a ConfigException exception is thrown.

Parameters:
key - The key to use to search for the configuration entry.
defaultValue - The default value to use if the requested entry does not exist.
Returns:
The DataSource value associated with the given key.
Throws:
ConfigException - Thrown if there was not exactly one requested element, or if the element is of the wrong data type or format.
See Also:
ConfigException

EAF 7.4 Util