Class UnmarshallerImpl
- java.lang.Object
-
- javax.xml.bind.helpers.AbstractUnmarshallerImpl
-
- com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl
-
- All Implemented Interfaces:
Closeable,AutoCloseable,Unmarshaller,ValidationEventHandler
public final class UnmarshallerImpl extends AbstractUnmarshallerImpl implements ValidationEventHandler, Closeable
Default Unmarshaller implementation.This class can be extended by the generated code to provide type-safe unmarshall methods.
- Author:
- Kohsuke KAWAGUCHI
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface javax.xml.bind.Unmarshaller
Unmarshaller.Listener
-
-
Field Summary
Fields Modifier and Type Field Description protected JAXBContextImplcontextOwningJAXBContextUnmarshallingContextcoordinatorstatic StringFACTORY-
Fields inherited from class javax.xml.bind.helpers.AbstractUnmarshallerImpl
validating
-
-
Constructor Summary
Constructors Constructor Description UnmarshallerImpl(JAXBContextImpl context, AssociationMap assoc)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidclose()Must be called from same thread which created the UnmarshallerImpl instance.UnmarshalExceptioncreateUnmarshalException(SAXException e)Creates an UnmarshalException from a SAXException.XmlVisitorcreateUnmarshallerHandler(InfosetScanner scanner, boolean inplace, JaxBeanInfo expectedType)Creates and configures a new unmarshalling pipe line.protected voidfinalize()<A extends XmlAdapter>
AgetAdapter(Class<A> type)Gets the adapter associated with the specified type.AttachmentUnmarshallergetAttachmentUnmarshaller()<T> JaxBeanInfo<T>getBeanInfo(Class<T> clazz)UnmarshallingContextgetContext()ValidationEventHandlergetEventHandler()Return the current event handler or the default event handler if one hasn't been set.Unmarshaller.ListenergetListener()ReturnUnmarshaller.Listenerregistered with thisUnmarshaller.ObjectgetProperty(String name)Default implementation of the getProperty method always throws PropertyException since there are no required properties.SchemagetSchema()Get the JAXP 1.3Schemaobject being used to perform unmarshal-time validation.UnmarshallerHandlergetUnmarshallerHandler()Get an unmarshaller handler object that can be used as a component in an XML pipeline.protected XMLReadergetXMLReader()Obtains a configured XMLReader.booleanhandleEvent(ValidationEvent event)Default error handling behavior forUnmarshaller.booleanhasEventHandler()Returns true if an event handler is installed.booleanisValidating()Deprecated.since 2.0static booleanneedsInterning(XMLReader reader)<A extends XmlAdapter>
voidsetAdapter(Class<A> type, A adapter)Associates a configured instance ofXmlAdapterwith this unmarshaller.voidsetAttachmentUnmarshaller(AttachmentUnmarshaller au)Associate a context that resolves cid's, content-id URIs, to binary data passed as attachments.voidsetListener(Unmarshaller.Listener listener)Register unmarshal event callbackUnmarshaller.Listenerwith thisUnmarshaller.voidsetProperty(String name, Object value)Default implementation of the setProperty method always throws PropertyException since there are no required properties.voidsetSchema(Schema schema)Specify the JAXP 1.3Schemaobject that should be used to validate subsequent unmarshal operations against.voidsetValidating(boolean validating)Deprecated.since 2.0Objectunmarshal(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 mappeddeclaredTypeand return the resulting content tree.Objectunmarshal(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 mappeddeclaredTypeand return the resulting content tree.Objectunmarshal(SAXSource source)Deprecated.<T> JAXBElement<T>unmarshal(Source source, Class<T> expectedType)Unmarshal XML data from the specified XML Source bydeclaredTypeand return the resulting content tree.Objectunmarshal(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 mappeddeclaredTypeand return the resulting content tree.protected Objectunmarshal(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)Objectunmarshal0(InputStream input, JaxBeanInfo expectedType)Objectunmarshal0(XMLStreamReader reader, JaxBeanInfo expectedType)Objectunmarshal0(Source source, JaxBeanInfo expectedType)Objectunmarshal0(Node node, JaxBeanInfo expectedType)-
Methods inherited from class javax.xml.bind.helpers.AbstractUnmarshallerImpl
setAdapter, setEventHandler, unmarshal, unmarshal, unmarshal, unmarshal, unmarshal, unmarshal
-
-
-
-
Field Detail
-
context
protected final JAXBContextImpl context
OwningJAXBContext
-
coordinator
public final UnmarshallingContext coordinator
-
FACTORY
public static final String FACTORY
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
UnmarshallerImpl
public UnmarshallerImpl(JAXBContextImpl context, AssociationMap assoc)
-
-
Method Detail
-
getUnmarshallerHandler
public UnmarshallerHandler getUnmarshallerHandler()
Description copied from interface:UnmarshallerGet an unmarshaller handler object that can be used as a component in an XML pipeline.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 oneUnmarshallerHandler, it should create more than oneUnmarshaller.- Specified by:
getUnmarshallerHandlerin interfaceUnmarshaller- Returns:
- the unmarshaller handler object
- See Also:
UnmarshallerHandler
-
getXMLReader
protected XMLReader getXMLReader() throws JAXBException
Obtains a configured XMLReader. This method is used when the client-specifiedSAXSourceobject doesn't have XMLReader.Unmarshalleris not re-entrant, so we will only use one instance of XMLReader. Overriden in order to fix potential security issue.- Overrides:
getXMLReaderin classAbstractUnmarshallerImpl- Throws:
JAXBException
-
createUnmarshallerHandler
public final XmlVisitor createUnmarshallerHandler(InfosetScanner scanner, boolean inplace, JaxBeanInfo expectedType)
Creates and configures a new unmarshalling pipe line. Depending on the setting, we put a validator as a filter.- Returns:
- A component that implements both
UnmarshallerHandlerandValidationEventHandler. 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.
-
needsInterning
public static boolean needsInterning(XMLReader reader)
-
unmarshal
protected Object unmarshal(XMLReader reader, InputSource source) throws JAXBException
Description copied from class:AbstractUnmarshallerImplUnmarshals an object by using the specified XMLReader and the InputSource. The callee should call the setErrorHandler method of the XMLReader so that errors are passed to the client-specified ValidationEventHandler.- Specified by:
unmarshalin classAbstractUnmarshallerImpl- Throws:
JAXBException
-
unmarshal
protected <T> JAXBElement<T> unmarshal(XMLReader reader, InputSource source, Class<T> expectedType) throws JAXBException
- Throws:
JAXBException
-
unmarshal
public <T> JAXBElement<T> unmarshal(Source source, Class<T> expectedType) throws JAXBException
Description copied from interface:UnmarshallerUnmarshal XML data from the specified XML Source bydeclaredTypeand return the resulting content tree.Implements Unmarshal by Declared Type
- Specified by:
unmarshalin interfaceUnmarshaller- Overrides:
unmarshalin classAbstractUnmarshallerImpl- Parameters:
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 holdsource's xml root element- Returns:
- Java content rooted by JAXB Element
- Throws:
JAXBException- If any unexpected errors occur while unmarshallingUnmarshalException- If theValidationEventHandlerreturns false from itshandleEventmethod or theUnmarshalleris unable to perform the XML to Java binding. See Unmarshalling XML Data
-
unmarshal0
public Object unmarshal0(Source source, JaxBeanInfo expectedType) throws JAXBException
- Throws:
JAXBException
-
getEventHandler
public final ValidationEventHandler getEventHandler()
Description copied from class:AbstractUnmarshallerImplReturn the current event handler or the default event handler if one hasn't been set.- Specified by:
getEventHandlerin interfaceUnmarshaller- Overrides:
getEventHandlerin classAbstractUnmarshallerImpl- Returns:
- the current ValidationEventHandler or the default event handler if it hasn't been set
-
hasEventHandler
public final boolean hasEventHandler()
Returns true if an event handler is installed.The default handler ignores any errors, and for that this method returns false.
-
unmarshal
public <T> JAXBElement<T> unmarshal(Node node, Class<T> expectedType) throws JAXBException
Description copied from interface:UnmarshallerUnmarshal XML data by JAXB mappeddeclaredTypeand return the resulting content tree.Implements Unmarshal by Declared Type
- Specified by:
unmarshalin interfaceUnmarshaller- Overrides:
unmarshalin classAbstractUnmarshallerImpl- Parameters:
node- the document/element to unmarshal XML data from. The caller must support at least Document and Element.expectedType- appropriate JAXB mapped class to holdnode's XML data.- Returns:
- JAXB Element representation of
node - Throws:
JAXBException- If any unexpected errors occur while unmarshallingUnmarshalException- If theValidationEventHandlerreturns false from itshandleEventmethod or theUnmarshalleris unable to perform the XML to Java binding. See Unmarshalling XML Data
-
unmarshal
public final Object unmarshal(Node node) throws JAXBException
Description copied from interface:UnmarshallerUnmarshal global XML data from the specified DOM tree and return the resulting content tree.Implements Unmarshal Global Root Element.
- Specified by:
unmarshalin interfaceUnmarshaller- Parameters:
node- the document/element to unmarshal XML data from. The caller must support at least Document and Element.- Returns:
- the newly created root object of the java content tree
- Throws:
JAXBException- If any unexpected errors occur while unmarshallingUnmarshalException- If theValidationEventHandlerreturns false from itshandleEventmethod or theUnmarshalleris unable to perform the XML to Java binding. See Unmarshalling XML Data- See Also:
Unmarshaller.unmarshal(org.w3c.dom.Node, Class)
-
unmarshal
@Deprecated public final Object unmarshal(SAXSource source) throws JAXBException
Deprecated.- Throws:
JAXBException
-
unmarshal0
public final Object unmarshal0(Node node, JaxBeanInfo expectedType) throws JAXBException
- Throws:
JAXBException
-
unmarshal
public Object unmarshal(XMLStreamReader reader) throws JAXBException
Description copied from interface:UnmarshallerUnmarshal XML data from the specified pull parser and return the resulting content tree.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
readerwill be pointing at the token right after the end event.- Specified by:
unmarshalin interfaceUnmarshaller- Overrides:
unmarshalin classAbstractUnmarshallerImpl- Parameters:
reader- The parser to be read.- Returns:
- the newly created root object of the java content tree.
- Throws:
JAXBException- If any unexpected errors occur while unmarshallingUnmarshalException- If theValidationEventHandlerreturns false from itshandleEventmethod or theUnmarshalleris unable to perform the XML to Java binding. See Unmarshalling XML Data- See Also:
Unmarshaller.unmarshal(javax.xml.stream.XMLStreamReader, Class)
-
unmarshal
public <T> JAXBElement<T> unmarshal(XMLStreamReader reader, Class<T> expectedType) throws JAXBException
Description copied from interface:UnmarshallerUnmarshal root element to JAXB mappeddeclaredTypeand 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
readerwill be pointing at the token right after the end event.- Specified by:
unmarshalin interfaceUnmarshaller- Overrides:
unmarshalin classAbstractUnmarshallerImpl- Parameters:
reader- The parser to be read.expectedType- appropriate JAXB mapped class to holdreader's START_ELEMENT XML data.- Returns:
- content tree rooted by JAXB Element representation
- Throws:
JAXBException- If any unexpected errors occur while unmarshallingUnmarshalException- If theValidationEventHandlerreturns false from itshandleEventmethod or theUnmarshalleris unable to perform the XML to Java binding. See Unmarshalling XML Data
-
unmarshal0
public Object unmarshal0(XMLStreamReader reader, JaxBeanInfo expectedType) throws JAXBException
- Throws:
JAXBException
-
unmarshal
public <T> JAXBElement<T> unmarshal(XMLEventReader reader, Class<T> expectedType) throws JAXBException
Description copied from interface:UnmarshallerUnmarshal root element to JAXB mappeddeclaredTypeand 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
readerwill be pointing at the token right after the end event.- Specified by:
unmarshalin interfaceUnmarshaller- Overrides:
unmarshalin classAbstractUnmarshallerImpl- Parameters:
reader- The parser to be read.expectedType- appropriate JAXB mapped class to holdreader's START_ELEMENT XML data.- Returns:
- content tree rooted by JAXB Element representation
- Throws:
JAXBException- If any unexpected errors occur while unmarshallingUnmarshalException- If theValidationEventHandlerreturns false from itshandleEventmethod or theUnmarshalleris unable to perform the XML to Java binding. See Unmarshalling XML Data
-
unmarshal
public Object unmarshal(XMLEventReader reader) throws JAXBException
Description copied from interface:UnmarshallerUnmarshal XML data from the specified pull parser and return the resulting content tree.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
readerwill be pointing at the token right after the end event.- Specified by:
unmarshalin interfaceUnmarshaller- Overrides:
unmarshalin classAbstractUnmarshallerImpl- Parameters:
reader- The parser to be read.- Returns:
- the newly created root object of the java content tree.
- Throws:
JAXBException- If any unexpected errors occur while unmarshallingUnmarshalException- If theValidationEventHandlerreturns false from itshandleEventmethod or theUnmarshalleris unable to perform the XML to Java binding. See Unmarshalling XML Data- See Also:
Unmarshaller.unmarshal(javax.xml.stream.XMLEventReader, Class)
-
unmarshal0
public Object unmarshal0(InputStream input, JaxBeanInfo expectedType) throws JAXBException
- Throws:
JAXBException
-
getProperty
public Object getProperty(String name) throws PropertyException
Description copied from class:AbstractUnmarshallerImplDefault implementation of the getProperty method always throws PropertyException since there are no required properties. If a provider needs to handle additional properties, it should override this method in a derived class.- Specified by:
getPropertyin interfaceUnmarshaller- Overrides:
getPropertyin classAbstractUnmarshallerImpl- Parameters:
name- the name of the property to retrieve- Returns:
- the value of the requested property
- Throws:
PropertyException- when there is an error retrieving the given property or value property name
-
setProperty
public void setProperty(String name, Object value) throws PropertyException
Description copied from class:AbstractUnmarshallerImplDefault implementation of the setProperty method always throws PropertyException since there are no required properties. If a provider needs to handle additional properties, it should override this method in a derived class.- Specified by:
setPropertyin interfaceUnmarshaller- Overrides:
setPropertyin classAbstractUnmarshallerImpl- Parameters:
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 set- Throws:
PropertyException- when there is an error processing the given property or value
-
setSchema
public void setSchema(Schema schema)
Description copied from interface:UnmarshallerSpecify the JAXP 1.3Schemaobject 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.- Specified by:
setSchemain interfaceUnmarshaller- Overrides:
setSchemain classAbstractUnmarshallerImpl- Parameters:
schema- Schema object to validate unmarshal operations against or null to disable validation
-
getSchema
public Schema getSchema()
Description copied from interface:UnmarshallerGet the JAXP 1.3Schemaobject 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;- Specified by:
getSchemain interfaceUnmarshaller- Overrides:
getSchemain classAbstractUnmarshallerImpl- Returns:
- the Schema object being used to perform unmarshal-time validation or null if not present
-
getAttachmentUnmarshaller
public AttachmentUnmarshaller getAttachmentUnmarshaller()
- Specified by:
getAttachmentUnmarshallerin interfaceUnmarshaller- Overrides:
getAttachmentUnmarshallerin classAbstractUnmarshallerImpl
-
setAttachmentUnmarshaller
public void setAttachmentUnmarshaller(AttachmentUnmarshaller au)
Description copied from interface: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.- Specified by:
setAttachmentUnmarshallerin interfaceUnmarshaller- Overrides:
setAttachmentUnmarshallerin classAbstractUnmarshallerImpl
-
isValidating
public boolean isValidating()
Deprecated.since 2.0Description copied from class:AbstractUnmarshallerImplIndicates whether or not the Unmarshaller is configured to validate during unmarshal operations.Note: I named this method isValidating() to stay in-line with JAXP, as opposed to naming it getValidating().
- Specified by:
isValidatingin interfaceUnmarshaller- Overrides:
isValidatingin classAbstractUnmarshallerImpl- Returns:
- true if the Unmarshaller is configured to validate during unmarshal operations, false otherwise
-
setValidating
public void setValidating(boolean validating)
Deprecated.since 2.0Description copied from class:AbstractUnmarshallerImplSpecifies whether or not the Unmarshaller should validate during unmarshal operations. By default, theUnmarshallerdoes not validate.This method may only be invoked before or after calling one of the unmarshal methods.
- Specified by:
setValidatingin interfaceUnmarshaller- Overrides:
setValidatingin classAbstractUnmarshallerImpl- Parameters:
validating- true if the Unmarshaller should validate during unmarshal, false otherwise
-
setAdapter
public <A extends XmlAdapter> void setAdapter(Class<A> type, A adapter)
Description copied from interface:UnmarshallerAssociates a configured instance ofXmlAdapterwith this unmarshaller.Every unmarshaller internally maintains a
Map<Class,XmlAdapter>, which it uses for unmarshalling classes whose fields/methods are annotated withXmlJavaTypeAdapter.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.- Specified by:
setAdapterin interfaceUnmarshaller- Overrides:
setAdapterin classAbstractUnmarshallerImpl- Parameters:
type- The type of the adapter. The specified instance will be used whenXmlJavaTypeAdapter.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.
-
getAdapter
public <A extends XmlAdapter> A getAdapter(Class<A> type)
Description copied from interface:UnmarshallerGets the adapter associated with the specified type. This is the reverse operation of theUnmarshaller.setAdapter(javax.xml.bind.annotation.adapters.XmlAdapter)method.- Specified by:
getAdapterin interfaceUnmarshaller- Overrides:
getAdapterin classAbstractUnmarshallerImpl
-
createUnmarshalException
public UnmarshalException createUnmarshalException(SAXException e)
Description copied from class:AbstractUnmarshallerImplCreates an UnmarshalException from a SAXException. This is an utility method provided for the derived classes.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.
- Overrides:
createUnmarshalExceptionin classAbstractUnmarshallerImpl- Returns:
- the resulting UnmarshalException
-
handleEvent
public boolean handleEvent(ValidationEvent event)
Default error handling behavior forUnmarshaller.- Specified by:
handleEventin interfaceValidationEventHandler- Parameters:
event- the encapsulated validation event information. It is a provider error if this parameter is null.- Returns:
- true if the JAXB Provider should attempt to continue the current
unmarshal, validate, or marshal operation after handling this
warning/error, false if the provider should terminate the current
operation with the appropriate
UnmarshalException,ValidationException, orMarshalException.
-
getBeanInfo
public <T> JaxBeanInfo<T> getBeanInfo(Class<T> clazz) throws JAXBException
- Throws:
JAXBException
-
getListener
public Unmarshaller.Listener getListener()
Description copied from interface:UnmarshallerReturn
Unmarshaller.Listenerregistered with thisUnmarshaller.- Specified by:
getListenerin interfaceUnmarshaller- Overrides:
getListenerin classAbstractUnmarshallerImpl- Returns:
- registered
Unmarshaller.Listenerornullif no Listener is registered with this Unmarshaller.
-
setListener
public void setListener(Unmarshaller.Listener listener)
Description copied from interface:UnmarshallerRegister unmarshal event callback
Unmarshaller.Listenerwith thisUnmarshaller.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.- Specified by:
setListenerin interfaceUnmarshaller- Overrides:
setListenerin classAbstractUnmarshallerImpl- Parameters:
listener- provides unmarshal event callbacks for thisUnmarshaller
-
getContext
public UnmarshallingContext getContext()
-
finalize
protected void finalize() throws Throwable
-
close
public void close() throws IOExceptionMust be called from same thread which created the UnmarshallerImpl instance.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
-