Class AbstractUnmarshallerImpl

  • All Implemented Interfaces:
    Unmarshaller

    public abstract class AbstractUnmarshallerImpl
    extends Object
    implements Unmarshaller
    Partial default Unmarshaller implementation.

    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
    • Field Detail

      • validating

        protected boolean validating
        whether or not the unmarshaller will validate
    • Constructor Detail

      • AbstractUnmarshallerImpl

        public AbstractUnmarshallerImpl()
    • Method Detail

      • getXMLReader

        protected XMLReader getXMLReader()
                                  throws JAXBException
        Obtains a configured XMLReader. This method is used when the client-specified SAXSource object doesn't have XMLReader. Unmarshaller is 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 JAXBException
        Indicates 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:
        isValidating in interface Unmarshaller
        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 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.

        Specified by:
        setEventHandler in interface Unmarshaller
        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 JAXBException
        Specifies whether or not the Unmarshaller should validate during unmarshal operations. By default, the Unmarshaller does not validate.

        This method may only be invoked before or after calling one of the unmarshal methods.

        Specified by:
        setValidating in interface Unmarshaller
        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:
        getEventHandler in interface Unmarshaller
        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:
        setProperty in interface Unmarshaller
        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:
        getProperty in interface Unmarshaller
        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