📄 axeswalker.java
字号:
return m_prevWalker; } /** * This is simply a way to bottle-neck the return of the next node, for * diagnostic purposes. * * @param n Node to return, or null. * * @return The argument. */ private int returnNextNode(int n) { return n; } /** * Get the next node in document order on the axes. * * @return the next node in document order on the axes, or null. */ protected int getNextNode() { if (m_foundLast) return DTM.NULL; if (m_isFresh) { m_currentNode = m_traverser.first(m_root); m_isFresh = false; } // I shouldn't have to do this the check for current node, I think. // numbering\numbering24.xsl fails if I don't do this. I think // it occurs as the walkers are backing up. -sb else if(DTM.NULL != m_currentNode) { m_currentNode = m_traverser.next(m_root, m_currentNode); } if (DTM.NULL == m_currentNode) this.m_foundLast = true; return m_currentNode; } /** * Moves the <code>TreeWalker</code> to the next visible node in document * order relative to the current node, and returns the new node. If the * current node has no next node, or if the search for nextNode attempts * to step upward from the TreeWalker's root node, returns * <code>null</code> , and retains the current node. * @return The new node, or <code>null</code> if the current node has no * next node in the TreeWalker's logical view. */ public int nextNode() { int nextNode = DTM.NULL; AxesWalker walker = wi().getLastUsedWalker(); while (true) { if (null == walker) break; nextNode = walker.getNextNode(); if (DTM.NULL == nextNode) { walker = walker.m_prevWalker; } else { if (walker.acceptNode(nextNode) != DTMIterator.FILTER_ACCEPT) { continue; } if (null == walker.m_nextWalker) { wi().setLastUsedWalker(walker); // return walker.returnNextNode(nextNode); break; } else { AxesWalker prev = walker; walker = walker.m_nextWalker; walker.setRoot(nextNode); walker.m_prevWalker = prev; continue; } } // if(null != nextNode) } // while(null != walker) return nextNode; } //============= End TreeWalker Implementation ============= /** * Get the index of the last node that can be itterated to. * * * @param xctxt XPath runtime context. * * @return the index of the last node that can be itterated to. */ public int getLastPos(XPathContext xctxt) { int pos = getProximityPosition(); AxesWalker walker; try { walker = (AxesWalker) clone(); } catch (CloneNotSupportedException cnse) { return -1; } walker.setPredicateCount(walker.getPredicateCount() - 1); walker.setNextWalker(null); walker.setPrevWalker(null); WalkingIterator lpi = wi(); AxesWalker savedWalker = lpi.getLastUsedWalker(); try { lpi.setLastUsedWalker(walker); int next; while (DTM.NULL != (next = walker.nextNode())) { pos++; } // TODO: Should probably save this in the iterator. } finally { lpi.setLastUsedWalker(savedWalker); } // System.out.println("pos: "+pos); return pos; } //============= State Data ============= /** * The DTM for the root. This can not be used, or must be changed, * for the filter walker, or any walker that can have nodes * from multiple documents. * Never, ever, access this value without going through getDTM(int node). */ private DTM m_dtm; /** * Set the DTM for this walker. * * @param dtm Non-null reference to a DTM. */ public void setDefaultDTM(DTM dtm) { m_dtm = dtm; } /** * Get the DTM for this walker. * * @return Non-null reference to a DTM. */ public DTM getDTM(int node) { // return wi().getXPathContext().getDTM(node); } /** * Returns true if all the nodes in the iteration well be returned in document * order. * Warning: This can only be called after setRoot has been called! * * @return true as a default. */ public boolean isDocOrdered() { return true; } /** * Returns the axis being iterated, if it is known. * * @return Axis.CHILD, etc., or -1 if the axis is not known or is of multiple * types. */ public int getAxis() { return m_axis; } /** * This will traverse the heararchy, calling the visitor for * each member. If the called visitor method returns * false, the subtree should not be called. * * @param owner The owner of the visitor, where that path may be * rewritten if needed. * @param visitor The visitor whose appropriate method will be called. */ public void callVisitors(ExpressionOwner owner, XPathVisitor visitor) { if(visitor.visitStep(owner, this)) { callPredicateVisitors(visitor); if(null != m_nextWalker) { m_nextWalker.callVisitors(this, visitor); } } } /** * @see ExpressionOwner#getExpression() */ public Expression getExpression() { return m_nextWalker; } /** * @see ExpressionOwner#setExpression(Expression) */ public void setExpression(Expression exp) { exp.exprSetParent(this); m_nextWalker = (AxesWalker)exp; } /** * @see Expression#deepEquals(Expression) */ public boolean deepEquals(Expression expr) { if (!super.deepEquals(expr)) return false; AxesWalker walker = (AxesWalker)expr; if(this.m_axis != walker.m_axis) return false; return true; } /** * The root node of the TreeWalker, as specified when it was created. */ transient int m_root = DTM.NULL; /** * The node at which the TreeWalker is currently positioned. */ private transient int m_currentNode = DTM.NULL; /** True if an itteration has not begun. */ transient boolean m_isFresh; /** The next walker in the location step chain. * @serial */ protected AxesWalker m_nextWalker; /** The previous walker in the location step chain, or null. * @serial */ AxesWalker m_prevWalker; /** The traversal axis from where the nodes will be filtered. */ protected int m_axis = -1; /** The DTM inner traversal class, that corresponds to the super axis. */ protected DTMAxisTraverser m_traverser; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -