org.sape.carbon.core.config.format
Class DefaultConfigurationFormatService

java.lang.Object
  |
  +--org.sape.carbon.core.config.format.DefaultConfigurationFormatService
All Implemented Interfaces:
ConfigurationFormatService

public class DefaultConfigurationFormatService
extends Object
implements ConfigurationFormatService

This default implementation of the configuration format serivce provides an XML based configuration to implemented interface form of configurations.

Copyright 2002 Sapient

Since:
carbon 1.0
Version:
$Revision: 1.34 $($Author: dvoet $ / $Date: 2003/07/29 18:57:25 $)
Author:
Greg Hinkle, January 2002

Field Summary
private  org.apache.commons.logging.Log log
          Provides a handle to Apache-commons logger
 
Constructor Summary
DefaultConfigurationFormatService()
           
 
Method Summary
 void alterChildConfiguration(Configuration parentConfig, String childName, Configuration newConfig)
          Alters the configuration named by childName within parentConfig, setting it to the value of newConfig.
protected  String constructIndexedName(String parentName, String name, int index)
          Creates an indexed name for use within the format service.
protected  String constructMapName(String parentName, String name, String key)
          Creates an indexed name for use within the format service.
 Configuration getChildConfiguration(Configuration parentConfig, String childName)
          Gets the child Configuration object of parentConfig that is named by the childName.
 Set getChildConfigurationNames(Configuration parentConfig)
          This implementation uses Introspection to determine the list of all attributes the parentConfig contains.
private  Class getContentType(Class configurationType, String attrName)
          Gets the type of class contained within the given map.
 Configuration newConfiguration(Class configurationClass)
           Creates a new configuration object of the type specified.
 Configuration readConfigurationStream(String name, InputStream in)
          Loads a Configuration object from the given InputStream.
 void writeConfigurationStream(Configuration configuration, OutputStream out)
          Stores the raw version of the provided Configuration object in the format that this format service implementation understands.
 
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

Constructor Detail

DefaultConfigurationFormatService

public DefaultConfigurationFormatService()
Method Detail

newConfiguration

public Configuration newConfiguration(Class configurationClass)

Creates a new configuration object of the type specified.

Specified by:
newConfiguration in interface ConfigurationFormatService
Parameters:
configurationClass - type of the configuration object to build
Returns:
the newly created configuration

readConfigurationStream

public Configuration readConfigurationStream(String name,
                                             InputStream in)
                                      throws ConfigurationFormatException

Loads a Configuration object from the given InputStream. This Configuration object will represent the full object-graph depiction of a live configuration.

Specified by:
readConfigurationStream in interface ConfigurationFormatService
Parameters:
name - The name of the configuration node
in - the InputStream from which the configuration will be read
Returns:
The Configuration object representing a live object graph of the data from the input stream
Throws:
ConfigurationFormatException - when there is a formatting error with the input stream

writeConfigurationStream

public void writeConfigurationStream(Configuration configuration,
                                     OutputStream out)
                              throws ConfigurationFormatException

Stores the raw version of the provided Configuration object in the format that this format service implementation understands.

Specified by:
writeConfigurationStream in interface ConfigurationFormatService
Parameters:
out - The output stream to which the raw configuration data should be written
configuration - The Configuration object to be stored; may be any subclass of Configuration
Throws:
ConfigurationFormatException - When unable to write a configuration's raw format to the output stream

constructIndexedName

protected String constructIndexedName(String parentName,
                                      String name,
                                      int index)
Creates an indexed name for use within the format service. If parentName is not null, an absolute name is created, otherwise, parentName is ignored.

Parameters:
parentName - for use when creating absolute indexed names, can be null for creating local names
name - name of indexed attribute, cannot be null
index - cannot be negative
Returns:
String indexed name
Since:
carbon 1.1

constructMapName

protected String constructMapName(String parentName,
                                  String name,
                                  String key)
Creates an indexed name for use within the format service. If parentName is not null, an absolute name is created, otherwise, parentName is ignored.

Parameters:
parentName - for use when creating absolute indexed names, can be null for creating local names
name - name of indexed attribute, cannot be null
key - they lookup key for the map attribute
Returns:
String indexed name
Since:
carbon 2.0

getChildConfiguration

public Configuration getChildConfiguration(Configuration parentConfig,
                                           String childName)
Description copied from interface: ConfigurationFormatService
Gets the child Configuration object of parentConfig that is named by the childName. childName may be an indexed (see constructIndexedName). Returns null if it does not exist.

Specified by:
getChildConfiguration in interface ConfigurationFormatService
Parameters:
parentConfig - parent of requested child configuration
childName - child configuration name
Returns:
Configuration the requested child or null if it does not exist with in config
See Also:
ConfigurationFormatService.getChildConfiguration(org.sape.carbon.core.config.Configuration, java.lang.String)

getChildConfigurationNames

public Set getChildConfigurationNames(Configuration parentConfig)
This implementation uses Introspection to determine the list of all attributes the parentConfig contains. It then uses the ConfigurationTypeService to determine which of those attributes are actually sub-configurations (i.e. complex types). If an attribute is a Map or Array, the actual data is retrieved from parentConfig and a name is returned for each element.

Specified by:
getChildConfigurationNames in interface ConfigurationFormatService
Parameters:
parentConfig - parent of requested child configuration names
Returns:
Set all child names, never null
See Also:
ConfigurationFormatService.getChildConfigurationNames(org.sape.carbon.core.config.Configuration)

alterChildConfiguration

public void alterChildConfiguration(Configuration parentConfig,
                                    String childName,
                                    Configuration newConfig)
Description copied from interface: ConfigurationFormatService
Alters the configuration named by childName within parentConfig, setting it to the value of newConfig. Note that if newConfig is has a name that falls outside of parentConfig a reference to newConfig is created, otherwise (newConfig.getConfigurationName().startsWith(parentConfig.getConfigurationName()) || newConfig.getConfigurationName() == null), the new value of childName is the actual value of newConfig. If the child does not exits, it is created. If newConfig is null, the child is removed.

Specified by:
alterChildConfiguration in interface ConfigurationFormatService
Parameters:
parentConfig - the parent containing childName
childName - the child to be altered
newConfig - the new value for the child config
See Also:
ConfigurationFormatService.alterChildConfiguration(org.sape.carbon.core.config.Configuration, java.lang.String, org.sape.carbon.core.config.Configuration)

getContentType

private Class getContentType(Class configurationType,
                             String attrName)
Gets the type of class contained within the given map. This assumes that all elements in the map are the same class.

Returns:
the type of class contained within the map.


Copyright 1999-2003 Sapient Corporation. All Rights Reserved.