|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.newdawn.slick.util.xml.ObjectTreeParser
public class ObjectTreeParser
Provides a method of parsing XML into an existing data model. This does not
provide the same functionality as JAXB or the variety of XML bindings out there. This
is a utility to map XML onto an existing data model. The idea being that the design level
model should not be driven by the XML schema thats defined. The two arn't always equal
and often you end up with a set of class that represent your XML that you then have
to traverse to extract into your normal data model.
This utility hopes to take a piece of XML and map it onto a previously designed data
model. At the moment it's way to tied to the structure of the XML but this will
hopefully change with time.
XML element names must be mapped to class names. This can be done in two ways either:
- Specify an explict mapping with addElementMapping()
- Specify the default package name and use the element name as the class name
Each attribute in an element is mapped into a property of the element class, preferably
through a set
Constructor Summary | |
---|---|
ObjectTreeParser()
Create an object tree parser with no default package |
|
ObjectTreeParser(java.lang.String defaultPackage)
Create an object tree parser specifing the default package where classes will be search for using the XML element name |
Method Summary | |
---|---|
void |
addElementMapping(java.lang.String elementName,
java.lang.Class elementClass)
Add a mapping between XML element name and class name |
void |
addIgnoredElement(java.lang.String elementName)
Add a name to the list of elements ignored |
java.lang.Object |
parse(java.lang.String ref)
Parse the XML document located by the slick resource loader using the reference given. |
java.lang.Object |
parse(java.lang.String name,
java.io.InputStream in)
Parse the XML document that can be read from the given input stream |
java.lang.Object |
parseOnto(java.lang.String name,
java.io.InputStream in,
java.lang.Object target)
Parse the XML document that can be read from the given input stream |
java.lang.Object |
parseOnto(java.lang.String ref,
java.lang.Object target)
Parse the XML document located by the slick resource loader using the reference given. |
void |
setAddMethodName(java.lang.String methodName)
Set the name of the method to use to add child objects to their parents. |
void |
setDefaultPackage(java.lang.String defaultPackage)
Set the default package which will be search for classes by their XML element name. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ObjectTreeParser()
public ObjectTreeParser(java.lang.String defaultPackage)
defaultPackage
- The default package to be searchedMethod Detail |
---|
public void addElementMapping(java.lang.String elementName, java.lang.Class elementClass)
elementName
- The name of the XML elementelementClass
- The class to be created for the given elementpublic void addIgnoredElement(java.lang.String elementName)
elementName
- The name to ignorepublic void setAddMethodName(java.lang.String methodName)
methodName
- The name of the method to callpublic void setDefaultPackage(java.lang.String defaultPackage)
defaultPackage
- The default package to be searchedpublic java.lang.Object parse(java.lang.String ref) throws SlickXMLException
ref
- The reference to the XML document
SlickXMLException
- Indicates a failure to parse the XML, most likely the
XML is malformed in some way.public java.lang.Object parse(java.lang.String name, java.io.InputStream in) throws SlickXMLException
name
- The name of the documentin
- The input stream from which the document can be read
SlickXMLException
- Indicates a failure to parse the XML, most likely the
XML is malformed in some way.public java.lang.Object parseOnto(java.lang.String ref, java.lang.Object target) throws SlickXMLException
ref
- The reference to the XML documenttarget
- The top level object that represents the root node
SlickXMLException
- Indicates a failure to parse the XML, most likely the
XML is malformed in some way.public java.lang.Object parseOnto(java.lang.String name, java.io.InputStream in, java.lang.Object target) throws SlickXMLException
name
- The name of the documentin
- The input stream from which the document can be readtarget
- The top level object that represents the root node
SlickXMLException
- Indicates a failure to parse the XML, most likely the
XML is malformed in some way.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |