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: ChildIterator.java,v 1.15 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. * "node()" patterns, that is, any children of the
  26. * context node.
  27. * @see com.sun.org.apache.xpath.internal.axes.LocPathIterator
  28. * @xsl.usage advanced
  29. */
  30. public class ChildIterator extends LocPathIterator
  31. {
  32. /**
  33. * Create a ChildIterator object.
  34. *
  35. * @param compiler A reference to the Compiler that contains the op map.
  36. * @param opPos The position within the op map, which contains the
  37. * location path expression for this itterator.
  38. * @param analysis Analysis bits of the entire pattern.
  39. *
  40. * @throws javax.xml.transform.TransformerException
  41. */
  42. ChildIterator(Compiler compiler, int opPos, int analysis)
  43. throws javax.xml.transform.TransformerException
  44. {
  45. super(compiler, opPos, analysis, false);
  46. }
  47. /**
  48. * Return the first node out of the nodeset, if this expression is
  49. * a nodeset expression. This is the default implementation for
  50. * nodesets.
  51. * <p>WARNING: Do not mutate this class from this function!</p>
  52. * @param xctxt The XPath runtime context.
  53. * @return the first node out of the nodeset, or DTM.NULL.
  54. */
  55. public int asNode(XPathContext xctxt)
  56. throws javax.xml.transform.TransformerException
  57. {
  58. int current = xctxt.getCurrentNode();
  59. DTM dtm = xctxt.getDTM(current);
  60. return dtm.getFirstChild(current);
  61. }
  62. /**
  63. * Returns the next node in the set and advances the position of the
  64. * iterator in the set. After a NodeIterator is created, the first call
  65. * to nextNode() returns the first node in the set.
  66. *
  67. * @return The next <code>Node</code> in the set being iterated over, or
  68. * <code>null</code> if there are no more members in that set.
  69. */
  70. public int nextNode()
  71. {
  72. if(m_foundLast)
  73. return DTM.NULL;
  74. int next;
  75. m_lastFetched = next = (DTM.NULL == m_lastFetched)
  76. ? m_cdtm.getFirstChild(m_context)
  77. : m_cdtm.getNextSibling(m_lastFetched);
  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. * Returns the axis being iterated, if it is known.
  92. *
  93. * @return Axis.CHILD, etc., or -1 if the axis is not known or is of multiple
  94. * types.
  95. */
  96. public int getAxis()
  97. {
  98. return com.sun.org.apache.xml.internal.dtm.Axis.CHILD;
  99. }
  100. }