org.apache.xml.dtm.ref.sax2dtm
Class SAX2RTFDTM

java.lang.Object
  extended by org.apache.xml.dtm.ref.DTMDefaultBase
      extended by org.apache.xml.dtm.ref.DTMDefaultBaseTraversers
          extended by org.apache.xml.dtm.ref.DTMDefaultBaseIterators
              extended by org.apache.xml.dtm.ref.sax2dtm.SAX2DTM
                  extended by org.apache.xml.dtm.ref.sax2dtm.SAX2RTFDTM
All Implemented Interfaces:
DTM, org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler, org.xml.sax.ext.DeclHandler, org.xml.sax.ext.LexicalHandler

public class SAX2RTFDTM
extends SAX2DTM

This is a subclass of SAX2DTM which has been modified to meet the needs of Result Tree Frameworks (RTFs). The differences are: 1) Multiple XML trees may be appended to the single DTM. This means that the root node of each document is _not_ node 0. Some code has had to be deoptimized to support this mode of operation, and an explicit mechanism for obtaining the Node Handle of the root node has been provided. 2) A stack of these documents is maintained, allowing us to "tail-prune" the most recently added trees off the end of the DTM as stylesheet elements (and thus variable contexts) are exited. PLEASE NOTE that this class may be _heavily_ dependent upon the internals of the SAX2DTM superclass, and must be maintained in parallel with that code. Arguably, they should be conditionals within a single class... but they have deen separated for performance reasons. (In fact, one could even argue about which is the superclass and which is the subclass; the current arrangement is as much about preserving stability of existing code during development as anything else.) %REVIEW% In fact, since the differences are so minor, I think it may be possible/practical to fold them back into the base SAX2DTM. Consider that as a future code-size optimization.


Nested Class Summary
 
Nested classes/interfaces inherited from class org.apache.xml.dtm.ref.DTMDefaultBaseIterators
DTMDefaultBaseIterators.AncestorIterator, DTMDefaultBaseIterators.AttributeIterator, DTMDefaultBaseIterators.ChildrenIterator, DTMDefaultBaseIterators.DescendantIterator, DTMDefaultBaseIterators.FollowingIterator, DTMDefaultBaseIterators.FollowingSiblingIterator, DTMDefaultBaseIterators.InternalAxisIteratorBase, DTMDefaultBaseIterators.NamespaceAttributeIterator, DTMDefaultBaseIterators.NamespaceChildrenIterator, DTMDefaultBaseIterators.NamespaceIterator, DTMDefaultBaseIterators.NthDescendantIterator, DTMDefaultBaseIterators.ParentIterator, DTMDefaultBaseIterators.PrecedingIterator, DTMDefaultBaseIterators.PrecedingSiblingIterator, DTMDefaultBaseIterators.RootIterator, DTMDefaultBaseIterators.SingletonIterator, DTMDefaultBaseIterators.TypedAncestorIterator, DTMDefaultBaseIterators.TypedAttributeIterator, DTMDefaultBaseIterators.TypedChildrenIterator, DTMDefaultBaseIterators.TypedDescendantIterator, DTMDefaultBaseIterators.TypedFollowingIterator, DTMDefaultBaseIterators.TypedFollowingSiblingIterator, DTMDefaultBaseIterators.TypedNamespaceIterator, DTMDefaultBaseIterators.TypedPrecedingIterator, DTMDefaultBaseIterators.TypedPrecedingSiblingIterator, DTMDefaultBaseIterators.TypedRootIterator, DTMDefaultBaseIterators.TypedSingletonIterator
 
Field Summary
private static boolean DEBUG
          Set true to monitor SAX events and similar diagnostic info.
private  int m_currentDocumentNode
          Most recently started Document, or null if the DTM is empty.
(package private)  int m_emptyCharsCount
          Tail-pruning mark: initial number of characters in use
(package private)  int m_emptyDataCount
          Tail-pruning mark: initial number of data items in use
(package private)  int m_emptyDataQNCount
          Tail-pruning mark: default initial number of dataOrQName slots in use
(package private)  int m_emptyNodeCount
          Tail-pruning mark: initial number of nodes in use
(package private)  int m_emptyNSDeclSetCount
          Tail-pruning mark: initial number of namespace declaration sets
(package private)  int m_emptyNSDeclSetElemsCount
          Tail-pruning mark: initial number of namespace declaration elements
(package private)  IntStack mark_char_size
          Tail-pruning mark: Number of size-of-data fields in use
(package private)  IntStack mark_data_size
          Tail-pruning mark: Number of data items in use
(package private)  IntStack mark_doq_size
          Tail-pruning mark: Number of dataOrQName slots in use
(package private)  IntStack mark_nsdeclelem_size
          Tail-pruning mark: Number of naespace declaration elements in use %REVIEW% I don't think number of NS sets is ever different from number of NS elements.
(package private)  IntStack mark_nsdeclset_size
          Tail-pruning mark: Number of namespace declaration sets in use %REVIEW% I don't think number of NS sets is ever different from number of NS elements.
(package private)  IntStack mark_size
          Tail-pruning mark: Number of nodes in use
 
Fields inherited from class org.apache.xml.dtm.ref.sax2dtm.SAX2DTM
m_chars, m_coalescedTextType, m_contextIndexes, m_data, m_dataOrQName, m_endDocumentOccured, m_idAttributes, m_insideDTD, m_locator, m_parents, m_pastFirstElement, m_prefixMappings, m_previous, m_sourceColumn, m_sourceLine, m_sourceSystemId, m_textPendingStart, m_textType, m_useSourceLocationProperty, m_valuesOrPrefixes, m_walker
 
Fields inherited from class org.apache.xml.dtm.ref.DTMDefaultBase
DEFAULT_BLOCKSIZE, DEFAULT_NUMBLOCKS, DEFAULT_NUMBLOCKS_SMALL, m_documentBaseURI, m_dtmIdent, m_elemIndexes, m_expandedNameTable, m_exptype, m_firstch, m_indexing, m_mgr, m_mgrDefault, m_namespaceDeclSetElements, m_namespaceDeclSets, m_nextsib, m_parent, m_prevsib, m_shouldStripWhitespaceStack, m_shouldStripWS, m_size, m_traversers, m_wsfilter, m_xstrf, NOTPROCESSED, ROOTNODE
 
Fields inherited from interface org.apache.xml.dtm.DTM
ATTRIBUTE_NODE, CDATA_SECTION_NODE, COMMENT_NODE, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_TYPE_NODE, ELEMENT_NODE, ENTITY_NODE, ENTITY_REFERENCE_NODE, NAMESPACE_NODE, NOTATION_NODE, NTYPES, NULL, PROCESSING_INSTRUCTION_NODE, ROOT_NODE, TEXT_NODE
 
Constructor Summary
SAX2RTFDTM(DTMManager mgr, javax.xml.transform.Source source, int dtmIdentity, DTMWSFilter whiteSpaceFilter, XMLStringFactory xstringfactory, boolean doIndexing)
           
 
Method Summary
protected  int _documentRoot(int nodeIdentifier)
          Given a node identifier, find the owning document node.
 void endDocument()
          Receive notification of the end of the document.
 int getDocument()
          Given a DTM, find the owning document node.
 int getDocumentRoot(int nodeHandle)
          Given a node handle, find the owning document node, using DTM semantics (Document owns itself) rather than DOM semantics (Document has no owner).
 boolean isTreeIncomplete()
           
 boolean popRewindMark()
          "Tail-pruning" support for RTFs.
 void pushRewindMark()
          "Tail-pruning" support for RTFs.
 void startDocument()
          Receive notification of the beginning of a new RTF document.
 
Methods inherited from class org.apache.xml.dtm.ref.sax2dtm.SAX2DTM
_dataOrQName, addNewDTMID, addNode, attributeDecl, characters, charactersFlush, clearCoRoutine, clearCoRoutine, comment, declAlreadyDeclared, dispatchCharactersEvents, dispatchToEvents, elementDecl, endCDATA, endDTD, endElement, endEntity, endPrefixMapping, error, externalEntityDecl, fatalError, getAttributeNode, getContentHandler, getDeclHandler, getDocumentTypeDeclarationPublicIdentifier, getDocumentTypeDeclarationSystemIdentifier, getDTDHandler, 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, startElement, startEntity, startPrefixMapping, unparsedEntityDecl, warning
 
Methods inherited from class org.apache.xml.dtm.ref.DTMDefaultBaseIterators
getAxisIterator, getTypedAxisIterator
 
Methods inherited from class org.apache.xml.dtm.ref.DTMDefaultBaseTraversers
getAxisTraverser
 
Methods inherited from class org.apache.xml.dtm.ref.DTMDefaultBase
_exptype, _firstch, _level, _nextsib, _parent, _prevsib, _type, appendChild, appendTextChild, declareNamespaceInContext, documentRegistration, documentRelease, dumpDTM, dumpNode, ensureSizeOfIndex, error, findGTE, findInSortedSuballocatedIntVector, findNamespaceContext, getDocumentAllDeclarationsProcessed, getDocumentBaseURI, getDocumentEncoding, getDocumentStandalone, getDocumentSystemIdentifier, getDocumentVersion, getDTMIDs, getExpandedTypeID, getExpandedTypeID, getFirstAttribute, getFirstAttributeIdentity, getFirstChild, getFirstNamespaceNode, getLastChild, getLevel, getLocalNameFromExpandedNameID, getManager, getNamespaceFromExpandedNameID, getNamespaceType, getNextAttribute, getNextAttributeIdentity, getNextNamespaceNode, getNextSibling, getNode, getNodeHandle, getNodeIdent, getNodeType, getOwnerDocument, getParent, getPreviousSibling, getShouldStripWhitespace, getStringValueChunk, getStringValueChunkCount, getTypedAttribute, getTypedFirstChild, getTypedNextSibling, hasChildNodes, indexNode, isCharacterElementContentWhitespace, isDocumentAllDeclarationsProcessed, isNodeAfter, isSupported, makeNodeHandle, makeNodeIdentity, popShouldStripWhitespace, pushShouldStripWhitespace, setDocumentBaseURI, setFeature, setShouldStripWhitespace, supportsPreStripping
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG

private static final boolean DEBUG
Set true to monitor SAX events and similar diagnostic info.

See Also:
Constant Field Values

m_currentDocumentNode

private int m_currentDocumentNode
Most recently started Document, or null if the DTM is empty.


mark_size

IntStack mark_size
Tail-pruning mark: Number of nodes in use


mark_data_size

IntStack mark_data_size
Tail-pruning mark: Number of data items in use


mark_char_size

IntStack mark_char_size
Tail-pruning mark: Number of size-of-data fields in use


mark_doq_size

IntStack mark_doq_size
Tail-pruning mark: Number of dataOrQName slots in use


mark_nsdeclset_size

IntStack mark_nsdeclset_size
Tail-pruning mark: Number of namespace declaration sets in use %REVIEW% I don't think number of NS sets is ever different from number of NS elements. We can probabably reduce these to a single stack and save some storage.


mark_nsdeclelem_size

IntStack mark_nsdeclelem_size
Tail-pruning mark: Number of naespace declaration elements in use %REVIEW% I don't think number of NS sets is ever different from number of NS elements. We can probabably reduce these to a single stack and save some storage.


m_emptyNodeCount

int m_emptyNodeCount
Tail-pruning mark: initial number of nodes in use


m_emptyNSDeclSetCount

int m_emptyNSDeclSetCount
Tail-pruning mark: initial number of namespace declaration sets


m_emptyNSDeclSetElemsCount

int m_emptyNSDeclSetElemsCount
Tail-pruning mark: initial number of namespace declaration elements


m_emptyDataCount

int m_emptyDataCount
Tail-pruning mark: initial number of data items in use


m_emptyCharsCount

int m_emptyCharsCount
Tail-pruning mark: initial number of characters in use


m_emptyDataQNCount

int m_emptyDataQNCount
Tail-pruning mark: default initial number of dataOrQName slots in use

Constructor Detail

SAX2RTFDTM

public SAX2RTFDTM(DTMManager mgr,
                  javax.xml.transform.Source source,
                  int dtmIdentity,
                  DTMWSFilter whiteSpaceFilter,
                  XMLStringFactory xstringfactory,
                  boolean doIndexing)
Method Detail

getDocument

public int getDocument()
Given a DTM, find the owning document node. In the case of SAX2RTFDTM, which may contain multiple documents, this returns the most recently started document, or null if the DTM is empty or no document is currently under construction. %REVIEW% Should we continue to report the most recent after construction has ended? I think not, given that it may have been tail-pruned.

Specified by:
getDocument in interface DTM
Overrides:
getDocument in class DTMDefaultBase
Returns:
int Node handle of Document node, or null if this DTM does not contain an "active" document.

getDocumentRoot

public int getDocumentRoot(int nodeHandle)
Given a node handle, find the owning document node, using DTM semantics (Document owns itself) rather than DOM semantics (Document has no owner). (I'm counting on the fact that getOwnerDocument() is implemented on top of this call, in the superclass, to avoid having to rewrite that one. Be careful if that code changes!)

Specified by:
getDocumentRoot in interface DTM
Overrides:
getDocumentRoot in class DTMDefaultBase
Parameters:
nodeHandle - the id of the node.
Returns:
int Node handle of owning document
See Also:
DTM.getOwnerDocument(int nodeHandle)

_documentRoot

protected int _documentRoot(int nodeIdentifier)
Given a node identifier, find the owning document node. Unlike the DOM, this considers the owningDocument of a Document to be itself. Note that in shared DTMs this may not be zero.

Parameters:
nodeIdentifier - the id of the starting node.
Returns:
int Node identifier of the root of this DTM tree

startDocument

public void startDocument()
                   throws org.xml.sax.SAXException
Receive notification of the beginning of a new RTF document. %REVIEW% Y'know, this isn't all that much of a deoptimization. We might want to consider folding the start/endDocument changes back into the main SAX2DTM so we don't have to expose so many fields (even as Protected) and carry the additional code.

Specified by:
startDocument in interface org.xml.sax.ContentHandler
Overrides:
startDocument in class SAX2DTM
Throws:
org.xml.sax.SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
ContentHandler.startDocument()

endDocument

public void endDocument()
                 throws org.xml.sax.SAXException
Receive notification of the end of the document. %REVIEW% Y'know, this isn't all that much of a deoptimization. We might want to consider folding the start/endDocument changes back into the main SAX2DTM so we don't have to expose so many fields (even as Protected).

Specified by:
endDocument in interface org.xml.sax.ContentHandler
Overrides:
endDocument in class SAX2DTM
Throws:
org.xml.sax.SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
ContentHandler.endDocument()

pushRewindMark

public void pushRewindMark()
"Tail-pruning" support for RTFs. This function pushes information about the current size of the DTM's data structures onto a stack, for use by popRewindMark() (which see). %REVIEW% I have no idea how to rewind m_elemIndexes. However, RTFs will not be indexed, so I can simply panic if that case arises. Hey, it works...


popRewindMark

public boolean popRewindMark()
"Tail-pruning" support for RTFs. This function pops the information previously saved by pushRewindMark (which see) and uses it to discard all nodes added to the DTM after that time. We expect that this will allow us to reuse storage more effectively. This is _not_ intended to be called while a document is still being constructed -- only between endDocument and the next startDocument %REVIEW% WARNING: This is the first use of some of the truncation methods. If Xalan blows up after this is called, that's a likely place to check. %REVIEW% Our original design for DTMs permitted them to share string pools. If there any risk that this might be happening, we can _not_ rewind and recover the string storage. One solution might to assert that DTMs used for RTFs Must Not take advantage of that feature, but this seems excessively fragile. Another, much less attractive, would be to just let them leak... Nah.

Returns:
true if and only if the pop completely emptied the RTF. That response is used when determining how to unspool RTF-started-while-RTF-open situations.

isTreeIncomplete

public boolean isTreeIncomplete()
Returns:
true if a DTM tree is currently under construction.