com.objectwave.configuration.xml
Class XmlConfigurationService

java.lang.Object
  |
  +--com.objectwave.configuration.xml.XmlConfigurationService
All Implemented Interfaces:
ConfigurationService

public class XmlConfigurationService
extends java.lang.Object
implements ConfigurationService

To use XML to configure your application, use this class as the default configuration service.
To use simply do the following

 ConfigurationService srvc = new XmlConfigurationService();
 ConfigurationServiceFactory.setDefaultConfigurationService( srvc );
 

Version:
$Id: XmlConfigurationService.java,v 1.1 2002/08/12 20:14:57 dave_hoag Exp $
Author:
David Hoag

Nested Class Summary
static class XmlConfigurationService.Test
           
 
Field Summary
protected  PropertyObjects propertyObjects
           
 
Constructor Summary
XmlConfigurationService()
          Constructor for the XmlConfigurationService object
 
Method Summary
 void addSupport(java.lang.String path, java.lang.String className)
           
 java.lang.String getCategoryId(PropertySource source)
          Categories are identified by the full name of the property source.
protected  java.lang.String getDefaultKey(PropertySource context)
          Gets the default key.
protected  java.lang.Object getDetail(PropertySource context, java.lang.String categoryId)
          Find the existing detail object.
 java.lang.Object getPropertyHolder(PropertySource context)
          Create and return an instance of the PropertyDetail.
 java.lang.Object getPropertyHolder(PropertySource context, java.lang.String categoryId)
          For the provided property source and category, locate & populate the PropertyDetail.
protected  java.lang.Object getPropertyHolderFromParser(PropertySource context, java.lang.String categoryId, javax.xml.parsers.SAXParser saxParser)
          Locate the XML document for the context and category, parse it, and set values on a new PropertyDetail.
protected  org.xml.sax.InputSource getXmlInputSource(PropertySource context, java.lang.String categoryId)
          Use an instance of XmlBootstrap to locate an XML document for the specified context and category.
protected  java.util.HashMap initDefaultStrategy(PropertySource context)
          This allows users of the configuration service to not specify Xml path to class mappings.
 void initialize()
          A unique cache of details per Configuration service instance.
protected static void initializeSaxParser()
           
protected  boolean isCachingDetail()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

propertyObjects

protected PropertyObjects propertyObjects
Constructor Detail

XmlConfigurationService

public XmlConfigurationService()
Constructor for the XmlConfigurationService object

Method Detail

initializeSaxParser

protected static void initializeSaxParser()

getCategoryId

public java.lang.String getCategoryId(PropertySource source)
Categories are identified by the full name of the property source.

Specified by:
getCategoryId in interface ConfigurationService
Parameters:
source -
Returns:
The CategoryId value

getPropertyHolder

public java.lang.Object getPropertyHolder(PropertySource context)
                                   throws ConfigurationException
Create and return an instance of the PropertyDetail. The instance will have its values set from the configuration service.

Specified by:
getPropertyHolder in interface ConfigurationService
Parameters:
context - The PropertySource attempting to locate the property detail.
Returns:
An instance of the context.getExpectClass filled with configured values.
Throws:
ConfigurationException

getPropertyHolder

public java.lang.Object getPropertyHolder(PropertySource context,
                                          java.lang.String categoryId)
                                   throws ConfigurationException
For the provided property source and category, locate & populate the PropertyDetail.

Specified by:
getPropertyHolder in interface ConfigurationService
Parameters:
context - The PropertySource attempting to locate the property detail.
categoryId - Likely the full class name of the property source.
Returns:
An instance of the context.getExpectClass filled with configured values.
Throws:
ConfigurationException

getDetail

protected java.lang.Object getDetail(PropertySource context,
                                     java.lang.String categoryId)
                              throws ConfigurationException
Find the existing detail object.

Parameters:
context - The object that will want this property information.
categoryId - The id that should uniquely identify the desired properties.
Returns:
An object that will have all of its declared fields set to values.
Throws:
ConfigurationException

getPropertyHolderFromParser

protected java.lang.Object getPropertyHolderFromParser(PropertySource context,
                                                       java.lang.String categoryId,
                                                       javax.xml.parsers.SAXParser saxParser)
                                                throws java.lang.Exception
Locate the XML document for the context and category, parse it, and set values on a new PropertyDetail.

Parameters:
context -
categoryId -
saxParser -
Returns:
An instance of the context.getExpectClass filled with configured values.
Throws:
java.lang.Exception - There are MANY ways we can fail

getDefaultKey

protected java.lang.String getDefaultKey(PropertySource context)
Gets the default key. This assumes that the root node of the XML property file matches the Class name of the expected class.

Parameters:
context -
Returns:
The DerrivedKey value

getXmlInputSource

protected org.xml.sax.InputSource getXmlInputSource(PropertySource context,
                                                    java.lang.String categoryId)
                                             throws java.lang.Exception
Use an instance of XmlBootstrap to locate an XML document for the specified context and category.

Parameters:
context - The Object looking for a PropertyDetails.
categoryId - Likely the full class name of the context.getExpectedClass
Returns:
The value provide the XML parser to get property values.
Throws:
java.lang.Exception
See Also:
XmlBootstrap.locateXmlMap(com.objectwave.configuration.PropertySource, java.lang.String)

isCachingDetail

protected boolean isCachingDetail()
Returns:
The CachingDetail value

initialize

public void initialize()
A unique cache of details per Configuration service instance.


addSupport

public void addSupport(java.lang.String path,
                       java.lang.String className)
Parameters:
path - The XML nodes that should translate to a Java class
className - The class to instantiate for each XML node of type path

initDefaultStrategy

protected java.util.HashMap initDefaultStrategy(PropertySource context)
This allows users of the configuration service to not specify Xml path to class mappings. It assumes that the Path will be the Class name (sans the package portion) of the expected class on the property source context.
Xml of will map to class context.getExpectedClass().getName().

Parameters:
context - The source attempting to locate property detail.
Returns: