1. package org.apache.xpath.axes;
  2. import javax.xml.transform.TransformerException;
  3. import org.apache.xpath.compiler.Compiler;
  4. import org.apache.xpath.patterns.NodeTest;
  5. import org.apache.xpath.XPathContext;
  6. import org.apache.xml.utils.PrefixResolver;
  7. //import org.w3c.dom.Node;
  8. //import org.w3c.dom.DOMException;
  9. import org.apache.xml.dtm.DTM;
  10. /**
  11. * <meta name="usage" content="advanced"/>
  12. * This class implements an optimized iterator for
  13. * "." patterns, that is, the self axes without any predicates.
  14. * @see org.apache.xpath.axes.WalkerFactory#newLocPathIterator
  15. */
  16. public class SelfIteratorNoPredicate extends LocPathIterator
  17. {
  18. /**
  19. * Create a SelfIteratorNoPredicate object.
  20. *
  21. * @param compiler A reference to the Compiler that contains the op map.
  22. * @param opPos The position within the op map, which contains the
  23. * location path expression for this itterator.
  24. * @param analysis Analysis bits.
  25. *
  26. * @throws javax.xml.transform.TransformerException
  27. */
  28. SelfIteratorNoPredicate(Compiler compiler, int opPos, int analysis)
  29. throws javax.xml.transform.TransformerException
  30. {
  31. super(compiler, opPos, analysis, false);
  32. }
  33. /**
  34. * Create a SelfIteratorNoPredicate object.
  35. *
  36. * @param compiler A reference to the Compiler that contains the op map.
  37. * @param opPos The position within the op map, which contains the
  38. * location path expression for this itterator.
  39. * @param analysis Analysis bits.
  40. *
  41. * @throws javax.xml.transform.TransformerException
  42. */
  43. public SelfIteratorNoPredicate()
  44. throws javax.xml.transform.TransformerException
  45. {
  46. super(null);
  47. }
  48. /**
  49. * Returns the next node in the set and advances the position of the
  50. * iterator in the set. After a NodeIterator is created, the first call
  51. * to nextNode() returns the first node in the set.
  52. *
  53. * @return The next <code>Node</code> in the set being iterated over, or
  54. * <code>null</code> if there are no more members in that set.
  55. */
  56. public int nextNode()
  57. {
  58. if (m_foundLast)
  59. return DTM.NULL;
  60. int next;
  61. DTM dtm = m_cdtm;
  62. m_lastFetched = next = (DTM.NULL == m_lastFetched)
  63. ? m_context
  64. : DTM.NULL;
  65. // m_lastFetched = next;
  66. if (DTM.NULL != next)
  67. {
  68. m_pos++;
  69. return next;
  70. }
  71. else
  72. {
  73. m_foundLast = true;
  74. return DTM.NULL;
  75. }
  76. }
  77. /**
  78. * Return the first node out of the nodeset, if this expression is
  79. * a nodeset expression. This is the default implementation for
  80. * nodesets. Derived classes should try and override this and return a
  81. * value without having to do a clone operation.
  82. * @param xctxt The XPath runtime context.
  83. * @return the first node out of the nodeset, or DTM.NULL.
  84. */
  85. public int asNode(XPathContext xctxt)
  86. throws javax.xml.transform.TransformerException
  87. {
  88. return xctxt.getCurrentNode();
  89. }
  90. /**
  91. * Get the index of the last node that can be itterated to.
  92. * This probably will need to be overridded by derived classes.
  93. *
  94. * @param xctxt XPath runtime context.
  95. *
  96. * @return the index of the last node that can be itterated to.
  97. */
  98. public int getLastPos(XPathContext xctxt)
  99. {
  100. return 1;
  101. }
  102. }