org.sapia.util.xml.confix
Class AbstractXMLProcessor

java.lang.Object
  |
  +--org.sapia.util.xml.confix.AbstractXMLProcessor
All Implemented Interfaces:
ConfixProcessorIF
Direct Known Subclasses:
Dom4jProcessor, JDOMProcessor, SAXProcessor

public abstract class AbstractXMLProcessor
extends Object
implements ConfixProcessorIF

This class defines the behavior for generating an object graph from an XML document.

Author:
Yanick Duchesne, Jean-Cedric Desrochers
Copyright:
Copyright © 2002-2003 Sapia Open Source Software. All Rights Reserved.
License:
Read the license.txt file of the jar or visit the license page at the Sapia OSS web site

Constructor Summary
AbstractXMLProcessor(ObjectFactoryIF anObjectFactory)
          Creates a new AbstractXMLProcessor instance with the argument passed in.
 
Method Summary
protected static void assignToParent(Object aParent, Object aChild, String anElementName)
          Assigns the given child object to the parent one.
protected static boolean containsMethod(String prefix, Object target, String elemName)
           
protected static String convertChars(char[] toConvert, String aSource)
           
protected static String formatElementName(String elemName)
          Formats an element name according to the rules defined by the above method.
protected  ObjectFactoryIF getObjectFactory()
          Returns the ObjectFactoryIF method held within this instance.
protected static Object invokeMethod(String aMethodName, Object aTarget, Object aValue)
          Invokes the method whose name is given on the provided target instance.
protected static void invokeSetter(String anElementName, Object aTarget, String anAttributeName, String aValue)
          Invokes the setXXXX/addXXXX method corresponding to the given attribute name.
protected static String toMethodName(String attrName)
          Converts the given attribute name to a method name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.sapia.util.xml.confix.ConfixProcessorIF
process
 

Constructor Detail

AbstractXMLProcessor

public AbstractXMLProcessor(ObjectFactoryIF anObjectFactory)
Creates a new AbstractXMLProcessor instance with the argument passed in.

Parameters:
anObjectFactory - The object factory of this processor.
Method Detail

assignToParent

protected static void assignToParent(Object aParent,
                                     Object aChild,
                                     String anElementName)
                              throws ConfigurationException
Assigns the given child object to the parent one. This method searches for the method name based on the elementName parameter, which is the name of an XML element. The method name must match either the setXXX or addXXX pattern; for example, for an XML element named 'elephant', the class of the parent object should contain either the setElephant or addElephant method.

Parameters:
aParent - the object to child will be set or added
aChild - the object to add to parent
anElementName - the name of the XML element to which a addXXX or setXXX method should correspond in the parent object.
Throws:
ConfigurationException

invokeSetter

protected static void invokeSetter(String anElementName,
                                   Object aTarget,
                                   String anAttributeName,
                                   String aValue)
                            throws ConfigurationException
Invokes the setXXXX/addXXXX method corresponding to the given attribute name. The method is invoked on the target instance. The passed in value is coerced to the type expected by the setter or adder method.

Parameters:
anElementName - the XML element name corresponding to the passed in target.
aTarget - the instance on which to invoke the method.
anAttributeName - the name of the attribute whose corresponding method is called.
aValue - the value to assign to the setter/adder method - the value is coerced to the type expected by the method.
ConfigurationException

invokeMethod

protected static Object invokeMethod(String aMethodName,
                                     Object aTarget,
                                     Object aValue)
                              throws ConfigurationException,
                                     NoSuchMethodException
Invokes the method whose name is given on the provided target instance.

Parameters:
aMethodName - the name of the method to invoke.
aTarget - the instance on which to invoke the method.
aValue - the value to pass to the method that will be called.
ConfigurationException
NoSuchMethodException

toMethodName

protected static String toMethodName(String attrName)
Converts the given attribute name to a method name. The following indicates how attribute names are converted to method names - the method name does not include the "set" or "add" prefix. All the following attribute names are resolved to "FirstName":


containsMethod

protected static boolean containsMethod(String prefix,
                                        Object target,
                                        String elemName)

formatElementName

protected static String formatElementName(String elemName)
Formats an element name according to the rules defined by the above method.


convertChars

protected static String convertChars(char[] toConvert,
                                     String aSource)

getObjectFactory

protected ObjectFactoryIF getObjectFactory()
Returns the ObjectFactoryIF method held within this instance.



Copyright © 2002 Sapia Open Source Software. All Rights Reserved.