org.sape.carbon.core.config
Class DefaultRootConfigurationService

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

public class DefaultRootConfigurationService
extends Object
implements ConfigurationService

Implementation of RootConfigurationService that traverses the node tree to fetch and store configuration data. Copyright 2001 Sapient

Since:
carbon 1.0
Version:
$Revision: 1.43 $($Author: dvoet $ / $Date: 2003/12/11 18:43:31 $)
Author:
Greg Hinkle, December 2001

Field Summary
private  ConfigurationCache cache
          Cache storing previously accessed configuration objects.
private  org.apache.commons.logging.Log log
          Provides a handle to Apache-commons logger
private  Node rootNode
          Handle to the root node used by this ConfigurationService.
 
Constructor Summary
protected DefaultRootConfigurationService(ConfigurationDocument configurationDocument)
          protected constructor prevents direct instantiation by classes other than the DefaultConfigurationServiceFactory but does not prevent extension.
 
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 configurationName)
           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 configurationName)
           Returns a Configuration object that contains all of the configuration data in the ConfigurationDocument located by configurationName.
private  String getRemainingTokens(StringTokenizer tokenizer)
          Assembles the remaining tokens into a string, used for error messages.
private  void initialize(ConfigurationDocument rootConfigurationDoc)
          Reads a LinkNodeConfiguration from the rootConfigurationDoc and uses the configured LinkNodeFactoryClass to create a new Node that is then set as the root node for the ConfigurationService.
 boolean nodeExists(String nodeName)
          Returns true if the node exists in the configuration repository and false if it does not exist.
private  Node recursiveNodeTraversal(Node node, StringTokenizer tokenizer)
          Returns the Node found by recursively fetching the next node name from tokenizer and scaling the node tree.
private  void recursiveStoreConfiguration(Node node, Configuration config, StringTokenizer tokenizer)
          Traverses down the node adding the sub-nodes.
private  boolean recursiveTraverseNodeTreeForNodeExists(Node node, StringTokenizer tokenizer)
          Returns true if a node is found by recursively tokenizing the configurationName by '/' characters and scaling the node tree.
 void storeConfiguration(String configurationName, Configuration config)
           The storeConfiguration method persists configuration data contained in config to the underlying ConfigurationDocument named by configurationName.
private  Node traverseNodeTree(String configurationName)
          Returns the Node found by recursively tokenizing the configurationName by '/' characters and scaling the node tree.
private  boolean traverseNodeTreeForNodeExists(String configurationName)
          Returns true if a node is found by recursively tokenizing the configurationName by '/' characters and scaling the node tree.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private org.apache.commons.logging.Log log
Provides a handle to Apache-commons logger


rootNode

private Node rootNode
Handle to the root node used by this ConfigurationService.


cache

private ConfigurationCache cache
Cache storing previously accessed configuration objects.

Since:
carbon 1.1
Constructor Detail

DefaultRootConfigurationService

protected DefaultRootConfigurationService(ConfigurationDocument configurationDocument)
protected constructor prevents direct instantiation by classes other than the DefaultConfigurationServiceFactory but does not prevent extension.

Parameters:
configurationDocument - the configuration document being loaded
Method Detail

fetchConfiguration

public Configuration fetchConfiguration(String configurationName)
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:
configurationName - 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 configurationName)
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:
configurationName - 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 configurationName,
                               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:
configurationName - 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)

addNodeListener

public void addNodeListener(String nodeName,
                            NodeEventListener 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, 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)

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)

initialize

private void initialize(ConfigurationDocument rootConfigurationDoc)
Reads a LinkNodeConfiguration from the rootConfigurationDoc and uses the configured LinkNodeFactoryClass to create a new Node that is then set as the root node for the ConfigurationService.

Parameters:
rootConfigurationDoc - Contains data required to initialize this instance of ConfigurationService and its root node.
See Also:
LinkNode, LinkNodeConfiguration

traverseNodeTree

private Node traverseNodeTree(String configurationName)
                       throws NodeNotFoundException
Returns the Node found by recursively tokenizing the configurationName by '/' characters and scaling the node tree.

Parameters:
configurationName - The full logical name of the configuration to be fetched, such as /nodeA/nodeB/configuration1.
Returns:
The node corresponding to configurationName.
Throws:
NodeNotFoundException - when a node can not be fetched.

recursiveNodeTraversal

private Node recursiveNodeTraversal(Node node,
                                    StringTokenizer tokenizer)
                             throws NodeNotFoundException
Returns the Node found by recursively fetching the next node name from tokenizer and scaling the node tree.

Parameters:
node - the current parent node in the node traversal.
tokenizer - The StringTokenizer used to access the next node to be traversed.
Returns:
The node corresponding to the final token in tokenizer.
Throws:
NodeNotFoundException - when a node can not be fetched.

traverseNodeTreeForNodeExists

private boolean traverseNodeTreeForNodeExists(String configurationName)
Returns true if a node is found by recursively tokenizing the configurationName by '/' characters and scaling the node tree.

Parameters:
configurationName - The full logical name of the configuration to be fetched, such as /nodeA/nodeB/configuration1.
Returns:
true if the node exists or false otherwise
Since:
carbon 1.1

recursiveTraverseNodeTreeForNodeExists

private boolean recursiveTraverseNodeTreeForNodeExists(Node node,
                                                       StringTokenizer tokenizer)
Returns true if a node is found by recursively tokenizing the configurationName by '/' characters and scaling the node tree.

Parameters:
node - the current parent node in the node traversal.
tokenizer - The StringTokenizer used to access the next node to be traversed.
Returns:
true if the node exists or false otherwise
Since:
carbon 1.1

recursiveStoreConfiguration

private void recursiveStoreConfiguration(Node node,
                                         Configuration config,
                                         StringTokenizer tokenizer)
                                  throws NodeCreationException,
                                         NodeIOException,
                                         ConfigurationFormatException
Traverses down the node adding the sub-nodes.

Parameters:
node - the node to add the children to
config - configuration to store
tokenizer - tokenizer of the full node name
Throws:
NodeCreationException - indicates an error creating the node
NodeIOException - indicates an error reading the node
ConfigurationFormatException - indicates an error in format of the configuration

getRemainingTokens

private String getRemainingTokens(StringTokenizer tokenizer)
Assembles the remaining tokens into a string, used for error messages.

Parameters:
tokenizer - the tokenizer to pull tokens from
Returns:
the remaining tokens delimited by Node.DELIMITER


Copyright 1999-2003 Sapient Corporation. All Rights Reserved.