001: /*
002: * Copyright 1999-2004 The Apache Software Foundation.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: /*
017: * $Id: ChildTestIterator.java,v 1.22 2005/01/23 01:02:10 mcnamara Exp $
018: */
019: package org.apache.xpath.axes;
020:
021: import org.apache.xml.dtm.Axis;
022: import org.apache.xml.dtm.DTM;
023: import org.apache.xml.dtm.DTMAxisTraverser;
024: import org.apache.xml.dtm.DTMIterator;
025: import org.apache.xpath.compiler.Compiler;
026:
027: /**
028: * This class implements an optimized iterator for
029: * children patterns that have a node test, and possibly a predicate.
030: * @see org.apache.xpath.axes.BasicTestIterator
031: * @xsl.usage advanced
032: */
033: public class ChildTestIterator extends BasicTestIterator {
034: static final long serialVersionUID = -7936835957960705722L;
035: /** The traverser to use to navigate over the descendants. */
036: transient protected DTMAxisTraverser m_traverser;
037:
038: /** The extended type ID, not set until setRoot. */
039: // protected int m_extendedTypeID;
040:
041: /**
042: * Create a ChildTestIterator object.
043: *
044: * @param compiler A reference to the Compiler that contains the op map.
045: * @param opPos The position within the op map, which contains the
046: * location path expression for this itterator.
047: *
048: * @throws javax.xml.transform.TransformerException
049: */
050: ChildTestIterator(Compiler compiler, int opPos, int analysis)
051: throws javax.xml.transform.TransformerException {
052: super (compiler, opPos, analysis);
053: }
054:
055: /**
056: * Create a ChildTestIterator object.
057: *
058: * @param traverser Traverser that tells how the KeyIterator is to be handled.
059: *
060: * @throws javax.xml.transform.TransformerException
061: */
062: public ChildTestIterator(DTMAxisTraverser traverser) {
063:
064: super (null);
065:
066: m_traverser = traverser;
067: }
068:
069: /**
070: * Get the next node via getNextXXX. Bottlenecked for derived class override.
071: * @return The next node on the axis, or DTM.NULL.
072: */
073: protected int getNextNode() {
074: if (true /* 0 == m_extendedTypeID */) {
075: m_lastFetched = (DTM.NULL == m_lastFetched) ? m_traverser
076: .first(m_context) : m_traverser.next(m_context,
077: m_lastFetched);
078: }
079: // else
080: // {
081: // m_lastFetched = (DTM.NULL == m_lastFetched)
082: // ? m_traverser.first(m_context, m_extendedTypeID)
083: // : m_traverser.next(m_context, m_lastFetched,
084: // m_extendedTypeID);
085: // }
086:
087: return m_lastFetched;
088: }
089:
090: /**
091: * Get a cloned Iterator that is reset to the beginning
092: * of the query.
093: *
094: * @return A cloned NodeIterator set of the start of the query.
095: *
096: * @throws CloneNotSupportedException
097: */
098: public DTMIterator cloneWithReset()
099: throws CloneNotSupportedException {
100:
101: ChildTestIterator clone = (ChildTestIterator) super
102: .cloneWithReset();
103: clone.m_traverser = m_traverser;
104:
105: return clone;
106: }
107:
108: /**
109: * Initialize the context values for this expression
110: * after it is cloned.
111: *
112: * @param context The XPath runtime context for this
113: * transformation.
114: */
115: public void setRoot(int context, Object environment) {
116: super .setRoot(context, environment);
117: m_traverser = m_cdtm.getAxisTraverser(Axis.CHILD);
118:
119: // String localName = getLocalName();
120: // String namespace = getNamespace();
121: // int what = m_whatToShow;
122: // // System.out.println("what: ");
123: // // NodeTest.debugWhatToShow(what);
124: // if(DTMFilter.SHOW_ALL == what ||
125: // ((DTMFilter.SHOW_ELEMENT & what) == 0)
126: // || localName == NodeTest.WILD
127: // || namespace == NodeTest.WILD)
128: // {
129: // m_extendedTypeID = 0;
130: // }
131: // else
132: // {
133: // int type = getNodeTypeTest(what);
134: // m_extendedTypeID = m_cdtm.getExpandedTypeID(namespace, localName, type);
135: // }
136:
137: }
138:
139: /**
140: * Returns the axis being iterated, if it is known.
141: *
142: * @return Axis.CHILD, etc., or -1 if the axis is not known or is of multiple
143: * types.
144: */
145: public int getAxis() {
146: return org.apache.xml.dtm.Axis.CHILD;
147: }
148:
149: /**
150: * Detaches the iterator from the set which it iterated over, releasing
151: * any computational resources and placing the iterator in the INVALID
152: * state. After<code>detach</code> has been invoked, calls to
153: * <code>nextNode</code> or<code>previousNode</code> will raise the
154: * exception INVALID_STATE_ERR.
155: */
156: public void detach() {
157: if (m_allowDetach) {
158: m_traverser = null;
159:
160: // Always call the superclass detach last!
161: super.detach();
162: }
163: }
164:
165: }
|