public class BadgerUnmarshaller extends Object implements Unmarshaller
Unmarshaller.Listener
Constructor and Description |
---|
BadgerUnmarshaller(JAXBContext context) |
Modifier and Type | Method and Description |
---|---|
<A extends XmlAdapter> |
getAdapter(Class<A> aClass)
Gets the adapter associated with the specified type.
|
AttachmentUnmarshaller |
getAttachmentUnmarshaller() |
protected org.codehaus.jettison.badgerfish.BadgerFishXMLStreamReader |
getBadgerFishReader(Reader reader) |
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 s)
Get the particular property in the underlying implementation of
Unmarshaller.
|
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.
|
boolean |
isValidating()
Indicates whether or not the Unmarshaller is configured to
validate during unmarshal operations.
|
<A extends XmlAdapter> |
setAdapter(Class<A> aClass,
A a)
Associates a configured instance of
XmlAdapter with this unmarshaller. |
void |
setAdapter(XmlAdapter xmlAdapter)
Associates a configured instance of
XmlAdapter with this unmarshaller. |
void |
setAttachmentUnmarshaller(AttachmentUnmarshaller attachmentUnmarshaller)
Associate a context that resolves cid's, content-id URIs, to
binary data passed as attachments.
|
void |
setEventHandler(ValidationEventHandler validationEventHandler)
Allow an application to register a ValidationEventHandler.
|
void |
setListener(Unmarshaller.Listener listener)
Register unmarshal event callback
Unmarshaller.Listener with this Unmarshaller . |
void |
setProperty(String s,
Object o)
Set the particular property in the underlying implementation of
Unmarshaller.
|
void |
setSchema(Schema schema)
Specify the JAXP 1.3
Schema
object that should be used to validate subsequent unmarshal operations
against. |
void |
setValidating(boolean b)
Specifies whether or not the default validation mechanism of the
Unmarshaller should validate during unmarshal operations.
|
Object |
unmarshal(File file)
Unmarshal XML data from the specified file and return the resulting
content tree.
|
Object |
unmarshal(InputSource inputSource)
Unmarshal XML data from the specified SAX InputSource and return the
resulting content tree.
|
Object |
unmarshal(InputStream inputStream)
Unmarshal XML data from the specified InputStream and return the
resulting content tree.
|
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> tClass)
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.
|
<T> JAXBElement<T> |
unmarshal(Source source,
Class<T> tClass)
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 xmlEventReader)
Unmarshal XML data from the specified pull parser and return the
resulting content tree.
|
<T> JAXBElement<T> |
unmarshal(XMLEventReader xmlEventReader,
Class<T> tClass)
Unmarshal root element to JAXB mapped declaredType
and return the resulting content tree.
|
Object |
unmarshal(XMLStreamReader xmlStreamReader)
Unmarshal XML data from the specified pull parser and return the
resulting content tree.
|
<T> JAXBElement<T> |
unmarshal(XMLStreamReader xmlStreamReader,
Class<T> tClass)
Unmarshal root element to JAXB mapped declaredType
and return the resulting content tree.
|
public BadgerUnmarshaller(JAXBContext context) throws JAXBException
JAXBException
public Object unmarshal(File file) throws JAXBException
Unmarshaller
Implements Unmarshal Global Root Element.
unmarshal
in interface Unmarshaller
file
- the file to unmarshal XML data fromJAXBException
- 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(InputStream inputStream) throws JAXBException
Unmarshaller
Implements Unmarshal Global Root Element.
unmarshal
in interface Unmarshaller
inputStream
- the InputStream to unmarshal XML data fromJAXBException
- 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(Reader reader) throws JAXBException
Unmarshaller
Implements Unmarshal Global Root Element.
unmarshal
in interface Unmarshaller
reader
- the Reader to unmarshal XML data fromJAXBException
- 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 Dataprotected org.codehaus.jettison.badgerfish.BadgerFishXMLStreamReader getBadgerFishReader(Reader reader) throws JAXBException
JAXBException
public Object unmarshal(URL url) throws JAXBException
Unmarshaller
Implements Unmarshal Global Root Element.
unmarshal
in interface Unmarshaller
url
- the url to unmarshal XML data fromJAXBException
- 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(InputSource inputSource) throws JAXBException
Unmarshaller
Implements Unmarshal Global Root Element.
unmarshal
in interface Unmarshaller
inputSource
- the input source to unmarshal XML data fromJAXBException
- 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(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)
public <T> JAXBElement<T> unmarshal(Node node, Class<T> tClass) throws JAXBException
Unmarshaller
Implements Unmarshal by Declared Type
unmarshal
in interface Unmarshaller
node
- the document/element to unmarshal XML data from.
The caller must support at least Document and Element.tClass
- 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 Object unmarshal(Source source) throws JAXBException
Unmarshaller
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.
unmarshal
in interface Unmarshaller
source
- the XML Source to unmarshal XML data from (providers are
only required to support SAXSource, DOMSource, and StreamSource)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.transform.Source, Class)
public <T> JAXBElement<T> unmarshal(Source source, Class<T> tClass) throws JAXBException
Unmarshaller
Implements Unmarshal by Declared Type
unmarshal
in interface Unmarshaller
source
- the XML Source to unmarshal XML data from (providers are
only required to support SAXSource, DOMSource, and StreamSource)tClass
- 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 unmarshal(XMLStreamReader xmlStreamReader) 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
xmlStreamReader
- 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 xmlStreamReader, Class<T> tClass) throws JAXBException
Unmarshaller
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
xmlStreamReader
- The parser to be read.tClass
- 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 xmlEventReader) 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
xmlEventReader
- 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 <T> JAXBElement<T> unmarshal(XMLEventReader xmlEventReader, Class<T> tClass) throws JAXBException
Unmarshaller
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
xmlEventReader
- The parser to be read.tClass
- 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 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
public void setValidating(boolean b) throws JAXBException
Unmarshaller
This method may only be invoked before or after calling one of the unmarshal methods.
This method only controls the JAXB Provider's default unmarshal-time validation mechanism - it has no impact on clients that specify their own validating SAX 2.0 compliant parser. Clients that specify their own unmarshal-time validation mechanism may wish to turn off the JAXB Provider's default validation mechanism via this API to avoid "double validation".
This method is deprecated as of JAXB 2.0 - please use the new
Unmarshaller.setSchema(javax.xml.validation.Schema)
API.
setValidating
in interface Unmarshaller
b
- true if the Unmarshaller should validate during
unmarshal, false otherwiseJAXBException
- if an error occurred while enabling or disabling
validation at unmarshal timepublic boolean isValidating() throws JAXBException
Unmarshaller
This API returns the state of the JAXB Provider's default unmarshal-time validation mechanism.
This method is deprecated as of JAXB 2.0 - please use the new
Unmarshaller.getSchema()
API.
isValidating
in interface Unmarshaller
JAXBException
- if an error occurs while retrieving the validating
flagpublic void setEventHandler(ValidationEventHandler validationEventHandler) throws JAXBException
Unmarshaller
The ValidationEventHandler 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 ValidationEventHandler before invoking the unmarshal methods, then ValidationEvents will be handled by the default event handler which will terminate the unmarshal operation after the first error or fatal error is encountered.
Calling this method with a null parameter will cause the Unmarshaller to revert back to the default event handler.
setEventHandler
in interface Unmarshaller
validationEventHandler
- the validation event handlerJAXBException
- if an error was encountered while setting the
event handlerpublic ValidationEventHandler getEventHandler() throws JAXBException
Unmarshaller
getEventHandler
in interface Unmarshaller
JAXBException
- if an error was encountered while getting the
current event handlerpublic void setProperty(String s, Object o) throws PropertyException
Unmarshaller
setProperty
in interface Unmarshaller
s
- 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.o
- the value of the property to be setPropertyException
- when there is an error processing the given
property or valuepublic Object getProperty(String s) throws PropertyException
Unmarshaller
getProperty
in interface Unmarshaller
s
- the name of the property to retrievePropertyException
- when there is an error retrieving the given property or value
property namepublic 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
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
public void setAdapter(XmlAdapter xmlAdapter)
Unmarshaller
XmlAdapter
with this unmarshaller.
This is a convenience method that invokes setAdapter(adapter.getClass(),adapter);
.
setAdapter
in interface Unmarshaller
Unmarshaller.setAdapter(Class,XmlAdapter)
public <A extends XmlAdapter> void setAdapter(Class<A> aClass, A a)
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
aClass
- The type of the adapter. The specified instance will be used when
XmlJavaTypeAdapter.value()
refers to this type.a
- 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> aClass)
Unmarshaller
Unmarshaller.setAdapter(javax.xml.bind.annotation.adapters.XmlAdapter)
method.getAdapter
in interface Unmarshaller
public void setAttachmentUnmarshaller(AttachmentUnmarshaller attachmentUnmarshaller)
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
public AttachmentUnmarshaller getAttachmentUnmarshaller()
getAttachmentUnmarshaller
in interface 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
listener
- provides unmarshal event callbacks for this Unmarshaller
public Unmarshaller.Listener getListener()
Unmarshaller
Return Unmarshaller.Listener
registered with this Unmarshaller
.
getListener
in interface Unmarshaller
Unmarshaller.Listener
or null
if no Listener is registered with this Unmarshaller.Copyright © 2016 JBoss by Red Hat. All rights reserved.