org.apache.xml.dtm.ref.sax2dtm

Class SAX2DTM2

Implemented Interfaces:
ContentHandler, DeclHandler, DTDHandler, EntityResolver, ErrorHandler, LexicalHandler, DTM
Known Direct Subclasses:
SAXImpl

public class SAX2DTM2
extends SAX2DTM

SAX2DTM2 is an optimized version of SAX2DTM which is used in non-incremental situation. It is used as the super class of the XSLTC SAXImpl. Many of the interfaces in SAX2DTM and DTMDefaultBase are overridden in SAX2DTM2 in order to allow fast, efficient access to the DTM model. Some nested iterators in DTMDefaultBaseIterators are also overridden in SAX2DTM2 for performance reasons.

Performance is the biggest consideration in the design of SAX2DTM2. To make the code most efficient, the incremental support is dropped in SAX2DTM2, which means that you should not use it in incremental situation. To reduce the overhead of pulling data from the DTM model, a few core interfaces in SAX2DTM2 have direct access to the internal arrays of the SuballocatedIntVectors.

The design of SAX2DTM2 may limit its extensibilty. If you have a reason to extend the SAX2DTM model, please extend from SAX2DTM instead of this class.

TODO: This class is currently only used by XSLTC. We need to investigate the possibility of also using it in Xalan-J Interpretive. Xalan's performance is likely to get an instant boost if we use SAX2DTM2 instead of SAX2DTM in non-incremental case.

%MK% The code in this class is critical to the XSLTC_DTM performance. Be very careful when making changes here!

Nested Class Summary

class
SAX2DTM2.AncestorIterator
Iterator that returns the ancestors of a given node in document order.
class
SAX2DTM2.AttributeIterator
Iterator that returns attribute nodes (of what nodes?)
class
SAX2DTM2.ChildrenIterator
Iterator that returns all immediate children of a given node
class
SAX2DTM2.DescendantIterator
Iterator that returns the descendants of a given node.
class
SAX2DTM2.FollowingIterator
Iterator that returns following nodes of for a given node.
class
SAX2DTM2.FollowingSiblingIterator
Iterator that returns all siblings of a given node.
class
SAX2DTM2.ParentIterator
Iterator that returns the parent of a given node.
class
SAX2DTM2.PrecedingIterator
Iterator that returns preceding nodes of a given node.
class
SAX2DTM2.PrecedingSiblingIterator
Iterator that returns preceding siblings of a given node
class
SAX2DTM2.TypedAncestorIterator
Typed iterator that returns the ancestors of a given node.
class
SAX2DTM2.TypedAttributeIterator
Iterator that returns attribute nodes of a given type
class
SAX2DTM2.TypedChildrenIterator
Iterator that returns children of a given type for a given node.
class
SAX2DTM2.TypedDescendantIterator
Typed iterator that returns the descendants of a given node.
class
SAX2DTM2.TypedFollowingIterator
Iterator that returns following nodes of a given type for a given node.
class
SAX2DTM2.TypedFollowingSiblingIterator
Iterator that returns all following siblings of a given node.
class
SAX2DTM2.TypedPrecedingIterator
Iterator that returns preceding nodes of agiven type for a given node.
class
SAX2DTM2.TypedPrecedingSiblingIterator
Iterator that returns preceding siblings of a given type for a given node
class
SAX2DTM2.TypedRootIterator
Iterator that returns the namespace nodes as defined by the XPath data model for a given node, filtered by extended type ID.
class
SAX2DTM2.TypedSingletonIterator
Iterator that returns a given node only if it is of a given type.

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

Fields inherited from class org.apache.xml.dtm.ref.DTMDefaultBase

DEFAULT_BLOCKSIZE, DEFAULT_NUMBLOCKS, DEFAULT_NUMBLOCKS_SMALL, ROOTNODE, m_mgr

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

SAX2DTM2(DTMManager mgr, Source source, int dtmIdentity, DTMWSFilter whiteSpaceFilter, XMLStringFactory xstringfactory, boolean doIndexing)
Construct a SAX2DTM2 object using the default block size.
SAX2DTM2(DTMManager mgr, Source source, int dtmIdentity, DTMWSFilter whiteSpaceFilter, XMLStringFactory xstringfactory, boolean doIndexing, int blocksize, boolean usePrevsib, boolean buildIdIndex, boolean newNameTable)
Construct a SAX2DTM2 object using the given block size.

Method Summary

int
_exptype(int identity)
Override DTMDefaultBase._exptype() by dropping the incremental code.
int
_exptype2(int identity)
The optimized version of DTMDefaultBase._exptype().
int
_exptype2Type(int exptype)
Return the node type from the expanded type
int
_firstch2(int identity)
The optimized version of DTMDefaultBase._firstch().
int
_nextsib2(int identity)
The optimized version of DTMDefaultBase._nextsib().
int
_parent2(int identity)
The optimized version of DTMDefaultBase._parent().
int
_type2(int identity)
The optimized version of DTMDefaultBase._type().
void
comment(ch[] , int start, int length)
Report an XML comment anywhere in the document.
void
dispatchCharactersEvents(int nodeHandle, ContentHandler ch, boolean normalize)
The optimized version of SAX2DTM.dispatchCharactersEvents(int, ContentHandler, boolean).
void
endDocument()
Receive notification of the end of the document.
void
endElement(String uri, String localName, String qName)
Receive notification of the end of an element.
int
getExpandedTypeID2(int nodeHandle)
The optimized version of DTMDefaultBase.getExpandedTypeID(int).
int
getFirstAttribute(int nodeHandle)
The optimized version of DTMDefaultBase.getFirstAttribute().
int
getIdForNamespace(String uri)
Get a prefix either from the uri mapping, or just make one up!
String
getLocalName(int nodeHandle)
Override SAX2DTM.getLocalName() in SAX2DTM2.
String
getNodeName(int nodeHandle)
The optimized version of SAX2DTM.getNodeName().
String
getNodeNameX(int nodeHandle)
The optimized version of SAX2DTM.getNodeNameX().
String
getNodeValue(int nodeHandle)
Given a node handle, return its node value.
String
getStringValue()
Returns the string value of the entire tree
XMLString
getStringValue(int nodeHandle)
Override SAX2DTM.getStringValue(int)

This method is only used by Xalan-J Interpretive.

String
getStringValueX(int nodeHandle)
The optimized version of SAX2DTM.getStringValue(int).
void
processingInstruction(String target, String data)
Override the processingInstruction() interface in SAX2DTM2.
void
startDocument()
Receive notification of the beginning of the document.
void
startElement(String uri, String localName, String qName, Attributes attributes)
Override SAX2DTM.startElement()

Receive notification of the start of an element.

Methods inherited from class org.apache.xml.dtm.ref.sax2dtm.SAX2DTM

attributeDecl, characters, clearCoRoutine, clearCoRoutine, comment, dispatchCharactersEvents, dispatchToEvents, elementDecl, endCDATA, endDTD, endDocument, endElement, endEntity, endPrefixMapping, error, externalEntityDecl, fatalError, getAttributeNode, getContentHandler, getDTDHandler, getDeclHandler, getDocumentTypeDeclarationPublicIdentifier, getDocumentTypeDeclarationSystemIdentifier, getElementById, getEntityResolver, getErrorHandler, getIdForNamespace, getLexicalHandler, getLocalName, getNamespaceURI, getNamespaceURI, getNodeName, getNodeNameX, getNodeValue, getNumberOfNodes, getPrefix, getPrefix, getSourceLocatorFor, getStringValue, getUnparsedEntityURI, ignorableWhitespace, internalEntityDecl, isAttributeSpecified, isWhitespace, migrateTo, needsTwoThreads, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, setIDAttribute, setIncrementalSAXSource, setProperty, setUseSourceLocation, skippedEntity, startCDATA, startDTD, startDocument, 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

appendChild, appendTextChild, dispatchCharactersEvents, dispatchToEvents, documentRegistration, documentRelease, dumpDTM, dumpNode, getAttributeNode, getDTMIDs, getDocument, getDocumentAllDeclarationsProcessed, getDocumentBaseURI, getDocumentEncoding, getDocumentRoot, getDocumentStandalone, getDocumentSystemIdentifier, getDocumentTypeDeclarationPublicIdentifier, getDocumentTypeDeclarationSystemIdentifier, getDocumentVersion, getElementById, getExpandedTypeID, getExpandedTypeID, getFirstAttribute, getFirstChild, getFirstNamespaceNode, getLastChild, getLevel, getLocalName, getLocalNameFromExpandedNameID, getManager, getNamespaceFromExpandedNameID, getNamespaceType, getNamespaceURI, getNextAttribute, getNextNamespaceNode, getNextSibling, getNode, getNodeHandle, getNodeIdent, getNodeName, getNodeNameX, getNodeType, getNodeValue, getOwnerDocument, getParent, getPrefix, getPreviousSibling, getStringValue, getStringValueChunk, getStringValueChunkCount, getTypedFirstChild, getTypedNextSibling, getUnparsedEntityURI, hasChildNodes, isAttributeSpecified, isCharacterElementContentWhitespace, isDocumentAllDeclarationsProcessed, isNodeAfter, isSupported, makeNodeHandle, makeNodeIdentity, migrateTo, setDocumentBaseURI, setFeature, supportsPreStripping

Constructor Details

SAX2DTM2

public SAX2DTM2(DTMManager mgr,
                Source source,
                int dtmIdentity,
                DTMWSFilter whiteSpaceFilter,
                XMLStringFactory xstringfactory,
                boolean doIndexing)
Construct a SAX2DTM2 object using the default block size.

SAX2DTM2

public SAX2DTM2(DTMManager mgr,
                Source source,
                int dtmIdentity,
                DTMWSFilter whiteSpaceFilter,
                XMLStringFactory xstringfactory,
                boolean doIndexing,
                int blocksize,
                boolean usePrevsib,
                boolean buildIdIndex,
                boolean newNameTable)
Construct a SAX2DTM2 object using the given block size.

Method Details

_exptype

public final int _exptype(int identity)
Override DTMDefaultBase._exptype() by dropping the incremental code.

This one is less efficient than _exptype2. It is only used during DTM building. _exptype2 is used after the document is fully built.


_exptype2

public final int _exptype2(int identity)
The optimized version of DTMDefaultBase._exptype().
Parameters:
identity - A node identity, which must not be equal to DTM.NULL

_exptype2Type

public final int _exptype2Type(int exptype)
Return the node type from the expanded type

_firstch2

public final int _firstch2(int identity)
The optimized version of DTMDefaultBase._firstch().
Parameters:
identity - A node identity, which must not be equal to DTM.NULL

_nextsib2

public final int _nextsib2(int identity)
The optimized version of DTMDefaultBase._nextsib().
Parameters:
identity - A node identity, which must not be equal to DTM.NULL

_parent2

public final int _parent2(int identity)
The optimized version of DTMDefaultBase._parent().
Parameters:
identity - A node identity, which must not be equal to DTM.NULL

_type2

public final int _type2(int identity)
The optimized version of DTMDefaultBase._type().
Parameters:
identity - A node identity, which must not be equal to DTM.NULL

comment

public void comment(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).

Overrides:
comment in interface SAX2DTM
Parameters:
start - The starting position in the array.
length - The number of characters to use from the array.

dispatchCharactersEvents

public final void dispatchCharactersEvents(int nodeHandle,
                                           ContentHandler ch,
                                           boolean normalize)
            throws SAXException
The optimized version of SAX2DTM.dispatchCharactersEvents(int, ContentHandler, boolean).

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.

Overrides:
dispatchCharactersEvents in interface SAX2DTM
Parameters:
nodeHandle - The node ID.
ch - A non-null reference to a ContentHandler.
normalize - true if the content should be normalized according to the rules for the XPath normalize-space function.

endDocument

public void endDocument()
            throws SAXException
Receive notification of the end of the document.
Overrides:
endDocument in interface SAX2DTM
See Also:
org.xml.sax.ContentHandler.endDocument

endElement

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).

Overrides:
endElement in interface SAX2DTM
Parameters:
uri - The Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed.
localName - The local name (without prefix), or the empty string if Namespace processing is not being performed.
qName - The qualified XML 1.0 name (with prefix), or the empty string if qualified names are not available.
See Also:
org.xml.sax.ContentHandler.endElement

getExpandedTypeID2

public final int getExpandedTypeID2(int nodeHandle)
The optimized version of DTMDefaultBase.getExpandedTypeID(int).

This one is only used by DOMAdapter.getExpandedTypeID(int), which is mostly called from the compiled translets.


getFirstAttribute

public final int getFirstAttribute(int nodeHandle)
The optimized version of DTMDefaultBase.getFirstAttribute().

Given a node handle, get the index of the node's first attribute.

Specified by:
getFirstAttribute in interface DTM
Overrides:
getFirstAttribute in interface DTMDefaultBase
Parameters:
nodeHandle - int Handle of the node.
Returns:
Handle of first attribute, or DTM.NULL to indicate none exists.

getIdForNamespace

public int getIdForNamespace(String uri)
Get a prefix either from the uri mapping, or just make one up!
Overrides:
getIdForNamespace in interface SAX2DTM
Parameters:
uri - The namespace URI, which may be null.
Returns:
The prefix if there is one, or null.

getLocalName

public String getLocalName(int nodeHandle)
Override SAX2DTM.getLocalName() in SAX2DTM2.

Processing for PIs is different. Given a node handle, return its XPath- style localname. (As defined in Namespaces, this is the portion of the name after any colon character).

Specified by:
getLocalName in interface DTM
Overrides:
getLocalName in interface SAX2DTM
Parameters:
nodeHandle - the id of the node.
Returns:
String Local name of this node.

getNodeName

public String getNodeName(int nodeHandle)
The optimized version of SAX2DTM.getNodeName().

Given a node handle, return its DOM-style node name. This will include names such as #text or #document.

Specified by:
getNodeName in interface DTM
Overrides:
getNodeName in interface SAX2DTM
Parameters:
nodeHandle - the id of the node.
Returns:
String Name of this node, which may be an empty string. %REVIEW% Document when empty string is possible... %REVIEW-COMMENT% It should never be empty, should it?

getNodeNameX

public final String getNodeNameX(int nodeHandle)
The optimized version of SAX2DTM.getNodeNameX().

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.

Specified by:
getNodeNameX in interface DTM
Overrides:
getNodeNameX in interface SAX2DTM
Parameters:
nodeHandle - the id of the node.
Returns:
String Name of this node, which may be an empty string.

getNodeValue

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.

Specified by:
getNodeValue in interface DTM
Overrides:
getNodeValue in interface SAX2DTM
Parameters:
nodeHandle - The node id.
Returns:
String Value of this node, or null if not meaningful for this node type.

getStringValue

public String getStringValue()
Returns the string value of the entire tree

getStringValue

public XMLString getStringValue(int nodeHandle)
Override SAX2DTM.getStringValue(int)

This method is only used by Xalan-J Interpretive. It is not used by XSLTC.

If the caller supplies an XMLStringFactory, the getStringValue() interface in SAX2DTM will be called. Otherwise just calls getStringValueX() and wraps the returned String in an XMLString. 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).

Specified by:
getStringValue in interface DTM
Overrides:
getStringValue in interface SAX2DTM
Parameters:
nodeHandle - The node ID.
Returns:
A string object that represents the string-value of the given node.

getStringValueX

public final String getStringValueX(int nodeHandle)
The optimized version of SAX2DTM.getStringValue(int).

%OPT% This is one of the most often used interfaces. Performance is critical here. This one is different from SAX2DTM.getStringValue(int) in that it returns a String instead of a XMLString. 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).

Parameters:
nodeHandle - The node ID.
Returns:
A string object that represents the string-value of the given node.

processingInstruction

public void processingInstruction(String target,
                                  String data)
            throws SAXException
Override the processingInstruction() interface in SAX2DTM2.

%OPT% This one is different from SAX2DTM.processingInstruction() in that we do not use extended types for PI nodes. The name of the PI is saved in the DTMStringPool. Receive notification of a processing instruction.

Overrides:
processingInstruction in interface SAX2DTM
Parameters:
target - The processing instruction target.
data - The processing instruction data, or null if none is supplied.
See Also:
org.xml.sax.ContentHandler.processingInstruction

startDocument

public void startDocument()
            throws SAXException
Receive notification of the beginning of the document.
Overrides:
startDocument in interface SAX2DTM
See Also:
org.xml.sax.ContentHandler.startDocument

startElement

public void startElement(String uri,
                         String localName,
                         String qName,
                         Attributes attributes)
            throws SAXException
Override SAX2DTM.startElement()

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).

Overrides:
startElement in interface SAX2DTM
Parameters:
uri - The Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed.
localName - The local name (without prefix), or the empty string if Namespace processing is not being performed.
qName - The qualified name (with prefix), or the empty string if qualified names are not available.
attributes - The specified or defaulted attributes.
See Also:
org.xml.sax.ContentHandler.startElement

Copyright B) 2004 Apache XML Project. All Rights Reserved.