com.objectwave.configuration.xml
Class ObjectBuilder

java.lang.Object
  |
  +--org.xml.sax.helpers.DefaultHandler
        |
        +--com.objectwave.configuration.xml.ObjectBuilder
All Implemented Interfaces:
org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler

public class ObjectBuilder
extends org.xml.sax.helpers.DefaultHandler

Look for a method of the set'VariableName' style. If the parameter type of the source object does not match the parameter type in the method, an attempt is made to convert tye type to the proper type. This class does not use ANY features from the inherited class (other than the constructor).

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

Constructor Summary
ObjectBuilder()
          Constructor for the ObjectBuilder object
 
Method Summary
 void associate(java.lang.String key, java.lang.String fullyQualifiedClassName)
           
 void connect(java.lang.Object parentObject, java.lang.String childName, java.lang.Object childObject)
          Connects the child to the parent object
protected  java.lang.Object createObject(java.lang.String className, org.xml.sax.Attributes atts)
           
protected  java.lang.reflect.Method findMutatorMethod(java.lang.Object source, java.lang.String methodName)
          Find a method called methodName.
protected  java.lang.Object[] getParameterValues(java.lang.reflect.Method method, java.lang.Object parameter)
          Assumes that the method takes 1 and only 1 parameter on the provided method.
 java.lang.Object getResult()
           
 void setObjectFormatter(ObjectFormatter value)
          Sets the ObjectFormatter attribute of the ObjectBuilder object
 void setTagToClassMap(java.util.Map map)
           
protected  void setValueWithMethod(java.lang.Object source, java.lang.Object parameter, java.lang.String methodName)
          Set the parameter value on the source object using the method methodName.
 void startElement(java.lang.String uri, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes atts)
           
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
characters, endDocument, endElement, endPrefixMapping, error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, startDocument, startPrefixMapping, unparsedEntityDecl, warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ObjectBuilder

public ObjectBuilder()
Constructor for the ObjectBuilder object

Method Detail

setTagToClassMap

public void setTagToClassMap(java.util.Map map)

getResult

public java.lang.Object getResult()

associate

public void associate(java.lang.String key,
                      java.lang.String fullyQualifiedClassName)

startElement

public void startElement(java.lang.String uri,
                         java.lang.String localName,
                         java.lang.String qName,
                         org.xml.sax.Attributes atts)
                  throws org.xml.sax.SAXException
Specified by:
startElement in interface org.xml.sax.ContentHandler
Overrides:
startElement in class org.xml.sax.helpers.DefaultHandler
org.xml.sax.SAXException

createObject

protected java.lang.Object createObject(java.lang.String className,
                                        org.xml.sax.Attributes atts)
                                 throws org.xml.sax.SAXException,
                                        java.lang.IllegalAccessException,
                                        java.lang.ClassNotFoundException,
                                        java.lang.InstantiationException
org.xml.sax.SAXException
java.lang.IllegalAccessException
java.lang.ClassNotFoundException
java.lang.InstantiationException

setObjectFormatter

public void setObjectFormatter(ObjectFormatter value)
Sets the ObjectFormatter attribute of the ObjectBuilder object

Parameters:
value - The new ObjectFormatter value

setValueWithMethod

protected void setValueWithMethod(java.lang.Object source,
                                  java.lang.Object parameter,
                                  java.lang.String methodName)
                           throws NotFoundException,
                                  java.lang.reflect.InvocationTargetException,
                                  java.lang.IllegalAccessException
Set the parameter value on the source object using the method methodName.

Parameters:
source - The object being changed.
parameter - A value to set on source.
methodName - A name of the method that should exist on source.
Throws:
NotFoundException - The method specified could not be found.
java.lang.reflect.InvocationTargetException - Trouble setting the value
java.lang.IllegalAccessException - No access rights to the method.

getParameterValues

protected java.lang.Object[] getParameterValues(java.lang.reflect.Method method,
                                                java.lang.Object parameter)
Assumes that the method takes 1 and only 1 parameter on the provided method. Convert the parameter to a class of the correct type.

Parameters:
method - A single argument method
parameter - The original parameter that is to be provided to the method.
Returns:
An Object [] that can be used as a parameter to the reflected invoke method.

connect

public void connect(java.lang.Object parentObject,
                    java.lang.String childName,
                    java.lang.Object childObject)
Connects the child to the parent object

Parameters:
parentObject - - The root object (ex. FruitBasket)
childObject - - The sub object of the root object (ex. Apple)
childName - - The logical name of the childObject

findMutatorMethod

protected java.lang.reflect.Method findMutatorMethod(java.lang.Object source,
                                                     java.lang.String methodName)
                                              throws NotFoundException
Find a method called methodName.

Parameters:
source -
methodName -
Returns:
Throws:
NotFoundException