org.sapia.util.xml.confix
Class ReflectionFactory

java.lang.Object
  extended by org.sapia.util.xml.confix.ReflectionFactory
All Implemented Interfaces:
ObjectFactoryIF

public class ReflectionFactory
extends java.lang.Object
implements ObjectFactoryIF

This class instantiates objects based on the name of XML elements, using these names to dynamically find the class of the objects to instantiate.

Author:
Yanick Duchesne
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

Nested Class Summary
static class ReflectionFactory.NullObjectImpl
           
 
Constructor Summary
ReflectionFactory(java.lang.String[] somePackages)
          Creates a new ReflectionFactory instance with the arguments passed in.
 
Method Summary
 void addPackage(java.lang.String aPackage)
          Adds the package passed in to this factory.
protected static java.lang.reflect.Method findVoidMethod(java.lang.Class owner, java.lang.String name)
           
static java.lang.String firstToUpper(java.lang.String aString)
          Utility to change the first letter of the string passed in to uppercase.
protected static java.lang.Object invokeMethod(java.lang.String aMethodPrefix, java.lang.String anElementName, java.lang.Object aTarget)
          Invokes a method on the target object using the method prefix and the element name passed in.
protected static boolean invokeVoidMethod(java.lang.Object aTarget, java.lang.String elementName)
           
 CreationStatus newObjectFor(java.lang.String aPrefix, java.lang.String aNamespaceURI, java.lang.String anElementName, java.lang.Object aParent)
          Creates an object for the element passed in.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReflectionFactory

public ReflectionFactory(java.lang.String[] somePackages)
Creates a new ReflectionFactory instance with the arguments passed in.

Parameters:
somePackages - The package from which to use reflection.
Method Detail

firstToUpper

public static java.lang.String firstToUpper(java.lang.String aString)
Utility to change the first letter of the string passed in to uppercase.

Returns:
The new string with the first letter in uppercase.

invokeMethod

protected static java.lang.Object invokeMethod(java.lang.String aMethodPrefix,
                                               java.lang.String anElementName,
                                               java.lang.Object aTarget)
Invokes a method on the target object using the method prefix and the element name passed in.

Parameters:
aMethodPrefix - The prefix of the method to call (create, add, ...).
anElementName - The element name for which we have to invoke a method.
aTarget - The target object on which the method invocation is done.
Returns:
The result of the method invocation or null if the method call failed.

invokeVoidMethod

protected static boolean invokeVoidMethod(java.lang.Object aTarget,
                                          java.lang.String elementName)

findVoidMethod

protected static java.lang.reflect.Method findVoidMethod(java.lang.Class owner,
                                                         java.lang.String name)

addPackage

public void addPackage(java.lang.String aPackage)
Adds the package passed in to this factory.

Parameters:
aPackage - The package to add.

newObjectFor

public CreationStatus newObjectFor(java.lang.String aPrefix,
                                   java.lang.String aNamespaceURI,
                                   java.lang.String anElementName,
                                   java.lang.Object aParent)
                            throws ObjectCreationException
Creates an object for the element passed in.

Specified by:
newObjectFor in interface ObjectFactoryIF
Parameters:
aPrefix - The namespace prefix of the element.
aNamespaceURI - The namespace URI of the element.
anElementName - The element name for wich to create an object.
aParent - The parent object of the object to create.
Throws:
ObjectCreationException - If an error occurs creating the object.


Copyright © 2011 Sapia OSS. All Rights Reserved.