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, unmarshalprotected final JAXBContextImpl context
JAXBContextpublic final UnmarshallingContext coordinator
public static final String FACTORY
public UnmarshallerImpl(JAXBContextImpl context, AssociationMap assoc)
public UnmarshallerHandler getUnmarshallerHandler()
UnmarshallerThe 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 UnmarshallerUnmarshallerHandlerprotected 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 AbstractUnmarshallerImplJAXBExceptionpublic 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
AbstractUnmarshallerImplunmarshal in class AbstractUnmarshallerImplJAXBExceptionprotected <T> JAXBElement<T> unmarshal(XMLReader reader, InputSource source, Class<T> expectedType) throws JAXBException
JAXBExceptionpublic <T> JAXBElement<T> unmarshal(Source source, Class<T> expectedType) throws JAXBException
UnmarshallerImplements Unmarshal by Declared Type
unmarshal in interface Unmarshallerunmarshal in class AbstractUnmarshallerImplsource - 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
JAXBExceptionpublic final ValidationEventHandler getEventHandler()
AbstractUnmarshallerImplgetEventHandler in interface UnmarshallergetEventHandler in class AbstractUnmarshallerImplpublic 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
UnmarshallerImplements Unmarshal by Declared Type
unmarshal in interface Unmarshallerunmarshal in class AbstractUnmarshallerImplnode - 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.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
UnmarshallerImplements Unmarshal Global Root Element.
unmarshal in interface Unmarshallernode - 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
JAXBExceptionpublic final Object unmarshal0(Node node, JaxBeanInfo expectedType) throws JAXBException
JAXBExceptionpublic Object unmarshal(XMLStreamReader reader) throws JAXBException
UnmarshallerImplements 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 Unmarshallerunmarshal in class AbstractUnmarshallerImplreader - 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
UnmarshallerThis 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 Unmarshallerunmarshal in class AbstractUnmarshallerImplreader - 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
JAXBExceptionpublic <T> JAXBElement<T> unmarshal(XMLEventReader reader, Class<T> expectedType) throws JAXBException
UnmarshallerThis 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 Unmarshallerunmarshal in class AbstractUnmarshallerImplreader - 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
UnmarshallerThis 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 Unmarshallerunmarshal in class AbstractUnmarshallerImplreader - 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
JAXBExceptionpublic Object getProperty(String name) throws PropertyException
AbstractUnmarshallerImplgetProperty in interface UnmarshallergetProperty in class AbstractUnmarshallerImplname - 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
AbstractUnmarshallerImplsetProperty in interface UnmarshallersetProperty in class AbstractUnmarshallerImplname - 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)
UnmarshallerSchema
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 UnmarshallersetSchema in class AbstractUnmarshallerImplschema - Schema object to validate unmarshal operations against or null to disable validationpublic Schema getSchema()
UnmarshallerSchema 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 UnmarshallergetSchema in class AbstractUnmarshallerImplpublic AttachmentUnmarshaller getAttachmentUnmarshaller()
getAttachmentUnmarshaller in interface UnmarshallergetAttachmentUnmarshaller in class AbstractUnmarshallerImplpublic void setAttachmentUnmarshaller(AttachmentUnmarshaller au)
UnmarshallerAssociate 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 UnmarshallersetAttachmentUnmarshaller in class AbstractUnmarshallerImplpublic boolean isValidating()
AbstractUnmarshallerImplNote: I named this method isValidating() to stay in-line with JAXP, as opposed to naming it getValidating().
isValidating in interface UnmarshallerisValidating in class AbstractUnmarshallerImplpublic void setValidating(boolean validating)
AbstractUnmarshallerImplThis method may only be invoked before or after calling one of the unmarshal methods.
setValidating in interface UnmarshallersetValidating in class AbstractUnmarshallerImplvalidating - true if the Unmarshaller should validate during
unmarshal, false otherwisepublic <A extends XmlAdapter> void setAdapter(Class<A> type, A adapter)
UnmarshallerXmlAdapter 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 UnmarshallersetAdapter in class AbstractUnmarshallerImpltype - 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)
UnmarshallerUnmarshaller.setAdapter(javax.xml.bind.annotation.adapters.XmlAdapter) method.getAdapter in interface UnmarshallergetAdapter in class AbstractUnmarshallerImplpublic UnmarshalException createUnmarshalException(SAXException e)
AbstractUnmarshallerImplWhen 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 AbstractUnmarshallerImplpublic boolean handleEvent(ValidationEvent event)
Unmarshaller.handleEvent in interface ValidationEventHandlerevent - the encapsulated validation event information. It is a
provider error if this parameter is null.public <T> JaxBeanInfo<T> getBeanInfo(Class<T> clazz) throws JAXBException
JAXBExceptionpublic Unmarshaller.Listener getListener()
UnmarshallerReturn Unmarshaller.Listener registered with this Unmarshaller.
getListener in interface UnmarshallergetListener in class AbstractUnmarshallerImplUnmarshaller.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 UnmarshallersetListener in class AbstractUnmarshallerImpllistener - provides unmarshal event callbacks for this Unmarshallerpublic UnmarshallingContext getContext()
protected void finalize()
throws Throwable
public void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableIOExceptionCopyright © 2018 JBoss by Red Hat. All rights reserved.