de.unidu.is.util
Class Config

java.lang.Object
  extended byde.unidu.is.util.Config

public class Config
extends java.lang.Object

A config file as an extension to PropertyMap, allowing for automatically loading from an existing file in directory conf/config (relative to a path in the system property "java.class.path") and saving in it. It is allowed that a key exists multiple times.

A property foo.bar which is already read from the configuration file can be referenced by ${foo.bar}. Currently, the property mind_home is set to the base directory of the system (the directory containing the configuration directory).

Since:
2001-08-02
Version:
$Revision: 1.10 $, $Date: 2005/03/19 16:59:20 $
Author:
Henrik Nottelmann

Constructor Summary
Config()
           
 
Method Summary
static void add(java.io.File file)
          Adds the content of the specified file to the config.
static void add(java.io.Reader reader)
          Adds the content of the specified reader to the config.
static void add(java.net.URL url)
          Adds the content of the specified URL to the config.
static void clear()
           
static boolean containsKey(java.lang.Object key)
          Tests if the config contains the specified key.
static boolean containsValue(java.lang.Object value)
          Tests if the config contains the specified value.
static java.lang.Object get(java.lang.Object key)
          Retrieves a value from the config specified by its key.
static boolean getBoolean(java.lang.Object key)
          Retrieves a value as a boolean from the config specified by its key.
static double getDouble(java.lang.Object key)
          Retrieves a value as a double from the config specified by its key.
static int getInt(java.lang.Object key)
          Retrieves a value as an integer from the config specified by its key.
static long getLong(java.lang.Object key)
          Retrieves a value as a long from the config specified by its key.
static PropertyMap getMap()
          Returns the complete map.
static java.lang.String getString(java.lang.Object key)
          Retrieves a value as a string from the config specified by its key.
static java.lang.String getString(java.lang.Object key, PropertyMap map)
          Retrieves a value as a string from the config specified by its key.
static void init(java.util.Map init)
          Inits the configuration class, and loads all config files "conf/config" which can be found if the property map is not set yet.
static boolean isEmpty()
          Tests if this config is empty.
static java.util.Set keySet()
          Returns the keys in the config.
static java.lang.Object put(java.lang.Object key, java.lang.Object value)
          Adds an entry to the config.
static void putAll(java.util.Map m)
          Adds all entries in the specified map to the config
static java.lang.Object remove(java.lang.Object key)
          Removes the entry defined by the specified key.
static void set(java.lang.Object key, java.lang.String value)
          Adds an entry to this config.
static void setBoolean(java.lang.Object key, boolean value)
          Adds an entry as a boolean to this config.
static void setDouble(java.lang.Object key, double value)
          Adds an entry as a double to this config.
static void setInt(java.lang.Object key, int value)
          Adds an entry as an integer to this config.
static void setLong(java.lang.Object key, long value)
          Adds an entry as a long to this config.
static void setString(java.lang.Object key, java.lang.String value)
          Adds an entry as a string to this config.
static int size()
          Returns the number of entries in the config
static java.util.Collection values()
          Returns the values in the config.
static void write(java.io.Writer writer)
          Writes the config to the specified writer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Config

public Config()
Method Detail

init

public static void init(java.util.Map init)
Inits the configuration class, and loads all config files "conf/config" which can be found if the property map is not set yet. In addition, the entries from the specified map are added to the config as initial keys.

Parameters:
init - map with initial keys

write

public static void write(java.io.Writer writer)
Writes the config to the specified writer.

Parameters:
writer - writer for the config

clear

public static void clear()

add

public static void add(java.io.File file)
Adds the content of the specified file to the config.

Parameters:
file - file to be added

add

public static void add(java.io.Reader reader)
Adds the content of the specified reader to the config.

Parameters:
reader - reader to be added

add

public static void add(java.net.URL url)
Adds the content of the specified URL to the config.

Parameters:
url - URL to be added

get

public static java.lang.Object get(java.lang.Object key)
Retrieves a value from the config specified by its key.

Parameters:
key - key to be retrieved
Returns:
value or null if the key is not stored

getBoolean

public static boolean getBoolean(java.lang.Object key)
Retrieves a value as a boolean from the config specified by its key.

Parameters:
key - key to be retrieved
Returns:
value or null if the key is not stored

getDouble

public static double getDouble(java.lang.Object key)
Retrieves a value as a double from the config specified by its key.

Parameters:
key - key to be retrieved
Returns:
value or null if the key is not stored

getInt

public static int getInt(java.lang.Object key)
Retrieves a value as an integer from the config specified by its key.

Parameters:
key - key to be retrieved
Returns:
value or null if the key is not stored

getLong

public static long getLong(java.lang.Object key)
Retrieves a value as a long from the config specified by its key.

Parameters:
key - key to be retrieved
Returns:
value or null if the key is not stored

getString

public static java.lang.String getString(java.lang.Object key)
Retrieves a value as a string from the config specified by its key.

Parameters:
key - key to be retrieved
Returns:
value or null if the key is not stored

getString

public static java.lang.String getString(java.lang.Object key,
                                         PropertyMap map)
Retrieves a value as a string from the config specified by its key.

Parameters:
key - key to be retrieved
map - map which is used if the key is not found in the config
Returns:
value or null if the key is not stored

set

public static void set(java.lang.Object key,
                       java.lang.String value)
Adds an entry to this config.

Parameters:
key - key to be added
value - value to be added

setBoolean

public static void setBoolean(java.lang.Object key,
                              boolean value)
Adds an entry as a boolean to this config.

Parameters:
key - key to be added
value - value to be added

setDouble

public static void setDouble(java.lang.Object key,
                             double value)
Adds an entry as a double to this config.

Parameters:
key - key to be added
value - value to be added

setInt

public static void setInt(java.lang.Object key,
                          int value)
Adds an entry as an integer to this config.

Parameters:
key - key to be added
value - value to be added

setLong

public static void setLong(java.lang.Object key,
                           long value)
Adds an entry as a long to this config.

Parameters:
key - key to be added
value - value to be added

setString

public static void setString(java.lang.Object key,
                             java.lang.String value)
Adds an entry as a string to this config.

Parameters:
key - key to be added
value - value to be added

put

public static java.lang.Object put(java.lang.Object key,
                                   java.lang.Object value)
Adds an entry to the config.

Parameters:
key - key to be added
value - value to be added
Returns:
the object previously stored for the specified key

putAll

public static void putAll(java.util.Map m)
Adds all entries in the specified map to the config

Parameters:
m - map which will be added to the config

remove

public static java.lang.Object remove(java.lang.Object key)
Removes the entry defined by the specified key.

Parameters:
key - key to be removed
Returns:
the object previously stored for the specified key

containsKey

public static boolean containsKey(java.lang.Object key)
Tests if the config contains the specified key.

Parameters:
key - key to be tested
Returns:
true iff the config contains the specified key

containsValue

public static boolean containsValue(java.lang.Object value)
Tests if the config contains the specified value.

Parameters:
value - value to be tested
Returns:
true iff the config contains the specified value

isEmpty

public static boolean isEmpty()
Tests if this config is empty.

Returns:
true iff this config is empty

size

public static int size()
Returns the number of entries in the config

Returns:
number of entries in the config

keySet

public static java.util.Set keySet()
Returns the keys in the config.

Returns:
keys in the config

values

public static java.util.Collection values()
Returns the values in the config.

Returns:
values in the config

getMap

public static PropertyMap getMap()
Returns the complete map.

Returns:
complete map