1. /*
  2. * The Apache Software License, Version 1.1
  3. *
  4. *
  5. * Copyright (c) 1999 The Apache Software Foundation. All rights
  6. * reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. *
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in
  17. * the documentation and/or other materials provided with the
  18. * distribution.
  19. *
  20. * 3. The end-user documentation included with the redistribution,
  21. * if any, must include the following acknowledgment:
  22. * "This product includes software developed by the
  23. * Apache Software Foundation (http://www.apache.org/)."
  24. * Alternately, this acknowledgment may appear in the software itself,
  25. * if and wherever such third-party acknowledgments normally appear.
  26. *
  27. * 4. The names "Xalan" and "Apache Software Foundation" must
  28. * not be used to endorse or promote products derived from this
  29. * software without prior written permission. For written
  30. * permission, please contact apache@apache.org.
  31. *
  32. * 5. Products derived from this software may not be called "Apache",
  33. * nor may "Apache" appear in their name, without prior written
  34. * permission of the Apache Software Foundation.
  35. *
  36. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  37. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  38. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  39. * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  40. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  41. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  42. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  43. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  44. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  45. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  46. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  47. * SUCH DAMAGE.
  48. * ====================================================================
  49. *
  50. * This software consists of voluntary contributions made by many
  51. * individuals on behalf of the Apache Software Foundation and was
  52. * originally based on software copyright (c) 1999, Lotus
  53. * Development Corporation., http://www.lotus.com. For more
  54. * information on the Apache Software Foundation, please see
  55. * <http://www.apache.org/>.
  56. */
  57. package org.apache.xpath.axes;
  58. import javax.xml.transform.TransformerException;
  59. import org.apache.xpath.compiler.Compiler;
  60. import org.apache.xpath.patterns.NodeTest;
  61. import org.apache.xpath.XPathContext;
  62. import org.apache.xml.utils.PrefixResolver;
  63. //import org.w3c.dom.Node;
  64. //import org.w3c.dom.DOMException;
  65. import org.apache.xml.dtm.DTM;
  66. import org.apache.xml.dtm.DTMIterator;
  67. /**
  68. * <meta name="usage" content="advanced"/>
  69. * This class implements an optimized iterator for
  70. * "node()" patterns, that is, any children of the
  71. * context node.
  72. * @see org.apache.xpath.axes.WalkerFactory#newLocPathIterator
  73. */
  74. public class ChildIterator extends LocPathIterator
  75. {
  76. /**
  77. * Create a ChildIterator object.
  78. *
  79. * @param compiler A reference to the Compiler that contains the op map.
  80. * @param opPos The position within the op map, which contains the
  81. * location path expression for this itterator.
  82. * @param analysis Analysis bits of the entire pattern.
  83. *
  84. * @throws javax.xml.transform.TransformerException
  85. */
  86. ChildIterator(Compiler compiler, int opPos, int analysis)
  87. throws javax.xml.transform.TransformerException
  88. {
  89. super(compiler, opPos, analysis, false);
  90. }
  91. /**
  92. * Return the first node out of the nodeset, if this expression is
  93. * a nodeset expression. This is the default implementation for
  94. * nodesets.
  95. * <p>WARNING: Do not mutate this class from this function!</p>
  96. * @param xctxt The XPath runtime context.
  97. * @return the first node out of the nodeset, or DTM.NULL.
  98. */
  99. public int asNode(XPathContext xctxt)
  100. throws javax.xml.transform.TransformerException
  101. {
  102. int current = xctxt.getCurrentNode();
  103. DTM dtm = xctxt.getDTM(current);
  104. return dtm.getFirstChild(current);
  105. }
  106. /**
  107. * Returns the next node in the set and advances the position of the
  108. * iterator in the set. After a NodeIterator is created, the first call
  109. * to nextNode() returns the first node in the set.
  110. *
  111. * @return The next <code>Node</code> in the set being iterated over, or
  112. * <code>null</code> if there are no more members in that set.
  113. */
  114. public int nextNode()
  115. {
  116. if(m_foundLast)
  117. return DTM.NULL;
  118. int next;
  119. m_lastFetched = next = (DTM.NULL == m_lastFetched)
  120. ? m_cdtm.getFirstChild(m_context)
  121. : m_cdtm.getNextSibling(m_lastFetched);
  122. // m_lastFetched = next;
  123. if (DTM.NULL != next)
  124. {
  125. m_pos++;
  126. return next;
  127. }
  128. else
  129. {
  130. m_foundLast = true;
  131. return DTM.NULL;
  132. }
  133. }
  134. /**
  135. * Returns the axis being iterated, if it is known.
  136. *
  137. * @return Axis.CHILD, etc., or -1 if the axis is not known or is of multiple
  138. * types.
  139. */
  140. public int getAxis()
  141. {
  142. return org.apache.xml.dtm.Axis.CHILD;
  143. }
  144. }