org.knowceans.util
Class Conf

java.lang.Object
  extended by java.util.Dictionary<K,V>
      extended by java.util.Hashtable<java.lang.Object,java.lang.Object>
          extended by java.util.Properties
              extended by org.knowceans.util.Conf
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.util.Map<java.lang.Object,java.lang.Object>

public class Conf
extends java.util.Properties

Reads configuration information from a properties file. Implemented as singleton.

The file is looked up according to the following priorities list:

This version allows the definition of variables that can be expanded at readtime:

Author:
heinrich
See Also:
Serialized Form

Constructor Summary
Conf(java.lang.String file)
           
 
Method Summary
static boolean exists()
          Allows to check if a configuration has been loaded from a file already (to reduce dynamic loading overhead).
static Conf get()
          get the instance of the singleton object
static java.lang.String get(java.lang.String key)
          get the named property from the singleton object
static java.lang.String getBasePath()
           
static boolean getBoolean(java.lang.String key)
          get a boolean value: true and 1 are allowed for true, anything else for false
static java.lang.Class getClass(java.lang.String clazz)
          Get class with the name specified by the property, using the default class loader.
static double getDouble(java.lang.String key)
          get a numeric value.
static double[] getDoubleArray(java.lang.String key)
          Get a double array from the file, where the vales are separated by comma, semicolon or space.
static float getFloat(java.lang.String key)
           
static java.lang.Object getInstance(java.lang.String clazz)
          Get an instance of the class that corresponds to the property name and has a default constructor.
static int getInt(java.lang.String key)
          Get an integer value.
static int[] getIntArray(java.lang.String key)
          Get an integer array from the file, where the vales are separated by comma, semicolon or space.
static long getLong(java.lang.String key)
          get a numeric value.
static java.lang.String getOverridePropFile()
          get the overridden properties file.
static java.lang.String getPropFile()
           
static boolean load(java.lang.String file)
          Instantiate the configuration, e.g., in the main class.
static void main(java.lang.String[] args)
           
static void overridePropFile(java.lang.String string)
          override the default properties file locations.
static void setBasePath(java.lang.String string)
           
static void setPropFile(java.lang.String string)
           
 
Methods inherited from class java.util.Properties
getProperty, getProperty, list, list, load, load, loadFromXML, propertyNames, save, setProperty, store, store, storeToXML, storeToXML, stringPropertyNames
 
Methods inherited from class java.util.Hashtable
clear, clone, contains, containsKey, containsValue, elements, entrySet, equals, get, hashCode, isEmpty, keys, keySet, put, putAll, remove, size, toString, values
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Conf

public Conf(java.lang.String file)
Method Detail

get

public static Conf get()
get the instance of the singleton object

Returns:

exists

public static boolean exists()
Allows to check if a configuration has been loaded from a file already (to reduce dynamic loading overhead).

Returns:

load

public static boolean load(java.lang.String file)
Instantiate the configuration, e.g., in the main class.

Parameters:
file -
Returns:
false if as the result of this call the configuration could NOT be loaded (can be used to find a conf file), false otherwise (if loading was successful or if class instance already exists)

get

public static java.lang.String get(java.lang.String key)
get the named property from the singleton object

Returns:
the value or null

getDouble

public static double getDouble(java.lang.String key)
get a numeric value.

Parameters:
key -
Returns:

getFloat

public static float getFloat(java.lang.String key)

getLong

public static long getLong(java.lang.String key)
get a numeric value.

Parameters:
key -
Returns:

getInt

public static int getInt(java.lang.String key)
Get an integer value.

Parameters:
key -
Returns:

getDoubleArray

public static double[] getDoubleArray(java.lang.String key)
Get a double array from the file, where the vales are separated by comma, semicolon or space.

Parameters:
key -
Returns:

getIntArray

public static int[] getIntArray(java.lang.String key)
Get an integer array from the file, where the vales are separated by comma, semicolon or space.

Parameters:
key -
Returns:

getBoolean

public static boolean getBoolean(java.lang.String key)
get a boolean value: true and 1 are allowed for true, anything else for false

Parameters:
key -
Returns:

getInstance

public static java.lang.Object getInstance(java.lang.String clazz)
                                    throws java.lang.Exception
Get an instance of the class that corresponds to the property name and has a default constructor. If no default constructor exists, use getClass() instantiate in the client code.

Parameters:
clazz -
Returns:
an instance of the class
Throws:
java.lang.Exception

getClass

public static java.lang.Class getClass(java.lang.String clazz)
                                throws java.lang.ClassNotFoundException
Get class with the name specified by the property, using the default class loader.

Parameters:
clazz -
Returns:
Throws:
java.lang.ClassNotFoundException

getBasePath

public static java.lang.String getBasePath()
Returns:

getPropFile

public static java.lang.String getPropFile()
Returns:

setBasePath

public static void setBasePath(java.lang.String string)
Parameters:
string -

setPropFile

public static void setPropFile(java.lang.String string)
Parameters:
string -

getOverridePropFile

public static java.lang.String getOverridePropFile()
get the overridden properties file. Set to null to return to normal lookup behaviour.

Returns:

overridePropFile

public static void overridePropFile(java.lang.String string)
override the default properties file locations. If this property is set, no search for other files is performed. Calling this method unloads existing properties.

Parameters:
string -

main

public static void main(java.lang.String[] args)