public class Unmarshaller extends Object
| Constructor and Description |
|---|
Unmarshaller()
An empty default constructor which: - sets the internal context to the backward compatibility
context - all other flags to defaults Internally the Unmarshaller(Class) constructor is called.
|
Unmarshaller(Class clazz)
A constructor which sets the root class.
|
Unmarshaller(InternalContext internalContext)
Creates a new basic Unmarshaller.
|
Unmarshaller(InternalContext internalContext,
Class c)
Creates a new Unmarshaller with the given Class.
|
Unmarshaller(InternalContext internalContext,
Class c,
ClassLoader loader)
Creates a new
Unmarshaller with the given Class. |
Unmarshaller(InternalContext internalContext,
Mapping mapping)
Creates a new Unmarshaller with the given Mapping.
|
Unmarshaller(InternalContext internalContext,
Object root)
Creates a new Unmarshaller with the given Object.
|
Unmarshaller(Mapping mapping)
Creates a new Unmarshaller with the given Mapping.
|
Unmarshaller(Object root)
Creates a new Unmarshaller with the given Object.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addNamespaceToPackageMapping(String nsURI,
String packageName)
Adds a mapping from the given namespace URI to the given package name.
|
UnmarshalHandler |
createHandler()
Creates and initalizes an UnmarshalHandler
|
static ContentHandler |
getContentHandler(UnmarshalHandler handler)
Returns a ContentHandler for the given UnmarshalHandler
|
InternalContext |
getInternalContext()
To get the internal XML Context that is in use.
|
String |
getProperty(String name)
Returns the value of the given Castor XML-specific property.
|
boolean |
isValidating()
Indicates whether or not validation should be performed during umarshalling.
|
void |
setClass(Class clazz)
Sets the 'expected'
Class instance on the Unmarshaller. |
void |
setClassLoader(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)
Deprecated.
|
void |
setEntityResolver(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 |
setInternalContext(InternalContext internalContext)
To set the internal XML Context to be used.
|
void |
setLogWriter(PrintWriter printWriter)
Deprecated.
|
void |
setMapping(Mapping mapping)
Sets the Mapping to use during unmarshalling.
|
void |
setObject(Object root)
Sets the 'expected'
Object instance on the Unmarshaller, into which will be
unmarshalled. |
void |
setObjectFactory(ObjectFactory objectFactory)
Set an object factory for the unmarshaller.
|
void |
setProperty(String name,
String value)
Sets a custom value of a given Castor XML-specific property.
|
void |
setResolver(XMLClassDescriptorResolver xmlClassDescriptorResolver)
Sets the XMLClassDescriptorResolver 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)
Deprecated.
replaced by
UnmarshalListener |
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.
|
Object |
unmarshal(AnyNode anyNode)
Unmarshals objects of this
Unmarshaller's Class type from an AnyNode instance. |
static Object |
unmarshal(Class c,
InputSource source)
Unmarshals Objects of the given Class type.
|
static Object |
unmarshal(Class c,
Node node)
Unmarshals Objects of the given Class type.
|
static Object |
unmarshal(Class c,
Reader reader)
Unmarshals Objects of the given Class type.
|
Object |
unmarshal(EventProducer eventProducer)
Deprecated.
please use @see #unmarshal(SAX2EventProducer) instead.
|
Object |
unmarshal(InputSource source)
Unmarshals Objects of this Unmarshaller's Class type.
|
Object |
unmarshal(Node node)
Unmarshals Objects of this Unmarshaller's Class type.
|
Object |
unmarshal(Reader reader)
Unmarshals Objects of this Unmarshaller's Class type.
|
Object |
unmarshal(SAX2EventAndErrorProducer eventProducer)
Unmarshals objects of this
Unmarshaller's class type. |
Object |
unmarshal(SAX2EventProducer eventProducer)
Unmarshals Objects of this Unmarshaller's Class type.
|
Object |
unmarshal(Source source)
Unmarshals ths given
Source instance. |
Object |
unmarshal(XMLEventReader eventReader)
Unmarshals objects of this
Unmarshaller's class type. |
Object |
unmarshal(XMLStreamReader streamReader)
Unmarshals objects of this
Unmarshaller's class type. |
public Unmarshaller()
public Unmarshaller(Class clazz)
clazz - root class for unmarshallingpublic Unmarshaller(InternalContext internalContext)
internalContext - the InternalContext to useIllegalArgumentException - if internalContext is nullpublic Unmarshaller(InternalContext internalContext, Class c)
internalContext - the InternalContext to usec - 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.IllegalArgumentException - if internalContext is nullpublic Unmarshaller(InternalContext internalContext, Class c, ClassLoader loader)
Unmarshaller with the given Class.internalContext - the InternalContext to be used, for config, and such...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.IllegalArgumentException - if internalContext is nullpublic Unmarshaller(Mapping mapping) throws MappingException
mapping - The Mapping to use.MappingException - in case that Unmarshaller fails to be instantiatedpublic Unmarshaller(InternalContext internalContext, Mapping mapping) throws MappingException
internalContext - the internal context to usemapping - The Mapping to use.MappingException - in case that Unmarshaller fails to be instantiatedIllegalArgumentException - if internalContext is nullpublic Unmarshaller(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.public Unmarshaller(InternalContext internalContext, Object root)
internalContext - the internal context to useroot - 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.IllegalArgumentException - if internalContext is nullpublic void addNamespaceToPackageMapping(String nsURI, String packageName)
nsURI - the namespace URI to map frompackageName - the package name to map topublic UnmarshalHandler createHandler()
public boolean isValidating()
public void setClass(Class clazz)
Class instance on the Unmarshaller.clazz - 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 void setObject(Object root)
Object instance on the Unmarshaller, into which will be
unmarshalled.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.public void setClassLoader(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)
public void setEntityResolver(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(PrintWriter printWriter)
printWriter - the PrintWriter to use for loggingpublic void setMapping(Mapping mapping) throws MappingException
mapping - Mapping to use during unmarshalling.MappingExceptionsetResolver(org.exolab.castor.xml.XMLClassDescriptorResolver)public void setReuseObjects(boolean reuse)
reuse - the boolean indicating whether or not to re-use existing objects in the object
model.public void setUnmarshalListener(UnmarshalListener listener)
UnmarshalListenerUnmarshalListener 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 application 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 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 application 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 Object unmarshal(Reader reader) throws MarshalException, ValidationException
reader - the Reader to read the XML fromMarshalException - when there is an error during the unmarshalling processValidationException - when there is a validation errorpublic Object unmarshal(EventProducer eventProducer) throws MarshalException, ValidationException
eventProducer - the EventProducer which produces the SAX eventsMarshalException - when there is an error during the unmarshalling processValidationException - when there is a validation errorpublic Object unmarshal(SAX2EventProducer eventProducer) throws MarshalException, ValidationException
eventProducer - the SAX2EventProducer instance which produces the SAX 2 eventsMarshalException - when there is an error during the unmarshalling processValidationException - when there is a validation errorpublic Object unmarshal(AnyNode anyNode) throws MarshalException
Unmarshaller's Class type from an AnyNode instance.
The Class must specify the proper access methods (setters/getters) in order for instances of
the Class to be properly unmarshalled.anyNode - AnyNode instance to be unmarshalled fromObject instance that is a result of unmarshalling.MarshalException - when there is an error during the unmarshalling processpublic Object unmarshal(InputSource source) throws MarshalException, ValidationException
source - the InputSource to read the XML fromMarshalException - when there is an error during the unmarshalling processValidationException - when there is a validation errorpublic Object unmarshal(Node node) throws MarshalException, ValidationException
node - the DOM node to read the XML fromMarshalException - when there is an error during the unmarshalling processValidationException - when there is a validation errorpublic Object unmarshal(XMLEventReader eventReader) throws MarshalException, ValidationException
Unmarshaller's class type. The class must specify the proper
access methods (setters/getters) in order for instances of the class to be properly
unmarshalled.eventReader - the StaX XMLEventReader to read XML from.MarshalException - indicates a general problem during the unmarshalling process.ValidationException - indicates a problem related to validation.public Object unmarshal(XMLStreamReader streamReader) throws MarshalException, ValidationException
Unmarshaller's class type. The class must specify the proper
access methods (setters/getters) in order for instances of the class to be properly
unmarshalled.streamReader - the STaX XMLStreamReader to read XML from.MarshalException - indicates a general problem during the unmarshalling process.ValidationException - indicates a problem related to validation.public Object unmarshal(SAX2EventAndErrorProducer eventProducer) throws MarshalException, ValidationException
Unmarshaller's class type. eventProducer - the SAX2EventAndErrorProducer instance which produces the SAX 2
events and handles SAX 2 errors.MarshalException - indiactes a general error during the unmarshalling process.ValidationException - indicates a validation error.public Object unmarshal(Source source) throws MarshalException, ValidationException
Source instance. Currently this method will support fallowing
classes DOMSource, SAXSource and StreamSource.source - the source to unmarshalIllegalArgumentException - if the given source is null or it is unsupportedMarshalException - indiactes a general error during the unmarshalling process.ValidationException - indicates a validation error.public static ContentHandler getContentHandler(UnmarshalHandler handler) throws SAXException
SAXExceptionpublic static Object unmarshal(Class c, 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 fromMarshalException - when there is an error during the unmarshalling processValidationException - when there is a validation errorpublic static Object unmarshal(Class c, 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 fromMarshalException - when there is an error during the unmarshalling processValidationException - when there is a validation errorpublic static Object unmarshal(Class c, 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 of.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 error.public void setObjectFactory(ObjectFactory objectFactory)
objectFactory - Factory used for constructing objects during unmarshalling.public String getProperty(String name)
name - Qualified name of the CASTOR XML-specific property.public void setProperty(String name, String value)
name - Name of the Castor XML propertyvalue - Custom value to set.public void setInternalContext(InternalContext internalContext)
internalContext - the context to be usedpublic InternalContext getInternalContext()
InternalContext in usepublic void setResolver(XMLClassDescriptorResolver xmlClassDescriptorResolver)
xmlClassDescriptorResolver - the XMLClassDescriptorResolver to use
Note: This method will nullify any Mapping currently being used by this
UnmarshallerCopyright © 2016. All rights reserved.