286N/A/*
286N/A * reserved comment block
286N/A * DO NOT REMOVE OR ALTER!
286N/A */
286N/A/*
286N/A * Copyright 1999-2004 The Apache Software Foundation.
286N/A *
286N/A * Licensed under the Apache License, Version 2.0 (the "License");
286N/A * you may not use this file except in compliance with the License.
286N/A * You may obtain a copy of the License at
286N/A *
286N/A * http://www.apache.org/licenses/LICENSE-2.0
286N/A *
286N/A * Unless required by applicable law or agreed to in writing, software
286N/A * distributed under the License is distributed on an "AS IS" BASIS,
286N/A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
286N/A * See the License for the specific language governing permissions and
286N/A * limitations under the License.
286N/A */
286N/A/*
286N/A * $Id: ChildIterator.java,v 1.2.4.2 2005/09/14 19:45:20 jeffsuttor Exp $
286N/A */
286N/Apackage com.sun.org.apache.xpath.internal.axes;
286N/A
286N/Aimport com.sun.org.apache.xml.internal.dtm.DTM;
286N/Aimport com.sun.org.apache.xml.internal.dtm.DTMFilter;
286N/Aimport com.sun.org.apache.xpath.internal.XPathContext;
286N/Aimport com.sun.org.apache.xpath.internal.compiler.Compiler;
286N/A
286N/A/**
286N/A * This class implements an optimized iterator for
286N/A * "node()" patterns, that is, any children of the
286N/A * context node.
286N/A * @see com.sun.org.apache.xpath.internal.axes.LocPathIterator
286N/A * @xsl.usage advanced
286N/A */
286N/Apublic class ChildIterator extends LocPathIterator
286N/A{
286N/A static final long serialVersionUID = -6935428015142993583L;
286N/A
286N/A /**
286N/A * Create a ChildIterator object.
286N/A *
286N/A * @param compiler A reference to the Compiler that contains the op map.
286N/A * @param opPos The position within the op map, which contains the
286N/A * location path expression for this itterator.
286N/A * @param analysis Analysis bits of the entire pattern.
286N/A *
286N/A * @throws javax.xml.transform.TransformerException
286N/A */
286N/A ChildIterator(Compiler compiler, int opPos, int analysis)
286N/A throws javax.xml.transform.TransformerException
286N/A {
286N/A super(compiler, opPos, analysis, false);
286N/A
286N/A // This iterator matches all kinds of nodes
286N/A initNodeTest(DTMFilter.SHOW_ALL);
286N/A }
286N/A
286N/A /**
286N/A * Return the first node out of the nodeset, if this expression is
286N/A * a nodeset expression. This is the default implementation for
286N/A * nodesets.
286N/A * <p>WARNING: Do not mutate this class from this function!</p>
286N/A * @param xctxt The XPath runtime context.
286N/A * @return the first node out of the nodeset, or DTM.NULL.
286N/A */
286N/A public int asNode(XPathContext xctxt)
286N/A throws javax.xml.transform.TransformerException
286N/A {
286N/A int current = xctxt.getCurrentNode();
286N/A
286N/A DTM dtm = xctxt.getDTM(current);
286N/A
286N/A return dtm.getFirstChild(current);
286N/A }
286N/A
286N/A /**
286N/A * Returns the next node in the set and advances the position of the
286N/A * iterator in the set. After a NodeIterator is created, the first call
286N/A * to nextNode() returns the first node in the set.
286N/A *
286N/A * @return The next <code>Node</code> in the set being iterated over, or
286N/A * <code>null</code> if there are no more members in that set.
286N/A */
286N/A public int nextNode()
286N/A {
286N/A if(m_foundLast)
286N/A return DTM.NULL;
286N/A
286N/A int next;
286N/A
286N/A m_lastFetched = next = (DTM.NULL == m_lastFetched)
286N/A ? m_cdtm.getFirstChild(m_context)
286N/A : m_cdtm.getNextSibling(m_lastFetched);
286N/A
286N/A // m_lastFetched = next;
286N/A if (DTM.NULL != next)
286N/A {
286N/A m_pos++;
286N/A return next;
286N/A }
286N/A else
286N/A {
286N/A m_foundLast = true;
286N/A
286N/A return DTM.NULL;
286N/A }
286N/A }
286N/A
286N/A /**
286N/A * Returns the axis being iterated, if it is known.
286N/A *
286N/A * @return Axis.CHILD, etc., or -1 if the axis is not known or is of multiple
286N/A * types.
286N/A */
286N/A public int getAxis()
286N/A {
286N/A return com.sun.org.apache.xml.internal.dtm.Axis.CHILD;
286N/A }
286N/A
286N/A
286N/A}