net.sf.xolite.utils
Class ClassObjectFactory

java.lang.Object
  extended by net.sf.xolite.utils.ClassObjectFactory
All Implemented Interfaces:
XMLObjectFactory

public class ClassObjectFactory
extends Object
implements XMLObjectFactory

Simple implementation of XmlObjectFactory based on class names.
Using this factory implies that the objects constructed by the factory have public constructor with no parameters.


Constructor Summary
ClassObjectFactory()
           
 
Method Summary
 XMLSerializable createObject(String namespaceUri, String localName, XMLEventParser parser)
          Create an object corresponding to the XML element of the given name.
 void defineElement(String localName, Class<?> clazz)
          Add the definition of an element without namespace to this factory.
 void defineElement(String localName, String className)
          Add the definition of an element without namespace to this factory.
 void defineElement(String namespaceUri, String localName, Class<?> clazz)
          Add the definition of an element to this factory.
 void defineElement(String namespaceUri, String localName, String className)
          Add the definition of an element to this factory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClassObjectFactory

public ClassObjectFactory()
Method Detail

defineElement

public void defineElement(String localName,
                          Class<?> clazz)
Add the definition of an element without namespace to this factory.
The namespace information will be ignored by the factory for this element.
Note: the given class must define a public constructor with no parameters and must implement the XMLSerializable interface.

Parameters:
localName - the local name of the element.
clazz - the class of the object to be created.

defineElement

public void defineElement(String localName,
                          String className)
Add the definition of an element without namespace to this factory.
The namespace information will be ignored by the factory for this element.
Note: the given class must define a public constructor with no parameters and must implement the XMLSerializable interface.

Parameters:
localName - the local name of the element.
className - the fully qualified class name of the object to be created.

defineElement

public void defineElement(String namespaceUri,
                          String localName,
                          Class<?> clazz)
Add the definition of an element to this factory.
Note: the given class must define a public constructor with no parameters and must implement the XMLSerializable interface.

Parameters:
namespaceUri - the element namespace URI
localName - the local name of the element.
clazz - the class of the object to be created.

defineElement

public void defineElement(String namespaceUri,
                          String localName,
                          String className)
Add the definition of an element to this factory.
Note: the given class must define a public constructor with no parameters and must implement the XMLSerializable interface.

Parameters:
namespaceUri - the element namespace URI
localName - the local name of the element.
className - the fully qualified class name of the object to be created.

createObject

public XMLSerializable createObject(String namespaceUri,
                                    String localName,
                                    XMLEventParser parser)
                             throws XMLParseException
Create an object corresponding to the XML element of the given name.

Specified by:
createObject in interface XMLObjectFactory
Parameters:
namespaceUri - the namespace URI of the XML element.
localName - the local name of the XML element.
parser - The current XML event parser, it is only used to have a locator of the current line in case of exception. (you can pass null if you don't need line reporting).
Throws:
XMLParseException - if the object is not defined or cannot be instantiated.


Copyright © 2012. All Rights Reserved.