Class ConfigMgr

java.lang.Object
  extended byConfigMgr

public class ConfigMgr
extends Object

A class to parse and store the config hash table. Handles comments with '#' as the first char, empty lines, and values that "have spaces and are in quotes". TODO: Revamp to use getBool/getString/getInt

Version:
$Revision: #16 $
Author:
Kevin Thompson [antiduh.csh.rit.edu]

Field Summary
private  Hashtable config
          This stores the key-value pairs that make up the ConfigMgr.
private  String configfile
          The filename of the file to read the runtime configuration data from.
 
Constructor Summary
ConfigMgr(String filename)
          Construct the class by saving the param and parsing the config file.
 
Method Summary
 Object get(String key)
          Retrieve a value given its key.
 Boolean getBool(String key)
          Retrieves the value of the key from the configuration, then attempts to parse boolean data from it.
 Integer getInt(String key)
          Retrieves the value of the key from the configuration, then attempts to parse integer data from it.
 String getString(String key)
          Retrieves the value of the given key from the configuration and then attempts to cast it to a String object.
private  void loadConfig(String filename)
          A helper method to parse and store the config.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

configfile

private String configfile
The filename of the file to read the runtime configuration data from.


config

private Hashtable config
This stores the key-value pairs that make up the ConfigMgr.

Constructor Detail

ConfigMgr

public ConfigMgr(String filename)
Construct the class by saving the param and parsing the config file. Sanity checks: make sure filename is not null or zero length, then check to see if file is a file and is readable.

Parameters:
filename - The name of the file that contains the config options.
Method Detail

loadConfig

private void loadConfig(String filename)
A helper method to parse and store the config.

Parameters:
filename - The name of the file to parse and store.

get

public Object get(String key)
Retrieve a value given its key.

Parameters:
key - The key of the value to get.

getInt

public Integer getInt(String key)
Retrieves the value of the key from the configuration, then attempts to parse integer data from it. If the method is unable to parse integer data from the data, then null is returned.

Parameters:
key - The key of the value to retrieve.

getBool

public Boolean getBool(String key)
Retrieves the value of the key from the configuration, then attempts to parse boolean data from it. If the method is unable to parse boolean data from the data, then null is returned. The data must either be the strings 'true' or 'false'. Anything else, and this method will return null.

Parameters:
key - The key of the value to retreive.

getString

public String getString(String key)
Retrieves the value of the given key from the configuration and then attempts to cast it to a String object. If the method is unable to cast the data to a String object, null is returned.

Parameters:
key - The key of the value to retreive.