org.sape.carbon.core.config
Class Config

java.lang.Object
  |
  +--org.sape.carbon.core.config.Config
All Implemented Interfaces:
ConfigurationService

public class Config
extends Object
implements ConfigurationService

Config implements a static singleton pattern to provide a single point of access for configuration data. Configuration data in the form of Configuration objects can be accessed from an underlying data store, and written to an underlying data store via Config. The Config is the preferred class for accessing configuration data.

Copyright 2002 Sapient

Since:
carbon 1.0
Version:
$Revision: 1.27 $($Author: dvoet $ / $Date: 2003/12/11 18:43:31 $)
Author:
Mike Redd, January 2002

Field Summary
private  ConfigurationService configService
          Cached reference to the initial ConfigurationService in the system.
private static Config INSTANCE
          Reference to the one and only instance of this class, following the Item 2 in Josh Bloch's "Effective Java".
static String ROOT_NODE_NAME
          The name of the root node for use in the fetchNode method
 
Constructor Summary
private Config()
          Private constructor to ensure that others do not instantiate a unique Config object.
 
Method Summary
 void addNodeListener(String nodeName, ConfigurationEventListener listener)
          Adds a listener to the specified node.
 void addNodeListener(String nodeName, NodeEventListener listener)
          Adds a listener to the specified node.
 Configuration createConfiguration(Class configurationType)
           This method is the primary interface to create new instances of Configuration Objects.
 Configuration fetchConfiguration(String name)
           Returns a Configuration object that contains all of the configuration data in the ConfigurationDocument located by configurationName.
 Node fetchNode(String nodeName)
          Traverses the internal node hierachy and returns the named node
 Configuration fetchWritableConfiguration(String name)
           Returns a Configuration object that contains all of the configuration data in the ConfigurationDocument located by configurationName.
 ConfigurationService getConfigurationService()
          Provides static access to the Configuration Service.
static Config getInstance()
          Accessor to the single instance of Config.
 boolean nodeExists(String nodeName)
          Returns true if the node exists in the configuration repository and false if it does not exist.
 void storeConfiguration(String name, Configuration config)
           The storeConfiguration method persists configuration data contained in config to the underlying ConfigurationDocument named by configurationName.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INSTANCE

private static Config INSTANCE
Reference to the one and only instance of this class, following the Item 2 in Josh Bloch's "Effective Java".


ROOT_NODE_NAME

public static final String ROOT_NODE_NAME
The name of the root node for use in the fetchNode method


configService

private ConfigurationService configService
Cached reference to the initial ConfigurationService in the system.

Constructor Detail

Config

private Config()
Private constructor to ensure that others do not instantiate a unique Config object.

Method Detail

getInstance

public static Config getInstance()
Accessor to the single instance of Config.

Returns:
The single instance of Config.

fetchConfiguration

public Configuration fetchConfiguration(String name)
Description copied from interface: ConfigurationService

Returns a Configuration object that contains all of the configuration data in the ConfigurationDocument located by configurationName.

The returned configuration may be a shared object that is read-only. If it is, the configuration's writable flag is set to false and exceptions will be thrown if an attempt is made to modify the object.

Specified by:
fetchConfiguration in interface ConfigurationService
Parameters:
name - The name of the requested configuration
Returns:
Configuration object that may be used to access discrete configuration data.
See Also:
ConfigurationService.fetchConfiguration(java.lang.String)

fetchWritableConfiguration

public Configuration fetchWritableConfiguration(String name)
Description copied from interface: ConfigurationService

Returns a Configuration object that contains all of the configuration data in the ConfigurationDocument located by configurationName.

The returned configuration is a mutable object and not thread-safe. All access to this object should be in a single threaded or synchronized context. To commit the changes that have been made to this object use the storeConfiguration method.

Specified by:
fetchWritableConfiguration in interface ConfigurationService
Parameters:
name - The name of the requested configuration
Returns:
Configuration object that may be used to access discrete configuration data.
See Also:
ConfigurationService.fetchWritableConfiguration(java.lang.String)

storeConfiguration

public void storeConfiguration(String name,
                               Configuration config)
                        throws ConfigurationStoreException
Description copied from interface: ConfigurationService

The storeConfiguration method persists configuration data contained in config to the underlying ConfigurationDocument named by configurationName. If the ConfigurationDocument does not exist, it is created along with all of its parent Nodes.

Specified by:
storeConfiguration in interface ConfigurationService
Parameters:
name - The name of the Configuration Document where the configuration data should be stored.
config - Configuration data to be persisted to the underlying data store.
Throws:
ConfigurationStoreException - data can not be written to the backing store.
See Also:
ConfigurationService.storeConfiguration(java.lang.String, org.sape.carbon.core.config.Configuration)

createConfiguration

public Configuration createConfiguration(Class configurationType)
Description copied from interface: ConfigurationService

This method is the primary interface to create new instances of Configuration Objects. This method is capable of creating an empty configuration object for an interface that extends the Configuration interface.

Specified by:
createConfiguration in interface ConfigurationService
Parameters:
configurationType - The Class of the configuration type to be created
Returns:
an empty instance of a configuration object implementing the provided class.
See Also:
ConfigurationService.createConfiguration(java.lang.Class)

fetchNode

public Node fetchNode(String nodeName)
               throws NodeNotFoundException
Description copied from interface: ConfigurationService
Traverses the internal node hierachy and returns the named node

Specified by:
fetchNode in interface ConfigurationService
Parameters:
nodeName - the '/' delimeted path to the node
Returns:
The node specifed by nodeName.
Throws:
NodeNotFoundException - when the cannot be found.
See Also:
ConfigurationService.fetchNode(java.lang.String)

nodeExists

public boolean nodeExists(String nodeName)
Description copied from interface: ConfigurationService
Returns true if the node exists in the configuration repository and false if it does not exist. This is meant to be an alternative to getting Node not found exceptions when you have nodes that aren't required.

Specified by:
nodeExists in interface ConfigurationService
Parameters:
nodeName - the '/' delimeted path to the node
Returns:
if the node exists
See Also:
ConfigurationService.nodeExists(java.lang.String)

addNodeListener

public void addNodeListener(String nodeName,
                            NodeEventListener listener)
                     throws NodeNotFoundException
Deprecated. use void addNodeListener(String nodeName, ConfigurationEventListener listener) instead

Description copied from interface: ConfigurationService
Adds a listener to the specified node.

Specified by:
addNodeListener in interface ConfigurationService
Parameters:
nodeName - the '/' delimeted path to the node
listener - the object that will be notified of NodeEvents
Throws:
NodeNotFoundException - if nodeName does not exist
See Also:
ConfigurationService.addNodeListener(String, NodeEventListener)

addNodeListener

public void addNodeListener(String nodeName,
                            ConfigurationEventListener listener)
                     throws NodeNotFoundException
Description copied from interface: ConfigurationService
Adds a listener to the specified node.

Specified by:
addNodeListener in interface ConfigurationService
Parameters:
nodeName - the '/' delimeted path to the node
listener - the object that will be notified of NodeEvents
Throws:
NodeNotFoundException - if nodeName does not exist
See Also:
ConfigurationService.addNodeListener(String, ConfigurationEventListener)

getConfigurationService

public ConfigurationService getConfigurationService()
Provides static access to the Configuration Service.

Returns:
returns the configuration service used by default in the system.


Copyright 1999-2003 Sapient Corporation. All Rights Reserved.