- java.lang.Object
-
- javax.xml.bind.helpers.AbstractUnmarshallerImpl
-
- All Implemented Interfaces:
Unmarshaller
public abstract class AbstractUnmarshallerImpl extends Object implements Unmarshaller
Partial defaultUnmarshallerimplementation.This class provides a partial default implementation for the
Unmarshallerinterface.A JAXB Provider has to implement five methods (getUnmarshallerHandler, unmarshal(Node), unmarshal(XMLReader,InputSource), unmarshal(XMLStreamReader), and unmarshal(XMLEventReader).
- Since:
- 1.6, JAXB 1.0
- See Also:
Unmarshaller
-
-
Nested Class Summary
-
Nested classes/interfaces declared in interface javax.xml.bind.Unmarshaller
Unmarshaller.Listener
-
-
Field Summary
Fields Modifier and Type Field Description protected booleanvalidatingwhether or not the unmarshaller will validate
-
Constructor Summary
Constructors Constructor Description AbstractUnmarshallerImpl()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected UnmarshalExceptioncreateUnmarshalException(SAXException e)Creates an UnmarshalException from a SAXException.ValidationEventHandlergetEventHandler()Return the current event handler or the default event handler if one hasn't been set.ObjectgetProperty(String name)Default implementation of the getProperty method always throws PropertyException since there are no required properties.protected XMLReadergetXMLReader()Obtains a configured XMLReader.booleanisValidating()Indicates whether or not the Unmarshaller is configured to validate during unmarshal operations.voidsetEventHandler(ValidationEventHandler handler)Allow an application to register a validation event handler.voidsetProperty(String name, Object value)Default implementation of the setProperty method always throws PropertyException since there are no required properties.voidsetValidating(boolean validating)Specifies whether or not the Unmarshaller should validate during unmarshal operations.protected abstract Objectunmarshal(XMLReader reader, InputSource source)Unmarshals an object by using the specified XMLReader and the InputSource.-
Methods declared in class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods declared in interface javax.xml.bind.Unmarshaller
getAdapter, getListener, getSchema, getUnmarshallerHandler, setAdapter, setAdapter, setAttachmentUnmarshaller, setListener, setSchema, unmarshal, unmarshal, unmarshal, unmarshal, unmarshal, unmarshal, unmarshal, unmarshal, unmarshal, unmarshal, unmarshal, unmarshal, unmarshal
-
-
-
-
Method Detail
-
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.- Throws:
JAXBException
-
unmarshal
protected abstract Object unmarshal(XMLReader reader, InputSource source) throws JAXBException
Unmarshals 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.- Throws:
JAXBException
-
isValidating
public boolean isValidating() throws JAXBExceptionIndicates 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- Returns:
- true if the Unmarshaller is configured to validate during unmarshal operations, false otherwise
- Throws:
JAXBException- if an error occurs while retrieving the validating flag
-
setEventHandler
public void setEventHandler(ValidationEventHandler handler) throws JAXBException
Allow an application to register a validation event handler.The validation event handler will be called by the JAXB Provider if any validation errors are encountered during calls to any of the
unmarshalmethods. 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.- Specified by:
setEventHandlerin interfaceUnmarshaller- Parameters:
handler- the validation event handler- Throws:
JAXBException- if an error was encountered while setting the event handler
-
setValidating
public void setValidating(boolean validating) throws JAXBExceptionSpecifies 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- Parameters:
validating- true if the Unmarshaller should validate during unmarshal, false otherwise- Throws:
JAXBException- if an error occurred while enabling or disabling validation at unmarshal time
-
getEventHandler
public ValidationEventHandler getEventHandler() throws JAXBException
Return the current event handler or the default event handler if one hasn't been set.- Specified by:
getEventHandlerin interfaceUnmarshaller- Returns:
- the current ValidationEventHandler or the default event handler if it hasn't been set
- Throws:
JAXBException- if an error was encountered while getting the current event handler
-
createUnmarshalException
protected UnmarshalException createUnmarshalException(SAXException e)
Creates 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.
- Returns:
- the resulting UnmarshalException
-
setProperty
public void setProperty(String name, Object value) throws PropertyException
Default 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- 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
-
getProperty
public Object getProperty(String name) throws PropertyException
Default 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- 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
-
-