org.sapia.util.xml.confix
Class ReflectionFactory

java.lang.Object
  |
  +--org.sapia.util.xml.confix.ReflectionFactory
All Implemented Interfaces:
ObjectFactoryIF

public class ReflectionFactory
extends 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

Constructor Summary
ReflectionFactory(String[] somePackages)
          Creates a new ReflectionFactory instance with the arguments passed in.
 
Method Summary
 void addPackage(String aPackage)
          Adds the package passed in to this factory.
static String firstToUpper(String aString)
          Utility to change the first letter of the string passed in to uppercase.
protected static Object invokeMethod(String aMethodPrefix, String anElementName, Object aTarget)
          Invokes a method on the target object using the method prefix and the element name passed in.
 CreationStatus newObjectFor(String aPrefix, String aNamespaceURI, String anElementName, 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(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 String firstToUpper(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 Object invokeMethod(String aMethodPrefix,
                                     String anElementName,
                                     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.

addPackage

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

Parameters:
aPackage - The package to add.

newObjectFor

public CreationStatus newObjectFor(String aPrefix,
                                   String aNamespaceURI,
                                   String anElementName,
                                   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 © 2002 Sapia Open Source Software. All Rights Reserved.