dtmdefaultbasetraversers.java

来自「JAVA 所有包」· Java 代码 · 共 1,744 行 · 第 1/4 页

JAVA
1,744
字号
     * @param expandedTypeID The expanded type ID that must match.     *     * @return the first node in the traversal.     */    public int first(int context, int expandedTypeID)    {			// %REVIEW% This looks like it might want shift into identity space			// to avoid repeated conversion in the individual functions      int first;      int type = getNodeType(context);      if ((DTM.ATTRIBUTE_NODE == type) || (DTM.NAMESPACE_NODE == type))      {        context = getParent(context);        first = getFirstChild(context);        if (NULL != first)        {          if (getExpandedTypeID(first) == expandedTypeID)            return first;          else            return next(context, first, expandedTypeID);        }      }      do      {        first = getNextSibling(context);        if (NULL == first)          context = getParent(context);        else        {          if (getExpandedTypeID(first) == expandedTypeID)            return first;          else            return next(context, first, expandedTypeID);        }      }      while (NULL == first && NULL != context);      return first;    }    /**     * 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 identity space			current=makeNodeIdentity(current);      while (true)      {        current++; // Only works on IDs, not handles.				// %REVIEW% Are we using handles or indexes?        int type = _type(current);  // may call nextNode()        if (NULL == type)          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)    {			// Compute in ID space			current=makeNodeIdentity(current);      while (true)      {        current++;        int etype = _exptype(current);  // may call nextNode()        if (NULL == etype)          return NULL;        if (etype != expandedTypeID)          continue;        return makeNodeHandle(current);  // make handle.      }    }  }  /**   * Implements traversal of the Ancestor access, in reverse document order.   */  private class FollowingSiblingTraverser 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 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)    {      while (DTM.NULL != (current = getNextSibling(current)))      {        if (getExpandedTypeID(current) == expandedTypeID)          return current;      }      return NULL;    }  }  /**   * Implements traversal of the Ancestor access, in reverse document order.   */  private class NamespaceDeclsTraverser 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 (context == current)             ? getFirstNamespaceNode(context, false)             : getNextNamespaceNode(context, current, false);    }    /**     * 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)    {      current = (context == current)                ? getFirstNamespaceNode(context, false)                : getNextNamespaceNode(context, current, false);      do      {        if (getExpandedTypeID(current) == expandedTypeID)          return current;      }      while (DTM.NULL             != (current = getNextNamespaceNode(context, current, false)));      return NULL;    }  }  /**   * Implements traversal of the Ancestor access, in reverse document order.   */  private class NamespaceTraverser 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 (context == current)             ? getFirstNamespaceNode(context, true)             : getNextNamespaceNode(context, current, true);    }    /**     * 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)    {      current = (context == current)                ? getFirstNamespaceNode(context, true)                : getNextNamespaceNode(context, current, true);      do      {        if (getExpandedTypeID(current) == expandedTypeID)          return current;      }      while (DTM.NULL             != (current = getNextNamespaceNode(context, current, true)));      return NULL;    }  }  /**   * Implements traversal of the Ancestor access, in reverse document order.   */  private class ParentTraverser 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.  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     * that the traversal starts from.     * @return the first node in the traversal.     */    public int first(int context)    {      return getParent(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 current, int expandedTypeID)    {			// Compute in ID space      current = makeNodeIdentity(current);      while (NULL != (current = m_parent.elementAt(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 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 PrecedingTraverser extends DTMAxisTraverser  {    /**     * Tell if the current identity is an ancestor of the context identity.     * This is an expensive operation, made worse by the stateless traversal.     * But the preceding axis is used fairly infrequently.     *     * @param contextIdent The context node of the axis traversal.     * @param currentIdent The node in question.     * @return true if the currentIdent node is an ancestor of contextIdent.     */    protected boolean isAncestor(int contextIdent, int currentIdent)    {			// %REVIEW% See comments in IsAfterAxis; using the "successor" of			// contextIdent is probably more efficient.      for (contextIdent = m_parent.elementAt(contextIdent); DTM.NULL != contextIdent;              contextIdent = m_parent.elementAt(contextIdent))      {        if (contextIdent == currentIdent)          return true;      }      return false;    }    /**     * 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 >= 0; current--)      {        short type = _type(current);        if (ATTRIBUTE_NODE == type || NAMESPACE_NODE == type                || isAncestor(subtreeRootIdent, current))          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                || isAncestor(subtreeRootIdent, current))          continue;        return makeNodeHandle(current);  // make handle.      }      return NULL;    }  }  /**   * Implements traversal of the Ancestor and the Preceding axis,   * in reverse document order.   */  private class PrecedingAndAncestorTraverser 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)

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?