org.jconfig
Class ConfigurationManager

java.lang.Object
  extended byorg.jconfig.ConfigurationManager

public class ConfigurationManager
extends java.lang.Object


Nested Class Summary
private static class ConfigurationManager.MyErrorHandler
           
 
Field Summary
private static java.util.Vector categories
           
private static ConfigurationManager cfgmgr
           
private static java.util.Hashtable parameter
           
private  boolean validate
           
 
Constructor Summary
ConfigurationManager()
           
 
Method Summary
 void addCategory(java.lang.String category)
           
 java.util.Enumeration getCategoryNames()
          This method returns an Enumeration of all categories.
static ConfigurationManager getInstance()
          This method returns an instance of the ConfigurationManager.
 java.util.Hashtable getProperties()
          This method will return a Hashtable that contains all properties for the category "general".
 java.util.Hashtable getProperties(java.lang.String category)
          This method will return a Hashtable that contains all properties for the selected category.
 java.lang.String getProperty(java.lang.String key)
          This method returns the value for a particular key The category is "general".
 java.lang.String getProperty(java.lang.String key, java.lang.String defaultValue)
          This method returns the value for a particular key.
 java.lang.String getProperty(java.lang.String key, java.lang.String defaultValue, java.lang.String category)
          This method returns the value for a particular key in the certain category.
 void load(java.io.File file)
          This method will read in a file and generate the properties
 void load(java.lang.String theURL)
          This method will read the content from an URL and generate the properties
 void loadProperties(java.io.File file)
          This method will store all categories and properties to a Java-properties file.
private  void processProperties(org.w3c.dom.Document doc)
           
 void setProperty(java.lang.String name, java.lang.String value)
          This method will set the value for a specific property in the category "general".
 void setProperty(java.lang.String name, java.lang.String value, java.lang.String category)
          This method will set the value for a specific property in the selected category.
 void setValidation(boolean validate)
          This method will set the flag if validation is used for parsing the file/stream from URL or not
 void store(java.io.File file)
          This method will save the current categories and their properties to a file
 void storeProperties(java.io.File file)
          This method will generate a Java-properties file.
 void storeProperties(java.io.File file, java.lang.String category)
          This method will write a Java-properties file and fill in the properties for the particular category.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

parameter

private static java.util.Hashtable parameter

categories

private static java.util.Vector categories

cfgmgr

private static ConfigurationManager cfgmgr

validate

private boolean validate
Constructor Detail

ConfigurationManager

public ConfigurationManager()
Method Detail

getProperty

public java.lang.String getProperty(java.lang.String key)
This method returns the value for a particular key The category is "general".

Parameters:
key - the name of the property
Returns:
the value as String or null

getProperty

public java.lang.String getProperty(java.lang.String key,
                                    java.lang.String defaultValue)
This method returns the value for a particular key. If this key does not exist then the method returns the defaultValue. The category is "general".

Parameters:
key - the name of the property
defaultValue - the value that will be returned if the property cannot be found
Returns:
the value as String or the defaultValue

getProperty

public java.lang.String getProperty(java.lang.String key,
                                    java.lang.String defaultValue,
                                    java.lang.String category)
This method returns the value for a particular key in the certain category. If this key does not exist then the method returns the defaultValue

Parameters:
key - the name of the property
defaultValue - the value that will be returned if the property cannot be found
category - the name of the category
Returns:
the value as String or the defaultValue

getInstance

public static ConfigurationManager getInstance()
This method returns an instance of the ConfigurationManager. If there is no instance then it will create a new one. In order to use the ConfigurationManager do the following: private ConfigurationManager cfgmgr = ConfigurationManager.getInstance();

Returns:
an instance of the ConfigurationManager

getCategoryNames

public java.util.Enumeration getCategoryNames()
This method returns an Enumeration of all categories. The names are stored as Strings inside the Enumeration.

Returns:
an enumeratiuon containing all names of all categories

getProperties

public java.util.Hashtable getProperties()
This method will return a Hashtable that contains all properties for the category "general". The properties are stored as key and value both as strings.

Returns:
a Hashtable that contains all properties for the category "general"

getProperties

public java.util.Hashtable getProperties(java.lang.String category)
This method will return a Hashtable that contains all properties for the selected category. The properties are stored as key and value both as strings.

Parameters:
category - the name of the category
Returns:
a Hashtable that contains all properties for this category

setProperty

public void setProperty(java.lang.String name,
                        java.lang.String value)
This method will set the value for a specific property in the category "general". If this property does not exist then it will be created

Parameters:
name - the name of the property
value - the value for this property

setProperty

public void setProperty(java.lang.String name,
                        java.lang.String value,
                        java.lang.String category)
This method will set the value for a specific property in the selected category. If this property does not exist then it will be created. If the category does not exist it will be created.

Parameters:
name - the name of the property
value - the value for this property
category - the name of the category

addCategory

public void addCategory(java.lang.String category)

store

public void store(java.io.File file)
           throws ConfigurationManagerException
This method will save the current categories and their properties to a file

Parameters:
file - the file that will be generated
Throws:
ConfigurationManagerException

processProperties

private void processProperties(org.w3c.dom.Document doc)

setValidation

public void setValidation(boolean validate)
This method will set the flag if validation is used for parsing the file/stream from URL or not

Parameters:
validate - true if the content should be validated first

load

public void load(java.io.File file)
          throws ConfigurationManagerException
This method will read in a file and generate the properties

Throws:
ConfigurationManagerException - if the file cannot be processed

load

public void load(java.lang.String theURL)
          throws ConfigurationManagerException
This method will read the content from an URL and generate the properties

Throws:
ConfigurationManagerException - if the file cannot be processed

loadProperties

public void loadProperties(java.io.File file)
                    throws ConfigurationManagerException
This method will store all categories and properties to a Java-properties file. All properties will be in the category "general". It will override an existing configuration.

Parameters:
file - the file
Throws:
ConfigurationManagerException - if the file cannot be processed

storeProperties

public void storeProperties(java.io.File file)
                     throws ConfigurationManagerException
This method will generate a Java-properties file. All categories will be saved as comments and only the properties are written to the file. The output is category.property=value

Parameters:
file - the file
Throws:
ConfigurationManagerException - if the file cannot be processed

storeProperties

public void storeProperties(java.io.File file,
                            java.lang.String category)
                     throws ConfigurationManagerException
This method will write a Java-properties file and fill in the properties for the particular category. The category will be saved as comment and only the properties are written to the file. The output is property=value. The category is not included in the property name.

Parameters:
file - the file
Throws:
ConfigurationManagerException - if the file cannot be processed