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: ChildTestIterator.java,v 1.20 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.Axis;
  21. import com.sun.org.apache.xml.internal.dtm.DTM;
  22. import com.sun.org.apache.xml.internal.dtm.DTMAxisTraverser;
  23. import com.sun.org.apache.xml.internal.dtm.DTMIterator;
  24. import com.sun.org.apache.xpath.internal.compiler.Compiler;
  25. /**
  26. * This class implements an optimized iterator for
  27. * children patterns that have a node test, and possibly a predicate.
  28. * @see com.sun.org.apache.xpath.internal.axes.BasicTestIterator
  29. * @xsl.usage advanced
  30. */
  31. public class ChildTestIterator extends BasicTestIterator
  32. {
  33. /** The traverser to use to navigate over the descendants. */
  34. transient protected DTMAxisTraverser m_traverser;
  35. /** The extended type ID, not set until setRoot. */
  36. // protected int m_extendedTypeID;
  37. /**
  38. * Create a ChildTestIterator object.
  39. *
  40. * @param compiler A reference to the Compiler that contains the op map.
  41. * @param opPos The position within the op map, which contains the
  42. * location path expression for this itterator.
  43. *
  44. * @throws javax.xml.transform.TransformerException
  45. */
  46. ChildTestIterator(Compiler compiler, int opPos, int analysis)
  47. throws javax.xml.transform.TransformerException
  48. {
  49. super(compiler, opPos, analysis);
  50. }
  51. /**
  52. * Create a ChildTestIterator object.
  53. *
  54. * @param traverser Traverser that tells how the KeyIterator is to be handled.
  55. *
  56. * @throws javax.xml.transform.TransformerException
  57. */
  58. public ChildTestIterator(DTMAxisTraverser traverser)
  59. {
  60. super(null);
  61. m_traverser = traverser;
  62. }
  63. /**
  64. * Get the next node via getNextXXX. Bottlenecked for derived class override.
  65. * @return The next node on the axis, or DTM.NULL.
  66. */
  67. protected int getNextNode()
  68. {
  69. if(true /* 0 == m_extendedTypeID */)
  70. {
  71. m_lastFetched = (DTM.NULL == m_lastFetched)
  72. ? m_traverser.first(m_context)
  73. : m_traverser.next(m_context, m_lastFetched);
  74. }
  75. // else
  76. // {
  77. // m_lastFetched = (DTM.NULL == m_lastFetched)
  78. // ? m_traverser.first(m_context, m_extendedTypeID)
  79. // : m_traverser.next(m_context, m_lastFetched,
  80. // m_extendedTypeID);
  81. // }
  82. return m_lastFetched;
  83. }
  84. /**
  85. * Get a cloned Iterator that is reset to the beginning
  86. * of the query.
  87. *
  88. * @return A cloned NodeIterator set of the start of the query.
  89. *
  90. * @throws CloneNotSupportedException
  91. */
  92. public DTMIterator cloneWithReset() throws CloneNotSupportedException
  93. {
  94. ChildTestIterator clone = (ChildTestIterator) super.cloneWithReset();
  95. clone.m_traverser = m_traverser;
  96. return clone;
  97. }
  98. /**
  99. * Initialize the context values for this expression
  100. * after it is cloned.
  101. *
  102. * @param execContext The XPath runtime context for this
  103. * transformation.
  104. */
  105. public void setRoot(int context, Object environment)
  106. {
  107. super.setRoot(context, environment);
  108. m_traverser = m_cdtm.getAxisTraverser(Axis.CHILD);
  109. // String localName = getLocalName();
  110. // String namespace = getNamespace();
  111. // int what = m_whatToShow;
  112. // // System.out.println("what: ");
  113. // // NodeTest.debugWhatToShow(what);
  114. // if(DTMFilter.SHOW_ALL == what ||
  115. // ((DTMFilter.SHOW_ELEMENT & what) == 0)
  116. // || localName == NodeTest.WILD
  117. // || namespace == NodeTest.WILD)
  118. // {
  119. // m_extendedTypeID = 0;
  120. // }
  121. // else
  122. // {
  123. // int type = getNodeTypeTest(what);
  124. // m_extendedTypeID = m_cdtm.getExpandedTypeID(namespace, localName, type);
  125. // }
  126. }
  127. /**
  128. * Returns the axis being iterated, if it is known.
  129. *
  130. * @return Axis.CHILD, etc., or -1 if the axis is not known or is of multiple
  131. * types.
  132. */
  133. public int getAxis()
  134. {
  135. return com.sun.org.apache.xml.internal.dtm.Axis.CHILD;
  136. }
  137. /**
  138. * Detaches the iterator from the set which it iterated over, releasing
  139. * any computational resources and placing the iterator in the INVALID
  140. * state. After<code>detach</code> has been invoked, calls to
  141. * <code>nextNode</code> or<code>previousNode</code> will raise the
  142. * exception INVALID_STATE_ERR.
  143. */
  144. public void detach()
  145. {
  146. if(m_allowDetach)
  147. {
  148. m_traverser = null;
  149. // Always call the superclass detach last!
  150. super.detach();
  151. }
  152. }
  153. }