dtmdefaultbasetraversers.java
来自「JAVA 所有包」· Java 代码 · 共 1,744 行 · 第 1/4 页
JAVA
1,744 行
{ // Compute in ID space int subtreeRootIdent = makeNodeIdentity(context ); for (current = makeNodeIdentity(current) - 1; current >= 0; current--) { short type = _type(current); if (ATTRIBUTE_NODE == type || NAMESPACE_NODE == type) continue; return makeNodeHandle(current); // make handle. } return NULL; } /** * 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) { // Compute in ID space int subtreeRootIdent = makeNodeIdentity(context); for (current = makeNodeIdentity(current) - 1; current >= 0; current--) { int exptype = m_exptype.elementAt(current); if (exptype != expandedTypeID) continue; return makeNodeHandle(current); // make handle. } return NULL; } } /** * Implements traversal of the Ancestor access, in reverse document order. */ private class PrecedingSiblingTraverser extends DTMAxisTraverser { /** * 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 getPreviousSibling(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) { while (DTM.NULL != (current = getPreviousSibling(current))) { if (getExpandedTypeID(current) == expandedTypeID) return current; } return NULL; } } /** * Implements traversal of the Self axis. */ private class SelfTraverser extends DTMAxisTraverser { /** * 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; } /** * 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. If the context * node does not match the expanded type ID, this function will return * false. * * @param context The context node of this traversal. * @param expandedTypeID The expanded type ID that must match. * * @return the first node in the traversal. */ public int first(int context, int expandedTypeID) { return (getExpandedTypeID(context) == expandedTypeID) ? context : 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 Always return NULL for this axis. */ public int next(int context, int current) { return NULL; } /** * 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) { return NULL; } } /** * Implements traversal of the Ancestor access, in reverse document order. */ private class AllFromRootTraverser extends AllFromNodeTraverser { /** * Return the root. * * @param context The context node of this traversal. * * @return the first node in the traversal. */ public int first(int context) { return getDocumentRoot(context); } /** * Return the root if it matches the expanded type ID. * * @param context The context node of this traversal. * @param expandedTypeID The expanded type ID that must match. * * @return the first node in the traversal. */ public int first(int context, int expandedTypeID) { return (getExpandedTypeID(getDocumentRoot(context)) == expandedTypeID) ? context : 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) { // Compute in ID space int subtreeRootIdent = makeNodeIdentity(context); for (current = makeNodeIdentity(current) + 1; ; current++) { // Kluge test: Just make sure +1 yielded a real node int type = _type(current); // may call nextNode() if (type == NULL) return NULL; 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) { // Compute in ID space int subtreeRootIdent = makeNodeIdentity(context); for (current = makeNodeIdentity(current) + 1; ; current++) { int exptype = _exptype(current); // may call nextNode() if (exptype == NULL) return NULL; if (exptype != expandedTypeID) continue; return makeNodeHandle(current); // make handle. } } } /** * Implements traversal of the Self axis. */ private class RootTraverser extends AllFromRootTraverser { /** * Return the root if it matches the expanded type ID, * else return null (nothing found) * * @param context The context node of this traversal. * @param expandedTypeID The expanded type ID that must match. * * @return the first node in the traversal. */ public int first(int context, int expandedTypeID) { int root=getDocumentRoot(context); return (getExpandedTypeID(root) == expandedTypeID) ? root : 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 Always return NULL for this axis. */ public int next(int context, int current) { return NULL; } /** * 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) { return NULL; } } /** * A non-xpath axis, returns all nodes that aren't namespaces or attributes, * from and including the root. */ private class DescendantOrSelfFromRootTraverser extends DescendantTraverser { /** * Get the first potential identity that can be returned, which is the axis * root context in this case. * * @param identity The node identity of the root context of the traversal. * * @return The identity argument. */ protected int getFirstPotential(int identity) { return identity; } /** * Get the first potential identity that can be returned. * @param handle handle to the root context. * @return identity of the root of the subtree. */ protected int getSubtreeRoot(int handle) { // %REVIEW% Shouldn't this always be 0? return makeNodeIdentity(getDocument()); } /** * Return the root. * * @param context The context node of this traversal. * * @return the first node in the traversal. */ public int first(int context) { return getDocumentRoot(context); } /** * 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 = 0; int firstPotential = getFirstPotential(identity); return makeNodeHandle(getNextIndexed(identity, firstPotential, expandedTypeID)); } int root = first(context); return next(root, root, expandedTypeID); } } /** * A non-xpath axis, returns all nodes that aren't namespaces or attributes, * from but not including the root. */ private class DescendantFromRootTraverser extends DescendantTraverser { /** * Get the first potential identity that can be returned, which is the axis * root context in this case. * * @param identity The node identity of the root context of the traversal. * * @return The identity argument. */ protected int getFirstPotential(int identity) { return _firstch(0); } /** * Get the first potential identity that can be returned. * @param handle handle to the root context. * @return identity of the root of the subtree. */ protected int getSubtreeRoot(int handle) { return 0; } /** * Return the root. * * @param context The context node of this traversal. * * @return the first node in the traversal. */ public int first(int context) { return makeNodeHandle(_firstch(0)); } /** * 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 = 0; int firstPotential = getFirstPotential(identity); return makeNodeHandle(getNextIndexed(identity, firstPotential, expandedTypeID)); } int root = getDocumentRoot(context); return next(root, root, expandedTypeID); } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?