|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.exolab.castor.xml.Unmarshaller
public class Unmarshaller
An unmarshaller to allowing unmarshalling of XML documents to Java Objects. The Class must specify the proper access methods (setters/getters) in order for instances of the Class to be properly unmarshalled.
Field Summary | |
---|---|
(package private) org.xml.sax.EntityResolver |
entityResolver
The EntityResolver used for resolving entities |
Constructor Summary | |
---|---|
Unmarshaller()
Creates a new basic Unmarshaller When using this constructor it will most likely be necessary to use a mapping file or ClassDescriptorResolver So that the Unmarshaller can find the classes during the unmarshalling process. |
|
Unmarshaller(java.lang.Class c)
Creates a new Unmarshaller with the given Class |
|
Unmarshaller(java.lang.Class c,
java.lang.ClassLoader loader)
Creates a new Unmarshaller with the given Class |
|
Unmarshaller(Mapping mapping)
Creates a new Unmarshaller with the given Mapping |
|
Unmarshaller(java.lang.Object root)
Creates a new Unmarshaller with the given Object |
Method Summary | |
---|---|
void |
addNamespaceToPackageMapping(java.lang.String nsURI,
java.lang.String packageName)
Adds a mapping from the given namespace URI to the given package name |
UnmarshalHandler |
createHandler()
Creates and initalizes an UnmarshalHandler |
static org.xml.sax.ContentHandler |
getContentHandler(UnmarshalHandler handler)
Returns a ContentHandler for the given UnmarshalHandler |
void |
setClassLoader(java.lang.ClassLoader loader)
Sets the ClassLoader to use when loading new classes. |
void |
setClearCollections(boolean clear)
Sets whether or not to clear collections (including arrays) upon first use to remove default values. |
void |
setDebug(boolean debug)
Turns debuging on or off. |
void |
setEntityResolver(org.xml.sax.EntityResolver entityResolver)
Sets the EntityResolver to use when resolving system and public ids with respect to entites and Document Type. |
void |
setIDResolver(IDResolver idResolver)
Sets the IDResolver to use when resolving IDREFs for which no associated element may exist in XML document. |
void |
setIgnoreExtraAttributes(boolean ignoreExtraAtts)
Sets whether or not attributes that do not match a specific field should simply be ignored or reported as an error. |
void |
setIgnoreExtraElements(boolean ignoreExtraElements)
Sets whether or not elements that do not match a specific field should simply be ignored or reported as an error. |
void |
setLogWriter(java.io.PrintWriter printWriter)
Sets the PrintWriter used for logging |
void |
setMapping(Mapping mapping)
Sets the Mapping to use during unmarshalling. |
void |
setResolver(ClassDescriptorResolver cdr)
Sets the ClassDescriptorResolver to use during unmarshalling |
void |
setReuseObjects(boolean reuse)
Sets a boolean that when true indicates that objects contained within the object model should be re-used where appropriate. |
void |
setUnmarshalListener(UnmarshalListener listener)
Sets an optional UnmarshalListener to receive pre and
post unmarshal notification for each Object in the tree. |
void |
setValidation(boolean validate)
Sets the flag for validation |
void |
setWhitespacePreserve(boolean preserve)
Sets the top-level whitespace (xml:space) to either preserving or non preserving. |
static java.lang.Object |
unmarshal(java.lang.Class c,
org.xml.sax.InputSource source)
Unmarshals Objects of the given Class type. |
static java.lang.Object |
unmarshal(java.lang.Class c,
org.w3c.dom.Node node)
Unmarshals Objects of the given Class type. |
static java.lang.Object |
unmarshal(java.lang.Class c,
java.io.Reader reader)
Unmarshals Objects of the given Class type. |
java.lang.Object |
unmarshal(EventProducer eventProducer)
Unmarshals Objects of this Unmarshaller's Class type. |
java.lang.Object |
unmarshal(org.xml.sax.InputSource source)
Unmarshals Objects of this Unmarshaller's Class type. |
java.lang.Object |
unmarshal(org.w3c.dom.Node node)
Unmarshals Objects of this Unmarshaller's Class type. |
java.lang.Object |
unmarshal(java.io.Reader reader)
Unmarshals Objects of this Unmarshaller's Class type. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
org.xml.sax.EntityResolver entityResolver
Constructor Detail |
---|
public Unmarshaller()
public Unmarshaller(java.lang.Class c)
c
- the Class to create the Unmarshaller for, this
may be null, if the Unmarshaller#setMapping is called
to load a mapping for the root element of xml document.public Unmarshaller(java.lang.Class c, java.lang.ClassLoader loader)
c
- the Class to create the Unmarshaller for, this
may be null, if the Unmarshaller#setMapping is called
to load a mapping for the root element of xml document.loader,
- the ClassLoader to use.public Unmarshaller(Mapping mapping) throws MappingException
mapping,
- the Mapping to use
MappingException
public Unmarshaller(java.lang.Object root)
root
- the instance to unmarshal into. This
may be null, if the Unmarshaller#setMapping is called
to load a mapping for the root element of xml document.Method Detail |
---|
public void addNamespaceToPackageMapping(java.lang.String nsURI, java.lang.String packageName)
nsURI
- the namespace URI to map frompackageName
- the package name to map topublic UnmarshalHandler createHandler()
public void setClassLoader(java.lang.ClassLoader loader)
loader
- the ClassLoader to usepublic void setClearCollections(boolean clear)
clear
- the boolean value that when true indicates
collections should be cleared upon first use.public void setDebug(boolean debug)
debug
- the flag indicating whether to generate debug information.
A value of true, will turn debuggin on.setLogWriter(java.io.PrintWriter)
public void setEntityResolver(org.xml.sax.EntityResolver entityResolver)
entityResolver
- the EntityResolver to use when
resolving System and Public ids.public void setIDResolver(IDResolver idResolver)
idResolver
- the IDResolver to use when resolving
IDREFs for which no associated element may exist in the
XML document.public void setIgnoreExtraAttributes(boolean ignoreExtraAtts)
ignoreExtraAtts
- a boolean that when true will
allow non-matched attributes to simply be ignored.public void setIgnoreExtraElements(boolean ignoreExtraElements)
ignoreExtraElements
- a boolean that when true will
allow non-matched elements to simply be ignored.public void setLogWriter(java.io.PrintWriter printWriter)
printWriter
- the PrintWriter to use for loggingpublic void setMapping(Mapping mapping) throws MappingException
mapping
- the Mapping to use during unmarshalling.
MappingException
setResolver(org.exolab.castor.xml.ClassDescriptorResolver)
public void setReuseObjects(boolean reuse)
reuse
- the boolean indicating whether or not
to re-use existing objects in the object model.public void setResolver(ClassDescriptorResolver cdr)
cdr
- the ClassDescriptorResolver to use
Note: This method will nullify any Mapping
currently being used by this Unmarshaller
public void setUnmarshalListener(UnmarshalListener listener)
UnmarshalListener
to receive pre and
post unmarshal notification for each Object in the tree.
An UnmarshalListener is often used to allow objects to
appropriately initialize themselves by taking appliction
specific behavior as they are unloaded.
Current only one (1) listener is allowed. If you need
register multiple listeners, you will have to create
your own master listener that will forward the
event notifications and manage the multiple
listeners.
listener
- the UnmarshalListener
to set.public void setValidation(boolean validate)
validate,
- a boolean to indicate whether or not
validation should be done during umarshalling. public void setWhitespacePreserve(boolean preserve)
preserve
- a boolean that when true enables
whitespace preserving by default.public java.lang.Object unmarshal(java.io.Reader reader) throws MarshalException, ValidationException
reader
- the Reader to read the XML from
MarshalException
- when there is an error during
the unmarshalling process
ValidationException
- when there is a validation errorpublic java.lang.Object unmarshal(EventProducer eventProducer) throws MarshalException, ValidationException
eventProducer
- the EventProducer which produces
the SAX events
MarshalException
- when there is an error during
the unmarshalling process
ValidationException
- when there is a validation errorpublic java.lang.Object unmarshal(org.xml.sax.InputSource source) throws MarshalException, ValidationException
source
- the InputSource to read the XML from
MarshalException
- when there is an error during
the unmarshalling process
ValidationException
- when there is a validation errorpublic java.lang.Object unmarshal(org.w3c.dom.Node node) throws MarshalException, ValidationException
node
- the DOM node to read the XML from
MarshalException
- when there is an error during
the unmarshalling process
ValidationException
- when there is a validation errorpublic static org.xml.sax.ContentHandler getContentHandler(UnmarshalHandler handler) throws org.xml.sax.SAXException
org.xml.sax.SAXException
public static java.lang.Object unmarshal(java.lang.Class c, java.io.Reader reader) throws MarshalException, ValidationException
Note:This is a *static* method, any mapping files set on a particular Unmarshaller instance, and any changes made via setters will be unavailable to this method.
c
- the Class to create a new instance ofreader
- the Reader to read the XML from
MarshalException
- when there is an error during
the unmarshalling process
ValidationException
- when there is a validation errorpublic static java.lang.Object unmarshal(java.lang.Class c, org.xml.sax.InputSource source) throws MarshalException, ValidationException
Note:This is a *static* method, any mapping files set on a particular Unmarshaller instance, and any changes made via setters will be unavailable to this method.
c
- the Class to create a new instance ofsource
- the InputSource to read the XML from
MarshalException
- when there is an error during
the unmarshalling process
ValidationException
- when there is a validation errorpublic static java.lang.Object unmarshal(java.lang.Class c, org.w3c.dom.Node node) throws MarshalException, ValidationException
Note:This is a *static* method, any mapping files set on a particular Unmarshaller instance, and any changes made via setters will be unavailable to this method.
c
- the Class to create a new instance ofsource
- the DOM Node to read the XML from
MarshalException
- when there is an error during
the unmarshalling process
ValidationException
- when there is a validation error
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |