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: ChildIterator.java,v 1.17 2004/08/17 19:25:34 jycli Exp $
018: */
019: package org.apache.xpath.axes;
020:
021: import org.apache.xml.dtm.DTM;
022: import org.apache.xml.dtm.DTMFilter;
023: import org.apache.xpath.XPathContext;
024: import org.apache.xpath.compiler.Compiler;
025:
026: /**
027: * This class implements an optimized iterator for
028: * "node()" patterns, that is, any children of the
029: * context node.
030: * @see org.apache.xpath.axes.LocPathIterator
031: * @xsl.usage advanced
032: */
033: public class ChildIterator extends LocPathIterator {
034: static final long serialVersionUID = -6935428015142993583L;
035:
036: /**
037: * Create a ChildIterator object.
038: *
039: * @param compiler A reference to the Compiler that contains the op map.
040: * @param opPos The position within the op map, which contains the
041: * location path expression for this itterator.
042: * @param analysis Analysis bits of the entire pattern.
043: *
044: * @throws javax.xml.transform.TransformerException
045: */
046: ChildIterator(Compiler compiler, int opPos, int analysis)
047: throws javax.xml.transform.TransformerException {
048: super (compiler, opPos, analysis, false);
049:
050: // This iterator matches all kinds of nodes
051: initNodeTest(DTMFilter.SHOW_ALL);
052: }
053:
054: /**
055: * Return the first node out of the nodeset, if this expression is
056: * a nodeset expression. This is the default implementation for
057: * nodesets.
058: * <p>WARNING: Do not mutate this class from this function!</p>
059: * @param xctxt The XPath runtime context.
060: * @return the first node out of the nodeset, or DTM.NULL.
061: */
062: public int asNode(XPathContext xctxt)
063: throws javax.xml.transform.TransformerException {
064: int current = xctxt.getCurrentNode();
065:
066: DTM dtm = xctxt.getDTM(current);
067:
068: return dtm.getFirstChild(current);
069: }
070:
071: /**
072: * Returns the next node in the set and advances the position of the
073: * iterator in the set. After a NodeIterator is created, the first call
074: * to nextNode() returns the first node in the set.
075: *
076: * @return The next <code>Node</code> in the set being iterated over, or
077: * <code>null</code> if there are no more members in that set.
078: */
079: public int nextNode() {
080: if (m_foundLast)
081: return DTM.NULL;
082:
083: int next;
084:
085: m_lastFetched = next = (DTM.NULL == m_lastFetched) ? m_cdtm
086: .getFirstChild(m_context) : m_cdtm
087: .getNextSibling(m_lastFetched);
088:
089: // m_lastFetched = next;
090: if (DTM.NULL != next) {
091: m_pos++;
092: return next;
093: } else {
094: m_foundLast = true;
095:
096: return DTM.NULL;
097: }
098: }
099:
100: /**
101: * Returns the axis being iterated, if it is known.
102: *
103: * @return Axis.CHILD, etc., or -1 if the axis is not known or is of multiple
104: * types.
105: */
106: public int getAxis() {
107: return org.apache.xml.dtm.Axis.CHILD;
108: }
109:
110: }
|