dtmdefaultbasetraversers.java
来自「JAVA 所有包」· Java 代码 · 共 1,744 行 · 第 1/4 页
JAVA
1,744 行
else { // %REVIEW% Dead code. Eliminate? for (int current = _firstch(makeNodeIdentity(context)); DTM.NULL != current; current = _nextsib(current)) { if (m_exptype.elementAt(current) == expandedTypeID) return makeNodeHandle(current); } return NULL; } } /** * Traverse to the next node after the current node. * * @param context The context node of this iteration. * @param current The current node of the iteration. * * @return the next node in the iteration, or DTM.NULL. */ public int next(int context, int current) { return getNextSibling(current); } /** * Traverse to the next node after the current node that is matched * by the expanded type ID. * * @param context The context node of this iteration. * @param current The current node of the iteration. * @param expandedTypeID The expanded type ID that must match. * * @return the next node in the iteration, or DTM.NULL. */ public int next(int context, int current, int expandedTypeID) { // Process in Identifier space for (current = _nextsib(makeNodeIdentity(current)); DTM.NULL != current; current = _nextsib(current)) { if (m_exptype.elementAt(current) == expandedTypeID) return makeNodeHandle(current); } return NULL; } } /** * Super class for derived classes that want a convenient way to access * the indexing mechanism. */ private abstract class IndexedDTMAxisTraverser extends DTMAxisTraverser { /** * Tell if the indexing is on and the given expanded type ID matches * what is in the indexes. Derived classes should call this before * calling {@link #getNextIndexed(int, int, int) getNextIndexed} method. * * @param expandedTypeID The expanded type ID being requested. * * @return true if it is OK to call the * {@link #getNextIndexed(int, int, int) getNextIndexed} method. */ protected final boolean isIndexed(int expandedTypeID) { return (m_indexing && ExpandedNameTable.ELEMENT == m_expandedNameTable.getType(expandedTypeID)); } /** * Tell if a node is outside the axis being traversed. This method must be * implemented by derived classes, and must be robust enough to handle any * node that occurs after the axis root. * * @param axisRoot The root identity of the axis. * @param identity The node in question. * * @return true if the given node falls outside the axis being traversed. */ protected abstract boolean isAfterAxis(int axisRoot, int identity); /** * Tell if the axis has been fully processed to tell if a the wait for * an arriving node should terminate. This method must be implemented * be a derived class. * * @param axisRoot The root identity of the axis. * * @return true if the axis has been fully processed. */ protected abstract boolean axisHasBeenProcessed(int axisRoot); /** * Get the next indexed node that matches the expanded type ID. Before * calling this function, one should first call * {@link #isIndexed(int) isIndexed} to make sure that the index can * contain nodes that match the given expanded type ID. * * @param axisRoot The root identity of the axis. * @param nextPotential The node found must match or occur after this node. * @param expandedTypeID The expanded type ID for the request. * * @return The node ID or NULL if not found. */ protected int getNextIndexed(int axisRoot, int nextPotential, int expandedTypeID) { int nsIndex = m_expandedNameTable.getNamespaceID(expandedTypeID); int lnIndex = m_expandedNameTable.getLocalNameID(expandedTypeID); while(true) { int next = findElementFromIndex(nsIndex, lnIndex, nextPotential); if (NOTPROCESSED != next) { if (isAfterAxis(axisRoot, next)) return NULL; // System.out.println("Found node via index: "+first); return next; } else if(axisHasBeenProcessed(axisRoot)) break; nextNode(); } return DTM.NULL; } } /** * Implements traversal of the Ancestor access, in reverse document order. */ private class DescendantTraverser extends IndexedDTMAxisTraverser { /** * Get the first potential identity that can be returned. This should * be overridded by classes that need to return the self node. * * @param identity The node identity of the root context of the traversal. * * @return The first potential node that can be in the traversal. */ protected int getFirstPotential(int identity) { return identity + 1; } /** * Tell if the axis has been fully processed to tell if a the wait for * an arriving node should terminate. * * @param axisRoot The root identity of the axis. * * @return true if the axis has been fully processed. */ protected boolean axisHasBeenProcessed(int axisRoot) { return !(m_nextsib.elementAt(axisRoot) == NOTPROCESSED); } /** * Get the subtree root identity from the handle that was passed in by * the caller. Derived classes may override this to change the root * context of the traversal. * * @param handle handle to the root context. * @return identity of the root of the subtree. */ protected int getSubtreeRoot(int handle) { return makeNodeIdentity(handle); } /** * Tell if this node identity is a descendant. Assumes that * the node info for the element has already been obtained. * * %REVIEW% This is really parentFollowsRootInDocumentOrder ... * which fails if the parent starts after the root ends. * May be sufficient for this class's logic, but misleadingly named! * * @param subtreeRootIdentity The root context of the subtree in question. * @param identity The index number of the node in question. * @return true if the index is a descendant of _startNode. */ protected boolean isDescendant(int subtreeRootIdentity, int identity) { return _parent(identity) >= subtreeRootIdentity; } /** * Tell if a node is outside the axis being traversed. This method must be * implemented by derived classes, and must be robust enough to handle any * node that occurs after the axis root. * * @param axisRoot The root identity of the axis. * @param identity The node in question. * * @return true if the given node falls outside the axis being traversed. */ protected boolean isAfterAxis(int axisRoot, int identity) { // %REVIEW% Is there *any* cheaper way to do this? // Yes. In ID space, compare to axisRoot's successor // (next-sib or ancestor's-next-sib). Probably shallower search. do { if(identity == axisRoot) return false; identity = m_parent.elementAt(identity); } while(identity >= axisRoot); return true; } /** * By the nature of the stateless traversal, the context node can not be * returned or the iteration will go into an infinate loop. So to traverse * an axis, the first function must be used to get the first node. * * <p>This method needs to be overloaded only by those axis that process * the self node. <\p> * * @param context The context node of this traversal. This is the point * of origin for the traversal -- its "root node" or starting point. * @param expandedTypeID The expanded type ID that must match. * * @return the first node in the traversal. */ public int first(int context, int expandedTypeID) { if (isIndexed(expandedTypeID)) { int identity = getSubtreeRoot(context); int firstPotential = getFirstPotential(identity); return makeNodeHandle(getNextIndexed(identity, firstPotential, expandedTypeID)); } return next(context, context, expandedTypeID); } /** * Traverse to the next node after the current node. * * @param context The context node of this iteration. * @param current The current node of the iteration. * * @return the next node in the iteration, or DTM.NULL. */ public int next(int context, int current) { int subtreeRootIdent = getSubtreeRoot(context); for (current = makeNodeIdentity(current) + 1; ; current++) { int type = _type(current); // may call nextNode() if (!isDescendant(subtreeRootIdent, current)) return NULL; if (ATTRIBUTE_NODE == type || NAMESPACE_NODE == type) continue; return makeNodeHandle(current); // make handle. } } /** * Traverse to the next node after the current node that is matched * by the expanded type ID. * * @param context The context node of this iteration. * @param current The current node of the iteration. * @param expandedTypeID The expanded type ID that must match. * * @return the next node in the iteration, or DTM.NULL. */ public int next(int context, int current, int expandedTypeID) { int subtreeRootIdent = getSubtreeRoot(context); current = makeNodeIdentity(current) + 1; if (isIndexed(expandedTypeID)) { return makeNodeHandle(getNextIndexed(subtreeRootIdent, current, expandedTypeID)); } for (; ; current++) { int exptype = _exptype(current); // may call nextNode() if (!isDescendant(subtreeRootIdent, current)) return NULL; if (exptype != expandedTypeID) continue; return makeNodeHandle(current); // make handle. } } } /** * Implements traversal of the Ancestor access, in reverse document order. */ private class DescendantOrSelfTraverser extends DescendantTraverser { /** * Get the first potential identity that can be returned, which is the * axis context, in this case. * * @param identity The node identity of the root context of the traversal. * * @return The axis context. */ protected int getFirstPotential(int identity) { return identity; } /** * By the nature of the stateless traversal, the context node can not be * returned or the iteration will go into an infinate loop. To see if * the self node should be processed, use this function. * * @param context The context node of this traversal. * * @return the first node in the traversal. */ public int first(int context) { return context; } } /** * Implements traversal of the entire subtree, including the root node. */ private class AllFromNodeTraverser extends DescendantOrSelfTraverser { /** * Traverse to the next node after the current node. * * @param context The context node of this iteration. * @param current The current node of the iteration. * * @return the next node in the iteration, or DTM.NULL. */ public int next(int context, int current) { int subtreeRootIdent = makeNodeIdentity(context); for (current = makeNodeIdentity(current) + 1; ; current++) { // Trickological code: _exptype() has the side-effect of // running nextNode until the specified node has been loaded, // and thus can be used to ensure that incremental construction of // the DTM has gotten this far. Using it just for that side-effect // is quite a kluge... _exptype(current); // make sure it's here. if (!isDescendant(subtreeRootIdent, current)) return NULL; return makeNodeHandle(current); // make handle. } } } /** * Implements traversal of the following access, in document order. */ private class FollowingTraverser extends DescendantTraverser { /** * Get the first of the following. * * @param context The context node of this traversal. This is the point * that the traversal starts from. * @return the first node in the traversal. */ public int first(int context) { // Compute in ID space context=makeNodeIdentity(context); int first; int type = _type(context); if ((DTM.ATTRIBUTE_NODE == type) || (DTM.NAMESPACE_NODE == type)) { context = _parent(context); first = _firstch(context); if (NULL != first) return makeNodeHandle(first); } do { first = _nextsib(context); if (NULL == first) context = _parent(context); } while (NULL == first && NULL != context); return makeNodeHandle(first); } /** * Get the first of the following. * * @param context The context node of this traversal. This is the point * of origin for the traversal -- its "root node" or starting point.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?