Class W3CDomHandler

  • All Implemented Interfaces:
    DomHandler<org.w3c.dom.Element,​javax.xml.transform.dom.DOMResult>

    public class W3CDomHandler
    extends java.lang.Object
    implements DomHandler<org.w3c.dom.Element,​javax.xml.transform.dom.DOMResult>
    DomHandler implementation for W3C DOM (org.w3c.dom package.)
    Author:
    Kohsuke Kawaguchi
    Since:
    1.6, JAXB 2.0
    • Constructor Summary

      Constructors 
      Constructor Description
      W3CDomHandler()
      Default constructor.
      W3CDomHandler​(javax.xml.parsers.DocumentBuilder builder)
      Constructor that allows applications to specify which DOM implementation to be used.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      javax.xml.transform.dom.DOMResult createUnmarshaller​(ValidationEventHandler errorHandler)
      When a JAXB provider needs to unmarshal a part of a document into an infoset representation, it first calls this method to create a Result object.
      javax.xml.parsers.DocumentBuilder getBuilder()  
      org.w3c.dom.Element getElement​(javax.xml.transform.dom.DOMResult r)
      Once the portion is sent to the Result.
      javax.xml.transform.Source marshal​(org.w3c.dom.Element element, ValidationEventHandler errorHandler)
      This method is called when a JAXB provider needs to marshal an element to XML.
      void setBuilder​(javax.xml.parsers.DocumentBuilder builder)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • W3CDomHandler

        public W3CDomHandler()
        Default constructor. It is up to a JAXB provider to decide which DOM implementation to use or how that is configured.
      • W3CDomHandler

        public W3CDomHandler​(javax.xml.parsers.DocumentBuilder builder)
        Constructor that allows applications to specify which DOM implementation to be used.
        Parameters:
        builder - must not be null. JAXB uses this DocumentBuilder to create a new element.
    • Method Detail

      • getBuilder

        public javax.xml.parsers.DocumentBuilder getBuilder()
      • setBuilder

        public void setBuilder​(javax.xml.parsers.DocumentBuilder builder)
      • createUnmarshaller

        public javax.xml.transform.dom.DOMResult createUnmarshaller​(ValidationEventHandler errorHandler)
        Description copied from interface: DomHandler
        When a JAXB provider needs to unmarshal a part of a document into an infoset representation, it first calls this method to create a Result object.

        A JAXB provider will then send a portion of the XML into the given result. Such a portion always form a subtree of the whole XML document rooted at an element.

        Specified by:
        createUnmarshaller in interface DomHandler<org.w3c.dom.Element,​javax.xml.transform.dom.DOMResult>
        Parameters:
        errorHandler - if any error happens between the invocation of this method and the invocation of DomHandler.getElement(Result), they must be reported to this handler. The caller must provide a non-null error handler. The Result object created from this method may hold a reference to this error handler.
        Returns:
        null if the operation fails. The error must have been reported to the error handler.
      • getElement

        public org.w3c.dom.Element getElement​(javax.xml.transform.dom.DOMResult r)
        Description copied from interface: DomHandler
        Once the portion is sent to the Result. This method is called by a JAXB provider to obtain the unmarshalled element representation.

        Multiple invocations of this method may return different objects. This method can be invoked only when the whole sub-tree are fed to the Result object.

        Specified by:
        getElement in interface DomHandler<org.w3c.dom.Element,​javax.xml.transform.dom.DOMResult>
        Parameters:
        r - The Result object created by DomHandler.createUnmarshaller(ValidationEventHandler).
        Returns:
        null if the operation fails. The error must have been reported to the error handler.
      • marshal

        public javax.xml.transform.Source marshal​(org.w3c.dom.Element element,
                                                  ValidationEventHandler errorHandler)
        Description copied from interface: DomHandler
        This method is called when a JAXB provider needs to marshal an element to XML.

        If non-null, the returned Source must contain a whole document rooted at one element, which will then be weaved into a bigger document that the JAXB provider is marshalling.

        Specified by:
        marshal in interface DomHandler<org.w3c.dom.Element,​javax.xml.transform.dom.DOMResult>
        errorHandler - Receives any errors happened during the process of converting an element into a Source. The caller must provide a non-null error handler.
        Returns:
        null if there was an error. The error should have been reported to the handler.