Class DOMForest


  • public final class DOMForest
    extends java.lang.Object
    Builds a DOM forest and maintains association from system IDs to DOM trees.

    A forest is a transitive reflexive closure of referenced documents. IOW, if a document is in a forest, all the documents referenced from it is in a forest, too. To support this semantics, DOMForest uses InternalizationLogic to find referenced documents.

    Some documents are marked as "root"s, meaning those documents were put into a forest explicitly, not because it is referenced from another document. (However, a root document can be referenced from other documents, too.)

    Author:
    Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static interface  DOMForest.Handler  
    • Field Summary

      Fields 
      Modifier and Type Field Description
      LocatorTable locatorTable
      Stores location information for all the trees in this forest.
      protected InternalizationLogic logic
      Schema language dependent part of the processing.
      java.util.Set<org.w3c.dom.Element> outerMostBindings
      Stores all the outer-most <jaxb:bindings> customizations.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean checkSchemaCorrectness​(ErrorReceiver errorHandler)
      Checks the correctness of the XML Schema documents and return true if it's OK.
      XMLParser createParser()
      Creates XMLParser for XSOM which reads documents from this DOMForest rather than doing a fresh parse.
      javax.xml.transform.sax.SAXSource createSAXSource​(java.lang.String systemId)
      Creates a SAXSource that, when parsed, reads from this DOMForest (instead of parsing the original source identified by the system ID.)
      void dump​(java.io.OutputStream out)
      Dumps the contents of the forest to the specified stream.
      org.w3c.dom.Document get​(java.lang.String systemId)
      Gets the DOM tree associated with the specified system ID, or null if none is found.
      org.xml.sax.EntityResolver getEntityResolver()  
      ErrorReceiver getErrorHandler()  
      org.w3c.dom.Document getOneDocument()
      Picks one document at random and returns it.
      DOMForest.Handler getParserHandler​(java.lang.String systemId, boolean root)
      Returns a ContentHandler to feed SAX events into.
      java.util.Set<java.lang.String> getRootDocuments()
      Returns a read-only set of root document system IDs.
      java.lang.String getSystemId​(org.w3c.dom.Document dom)
      Gets the system ID from which the given DOM is parsed.
      org.w3c.dom.Document[] listDocuments()
      Gets all the parsed documents.
      java.lang.String[] listSystemIDs()
      Gets all the system IDs of the documents.
      org.w3c.dom.Document parse​(java.lang.String systemId, boolean root)
      Parses an XML at the given location ( and XMLs referenced by it) into DOM trees and stores them to this forest.
      org.w3c.dom.Document parse​(java.lang.String systemId, javax.xml.stream.XMLStreamReader parser, boolean root)  
      org.w3c.dom.Document parse​(java.lang.String systemId, org.xml.sax.InputSource inputSource, boolean root)
      Parses the given document and add it to the DOM forest.
      org.w3c.dom.Document parse​(org.xml.sax.InputSource source, boolean root)  
      void setEntityResolver​(org.xml.sax.EntityResolver entityResolver)  
      void setErrorHandler​(ErrorReceiver errorHandler)  
      SCDBasedBindingSet transform​(boolean enableSCD)
      Performs internalization.
      void weakSchemaCorrectnessCheck​(javax.xml.validation.SchemaFactory sf)
      Performs the schema correctness check by using JAXP 1.3.
      • Methods inherited from class java.lang.Object

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

      • locatorTable

        public final LocatorTable locatorTable
        Stores location information for all the trees in this forest.
      • outerMostBindings

        public final java.util.Set<org.w3c.dom.Element> outerMostBindings
        Stores all the outer-most <jaxb:bindings> customizations.
      • logic

        protected final InternalizationLogic logic
        Schema language dependent part of the processing.
    • Constructor Detail

      • DOMForest

        public DOMForest​(javax.xml.parsers.SAXParserFactory parserFactory,
                         javax.xml.parsers.DocumentBuilder documentBuilder,
                         InternalizationLogic logic)
    • Method Detail

      • get

        public org.w3c.dom.Document get​(java.lang.String systemId)
        Gets the DOM tree associated with the specified system ID, or null if none is found.
      • getRootDocuments

        public java.util.Set<java.lang.String> getRootDocuments()
        Returns a read-only set of root document system IDs.
      • getOneDocument

        public org.w3c.dom.Document getOneDocument()
        Picks one document at random and returns it.
      • checkSchemaCorrectness

        public boolean checkSchemaCorrectness​(ErrorReceiver errorHandler)
        Checks the correctness of the XML Schema documents and return true if it's OK.

        This method performs a weaker version of the tests where error messages are provided without line number information. So whenever possible use SchemaConstraintChecker.

        See Also:
        SchemaConstraintChecker
      • getSystemId

        public java.lang.String getSystemId​(org.w3c.dom.Document dom)
        Gets the system ID from which the given DOM is parsed.

        Poor-man's base URI.

      • parse

        public org.w3c.dom.Document parse​(org.xml.sax.InputSource source,
                                          boolean root)
                                   throws org.xml.sax.SAXException
        Throws:
        org.xml.sax.SAXException
      • parse

        public org.w3c.dom.Document parse​(java.lang.String systemId,
                                          boolean root)
                                   throws org.xml.sax.SAXException,
                                          java.io.IOException
        Parses an XML at the given location ( and XMLs referenced by it) into DOM trees and stores them to this forest.
        Returns:
        the parsed DOM document object.
        Throws:
        org.xml.sax.SAXException
        java.io.IOException
      • getParserHandler

        public DOMForest.Handler getParserHandler​(java.lang.String systemId,
                                                  boolean root)
        Returns a ContentHandler to feed SAX events into.

        The client of this class can feed SAX events into the handler to parse a document into this DOM forest.

      • parse

        public org.w3c.dom.Document parse​(java.lang.String systemId,
                                          org.xml.sax.InputSource inputSource,
                                          boolean root)
                                   throws org.xml.sax.SAXException
        Parses the given document and add it to the DOM forest.
        Returns:
        null if there was a parse error. otherwise non-null.
        Throws:
        org.xml.sax.SAXException
      • parse

        public org.w3c.dom.Document parse​(java.lang.String systemId,
                                          javax.xml.stream.XMLStreamReader parser,
                                          boolean root)
                                   throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • transform

        public SCDBasedBindingSet transform​(boolean enableSCD)
        Performs internalization. This method should be called only once, only after all the schemas are parsed.
        Returns:
        the returned bindings need to be applied after schema components are built.
      • weakSchemaCorrectnessCheck

        public void weakSchemaCorrectnessCheck​(javax.xml.validation.SchemaFactory sf)
        Performs the schema correctness check by using JAXP 1.3.

        This is "weak", because SchemaFactory.newSchema(Source[]) doesn't handle inclusions very correctly (it ends up parsing it from its original source, not in this tree), and because it doesn't handle two documents for the same namespace very well.

        We should eventually fix JAXP (and Xerces), but meanwhile this weaker and potentially wrong correctness check is still better than nothing when used inside JAX-WS (JAXB CLI and Ant does a better job of checking this.)

        To receive errors, use SchemaFactory.setErrorHandler(ErrorHandler).

      • createSAXSource

        @NotNull
        public javax.xml.transform.sax.SAXSource createSAXSource​(java.lang.String systemId)
        Creates a SAXSource that, when parsed, reads from this DOMForest (instead of parsing the original source identified by the system ID.)
      • createParser

        public XMLParser createParser()
        Creates XMLParser for XSOM which reads documents from this DOMForest rather than doing a fresh parse. The net effect is that XSOM will read transformed XML Schemas instead of the original documents.
      • getEntityResolver

        public org.xml.sax.EntityResolver getEntityResolver()
      • setEntityResolver

        public void setEntityResolver​(org.xml.sax.EntityResolver entityResolver)
      • setErrorHandler

        public void setErrorHandler​(ErrorReceiver errorHandler)
      • listDocuments

        public org.w3c.dom.Document[] listDocuments()
        Gets all the parsed documents.
      • listSystemIDs

        public java.lang.String[] listSystemIDs()
        Gets all the system IDs of the documents.
      • dump

        public void dump​(java.io.OutputStream out)
                  throws java.io.IOException
        Dumps the contents of the forest to the specified stream. This is a debug method. As such, error handling is sloppy.
        Throws:
        java.io.IOException