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