org.jconfig
Class ConfigurationManager

java.lang.Object
  |
  +--org.jconfig.ConfigurationManager

public class ConfigurationManager
extends java.lang.Object

This class manages all configurations. This is the main entry point. You can get the configurations from the ConfigurationManager. The simple way is:
public static final Configuration config = ConfigurationManager.getConfiguration();
or:
public static final Configuration config = ConfigurationManager.getConfiguration("myconfig");

If you use the getConfiguration() the ConfigurationManager will return the configuration with the name "default". If there is no configuration wit the given name then the ConfigurationManager will use the InputStreamHandler and will try to read the file "config.xml". This file has to be in the classpath.

Author:
Andreas Mecky andreas.mecky@xcom.de, Terry Dye terry.dye@xcom.de

Method Summary
 void addFileListener(java.lang.String configName, FileListener fl)
           
static Configuration getConfiguration()
          This method returns the configuration with the name "default".
static Configuration getConfiguration(java.lang.String name)
          This method returns the configuration for the specific name.
 ConfigurationHandler getConfigurationHandler(java.lang.String name)
          Returns the handler used during the creation of the Configuration.
 java.lang.String[] getConfigurationNames()
          This method will return all configurations names
static ConfigurationManager getInstance()
          This method returns the one and only instance of the ConfigurationManager.
 void load(ConfigurationHandler configurationHandler, java.lang.String configurationName)
          This method will load a configuration with the specific ConfigurationHandler and store it in the internal map with the given name.
 void reload(java.lang.String name)
          This method will reload a configuration with the same handler that was used for the initially loading.
 void removeConfiguration(java.lang.String configName)
          This method removes a configuration from the ConfigurationManager
 void save(ConfigurationHandler handler, Configuration config)
          This method will save a configuration using the defined ConfigurationHandler.
 void save(java.lang.String configName)
          This method will store the configuration for the given name using the associated handler that was used when the configuration was loaded.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static ConfigurationManager getInstance()
This method returns the one and only instance of the ConfigurationManager.
Returns:
the instance of the ConfigurationManager

getConfiguration

public static Configuration getConfiguration()
This method returns the configuration with the name "default". It calls getConfiguration("default").
Returns:
the configuration

getConfiguration

public static Configuration getConfiguration(java.lang.String name)
This method returns the configuration for the specific name. If there is no configuration then it will use the InputStreamHandler and take "config.xml" as filename.

Implementation detail: A new instance of the ConfigurationManager will be created/instantiated if one does not exist.

An empty Configuration will be returned if the Configuration sought after is not found.

This method will first look for a file called "name"_config.xml. If this file does not exist it will look for the default config.xml file.

Note that if the name is "default" then the method will directly look for the config.xml file since this is the reserved name for the default configuration.
Parameters:
name - the name of the configuration
Returns:
the configuration

load

public void load(ConfigurationHandler configurationHandler,
                 java.lang.String configurationName)
          throws ConfigurationManagerException
This method will load a configuration with the specific ConfigurationHandler and store it in the internal map with the given name.
Parameters:
configHandler - an implementation of the ConfigurationHandler
configurationName - the name of the configuration

save

public void save(java.lang.String configName)
          throws ConfigurationManagerException
This method will store the configuration for the given name using the associated handler that was used when the configuration was loaded.
Parameters:
configName - the name of the configuration
Throws:
ConfigurationManagerException -  

addFileListener

public void addFileListener(java.lang.String configName,
                            FileListener fl)

save

public void save(ConfigurationHandler handler,
                 Configuration config)
          throws ConfigurationManagerException
This method will save a configuration using the defined ConfigurationHandler. In most cases it is simpler to use the save(String configName) method since the ConfigurationManager stores the handler that is asscociated with the configuration. Use this method if you want to use a different handler. For example you have used the URLHandler to download a configuration from a webserver and now want to save the file to a local directory
Parameters:
handler - the ConfigurationHandler that will be used to store the configuration
config - the configuration to store
Throws:
ConfigurationManagerException -  

removeConfiguration

public void removeConfiguration(java.lang.String configName)
This method removes a configuration from the ConfigurationManager
Parameters:
configName - the name of the configuration

reload

public void reload(java.lang.String name)
            throws ConfigurationManagerException
This method will reload a configuration with the same handler that was used for the initially loading.
Parameters:
name - name of the configuration

getConfigurationHandler

public ConfigurationHandler getConfigurationHandler(java.lang.String name)
Returns the handler used during the creation of the Configuration.
Parameters:
name -  
Returns:
 
Since:
Aug 26, 2003 2:35:20 PM

getConfigurationNames

public java.lang.String[] getConfigurationNames()
This method will return all configurations names
Returns:
a String[] containing all configuration names


Copyright © 2001-2003 Andreas Mecky, Terry Dye. All Rights Reserved.