com.monoserv
Class MonoConfiguration

java.lang.Object
  extended by com.monoserv.patterns.Singleton
      extended by com.monoserv.MonoConfiguration

public class MonoConfiguration
extends Singleton

A configuration object that works as a Singleton object and returns data stored in a configuration file. The configuration file is essentially a properties file. The default filename configuration file is "monoserv.config".


Constructor Summary
protected MonoConfiguration()
          Hide the constructor - not needed with Singletons
 
Method Summary
static java.lang.String getField(java.lang.String key)
          Checks the internal hashtable that has the configuration data and returns the value of the associated field if it exists.
 java.lang.Object getInstance()
          Convienence function for getInstance("monoserv.config")
static java.lang.Object getInstance(java.lang.String filename)
          Instantiates the global object if it has not already been created.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MonoConfiguration

protected MonoConfiguration()
Hide the constructor - not needed with Singletons

Method Detail

getInstance

public java.lang.Object getInstance()
Convienence function for getInstance("monoserv.config")

Specified by:
getInstance in class Singleton
Returns:
The MonoConfiguration objec instance.
See Also:
getInstance(String)

getInstance

public static java.lang.Object getInstance(java.lang.String filename)
                                    throws java.lang.RuntimeException
Instantiates the global object if it has not already been created. This will also automatically read the configuration file passed. It will throw RuntimeExceptions is it cannot find the configuration file (FileNotFoundException), or if a general IO Error occurs (IOException) and a generic Exception if any other unknown error occurs.

Parameters:
filename - The file and path of the configuration file.
Returns:
The MonoConfiguration object
Throws:
java.lang.RuntimeException - If an error occurs

getField

public static java.lang.String getField(java.lang.String key)
                                 throws java.lang.RuntimeException
Checks the internal hashtable that has the configuration data and returns the value of the associated field if it exists. If the configuration file has been successfully read, and data is in memory, and the key requested exists in memory, then the value is returned. All other conditions means an exception will be thrown.

Parameters:
key - The name of the field that you want the value of
Returns:
String the Value of the key if the above requirements are met.
Throws:
java.lang.RuntimeException - If a field is not found.