|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sourceforge.cilib.xml.XMLObjectFactory
public class XMLObjectFactory
The XMLObjectFactory
can be used to manage the construction of any object
based on an XML description. This class uses reflection to set properties
and call arbitrary methods of the object under contruction.
Example:
// Parse the XML document DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(new File("example.xml")); // Here, construct is the XML element to read the configuration from Element description = (Element) doc.getElementsByTagName("construct").item(0); // The document is only necessary for idrefs, there is a // second constructor that accepts just the element XMLObjectFactory factory = new XMLObjectFactory(doc, description); // Finally, call newObject() whenever you want to construct a new // object according to the configuration in the given XML element Object object = factory.newObject();
Each time XMLObjectFactory
encounters a class attribute in the XML, an
instance of the specified class is instanciated. Nested elements are
interpreted as either properties to be set or methods to be called on this
newly constructed object. If no class attribute is specified then the element
is interpreted as a Java primitive type or a string. Elements can be nested in
a hierarchical fashion to handle the construction of complex objects.
Note: Requires the Java API for XML processing (JAXP).
See: Factory Demo for XML samples.
Constructor Summary | |
---|---|
XMLObjectFactory(Document xmlDocument,
Element xmlObjectDescription)
Creates a new instance of XMLObjectFactory for constructing objects
given an XML description and an XML document for handling idrefs. |
|
XMLObjectFactory(Element xmlObjectDescription)
Creates a new instance of XMLObjectFactory for constructing objects
given an XML description. |
Method Summary | |
---|---|
protected void |
error(Element element,
String message)
|
Object |
newObject()
Constructs a new Object based on the underlying XML object description. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public XMLObjectFactory(Element xmlObjectDescription)
XMLObjectFactory
for constructing objects
given an XML description.
xmlObjectDescription
- An XML element that describes the objects to be constructed by this factory.public XMLObjectFactory(Document xmlDocument, Element xmlObjectDescription)
XMLObjectFactory
for constructing objects
given an XML description and an XML document for handling idrefs.
xmlObjectDescription
- An XML element that describes the objects to be constructed by this factory.xmlDocument
- The XML document to search for any idrefs.Method Detail |
---|
public Object newObject()
Object
based on the underlying XML object description.
Object
constructed according to the given description.
FactoryException
- In case the object cannot be constructed.protected void error(Element element, String message)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |