Class UnmarshallerImpl
- All Implemented Interfaces:
Unmarshaller,ValidationEventHandler,Closeable,AutoCloseable
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 jakarta.xml.bind.Unmarshaller
Unmarshaller.Listener -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final JAXBContextImplOwningJAXBContextfinal UnmarshallingContextstatic final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Must be called from same thread which created the UnmarshallerImpl instance.Creates an UnmarshalException from a SAXException.createUnmarshallerHandler(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.<T> JaxBeanInfo<T>getBeanInfo(Class<T> clazz) Return the current event handler or the default event handler if one hasn't been set.ReturnUnmarshaller.Listenerregistered with thisUnmarshaller.getProperty(String name) Default implementation of the getProperty method always throws PropertyException since there are no required properties.Get the JAXPSchemaobject being used to perform unmarshal-time validation.Get an unmarshaller handler object that can be used as a component in an XML pipeline.protected XMLReaderObtains a configured XMLReader.booleanhandleEvent(ValidationEvent event) Default error handling behavior forUnmarshaller.booleanReturns true if an event handler is installed.booleanDeprecated.since 2.0static booleanneedsInterning(XMLReader reader) <A extends XmlAdapter<?,?>>
voidsetAdapter(Class<A> type, A adapter) Associates a configured instance ofXmlAdapterwith this unmarshaller.voidAssociate 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.voidSpecify the JAXPSchemaobject that should be used to validate subsequent unmarshal operations against.voidsetValidating(boolean validating) Deprecated.since 2.0unmarshal(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 Jakarta XML Binding mappeddeclaredTypeand return the resulting content tree.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 Jakarta XML Binding mappeddeclaredTypeand return the resulting content tree.Deprecated.<T> JAXBElement<T>Unmarshal XML data from the specified XML Source bydeclaredTypeand return the resulting content tree.Unmarshal global XML data from the specified DOM tree and return the resulting content tree.<T> JAXBElement<T>Unmarshal XML data by Jakarta XML Binding mappeddeclaredTypeand return the resulting content tree.protected Objectunmarshal(XMLReader reader, InputSource source) Unmarshalls an object by using the specified XMLReader and the InputSource.protected <T> JAXBElement<T>unmarshal(XMLReader reader, InputSource source, Class<T> expectedType) unmarshal0(InputStream input, JaxBeanInfo expectedType) unmarshal0(XMLStreamReader reader, JaxBeanInfo expectedType) unmarshal0(Source source, JaxBeanInfo expectedType) unmarshal0(Node node, JaxBeanInfo expectedType) Methods inherited from class jakarta.xml.bind.helpers.AbstractUnmarshallerImpl
setAdapter, setEventHandler, unmarshal, unmarshal, unmarshal, unmarshal, unmarshal, unmarshal
-
Field Details
-
context
OwningJAXBContext -
coordinator
-
FACTORY
- See Also:
-
-
Constructor Details
-
UnmarshallerImpl
-
-
Method Details
-
getUnmarshallerHandler
Description copied from interface:UnmarshallerGet an unmarshaller handler object that can be used as a component in an XML pipeline.The Jakarta XML Binding 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:
-
getXMLReader
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 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
-
unmarshal
Description copied from class:AbstractUnmarshallerImplUnmarshalls 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
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- Type Parameters:
T- the XML Binding mapped class- Parameters:
source- the XML Source to unmarshal XML data from (providers are only required to support SAXSource, DOMSource, and StreamSource)expectedType- appropriate Jakarta XML Binding mapped class to holdsource's xml root element- Returns:
- Java content rooted by JAXBElement
- 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
- Throws:
JAXBException
-
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 boolean hasEventHandler()Returns true if an event handler is installed.The default handler ignores any errors, and for that this method returns false.
-
unmarshal
Description copied from interface:UnmarshallerUnmarshal XML data by Jakarta XML Binding mappeddeclaredTypeand return the resulting content tree.Implements Unmarshal by Declared Type
- Specified by:
unmarshalin interfaceUnmarshaller- Overrides:
unmarshalin classAbstractUnmarshallerImpl- Type Parameters:
T- the XML Binding mapped class- Parameters:
node- the document/element to unmarshal XML data from. The caller must support at least Document and Element.expectedType- appropriate Jakarta XML Binding mapped class to holdnode's XML data.- Returns:
- JAXBElement 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
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:
-
unmarshal
Deprecated.- Throws:
JAXBException
-
unmarshal0
- Throws:
JAXBException
-
unmarshal
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:
-
unmarshal
public <T> JAXBElement<T> unmarshal(XMLStreamReader reader, Class<T> expectedType) throws JAXBException Description copied from interface:UnmarshallerUnmarshal root element to Jakarta XML Binding 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- Type Parameters:
T- the XML Binding mapped class- Parameters:
reader- The parser to be read.expectedType- appropriate Jakarta XML Binding mapped class to holdreader's START_ELEMENT XML data.- Returns:
- content tree rooted by JAXBElement 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
- Throws:
JAXBException
-
unmarshal
public <T> JAXBElement<T> unmarshal(XMLEventReader reader, Class<T> expectedType) throws JAXBException Description copied from interface:UnmarshallerUnmarshal root element to Jakarta XML Binding 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- Type Parameters:
T- the XML Binding mapped class- Parameters:
reader- The parser to be read.expectedType- appropriate Jakarta XML Binding mapped class to holdreader's START_ELEMENT XML data.- Returns:
- content tree rooted by JAXBElement 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
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:
-
unmarshal0
- Throws:
JAXBException
-
getProperty
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
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
Description copied from interface:UnmarshallerSpecify the JAXPSchemaobject that should be used to validate subsequent unmarshal operations against. Passing null into this method will disable validation.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
Description copied from interface:UnmarshallerGet the JAXPSchemaobject 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.- Specified by:
getSchemain interfaceUnmarshaller- Overrides:
getSchemain classAbstractUnmarshallerImpl- Returns:
- the Schema object being used to perform unmarshal-time validation or null if not present
-
getAttachmentUnmarshaller
- Specified by:
getAttachmentUnmarshallerin interfaceUnmarshaller- Overrides:
getAttachmentUnmarshallerin classAbstractUnmarshallerImpl
-
setAttachmentUnmarshaller
Description copied from interface:UnmarshallerAssociate a context that resolves cid's, content-id URIs, to binary data passed as attachments. Unmarshal time validation, enabled viaUnmarshaller.setSchema(Schema), must be supported even when unmarshaller is performing XOP processing.- Specified by:
setAttachmentUnmarshallerin interfaceUnmarshaller- Overrides:
setAttachmentUnmarshallerin classAbstractUnmarshallerImpl- Parameters:
au- the attachment unmarshaller to be set
-
isValidating
Deprecated.since 2.0 -
setValidating
Deprecated.since 2.0 -
setAdapter
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- Type Parameters:
A- the type of the adapter- 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
Description copied from interface:UnmarshallerGets the adapter associated with the specified type. This is the reverse operation of theUnmarshaller.setAdapter(A)method.- Specified by:
getAdapterin interfaceUnmarshaller- Overrides:
getAdapterin classAbstractUnmarshallerImpl- Type Parameters:
A- the type of the adapter- Parameters:
type- The type of the adapter. The specified instance will be used whenXmlJavaTypeAdapter.value()refers to this type.- Returns:
- The adapter associated with the specified type.
-
createUnmarshalException
Description copied from class:AbstractUnmarshallerImplCreates an UnmarshalException from a SAXException.This is a 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 to SAXException and reduce those excessive wrapping.
- Overrides:
createUnmarshalExceptionin classAbstractUnmarshallerImpl- Returns:
- the resulting UnmarshalException
-
handleEvent
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 Jakarta XML Binding 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
- Throws:
JAXBException
-
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
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
-
finalize
-
close
Must be called from same thread which created the UnmarshallerImpl instance.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-