public abstract class DTMDefaultBase extends Object implements DTM
DTMDefaultBase class serves as a helper base for DTMs. It sets up structures for
navigation and type, while leaving data management and construction to the derived classes.| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_BLOCKSIZE
The default block size of the node arrays
|
static int |
DEFAULT_NUMBLOCKS
The number of blocks for the node arrays
|
static int |
DEFAULT_NUMBLOCKS_SMALL
The number of blocks used for small documents & RTFs
|
protected String |
m_documentBaseURI
The base URI for this document.
|
protected SuballocatedIntVector |
m_dtmIdent
The document identity number(s).
|
protected int[][][] |
m_elemIndexes
These hold indexes to elements based on namespace and local name.
|
protected ExpandedNameTable |
m_expandedNameTable
The table for exandedNameID lookups.
|
protected SuballocatedIntVector |
m_exptype
The expanded names, one array element for each node.
|
protected SuballocatedIntVector |
m_firstch
First child values, one array element for each node.
|
protected boolean |
m_indexing
true if indexing is turned on.
|
DTMManager |
m_mgr
The DTM manager who "owns" this DTM.
|
protected DTMManagerDefault |
m_mgrDefault
m_mgr cast to DTMManagerDefault, or null if it isn't an instance (Efficiency hook)
|
protected SuballocatedIntVector |
m_namespaceDeclSetElements
SuballocatedIntVector of elements at which corresponding namespaceDeclSets were defined
|
protected List<SuballocatedIntVector> |
m_namespaceDeclSets
Vector of SuballocatedIntVectors of NS decl sets
|
protected SuballocatedIntVector |
m_nextsib
Next sibling values, one array element for each node.
|
protected SuballocatedIntVector |
m_parent
Previous sibling values, one array element for each node.
|
protected SuballocatedIntVector |
m_prevsib
Previous sibling values, one array element for each node.
|
protected int |
m_size
The number of nodes, which is also used to determine the next node index.
|
protected DTMAxisTraverser[] |
m_traversers
Stateless axis traversers, lazely built.
|
protected static int |
NOTPROCESSED
The value to use when the information has not been built yet.
|
static int |
ROOTNODE
The identity of the root node.
|
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, TEXT_NODE| Constructor and Description |
|---|
DTMDefaultBase(DTMManager mgr,
Source source,
int dtmIdentity,
boolean doIndexing)
Construct a DTMDefaultBase object using the default block size.
|
DTMDefaultBase(DTMManager mgr,
Source source,
int dtmIdentity,
boolean doIndexing,
int blocksize,
boolean usePrevsib)
Construct a DTMDefaultBase object from a DOM node.
|
| Modifier and Type | Method and Description |
|---|---|
protected int |
_exptype(int identity)
Get the expanded type ID for the given node identity.
|
protected int |
_firstch(int identity)
Get the first child for the given node identity.
|
protected int |
_level(int identity)
Get the level in the tree for the given node identity.
|
protected int |
_nextsib(int identity)
Get the next sibling for the given node identity.
|
protected int |
_parent(int identity)
Get the parent for the given node identity.
|
protected int |
_prevsib(int identity)
Get the previous sibling for the given node identity.
|
protected short |
_type(int identity)
Get the simple type ID for the given node identity.
|
protected void |
declareNamespaceInContext(int elementNodeIndex,
int namespaceNodeIndex)
Build table of namespace declaration locations during DTM construction.
|
void |
dumpDTM(OutputStream os)
Diagnostics function to dump the DTM.
|
String |
dumpNode(int nodeHandle)
Diagnostics function to dump a single node.
|
protected void |
ensureSizeOfIndex(int namespaceID,
int LocalNameID)
Ensure that the size of the element indexes can hold the information.
|
protected int |
findGTE(int[] list,
int start,
int len,
int value)
Find the first index that occurs in the list that is greater than or equal to the given value.
|
protected int |
findInSortedSuballocatedIntVector(SuballocatedIntVector vector,
int lookfor)
Subroutine: Locate the specified node within m_namespaceDeclSetElements, or the last element
which preceeds it in document order
%REVIEW% Inlne this into findNamespaceContext?
|
protected SuballocatedIntVector |
findNamespaceContext(int elementNodeIndex)
Retrieve list of namespace declaration locations active at this node.
|
abstract int |
getAttributeNode(int nodeHandle,
String namespaceURI,
String name)
Retrieves an attribute node by local name and namespace URI
%TBD% Note that we currently have no way to support the DOM's old getAttribute() call, which
accesses only the qname.
|
int |
getDocument()
Given a DTM which contains only a single document, find the Node Handle of the Document node.
|
int |
getDocumentRoot(int nodeHandle)
Given a node handle, find the owning document node.
|
abstract int |
getElementById(String elementId)
Returns the
Element whose ID is given by elementId. |
int |
getExpandedTypeID(int nodeHandle)
Given a node handle, return an ID that represents the node's expanded name.
|
int |
getExpandedTypeID(String namespace,
String localName,
int type)
Given an expanded name, return an ID.
|
int |
getFirstAttribute(int nodeHandle)
Given a node handle, get the index of the node's first attribute.
|
protected int |
getFirstAttributeIdentity(int identity)
Given a node identity, get the index of the node's first attribute.
|
int |
getFirstChild(int nodeHandle)
Given a node handle, get the handle of the node's first child.
|
int |
getFirstNamespaceNode(int nodeHandle,
boolean inScope)
Given a node handle, get the index of the node's first namespace node.
|
int |
getLastChild(int nodeHandle)
Given a node handle, get the handle of the node's last child.
|
abstract String |
getLocalName(int nodeHandle)
Given a node handle, return its DOM-style localname.
|
DTMManager |
getManager()
Query which DTMManager this DTM is currently being handled by.
|
abstract 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.)
|
int |
getNextAttribute(int nodeHandle)
Given a node handle, advance to the next attribute.
|
protected int |
getNextAttributeIdentity(int identity)
Given a node identity for an attribute, advance to the next attribute.
|
int |
getNextNamespaceNode(int baseHandle,
int nodeHandle,
boolean inScope)
Given a namespace handle, advance to the next namespace in the same scope (local or
local-plus-inherited, as selected by getFirstNamespaceNode)
|
protected abstract int |
getNextNodeIdentity(int identity)
Get the next node identity value in the list, and call the iterator if it hasn't been added
yet.
|
int |
getNextSibling(int nodeHandle)
Given a node handle, advance to its next sibling.
|
Node |
getNode(int nodeHandle)
Return an DOM node for the given node.
|
abstract String |
getNodeName(int nodeHandle)
Given a node handle, return its DOM-style node name.
|
String |
getNodeNameX(int nodeHandle)
Given a node handle, return the XPath node name.
|
short |
getNodeType(int nodeHandle)
Given a node handle, return its DOM-style node type.
|
abstract String |
getNodeValue(int nodeHandle)
Given a node handle, return its node value.
|
int |
getOwnerDocument(int nodeHandle)
Given a node handle, find the owning document node.
|
int |
getParent(int nodeHandle)
Given a node handle, find its parent node.
|
abstract String |
getPrefix(int nodeHandle)
Given a namespace handle, return the prefix that the namespace decl is mapping.
|
int |
getPreviousSibling(int nodeHandle)
Given a node handle, find its preceeding sibling.
|
abstract XString |
getStringValue(int nodeHandle)
Get the string-value of a node as a String object (see ...
|
protected void |
indexNode(int expandedTypeID,
int identity)
Add a node to the element indexes.
|
boolean |
isNodeAfter(int nodeHandle1,
int nodeHandle2)
Figure out whether nodeHandle2 should be considered as being later in the document than
nodeHandle1, in Document Order as defined by the XPath model.
|
int |
makeNodeHandle(int nodeIdentity)
Given a node identity, return a node handle.
|
int |
makeNodeIdentity(int nodeHandle)
Given a node handle, return a node identity.
|
protected abstract boolean |
nextNode()
This method should try and build one or more nodes in the table.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetAxisIterator, getAxisTraverserpublic static final int ROOTNODE
protected int m_size
protected final SuballocatedIntVector m_exptype
protected final SuballocatedIntVector m_firstch
protected final SuballocatedIntVector m_nextsib
protected SuballocatedIntVector m_prevsib
protected final SuballocatedIntVector m_parent
protected List<SuballocatedIntVector> m_namespaceDeclSets
protected SuballocatedIntVector m_namespaceDeclSetElements
protected int[][][] m_elemIndexes
public static final int DEFAULT_BLOCKSIZE
public static final int DEFAULT_NUMBLOCKS
public static final int DEFAULT_NUMBLOCKS_SMALL
protected static final int NOTPROCESSED
public final DTMManager m_mgr
protected DTMManagerDefault m_mgrDefault
protected final SuballocatedIntVector m_dtmIdent
protected final String m_documentBaseURI
protected final ExpandedNameTable m_expandedNameTable
protected final boolean m_indexing
protected DTMAxisTraverser[] m_traversers
public DTMDefaultBase(DTMManager mgr, Source source, int dtmIdentity, boolean doIndexing)
mgr - The DTMManager who owns this DTM.source - The object that is used to specify the construction source.dtmIdentity - The DTM identity ID for this DTM.doIndexing - true if the caller considers it worth it to use indexing schemes.public DTMDefaultBase(DTMManager mgr, Source source, int dtmIdentity, boolean doIndexing, int blocksize, boolean usePrevsib)
mgr - The DTMManager who owns this DTM.source - The object that is used to specify the construction source.dtmIdentity - The DTM identity ID for this DTM.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.protected void ensureSizeOfIndex(int namespaceID,
int LocalNameID)
namespaceID - Namespace ID index.LocalNameID - Local name ID.protected void indexNode(int expandedTypeID,
int identity)
expandedTypeID - The expanded type ID of the node.identity - The node identity index.protected int findGTE(int[] list,
int start,
int len,
int value)
list - A list of integers.start - The start index to begin the search.len - The number of items to search.value - Find the slot that has a value that is greater than or identical to this argument.protected abstract int getNextNodeIdentity(int identity)
identity - The node identity (index).protected abstract boolean nextNode()
protected short _type(int identity)
identity - The node identity.protected int _exptype(int identity)
identity - The node identity.protected int _level(int identity)
identity - The node identity.protected int _firstch(int identity)
identity - The node identity.protected int _nextsib(int identity)
identity - The node identity.protected int _prevsib(int identity)
identity - The node identity.protected int _parent(int identity)
identity - The node identity.public void dumpDTM(OutputStream os)
public String dumpNode(int nodeHandle)
%REVIEW% KNOWN GLITCH: If you pass it a node index rather than a node handle, it works just fine... but the displayed identity number before the colon is different, which complicates comparing it with nodes printed the other way. We could always OR the DTM ID into the value, to suppress that distinction...
%REVIEW% This might want to be moved up to DTMDefaultBase, or possibly DTM itself, since it's a useful diagnostic and uses only DTM's public APIs.
public final int makeNodeHandle(int nodeIdentity)
This has been made FINAL to facilitate inlining, since we do not expect any subclass of DTMDefaultBase to ever change the algorithm. (I don't really like doing so, and would love to have an excuse not to...)
%REVIEW% Is it worth trying to specialcase small documents? %REVIEW% Should this be exposed at the package/public layers?
nodeIdentity - Internal offset to this node's records.public final int makeNodeIdentity(int nodeHandle)
This has been made FINAL to facilitate inlining, since we do not expect any subclass of DTMDefaultBase to ever change the algorithm. (I don't really like doing so, and would love to have an excuse not to...)
%OPT% Performance is critical for this operation.
%REVIEW% Should this be exposed at the package/public layers?
nodeHandle - (external representation of node)public int getFirstChild(int nodeHandle)
getFirstChild in interface DTMnodeHandle - int Handle of the node.public int getLastChild(int nodeHandle)
getLastChild in interface DTMnodeHandle - int Handle of the node.public abstract int getAttributeNode(int nodeHandle,
String namespaceURI,
String name)
%TBD% Note that we currently have no way to support the DOM's old getAttribute() call, which accesses only the qname.
getAttributeNode in interface DTMnodeHandle - Handle of the node upon which to look up this attribute.namespaceURI - The namespace URI of the attribute to retrieve, or null.name - The local name of the attribute to retrieve.nodeName) or
DTM.NULL if there is no such attribute.public int getFirstAttribute(int nodeHandle)
getFirstAttribute in interface DTMnodeHandle - int Handle of the node.protected int getFirstAttributeIdentity(int identity)
identity - int identity of the node.public int getNextSibling(int nodeHandle)
getNextSibling in interface DTMnodeHandle - int Handle of the node.public int getPreviousSibling(int nodeHandle)
getPreviousSibling in interface DTMnodeHandle - the id of the node.public int getNextAttribute(int nodeHandle)
getNextAttribute in interface DTMnodeHandle - int Handle of the node.protected int getNextAttributeIdentity(int identity)
identity - int identity of the attribute node. This must be an attribute
node.protected void declareNamespaceInContext(int elementNodeIndex,
int namespaceNodeIndex)
NOTE: Since this occurs during model build, nodes will be encountered in doucment order and thus the table will be ordered by element, permitting binary-search as a possible retrieval optimization.
%REVIEW% Directly managed arrays rather than vectors? %REVIEW% Handles or IDs? Given usage, I think handles.
protected SuballocatedIntVector findNamespaceContext(int elementNodeIndex)
%REVIEW% Directly managed arrays rather than vectors? %REVIEW% Handles or IDs? Given usage, I think handles.
protected int findInSortedSuballocatedIntVector(SuballocatedIntVector vector, int lookfor)
%REVIEW% Inlne this into findNamespaceContext? Create SortedSuballocatedIntVector type?
vector - the vectorlookfor - the lookforpublic int getFirstNamespaceNode(int nodeHandle,
boolean inScope)
getFirstNamespaceNode in interface DTMnodeHandle - handle to node, which should probably be an element node, but need not be.inScope - true if all namespaces in scope should be returned, false if only the node's own
namespace declarations should be returned.public int getNextNamespaceNode(int baseHandle,
int nodeHandle,
boolean inScope)
getNextNamespaceNode in interface DTMbaseHandle - handle to original node from where the first child was relative to (needed to
return nodes in document order).nodeHandle - handle to node which must be of type NAMESPACE_NODE. NEEDSDOC @param
inScopepublic int getParent(int nodeHandle)
public int getDocument()
getDocument in interface DTMpublic int getOwnerDocument(int nodeHandle)
getOwnerDocument in interface DTMnodeHandle - the id of the node.DTM.getDocumentRoot(int nodeHandle)public int getDocumentRoot(int nodeHandle)
getDocumentRoot in interface DTMnodeHandle - the id of the node.DTM.getOwnerDocument(int nodeHandle)public abstract XString getStringValue(int nodeHandle)
getStringValue in interface DTMnodeHandle - The node ID.public int getExpandedTypeID(int nodeHandle)
getExpandedTypeID in interface DTMnodeHandle - The handle to the node in question.public int getExpandedTypeID(String namespace, String localName, int type)
NEEDSDOC @param namespace NEEDSDOC @param localName NEEDSDOC @param type
getExpandedTypeID in interface DTMpublic abstract String getNodeName(int nodeHandle)
getNodeName in interface DTMnodeHandle - the id of the node.public String getNodeNameX(int nodeHandle)
getNodeNameX in interface DTMnodeHandle - the id of the node.public abstract String getLocalName(int nodeHandle)
getLocalName in interface DTMnodeHandle - the id of the node.public abstract String getPrefix(int nodeHandle)
%REVIEW% Are you sure you want "" for no prefix?
public abstract String getNamespaceURI(int nodeHandle)
getNamespaceURI in interface DTMnodeHandle - the id of the node.public abstract String getNodeValue(int nodeHandle)
getNodeValue in interface DTMnodeHandle - The node id.public short getNodeType(int nodeHandle)
%REVIEW% Generally, returning short is false economy. Return int?
getNodeType in interface DTMnodeHandle - The node id.public abstract int getElementById(String elementId)
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.
getElementById in interface DTMelementId - The unique id value for an element.public boolean isNodeAfter(int nodeHandle1,
int nodeHandle2)
There are some cases where ordering isn't defined, and neither are the results of this function -- though we'll generally return true.
%REVIEW% Make sure this does the right thing with attribute nodes!!!
%REVIEW% Consider renaming for clarity. Perhaps isDocumentOrder(a,b)?
isNodeAfter in interface DTMnodeHandle1 - DOM Node to perform position comparison on.nodeHandle2 - DOM Node to perform position comparison on.(firstNode.documentOrderPosition <= secondNode.documentOrderPosition)
.public Node getNode(int nodeHandle)
public DTMManager getManager()
%REVEW% Should this become part of the base DTM API?
Copyright © 2022–2025 HtmlUnit. All rights reserved.