java.lang.Objectjavax.xml.bind.helpers.AbstractUnmarshallerImpl
public abstract class AbstractUnmarshallerImpl
Partial default Unmarshaller implementation.
This class provides a partial default implementation for the Unmarshaller interface.
A JAXB Provider has to implement five methods (getUnmarshallerHandler, unmarshal(Node), unmarshal(XMLReader,InputSource), unmarshal(XMLStreamReader), and unmarshal(XMLEventReader).
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface javax.xml.bind. Unmarshaller |
---|
Unmarshaller.Listener |
Field Summary | |
---|---|
protected boolean |
validating
whether or not the unmarshaller will validate |
Constructor Summary | |
---|---|
AbstractUnmarshallerImpl
() |
Method Summary | ||
---|---|---|
protected UnmarshalException |
createUnmarshalException
(
SAXException
e) Creates an UnmarshalException from a SAXException. |
|
|
getAdapter
(
Class
<A> type) Gets the adapter associated with the specified type. |
|
AttachmentUnmarshaller |
getAttachmentUnmarshaller
() |
|
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. |
|
protected XMLReader |
getXMLReader
() Obtains a configured XMLReader. |
|
boolean |
isValidating
() Indicates whether or not the Unmarshaller is configured to validate during unmarshal operations. |
|
|
setAdapter
(
Class
<A> type, A adapter) Associates a configured instance of XmlAdapter with this unmarshaller. |
|
void |
setAdapter
(
XmlAdapter
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 |
setEventHandler
(
ValidationEventHandler
handler) Allow an application to register a validation event handler. |
|
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) Specifies whether or not the Unmarshaller should validate during unmarshal operations. |
|
Object |
unmarshal
(
File
f) Unmarshal XML data from the specified file and return the resulting content tree. |
|
Object |
unmarshal
(
InputSource
source) Unmarshal XML data from the specified SAX InputSource and return the resulting content tree. |
|
Object |
unmarshal
(
InputStream
is) Unmarshal XML data from the specified InputStream and return the resulting content tree. |
|
|
unmarshal
(
Node
node,
Class
<T> expectedType) Unmarshal XML data by JAXB mapped declaredType and return the resulting content tree. |
|
Object |
unmarshal
(
Reader
reader) Unmarshal XML data from the specified Reader and return the resulting content tree. |
|
Object |
unmarshal
(
Source
source) Unmarshal XML data from the specified XML Source and return the resulting content tree. |
|
|
unmarshal
(
Source
source,
Class
<T> expectedType) Unmarshal XML data from the specified XML Source by declaredType and return the resulting content tree. |
|
Object |
unmarshal
(
URL
url) Unmarshal XML data from the specified URL and return the resulting content tree. |
|
Object |
unmarshal
(
XMLEventReader
reader) Unmarshal XML data from the specified pull parser and return the resulting content tree. |
|
|
unmarshal
(
XMLEventReader
reader,
Class
<T> expectedType) Unmarshal root element to JAXB mapped declaredType and return the resulting content tree. |
|
protected abstract Object |
unmarshal
(
XMLReader
reader,
InputSource
source) Unmarshals an object by using the specified XMLReader and the InputSource. |
|
Object |
unmarshal
(
XMLStreamReader
reader) Unmarshal XML data from the specified pull parser and return the resulting content tree. |
|
|
unmarshal
(
XMLStreamReader
reader,
Class
<T> expectedType) Unmarshal root element to JAXB mapped declaredType and return the resulting content tree. |
Methods inherited from class java.lang. Object |
---|
clone , equals , finalize , getClass , hashCode , notify , notifyAll , toString , wait , wait , wait |
Methods inherited from interface javax.xml.bind. Unmarshaller |
---|
getUnmarshallerHandler , unmarshal |
Field Detail |
---|
protected boolean validating
Constructor Detail |
---|
public AbstractUnmarshallerImpl()
Method Detail |
---|
protected XMLReader getXMLReader() throws JAXBException
public Object unmarshal(Source source) throws JAXBException
Implements Unmarshal Global Root Element .
A client application can choose not to use the default parser mechanism supplied with their JAXB provider. Any SAX 2.0 compliant parser can be substituted for the JAXB provider's default mechanism. To do so, the client application must properly configure a SAXSource containing an XMLReader implemented by the SAX 2.0 parser provider. If the XMLReader has an org.xml.sax.ErrorHandler registered on it, it will be replaced by the JAXB Provider so that validation errors can be reported via the ValidationEventHandler mechanism of JAXB. If the SAXSource does not contain an XMLReader , then the JAXB provider's default parser mechanism will be used.
This parser replacement mechanism can also be used to replace the JAXB provider's unmarshal-time validation engine. The client application must properly configure their SAX 2.0 compliant parser to perform validation (as shown in the example above). Any SAXParserExceptions encountered by the parser during the unmarshal operation will be processed by the JAXB provider and converted into JAXB ValidationEvent objects which will be reported back to the client via the ValidationEventHandler registered with the Unmarshaller . Note: specifying a substitute validating SAX 2.0 parser for unmarshalling does not necessarily replace the validation engine used by the JAXB provider for performing on-demand validation.
The only way for a client application to specify an alternate parser mechanism to be used during unmarshal is via the unmarshal(SAXSource) API. All other forms of the unmarshal method (File, URL, Node, etc) will use the JAXB provider's default parser and validator mechanisms.
protected abstract Object unmarshal(XMLReader reader, InputSource source) throws JAXBException
public final Object unmarshal(InputSource source) throws JAXBException
Implements Unmarshal Global Root Element .
public final Object unmarshal(URL url) throws JAXBException
Implements Unmarshal Global Root Element .
public final Object unmarshal(File f) throws JAXBException
Implements Unmarshal Global Root Element .
public final Object unmarshal(InputStream is) throws JAXBException
Implements Unmarshal Global Root Element .
public final Object unmarshal(Reader reader) throws JAXBException
Implements Unmarshal Global Root Element .
public boolean isValidating() throws JAXBException
Note: I named this method isValidating() to stay in-line with JAXP, as opposed to naming it getValidating().
public void setEventHandler(ValidationEventHandler handler) throws JAXBException
The validation event handler will be called by the JAXB Provider if any validation errors are encountered during calls to any of the unmarshal methods. If the client application does not register a validation event handler before invoking the unmarshal methods, then all validation events will be silently ignored and may result in unexpected behaviour.
public void setValidating(boolean validating) throws JAXBException
This method may only be invoked before or after calling one of the unmarshal methods.
public ValidationEventHandler getEventHandler() throws JAXBException
protected UnmarshalException createUnmarshalException(SAXException e)
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.
public void setProperty(String name, Object value) throws PropertyException
public Object getProperty(String name) throws PropertyException
public Object unmarshal(XMLEventReader reader) throws JAXBException
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.
public Object unmarshal(XMLStreamReader reader) throws JAXBException
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.
public <T> JAXBElement<T> unmarshal(Node node, Class<T> expectedType) throws JAXBException
Implements Unmarshal by Declared Type
public <T> JAXBElement<T> unmarshal(Source source, Class<T> expectedType) throws JAXBException
Implements Unmarshal by Declared Type
See SAX 2.0 Parser Pluggability
public <T> JAXBElement<T> unmarshal(XMLStreamReader reader, Class<T> expectedType) throws JAXBException
This method implements
unmarshal by declaredType
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.
public <T> JAXBElement<T> unmarshal(XMLEventReader reader, Class<T> expectedType) throws JAXBException
This method implements
unmarshal by declaredType
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.
public void setSchema(Schema schema)
This method replaces the deprecated setValidating(boolean) API.
Initially this property is set to null .
public Schema getSchema()
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;
public void setAdapter(XmlAdapter adapter)
This is a convenience method that invokes setAdapter(adapter.getClass(),adapter);.
public <A extends XmlAdapter> void setAdapter(Class<A> type, A adapter)
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.
public <A extends XmlAdapter> A getAdapter(Class<A> type)
public void setAttachmentUnmarshaller(AttachmentUnmarshaller au)
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.
public AttachmentUnmarshaller getAttachmentUnmarshaller()
public void setListener(Unmarshaller.Listener listener)
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 .
public Unmarshaller.Listener getListener()
Return Unmarshaller.Listener registered with this Unmarshaller .