1. /*
  2. * Copyright 1999-2004 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /*
  17. * $Id: DTMAxisTraverser.java,v 1.4 2004/02/16 23:03:44 minchau Exp $
  18. */
  19. package com.sun.org.apache.xml.internal.dtm;
  20. /**
  21. * A class that implements traverses DTMAxisTraverser interface can traverse
  22. * a set of nodes, usually as defined by an XPath axis. It is different from
  23. * an iterator, because it does not need to hold state, and, in fact, must not
  24. * hold any iteration-based state. It is meant to be implemented as an inner
  25. * class of a DTM, and returned by the getAxisTraverser(final int axis)
  26. * function.
  27. *
  28. * <p>A DTMAxisTraverser can probably not traverse a reverse axis in
  29. * document order.</p>
  30. *
  31. * <p>Typical usage:</p>
  32. * <pre><code>
  33. * for(int nodeHandle=myTraverser.first(myContext);
  34. * nodeHandle!=DTM.NULL;
  35. * nodeHandle=myTraverser.next(myContext,nodeHandle))
  36. * { ... processing for node indicated by nodeHandle goes here ... }
  37. * </code></pre>
  38. *
  39. * @author Scott Boag
  40. */
  41. public abstract class DTMAxisTraverser
  42. {
  43. /**
  44. * By the nature of the stateless traversal, the context node can not be
  45. * returned or the iteration will go into an infinate loop. So to traverse
  46. * an axis, the first function must be used to get the first node.
  47. *
  48. * <p>This method needs to be overloaded only by those axis that process
  49. * the self node. <\p>
  50. *
  51. * @param context The context node of this traversal. This is the point
  52. * that the traversal starts from.
  53. * @return the first node in the traversal.
  54. */
  55. public int first(int context)
  56. {
  57. return next(context, context);
  58. }
  59. /**
  60. * By the nature of the stateless traversal, the context node can not be
  61. * returned or the iteration will go into an infinate loop. So to traverse
  62. * an axis, the first function must be used to get the first node.
  63. *
  64. * <p>This method needs to be overloaded only by those axis that process
  65. * the self node. <\p>
  66. *
  67. * @param context The context node of this traversal. This is the point
  68. * of origin for the traversal -- its "root node" or starting point.
  69. * @param extendedTypeID The extended type ID that must match.
  70. *
  71. * @return the first node in the traversal.
  72. */
  73. public int first(int context, int extendedTypeID)
  74. {
  75. return next(context, context, extendedTypeID);
  76. }
  77. /**
  78. * Traverse to the next node after the current node.
  79. *
  80. * @param context The context node of this traversal. This is the point
  81. * of origin for the traversal -- its "root node" or starting point.
  82. * @param current The current node of the traversal. This is the last known
  83. * location in the traversal, typically the node-handle returned by the
  84. * previous traversal step. For the first traversal step, context
  85. * should be set equal to current. Note that in order to test whether
  86. * context is in the set, you must use the first() method instead.
  87. *
  88. * @return the next node in the iteration, or DTM.NULL.
  89. * @see first(int)
  90. */
  91. public abstract int next(int context, int current);
  92. /**
  93. * Traverse to the next node after the current node that is matched
  94. * by the extended type ID.
  95. *
  96. * @param context The context node of this traversal. This is the point
  97. * of origin for the traversal -- its "root node" or starting point.
  98. * @param current The current node of the traversal. This is the last known
  99. * location in the traversal, typically the node-handle returned by the
  100. * previous traversal step. For the first traversal step, context
  101. * should be set equal to current. Note that in order to test whether
  102. * context is in the set, you must use the first() method instead.
  103. * @param extendedTypeID The extended type ID that must match.
  104. *
  105. * @return the next node in the iteration, or DTM.NULL.
  106. * @see first(int,int)
  107. */
  108. public abstract int next(int context, int current, int extendedTypeID);
  109. }