Save This Page
Home » openjdk-7 » com.sun.org.apache.xml.internal » dtm » ref » sax2dtm » [javadoc | source]
com.sun.org.apache.xml.internal.dtm.ref.sax2dtm
public class: SAX2DTM [javadoc | source]
java.lang.Object
   com.sun.org.apache.xml.internal.dtm.ref.DTMDefaultBase
      com.sun.org.apache.xml.internal.dtm.ref.DTMDefaultBaseTraversers
         com.sun.org.apache.xml.internal.dtm.ref.DTMDefaultBaseIterators
            com.sun.org.apache.xml.internal.dtm.ref.sax2dtm.SAX2DTM

All Implemented Interfaces:
    ContentHandler, DTDHandler, ErrorHandler, DeclHandler, EntityResolver, LexicalHandler, DTM

Direct Known Subclasses:
    SAX2RTFDTM, SAXImpl

This class implements a DTM that tends to be optimized more for speed than for compactness, that is constructed via SAX2 ContentHandler events.
Field Summary
protected  FastStringBuffer m_chars    All the character content, including attribute values, are stored in this buffer. %REVIEW% Should this have an option of being shared across DTMs? Sequentially only; not threadsafe... Currently, I think not. %REVIEW% Initial size was pushed way down to reduce weight of RTFs. pending reduction in number of RTF DTMs. Now that we're sharing a DTM between RTFs, and tail-pruning... consider going back to the larger/faster. Made protected rather than private so SAX2RTFDTM can access it. 
protected  SuballocatedIntVector m_data    This vector holds offset and length data. 
protected transient  IntStack m_parents    The parent stack, needed only for construction. Made protected rather than private so SAX2RTFDTM can access it. 
protected transient  int m_previous    The current previous node, needed only for construction time. Made protected rather than private so SAX2RTFDTM can access it. 
protected transient  Vector m_prefixMappings    Namespace support, only relevent at construction time. Made protected rather than private so SAX2RTFDTM can access it. 
protected transient  IntStack m_contextIndexes    Namespace support, only relevent at construction time. Made protected rather than private so SAX2RTFDTM can access it. 
protected transient  int m_textType    Type of next characters() event within text block in prgress. 
protected transient  int m_coalescedTextType    Type of coalesced text block. See logic in the characters() method. 
protected transient  Locator m_locator    The SAX Document locator 
protected transient  boolean m_insideDTD    We are inside the DTD. This is used for ignoring comments. 
protected  DTMTreeWalker m_walker    Tree Walker for dispatchToEvents. 
protected  DTMStringPool m_valuesOrPrefixes    pool of string values that come as strings. 
protected  boolean m_endDocumentOccured    End document has been reached. Made protected rather than private so SAX2RTFDTM can access it. 
protected  SuballocatedIntVector m_dataOrQName    Data or qualified name values, one array element for each node. 
protected  Hashtable m_idAttributes    This table holds the ID string to node associations, for XML IDs. 
protected  int m_textPendingStart    The starting offset within m_chars for the text or CDATA_SECTION node currently being acumulated, or -1 if there is no text node in progress 
protected  boolean m_useSourceLocationProperty    Describes whether information about document source location should be maintained or not. Made protected for access by SAX2RTFDTM. 
protected  StringVector m_sourceSystemId    Made protected for access by SAX2RTFDTM. 
protected  IntVector m_sourceLine    Made protected for access by SAX2RTFDTM. 
protected  IntVector m_sourceColumn    Made protected for access by SAX2RTFDTM. 
 boolean m_pastFirstElement     
Fields inherited from com.sun.org.apache.xml.internal.dtm.ref.DTMDefaultBase:
JJK_DEBUG,  ROOTNODE,  m_size,  m_exptype,  m_firstch,  m_nextsib,  m_prevsib,  m_parent,  m_namespaceDeclSets,  m_namespaceDeclSetElements,  m_elemIndexes,  DEFAULT_BLOCKSIZE,  DEFAULT_NUMBLOCKS,  DEFAULT_NUMBLOCKS_SMALL,  NOTPROCESSED,  m_mgr,  m_mgrDefault,  m_dtmIdent,  m_documentBaseURI,  m_wsfilter,  m_shouldStripWS,  m_shouldStripWhitespaceStack,  m_xstrf,  m_expandedNameTable,  m_indexing,  m_traversers
Constructor:
 public SAX2DTM(DTMManager mgr,
    Source source,
    int dtmIdentity,
    DTMWSFilter whiteSpaceFilter,
    XMLStringFactory xstringfactory,
    boolean doIndexing) 
    Construct a SAX2DTM object using the default block size.
    Parameters:
    mgr - The DTMManager who owns this DTM.
    source - the JAXP 1.1 Source object for this DTM.
    dtmIdentity - The DTM identity ID for this DTM.
    whiteSpaceFilter - The white space filter for this DTM, which may be null.
    xstringfactory - XMLString factory for creating character content.
    doIndexing - true if the caller considers it worth it to use indexing schemes.
 public SAX2DTM(DTMManager mgr,
    Source source,
    int dtmIdentity,
    DTMWSFilter whiteSpaceFilter,
    XMLStringFactory xstringfactory,
    boolean doIndexing,
    int blocksize,
    boolean usePrevsib,
    boolean newNameTable) 
    Construct a SAX2DTM object ready to be constructed from SAX2 ContentHandler events.
    Parameters:
    mgr - The DTMManager who owns this DTM.
    source - the JAXP 1.1 Source object for this DTM.
    dtmIdentity - The DTM identity ID for this DTM.
    whiteSpaceFilter - The white space filter for this DTM, which may be null.
    xstringfactory - XMLString factory for creating character content.
    doIndexing - true if the caller considers it worth it to use indexing schemes.
    blocksize - The block size of the DTM.
    usePrevsib - true if we want to build the previous sibling node array.
    newNameTable - true if we want to use a new ExpandedNameTable for this DTM.
Method from com.sun.org.apache.xml.internal.dtm.ref.sax2dtm.SAX2DTM Summary:
_dataOrQName,   addNewDTMID,   addNode,   attributeDecl,   characters,   charactersFlush,   clearCoRoutine,   clearCoRoutine,   comment,   declAlreadyDeclared,   dispatchCharactersEvents,   dispatchToEvents,   elementDecl,   endCDATA,   endDTD,   endDocument,   endElement,   endEntity,   endPrefixMapping,   error,   externalEntityDecl,   fatalError,   getAttributeNode,   getContentHandler,   getDTDHandler,   getDeclHandler,   getDocumentTypeDeclarationPublicIdentifier,   getDocumentTypeDeclarationSystemIdentifier,   getElementById,   getEntityResolver,   getErrorHandler,   getFixedNames,   getIdForNamespace,   getLexicalHandler,   getLocalName,   getNamespaceURI,   getNamespaceURI,   getNextNodeIdentity,   getNodeName,   getNodeNameX,   getNodeValue,   getNumberOfNodes,   getPrefix,   getPrefix,   getSourceLocatorFor,   getStringValue,   getUnparsedEntityURI,   ignorableWhitespace,   internalEntityDecl,   isAttributeSpecified,   isWhitespace,   migrateTo,   needsTwoThreads,   nextNode,   notationDecl,   processingInstruction,   resolveEntity,   setDocumentLocator,   setIDAttribute,   setIncrementalSAXSource,   setProperty,   setSourceLocation,   setUseSourceLocation,   skippedEntity,   startCDATA,   startDTD,   startDocument,   startElement,   startEntity,   startPrefixMapping,   unparsedEntityDecl,   warning
Methods from com.sun.org.apache.xml.internal.dtm.ref.DTMDefaultBaseIterators:
getAxisIterator,   getTypedAxisIterator
Methods from com.sun.org.apache.xml.internal.dtm.ref.DTMDefaultBaseTraversers:
getAxisTraverser
Methods from com.sun.org.apache.xml.internal.dtm.ref.DTMDefaultBase:
_exptype,   _firstch,   _level,   _nextsib,   _parent,   _prevsib,   _type,   appendChild,   appendTextChild,   declareNamespaceInContext,   dispatchCharactersEvents,   dispatchToEvents,   documentRegistration,   documentRelease,   dumpDTM,   dumpNode,   ensureSizeOfIndex,   error,   findElementFromIndex,   findGTE,   findInSortedSuballocatedIntVector,   findNamespaceContext,   getAttributeNode,   getDTMIDs,   getDocument,   getDocumentAllDeclarationsProcessed,   getDocumentBaseURI,   getDocumentEncoding,   getDocumentRoot,   getDocumentStandalone,   getDocumentSystemIdentifier,   getDocumentTypeDeclarationPublicIdentifier,   getDocumentTypeDeclarationSystemIdentifier,   getDocumentVersion,   getElementById,   getExpandedTypeID,   getExpandedTypeID,   getFirstAttribute,   getFirstAttributeIdentity,   getFirstChild,   getFirstNamespaceNode,   getLastChild,   getLevel,   getLocalName,   getLocalNameFromExpandedNameID,   getManager,   getNamespaceFromExpandedNameID,   getNamespaceType,   getNamespaceURI,   getNextAttribute,   getNextAttributeIdentity,   getNextNamespaceNode,   getNextNodeIdentity,   getNextSibling,   getNode,   getNodeHandle,   getNodeIdent,   getNodeName,   getNodeNameX,   getNodeType,   getNodeValue,   getNumberOfNodes,   getOwnerDocument,   getParent,   getPrefix,   getPreviousSibling,   getShouldStripWhitespace,   getStringValue,   getStringValueChunk,   getStringValueChunkCount,   getTypedAttribute,   getTypedFirstChild,   getTypedNextSibling,   getUnparsedEntityURI,   hasChildNodes,   indexNode,   isAttributeSpecified,   isCharacterElementContentWhitespace,   isDocumentAllDeclarationsProcessed,   isNodeAfter,   isSupported,   makeNodeHandle,   makeNodeIdentity,   migrateTo,   nextNode,   popShouldStripWhitespace,   pushShouldStripWhitespace,   setDocumentBaseURI,   setFeature,   setShouldStripWhitespace,   supportsPreStripping
Methods from java.lang.Object:
equals,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from com.sun.org.apache.xml.internal.dtm.ref.sax2dtm.SAX2DTM Detail:
 protected int _dataOrQName(int identity) 
    Get the data or qualified name for the given node identity.
 protected  void addNewDTMID(int nodeIndex) 
    Get a new DTM ID beginning at the specified node index.
 protected int addNode(int type,
    int expandedTypeID,
    int parentIndex,
    int previousSibling,
    int dataOrPrefix,
    boolean canHaveFirstChild) 
    Construct the node map from the node.
 public  void attributeDecl(String eName,
    String aName,
    String type,
    String valueDefault,
    String value) throws SAXException 
    Report an attribute type declaration.

    Only the effective (first) declaration for an attribute will be reported. The type will be one of the strings "CDATA", "ID", "IDREF", "IDREFS", "NMTOKEN", "NMTOKENS", "ENTITY", "ENTITIES", or "NOTATION", or a parenthesized token group with the separator "|" and all whitespace removed.

 public  void characters(char[] ch,
    int start,
    int length) throws SAXException 
    Receive notification of character data inside an element.

    By default, do nothing. Application writers may override this method to take specific actions for each chunk of character data (such as adding the data to a node or buffer, or printing it to a file).

 protected  void charactersFlush() 
    Check whether accumulated text should be stripped; if not, append the appropriate flavor of text/cdata node.
 public  void clearCoRoutine() 
    Ask the CoRoutine parser to doTerminate and clear the reference.
 public  void clearCoRoutine(boolean callDoTerminate) 
    Ask the CoRoutine parser to doTerminate and clear the reference. If the CoRoutine parser has already been cleared, this will have no effect.
 public  void comment(char[] ch,
    int start,
    int length) throws SAXException 
    Report an XML comment anywhere in the document.

    This callback will be used for comments inside or outside the document element, including comments in the external DTD subset (if read).

 protected boolean declAlreadyDeclared(String prefix) 
    Check if a declaration has already been made for a given prefix.
 public  void dispatchCharactersEvents(int nodeHandle,
    ContentHandler ch,
    boolean normalize) throws SAXException 
    Directly call the characters method on the passed ContentHandler for the string-value of the given node (see http://www.w3.org/TR/xpath#data-model for the definition of a node's string-value). Multiple calls to the ContentHandler's characters methods may well occur for a single call to this method.
 public  void dispatchToEvents(int nodeHandle,
    ContentHandler ch) throws SAXException 
    Directly create SAX parser events from a subtree.
 public  void elementDecl(String name,
    String model) throws SAXException 
    Report an element type declaration.

    The content model will consist of the string "EMPTY", the string "ANY", or a parenthesised group, optionally followed by an occurrence indicator. The model will be normalized so that all whitespace is removed,and will include the enclosing parentheses.

 public  void endCDATA() throws SAXException 
    Report the end of a CDATA section.
 public  void endDTD() throws SAXException 
    Report the end of DTD declarations.
 public  void endDocument() throws SAXException 
    Receive notification of the end of the document.
 public  void endElement(String uri,
    String localName,
    String qName) throws SAXException 
    Receive notification of the end of an element.

    By default, do nothing. Application writers may override this method in a subclass to take specific actions at the end of each element (such as finalising a tree node or writing output to a file).

 public  void endEntity(String name) throws SAXException 
    Report the end of an entity.
 public  void endPrefixMapping(String prefix) throws SAXException 
    Receive notification of the end of a Namespace mapping.

    By default, do nothing. Application writers may override this method in a subclass to take specific actions at the end of each prefix mapping.

 public  void error(SAXParseException e) throws SAXException 
    Receive notification of a recoverable parser error.

    The default implementation does nothing. Application writers may override this method in a subclass to take specific actions for each error, such as inserting the message in a log file or printing it to the console.

 public  void externalEntityDecl(String name,
    String publicId,
    String systemId) throws SAXException 
    Report a parsed external entity declaration.

    Only the effective (first) declaration for each entity will be reported.

 public  void fatalError(SAXParseException e) throws SAXException 
    Report a fatal XML parsing error.

    The default implementation throws a SAXParseException. Application writers may override this method in a subclass if they need to take specific actions for each fatal error (such as collecting all of the errors into a single report): in any case, the application must stop all regular processing when this method is invoked, since the document is no longer reliable, and the parser may no longer report parsing events.

 public int getAttributeNode(int nodeHandle,
    String namespaceURI,
    String name) 
    Retrieves an attribute node by by qualified name and namespace URI.
 public ContentHandler getContentHandler() 
    getContentHandler returns "our SAX builder" -- the thing that someone else should send SAX events to in order to extend this DTM model. %REVIEW% Should this return null if constrution already done/begun?
 public DTDHandler getDTDHandler() 
    Return this DTM's DTDHandler.
 public DeclHandler getDeclHandler() 
    Return this DTM's DeclHandler.
 public String getDocumentTypeDeclarationPublicIdentifier() 
    Return the public identifier of the external subset, normalized as described in 4.2.2 External Entities [XML]. If there is no external subset or if it has no public identifier, this property has no value.
 public String getDocumentTypeDeclarationSystemIdentifier() 
    A document type declaration information item has the following properties: 1. [system identifier] The system identifier of the external subset, if it exists. Otherwise this property has no value.
 public int getElementById(String elementId) 
    Returns the Element whose ID is given by elementId. If no such element exists, returns DTM.NULL. Behavior is not defined if more than one element has this ID. Attributes (including those with the name "ID") are not of type ID unless so defined by DTD/Schema information available to the DTM implementation. Implementations that do not know whether attributes are of type ID or not are expected to return DTM.NULL.

    %REVIEW% Presumably IDs are still scoped to a single document, and this operation searches only within a single document, right? Wouldn't want collisions between DTMs in the same process.

 public EntityResolver getEntityResolver() 
    Return this DTM's EntityResolver.
 public ErrorHandler getErrorHandler() 
    Return this DTM's ErrorHandler.
 public String getFixedNames(int type) 
 public int getIdForNamespace(String uri) 
    Get a prefix either from the uri mapping, or just make one up!
 public LexicalHandler getLexicalHandler() 
    Return this DTM's lexical handler. %REVIEW% Should this return null if constrution already done/begun?
 public String getLocalName(int nodeHandle) 
    Given a node handle, return its XPath-style localname. (As defined in Namespaces, this is the portion of the name after any colon character).
 public String getNamespaceURI(int nodeHandle) 
    Given a node handle, return its DOM-style namespace URI (As defined in Namespaces, this is the declared URI which this node's prefix -- or default in lieu thereof -- was mapped to.)

    %REVIEW% Null or ""? -sb

 public String getNamespaceURI(String prefix) 
    Get a prefix either from the qname or from the uri mapping, or just make one up!
 protected int getNextNodeIdentity(int identity) 
    Get the next node identity value in the list, and call the iterator if it hasn't been added yet.
 public String getNodeName(int nodeHandle) 
    Given a node handle, return its DOM-style node name. This will include names such as #text or #document.
 public String getNodeNameX(int nodeHandle) 
    Given a node handle, return the XPath node name. This should be the name as described by the XPath data model, NOT the DOM-style name.
 public String getNodeValue(int nodeHandle) 
    Given a node handle, return its node value. This is mostly as defined by the DOM, but may ignore some conveniences.

 public int getNumberOfNodes() 
    Get the number of nodes that have been added.
 public String getPrefix(int nodeHandle) 
    Given a namespace handle, return the prefix that the namespace decl is mapping. Given a node handle, return the prefix used to map to the namespace.

    %REVIEW% Are you sure you want "" for no prefix?

    %REVIEW-COMMENT% I think so... not totally sure. -sb

 public String getPrefix(String qname,
    String uri) 
    Get a prefix either from the qname or from the uri mapping, or just make one up!
 public SourceLocator getSourceLocatorFor(int node) 
    Retrieve the SourceLocator associated with a specific node. This is only meaningful if the XalanProperties.SOURCE_LOCATION flag was set True using setProperty; if it was never set, or was set false, we will return null. (We _could_ return a locator with the document's base URI and bogus line/column information. Trying that; see the else clause.)
 public XMLString getStringValue(int nodeHandle) 
    Get the string-value of a node as a String object (see http://www.w3.org/TR/xpath#data-model for the definition of a node's string-value).
 public String getUnparsedEntityURI(String name) 
    The getUnparsedEntityURI function returns the URI of the unparsed entity with the specified name in the same document as the context node (see [3.3 Unparsed Entities]). It returns the empty string if there is no such entity.

    XML processors may choose to use the System Identifier (if one is provided) to resolve the entity, rather than the URI in the Public Identifier. The details are dependent on the processor, and we would have to support some form of plug-in resolver to handle this properly. Currently, we simply return the System Identifier if present, and hope that it a usable URI or that our caller can map it to one. TODO: Resolve Public Identifiers... or consider changing function name.

    If we find a relative URI reference, XML expects it to be resolved in terms of the base URI of the document. The DOM doesn't do that for us, and it isn't entirely clear whether that should be done here; currently that's pushed up to a higher level of our application. (Note that DOM Level 1 didn't store the document's base URI.) TODO: Consider resolving Relative URIs.

    (The DOM's statement that "An XML processor may choose to completely expand entities before the structure model is passed to the DOM" refers only to parsed entities, not unparsed, and hence doesn't affect this function.)

 public  void ignorableWhitespace(char[] ch,
    int start,
    int length) throws SAXException 
    Receive notification of ignorable whitespace in element content.

    By default, do nothing. Application writers may override this method to take specific actions for each chunk of ignorable whitespace (such as adding data to a node or buffer, or printing it to a file).

 public  void internalEntityDecl(String name,
    String value) throws SAXException 
    Report an internal entity declaration.

    Only the effective (first) declaration for each entity will be reported.

 public boolean isAttributeSpecified(int attributeHandle) 
    5. [specified] A flag indicating whether this attribute was actually specified in the start-tag of its element, or was defaulted from the DTD.
 public boolean isWhitespace(int nodeHandle) 
    Determine if the string-value of a node is whitespace
 public  void migrateTo(DTMManager manager) 
    Migrate a DTM built with an old DTMManager to a new DTMManager. After the migration, the new DTMManager will treat the DTM as one that is built by itself. This is used to support DTM sharing between multiple transformations.
 public boolean needsTwoThreads() 
 protected boolean nextNode() 
    This method should try and build one or more nodes in the table.
 public  void notationDecl(String name,
    String publicId,
    String systemId) throws SAXException 
    Receive notification of a notation declaration.

    By default, do nothing. Application writers may override this method in a subclass if they wish to keep track of the notations declared in a document.

 public  void processingInstruction(String target,
    String data) throws SAXException 
    Receive notification of a processing instruction.

    By default, do nothing. Application writers may override this method in a subclass to take specific actions for each processing instruction, such as setting status variables or invoking other methods.

 public InputSource resolveEntity(String publicId,
    String systemId) throws SAXException 
    Resolve an external entity.

    Always return null, so that the parser will use the system identifier provided in the XML document. This method implements the SAX default behaviour: application writers can override it in a subclass to do special translations such as catalog lookups or URI redirection.

 public  void setDocumentLocator(Locator locator) 
    Receive a Locator object for document events.

    By default, do nothing. Application writers may override this method in a subclass if they wish to store the locator for use with other document events.

 public  void setIDAttribute(String id,
    int elem) 
    Set an ID string to node association in the ID table.
 public  void setIncrementalSAXSource(IncrementalSAXSource incrementalSAXSource) 
    Bind a IncrementalSAXSource to this DTM. If we discover we need nodes that have not yet been built, we will ask this object to send us more events, and it will manage interactions with its data sources. Note that we do not actually build the IncrementalSAXSource, since we don't know what source it's reading from, what thread that source will run in, or when it will run.
 public  void setProperty(String property,
    Object value) 
    Set a run time property for this DTM instance. %REVIEW% Now that we no longer use this method to support getSourceLocatorFor, can we remove it?
 protected  void setSourceLocation() 
    Store the source location of the current node. This method must be called as every node is added to the DTM or for no node.
 public  void setUseSourceLocation(boolean useSourceLocation) 
    Set whether information about document source location should be maintained or not.
 public  void skippedEntity(String name) throws SAXException 
    Receive notification of a skipped entity.

    By default, do nothing. Application writers may override this method in a subclass to take specific actions for each processing instruction, such as setting status variables or invoking other methods.

 public  void startCDATA() throws SAXException 
    Report the start of a CDATA section.

    The contents of the CDATA section will be reported through the regular characters event.

 public  void startDTD(String name,
    String publicId,
    String systemId) throws SAXException 
    Report the start of DTD declarations, if any.

    Any declarations are assumed to be in the internal subset unless otherwise indicated by a startEntity event.

    Note that the start/endDTD events will appear within the start/endDocument events from ContentHandler and before the first startElement event.

 public  void startDocument() throws SAXException 
    Receive notification of the beginning of the document.
 public  void startElement(String uri,
    String localName,
    String qName,
    Attributes attributes) throws SAXException 
    Receive notification of the start of an element.

    By default, do nothing. Application writers may override this method in a subclass to take specific actions at the start of each element (such as allocating a new tree node or writing output to a file).

 public  void startEntity(String name) throws SAXException 
    Report the beginning of an entity in content.

    NOTE: entity references in attribute values -- and the start and end of the document entity -- are never reported.

    The start and end of the external DTD subset are reported using the pseudo-name "[dtd]". All other events must be properly nested within start/end entity events.

    Note that skipped entities will be reported through the skippedEntity event, which is part of the ContentHandler interface.

 public  void startPrefixMapping(String prefix,
    String uri) throws SAXException 
    Receive notification of the start of a Namespace mapping.

    By default, do nothing. Application writers may override this method in a subclass to take specific actions at the start of each Namespace prefix scope (such as storing the prefix mapping).

 public  void unparsedEntityDecl(String name,
    String publicId,
    String systemId,
    String notationName) throws SAXException 
    Receive notification of an unparsed entity declaration.

    By default, do nothing. Application writers may override this method in a subclass to keep track of the unparsed entities declared in a document.

 public  void warning(SAXParseException e) throws SAXException 
    Receive notification of a parser warning.

    The default implementation does nothing. Application writers may override this method in a subclass to take specific actions for each warning, such as inserting the message in a log file or printing it to the console.