Top Description Inners Fields Constructors Methods
com.sun.tools.xjc.reader.internalizer

public final Class DOMForest

extends Object
Class Inheritance
Imports
com.sun.istack.NotNull, .XMLStreamReaderToContentHandler, com.sun.tools.xjc.ErrorReceiver, .Options, com.sun.tools.xjc.reader.Const, com.sun.tools.xjc.reader.xmlschema.parser.SchemaConstraintChecker, com.sun.tools.xjc.util.ErrorReceiverFilter, org.glassfish.jaxb.core.marshaller.DataWriter, org.glassfish.jaxb.core.v2.util.XmlFactory, com.sun.xml.xsom.parser.JAXPParser, .XMLParser, org.w3c.dom.Document, .Element, org.xml.sax.*, org.xml.sax.helpers.XMLFilterImpl, javax.xml.parsers.DocumentBuilder, .DocumentBuilderFactory, .ParserConfigurationException, .SAXParserFactory, javax.xml.stream.XMLStreamException, .XMLStreamReader, javax.xml.transform.Source, .Transformer, .TransformerException, .TransformerFactory, javax.xml.transform.dom.DOMSource, javax.xml.transform.sax.SAXResult, .SAXSource, javax.xml.validation.SchemaFactory, java.io.IOException, .OutputStream, .OutputStreamWriter, java.util.*

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 ([email protected])

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
private abstract static class

Field Summary

Modifier and TypeField and Description
private final Map<String, Document>
core

actual data storage map<SystemId,Document>.

private final DocumentBuilder
private EntityResolver
entityResolver

Used to resolve references to other schema documents.

private ErrorReceiver
errorReceiver

Errors encountered during the parsing will be sent to this object.

public final LocatorTable
locatorTable

Stores location information for all the trees in this forest.

protected final InternalizationLogic
logic

Schema language dependent part of the processing.

private final Options
public final Set<Element>
outerMostBindings

Stores all the outer-most <jaxb:bindings> customizations.

private final SAXParserFactory
private final Set<String>
rootDocuments

To correctly feed documents to a schema parser, we need to remember which documents (of the forest) were given as the root documents, and which of them are read as included/imported documents.

Constructor Summary

AccessConstructor and Description
public
DOMForest(SAXParserFactory parserFactory, DocumentBuilder documentBuilder, InternalizationLogic logic)

public

Method Summary

Modifier and TypeMethod and Description
public boolean
checkSchemaCorrectness(ErrorReceiver errorHandler)

Checks the correctness of the XML Schema documents and return true if it's OK.

public XMLParser
createParser()

Creates XMLParser for XSOM which reads documents from this DOMForest rather than doing a fresh parse.

public SAXSource
createSAXSource(String systemId)

Creates a SAXSource that, when parsed, reads from this (instead of parsing the original source identified by the system ID.)

public void
dump(OutputStream out)

Dumps the contents of the forest to the specified stream.

public Document
get(String systemId)

Gets the DOM tree associated with the specified system ID, or null if none is found.

public EntityResolver
public ErrorReceiver
public Document
getOneDocument()

Picks one document at random and returns it.

private ContentHandler
getParserHandler(Document dom)

Returns a ContentHandler to feed SAX events into.

public DOMForest.Handler
getParserHandler(String systemId, boolean root)

Returns a ContentHandler to feed SAX events into.

private String
getPath(String key)

Strips off the leading 'file:///' portion from an URL.

public Set<String>
getRootDocuments()

Returns a read-only set of root document system IDs.

public String
getSystemId(Document dom)

Gets the system ID from which the given DOM is parsed.

public Document[]
listDocuments()

Gets all the parsed documents.

public String[]
listSystemIDs()

Gets all the system IDs of the documents.

public Document
parse(InputSource source, boolean root)

public Document

Returns:

the parsed DOM document object.
parse
(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.

public Document

Returns:

null if there was a parse error. otherwise non-null.
parse
(String systemId, InputSource inputSource, boolean root)

Parses the given document and add it to the DOM forest.

public Document
parse(String systemId, XMLStreamReader parser, boolean root)

public void
public void
public SCDBasedBindingSet

Returns:

the returned bindings need to be applied after schema components are built.
transform
(boolean enableSCD)

Performs internalization.

public void
weakSchemaCorrectnessCheck(SchemaFactory sf)

Performs the schema correctness check by using JAXP 1.3.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

coreback to summary
private final Map<String, Document> core

actual data storage map<SystemId,Document>.

documentBuilderback to summary
private final DocumentBuilder documentBuilder
entityResolverback to summary
private EntityResolver entityResolver

Used to resolve references to other schema documents.

errorReceiverback to summary
private ErrorReceiver errorReceiver

Errors encountered during the parsing will be sent to this object.

locatorTableback to summary
public final LocatorTable locatorTable

Stores location information for all the trees in this forest.

logicback to summary
protected final InternalizationLogic logic

Schema language dependent part of the processing.

optionsback to summary
private final Options options
outerMostBindingsback to summary
public final Set<Element> outerMostBindings

Stores all the outer-most <jaxb:bindings> customizations.

parserFactoryback to summary
private final SAXParserFactory parserFactory
rootDocumentsback to summary
private final Set<String> rootDocuments

To correctly feed documents to a schema parser, we need to remember which documents (of the forest) were given as the root documents, and which of them are read as included/imported documents.

Set of system ids as strings.

Constructor Detail

DOMForestback to summary
public DOMForest(SAXParserFactory parserFactory, DocumentBuilder documentBuilder, InternalizationLogic logic)
DOMForestback to summary
public DOMForest(InternalizationLogic logic, Options opt)

Method Detail

checkSchemaCorrectnessback to summary
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
createParserback to summary
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.

createSAXSourceback to summary
public SAXSource createSAXSource(String systemId)

Creates a SAXSource that, when parsed, reads from this (instead of parsing the original source identified by the system ID.)

Annotations
@NotNull
dumpback to summary
public void dump(OutputStream out) throws IOException

Dumps the contents of the forest to the specified stream. This is a debug method. As such, error handling is sloppy.

getback to summary
public Document get(String systemId)

Gets the DOM tree associated with the specified system ID, or null if none is found.

getEntityResolverback to summary
public EntityResolver getEntityResolver()
getErrorHandlerback to summary
public ErrorReceiver getErrorHandler()
getOneDocumentback to summary
public Document getOneDocument()

Picks one document at random and returns it.

getParserHandlerback to summary
private ContentHandler getParserHandler(Document dom)

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. This version requires that the DOM object to be created and registered to the map beforehand.

getParserHandlerback to summary
public DOMForest.Handler getParserHandler(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.

getPathback to summary
private String getPath(String key)

Strips off the leading 'file:///' portion from an URL.

getRootDocumentsback to summary
public Set<String> getRootDocuments()

Returns a read-only set of root document system IDs.

getSystemIdback to summary
public String getSystemId(Document dom)

Gets the system ID from which the given DOM is parsed.

Poor-man's base URI.

listDocumentsback to summary
public Document[] listDocuments()

Gets all the parsed documents.

listSystemIDsback to summary
public String[] listSystemIDs()

Gets all the system IDs of the documents.

parseback to summary
public Document parse(InputSource source, boolean root) throws SAXException
parseback to summary
public Document parse(String systemId, boolean root) throws SAXException, IOException

Parses an XML at the given location ( and XMLs referenced by it) into DOM trees and stores them to this forest.

Returns:Document

the parsed DOM document object.

parseback to summary
public Document parse(String systemId, InputSource inputSource, boolean root) throws SAXException

Parses the given document and add it to the DOM forest.

Returns:Document

null if there was a parse error. otherwise non-null.

parseback to summary
public Document parse(String systemId, XMLStreamReader parser, boolean root) throws XMLStreamException
setEntityResolverback to summary
public void setEntityResolver(EntityResolver entityResolver)
setErrorHandlerback to summary
public void setErrorHandler(ErrorReceiver errorHandler)
transformback to summary
public SCDBasedBindingSet transform(boolean enableSCD)

Performs internalization. This method should be called only once, only after all the schemas are parsed.

Returns:SCDBasedBindingSet

the returned bindings need to be applied after schema components are built.

weakSchemaCorrectnessCheckback to summary
public void weakSchemaCorrectnessCheck(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).

com.sun.tools.xjc.reader.internalizer back to summary

public Interface DOMForest.Handler

extends ContentHandler
Known Direct Implementers
com.sun.tools.xjc.reader.internalizer.DOMForest.HandlerImpl

Method Summary

Modifier and TypeMethod and Description
public Document
getDocument()

Gets the DOM that was built.

Inherited from org.xml.sax.ContentHandler:
charactersdeclarationendDocumentendElementendPrefixMappingignorableWhitespaceprocessingInstructionsetDocumentLocatorskippedEntitystartDocumentstartElementstartPrefixMapping

Method Detail

getDocumentback to summary
public Document getDocument()

Gets the DOM that was built.

com.sun.tools.xjc.reader.internalizer back to summary

private abstract Class DOMForest.HandlerImpl

extends XMLFilterImpl
implements Handler
Class Inheritance
All Implemented Interfaces
com.sun.tools.xjc.reader.internalizer.DOMForest.Handler, org.xml.sax.ContentHandler

Constructor Summary

AccessConstructor and Description
private

Method Summary

Inherited from org.xml.sax.helpers.XMLFilterImpl:
charactersendDocumentendElementendPrefixMappingerrorfatalErrorgetContentHandlergetDTDHandlergetEntityResolvergetErrorHandlergetFeaturegetParentgetPropertyignorableWhitespacenotationDeclparseparseprocessingInstructionresolveEntitysetContentHandlersetDocumentLocatorsetDTDHandlersetEntityResolversetErrorHandlersetFeaturesetParentsetPropertyskippedEntitystartDocumentstartElementstartPrefixMappingunparsedEntityDeclwarning

Constructor Detail

HandlerImplback to summary
private HandlerImpl()