public final class UnmarshallerImpl extends AbstractUnmarshallerImpl implements ValidationEventHandler, Closeable
This class can be extended by the generated code to provide type-safe unmarshall methods.
Unmarshaller.Listener
Modifier and Type | Field and Description |
---|---|
protected JAXBContextImpl |
context
Owning
JAXBContext |
UnmarshallingContext |
coordinator |
static String |
FACTORY |
validating
Constructor and Description |
---|
UnmarshallerImpl(JAXBContextImpl context,
AssociationMap assoc) |
Modifier and Type | Method and Description |
---|---|
void |
close()
Must be called from same thread which created the UnmarshallerImpl instance.
|
UnmarshalException |
createUnmarshalException(SAXException e)
Creates an UnmarshalException from a SAXException.
|
XmlVisitor |
createUnmarshallerHandler(InfosetScanner scanner,
boolean inplace,
JaxBeanInfo expectedType)
Creates and configures a new unmarshalling pipe line.
|
protected void |
finalize() |
<A extends XmlAdapter> |
getAdapter(Class<A> type)
Gets the adapter associated with the specified type.
|
AttachmentUnmarshaller |
getAttachmentUnmarshaller() |
<T> JaxBeanInfo<T> |
getBeanInfo(Class<T> clazz) |
UnmarshallingContext |
getContext() |
ValidationEventHandler |
getEventHandler()
Return the current event handler or the default event handler if one
hasn't been set.
|
Unmarshaller.Listener |
getListener()
Return
Unmarshaller.Listener registered with this Unmarshaller . |
Object |
getProperty(String name)
Default implementation of the getProperty method always
throws PropertyException since there are no required
properties.
|
Schema |
getSchema()
Get the JAXP 1.3
Schema object
being used to perform unmarshal-time validation. |
UnmarshallerHandler |
getUnmarshallerHandler()
Get an unmarshaller handler object that can be used as a component in
an XML pipeline.
|
protected XMLReader |
getXMLReader()
Obtains a configured XMLReader.
|
boolean |
handleEvent(ValidationEvent event)
Default error handling behavior for
Unmarshaller . |
boolean |
hasEventHandler()
Returns true if an event handler is installed.
|
boolean |
isValidating()
Deprecated.
since 2.0
|
static boolean |
needsInterning(XMLReader reader) |
<A extends XmlAdapter> |
setAdapter(Class<A> type,
A adapter)
Associates a configured instance of
XmlAdapter with this unmarshaller. |
void |
setAttachmentUnmarshaller(AttachmentUnmarshaller au)
Associate a context that resolves cid's, content-id URIs, to
binary data passed as attachments.
|
void |
setListener(Unmarshaller.Listener listener)
Register unmarshal event callback
Unmarshaller.Listener with this Unmarshaller . |
void |
setProperty(String name,
Object value)
Default implementation of the setProperty method always
throws PropertyException since there are no required
properties.
|
void |
setSchema(Schema schema)
Specify the JAXP 1.3
Schema
object that should be used to validate subsequent unmarshal operations
against. |
void |
setValidating(boolean validating)
Deprecated.
since 2.0
|
Object |
unmarshal(Node node)
Unmarshal global XML data from the specified DOM tree and return the resulting
content tree.
|
<T> JAXBElement<T> |
unmarshal(Node node,
Class<T> expectedType)
Unmarshal XML data by JAXB mapped
declaredType
and return the resulting content tree. |
Object |
unmarshal(SAXSource source)
Deprecated.
|
<T> JAXBElement<T> |
unmarshal(Source source,
Class<T> expectedType)
Unmarshal XML data from the specified XML Source by
declaredType and return the
resulting content tree. |
Object |
unmarshal(XMLEventReader reader)
Unmarshal XML data from the specified pull parser and return the
resulting content tree.
|
<T> JAXBElement<T> |
unmarshal(XMLEventReader reader,
Class<T> expectedType)
Unmarshal root element to JAXB mapped
declaredType
and return the resulting content tree. |
protected Object |
unmarshal(XMLReader reader,
InputSource source)
Unmarshals an object by using the specified XMLReader and the InputSource.
|
protected <T> JAXBElement<T> |
unmarshal(XMLReader reader,
InputSource source,
Class<T> expectedType) |
Object |
unmarshal(XMLStreamReader reader)
Unmarshal XML data from the specified pull parser and return the
resulting content tree.
|
<T> JAXBElement<T> |
unmarshal(XMLStreamReader reader,
Class<T> expectedType)
Unmarshal root element to JAXB mapped
declaredType
and return the resulting content tree. |
Object |
unmarshal0(InputStream input,
JaxBeanInfo expectedType) |
Object |
unmarshal0(Node node,
JaxBeanInfo expectedType) |
Object |
unmarshal0(Source source,
JaxBeanInfo expectedType) |
Object |
unmarshal0(XMLStreamReader reader,
JaxBeanInfo expectedType) |
setAdapter, setEventHandler, unmarshal, unmarshal, unmarshal, unmarshal, unmarshal, unmarshal
protected final JAXBContextImpl context
JAXBContext
public final UnmarshallingContext coordinator
public static final String FACTORY
public UnmarshallerImpl(JAXBContextImpl context, AssociationMap assoc)
public UnmarshallerHandler getUnmarshallerHandler()
Unmarshaller
The JAXB Provider can return the same handler object for multiple
invocations of this method. In other words, this method does not
necessarily create a new instance of UnmarshallerHandler
. If the
application needs to use more than one UnmarshallerHandler
, it
should create more than one Unmarshaller
.
getUnmarshallerHandler
in interface Unmarshaller
UnmarshallerHandler
protected XMLReader getXMLReader() throws JAXBException
SAXSource
object doesn't have XMLReader.
Unmarshaller
is not re-entrant, so we will
only use one instance of XMLReader.
Overriden in order to fix potential security issue.getXMLReader
in class AbstractUnmarshallerImpl
JAXBException
public final XmlVisitor createUnmarshallerHandler(InfosetScanner scanner, boolean inplace, JaxBeanInfo expectedType)
UnmarshallerHandler
and ValidationEventHandler
. All the parsing errors
should be reported to this error handler for the unmarshalling
process to work correctly.
Also, returned handler expects all the XML names to be interned.public static boolean needsInterning(XMLReader reader)
protected Object unmarshal(XMLReader reader, InputSource source) throws JAXBException
AbstractUnmarshallerImpl
unmarshal
in class AbstractUnmarshallerImpl
JAXBException
protected <T> JAXBElement<T> unmarshal(XMLReader reader, InputSource source, Class<T> expectedType) throws JAXBException
JAXBException
public <T> JAXBElement<T> unmarshal(Source source, Class<T> expectedType) throws JAXBException
Unmarshaller
declaredType
and return the
resulting content tree.
Implements Unmarshal by Declared Type
unmarshal
in interface Unmarshaller
unmarshal
in class AbstractUnmarshallerImpl
source
- the XML Source to unmarshal XML data from (providers are
only required to support SAXSource, DOMSource, and StreamSource)expectedType
- appropriate JAXB mapped class to hold source
's xml root elementJAXBException
- If any unexpected errors occur while unmarshallingUnmarshalException
- If the ValidationEventHandler
returns false from its handleEvent
method or the
Unmarshaller
is unable to perform the XML to Java
binding. See Unmarshalling XML Datapublic Object unmarshal0(Source source, JaxBeanInfo expectedType) throws JAXBException
JAXBException
public final ValidationEventHandler getEventHandler()
AbstractUnmarshallerImpl
getEventHandler
in interface Unmarshaller
getEventHandler
in class AbstractUnmarshallerImpl
public final boolean hasEventHandler()
The default handler ignores any errors, and for that this method returns false.
public <T> JAXBElement<T> unmarshal(Node node, Class<T> expectedType) throws JAXBException
Unmarshaller
declaredType
and return the resulting content tree.
Implements Unmarshal by Declared Type
unmarshal
in interface Unmarshaller
unmarshal
in class AbstractUnmarshallerImpl
node
- the document/element to unmarshal XML data from.
The caller must support at least Document and Element.expectedType
- appropriate JAXB mapped class to hold node
's XML data.node
JAXBException
- If any unexpected errors occur while unmarshallingUnmarshalException
- If the ValidationEventHandler
returns false from its handleEvent
method or the
Unmarshaller
is unable to perform the XML to Java
binding. See Unmarshalling XML Datapublic final Object unmarshal(Node node) throws JAXBException
Unmarshaller
Implements Unmarshal Global Root Element.
unmarshal
in interface Unmarshaller
node
- the document/element to unmarshal XML data from.
The caller must support at least Document and Element.JAXBException
- If any unexpected errors occur while unmarshallingUnmarshalException
- If the ValidationEventHandler
returns false from its handleEvent
method or the
Unmarshaller
is unable to perform the XML to Java
binding. See Unmarshalling XML DataUnmarshaller.unmarshal(org.w3c.dom.Node, Class)
@Deprecated public final Object unmarshal(SAXSource source) throws JAXBException
JAXBException
public final Object unmarshal0(Node node, JaxBeanInfo expectedType) throws JAXBException
JAXBException
public Object unmarshal(XMLStreamReader reader) throws JAXBException
Unmarshaller
Implements Unmarshal Global Root Element.
This method assumes that the parser is on a START_DOCUMENT or
START_ELEMENT event. Unmarshalling will be done from this
start event to the corresponding end event. If this method
returns successfully, the reader
will be pointing at
the token right after the end event.
unmarshal
in interface Unmarshaller
unmarshal
in class AbstractUnmarshallerImpl
reader
- The parser to be read.JAXBException
- If any unexpected errors occur while unmarshallingUnmarshalException
- If the ValidationEventHandler
returns false from its handleEvent
method or the
Unmarshaller
is unable to perform the XML to Java
binding. See Unmarshalling XML DataUnmarshaller.unmarshal(javax.xml.stream.XMLStreamReader, Class)
public <T> JAXBElement<T> unmarshal(XMLStreamReader reader, Class<T> expectedType) throws JAXBException
Unmarshaller
declaredType
and return the resulting content tree.
This method implements unmarshal by declaredType.
This method assumes that the parser is on a START_DOCUMENT or
START_ELEMENT event. Unmarshalling will be done from this
start event to the corresponding end event. If this method
returns successfully, the reader
will be pointing at
the token right after the end event.
unmarshal
in interface Unmarshaller
unmarshal
in class AbstractUnmarshallerImpl
reader
- The parser to be read.expectedType
- appropriate JAXB mapped class to hold reader
's START_ELEMENT XML data.JAXBException
- If any unexpected errors occur while unmarshallingUnmarshalException
- If the ValidationEventHandler
returns false from its handleEvent
method or the
Unmarshaller
is unable to perform the XML to Java
binding. See Unmarshalling XML Datapublic Object unmarshal0(XMLStreamReader reader, JaxBeanInfo expectedType) throws JAXBException
JAXBException
public <T> JAXBElement<T> unmarshal(XMLEventReader reader, Class<T> expectedType) throws JAXBException
Unmarshaller
declaredType
and return the resulting content tree.
This method implements unmarshal by declaredType.
This method assumes that the parser is on a START_DOCUMENT or
START_ELEMENT event. Unmarshalling will be done from this
start event to the corresponding end event. If this method
returns successfully, the reader
will be pointing at
the token right after the end event.
unmarshal
in interface Unmarshaller
unmarshal
in class AbstractUnmarshallerImpl
reader
- The parser to be read.expectedType
- appropriate JAXB mapped class to hold reader
's START_ELEMENT XML data.JAXBException
- If any unexpected errors occur while unmarshallingUnmarshalException
- If the ValidationEventHandler
returns false from its handleEvent
method or the
Unmarshaller
is unable to perform the XML to Java
binding. See Unmarshalling XML Datapublic Object unmarshal(XMLEventReader reader) throws JAXBException
Unmarshaller
This method is an Unmarshal Global Root method.
This method assumes that the parser is on a START_DOCUMENT or
START_ELEMENT event. Unmarshalling will be done from this
start event to the corresponding end event. If this method
returns successfully, the reader
will be pointing at
the token right after the end event.
unmarshal
in interface Unmarshaller
unmarshal
in class AbstractUnmarshallerImpl
reader
- The parser to be read.JAXBException
- If any unexpected errors occur while unmarshallingUnmarshalException
- If the ValidationEventHandler
returns false from its handleEvent
method or the
Unmarshaller
is unable to perform the XML to Java
binding. See Unmarshalling XML DataUnmarshaller.unmarshal(javax.xml.stream.XMLEventReader, Class)
public Object unmarshal0(InputStream input, JaxBeanInfo expectedType) throws JAXBException
JAXBException
public Object getProperty(String name) throws PropertyException
AbstractUnmarshallerImpl
getProperty
in interface Unmarshaller
getProperty
in class AbstractUnmarshallerImpl
name
- the name of the property to retrievePropertyException
- when there is an error retrieving the given property or value
property namepublic void setProperty(String name, Object value) throws PropertyException
AbstractUnmarshallerImpl
setProperty
in interface Unmarshaller
setProperty
in class AbstractUnmarshallerImpl
name
- the name of the property to be set. This value can either
be specified using one of the constant fields or a user
supplied string.value
- the value of the property to be setPropertyException
- when there is an error processing the given
property or valuepublic void setSchema(Schema schema)
Unmarshaller
Schema
object that should be used to validate subsequent unmarshal operations
against. Passing null into this method will disable validation.
This method replaces the deprecated setValidating(boolean)
API.
Initially this property is set to null
.
setSchema
in interface Unmarshaller
setSchema
in class AbstractUnmarshallerImpl
schema
- Schema object to validate unmarshal operations against or null to disable validationpublic Schema getSchema()
Unmarshaller
Schema
object
being used to perform unmarshal-time validation. If there is no
Schema set on the unmarshaller, then this method will return null
indicating that unmarshal-time validation will not be performed.
This method provides replacement functionality for the deprecated
Unmarshaller.isValidating()
API as well as access to the Schema object.
To determine if the Unmarshaller has validation enabled, simply
test the return type for null:
boolean isValidating = u.getSchema()!=null;
getSchema
in interface Unmarshaller
getSchema
in class AbstractUnmarshallerImpl
public AttachmentUnmarshaller getAttachmentUnmarshaller()
getAttachmentUnmarshaller
in interface Unmarshaller
getAttachmentUnmarshaller
in class AbstractUnmarshallerImpl
public void setAttachmentUnmarshaller(AttachmentUnmarshaller au)
Unmarshaller
Associate a context that resolves cid's, content-id URIs, to binary data passed as attachments.
Unmarshal time validation, enabled via Unmarshaller.setSchema(Schema)
,
must be supported even when unmarshaller is performing XOP processing.
setAttachmentUnmarshaller
in interface Unmarshaller
setAttachmentUnmarshaller
in class AbstractUnmarshallerImpl
public boolean isValidating()
AbstractUnmarshallerImpl
Note: I named this method isValidating() to stay in-line with JAXP, as opposed to naming it getValidating().
isValidating
in interface Unmarshaller
isValidating
in class AbstractUnmarshallerImpl
public void setValidating(boolean validating)
AbstractUnmarshallerImpl
Unmarshaller
does
not validate.
This method may only be invoked before or after calling one of the unmarshal methods.
setValidating
in interface Unmarshaller
setValidating
in class AbstractUnmarshallerImpl
validating
- true if the Unmarshaller should validate during
unmarshal, false otherwisepublic <A extends XmlAdapter> void setAdapter(Class<A> type, A adapter)
Unmarshaller
XmlAdapter
with this unmarshaller.
Every unmarshaller internally maintains a
Map
<Class
,XmlAdapter
>,
which it uses for unmarshalling classes whose fields/methods are annotated
with XmlJavaTypeAdapter
.
This method allows applications to use a configured instance of XmlAdapter
.
When an instance of an adapter is not given, an unmarshaller will create
one by invoking its default constructor.
setAdapter
in interface Unmarshaller
setAdapter
in class AbstractUnmarshallerImpl
type
- The type of the adapter. The specified instance will be used when
XmlJavaTypeAdapter.value()
refers to this type.adapter
- The instance of the adapter to be used. If null, it will un-register
the current adapter set for this type.public <A extends XmlAdapter> A getAdapter(Class<A> type)
Unmarshaller
Unmarshaller.setAdapter(javax.xml.bind.annotation.adapters.XmlAdapter)
method.getAdapter
in interface Unmarshaller
getAdapter
in class AbstractUnmarshallerImpl
public UnmarshalException createUnmarshalException(SAXException e)
AbstractUnmarshallerImpl
When a provider-implemented ContentHandler wants to throw a JAXBException, it needs to wrap the exception by a SAXException. If the unmarshaller implementation blindly wrap SAXException by JAXBException, such an exception will be a JAXBException wrapped by a SAXException wrapped by another JAXBException. This is silly.
This method checks the nested exception of SAXException and reduce those excessive wrapping.
createUnmarshalException
in class AbstractUnmarshallerImpl
public boolean handleEvent(ValidationEvent event)
Unmarshaller
.handleEvent
in interface ValidationEventHandler
event
- the encapsulated validation event information. It is a
provider error if this parameter is null.UnmarshalException
,
ValidationException
, or MarshalException
.public <T> JaxBeanInfo<T> getBeanInfo(Class<T> clazz) throws JAXBException
JAXBException
public Unmarshaller.Listener getListener()
Unmarshaller
Return Unmarshaller.Listener
registered with this Unmarshaller
.
getListener
in interface Unmarshaller
getListener
in class AbstractUnmarshallerImpl
Unmarshaller.Listener
or null
if no Listener is registered with this Unmarshaller.public void setListener(Unmarshaller.Listener listener)
Unmarshaller
Register unmarshal event callback Unmarshaller.Listener
with this Unmarshaller
.
There is only one Listener per Unmarshaller. Setting a Listener replaces the previous set Listener.
One can unregister current Listener by setting listener to null
.
setListener
in interface Unmarshaller
setListener
in class AbstractUnmarshallerImpl
listener
- provides unmarshal event callbacks for this Unmarshaller
public UnmarshallingContext getContext()
protected void finalize() throws Throwable
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
Copyright © 2018 JBoss by Red Hat. All rights reserved.