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: BasicTestIterator.java,v 1.2.4.1 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.xml.internal.dtm.DTMIterator;
286N/Aimport com.sun.org.apache.xml.internal.utils.PrefixResolver;
286N/Aimport com.sun.org.apache.xpath.internal.compiler.Compiler;
293N/Aimport com.sun.org.apache.xpath.internal.compiler.OpMap;
286N/A
286N/A/**
286N/A * Base for iterators that handle predicates. Does the basic next
286N/A * node logic, so all the derived iterator has to do is get the
286N/A * next node.
286N/A */
286N/Apublic abstract class BasicTestIterator extends LocPathIterator
286N/A{
286N/A static final long serialVersionUID = 3505378079378096623L;
286N/A /**
286N/A * Create a LocPathIterator object.
286N/A *
286N/A * @param nscontext The namespace context for this iterator,
286N/A * should be OK if null.
286N/A */
286N/A protected BasicTestIterator()
286N/A {
286N/A }
286N/A
286N/A
286N/A /**
286N/A * Create a LocPathIterator object.
286N/A *
286N/A * @param nscontext The namespace context for this iterator,
286N/A * should be OK if null.
286N/A */
286N/A protected BasicTestIterator(PrefixResolver nscontext)
286N/A {
286N/A
286N/A super(nscontext);
286N/A }
286N/A
286N/A /**
286N/A * Create a LocPathIterator object, including creation
286N/A * of step walkers from the opcode list, and call back
286N/A * into the Compiler to create predicate expressions.
286N/A *
286N/A * @param compiler The Compiler which is creating
286N/A * this expression.
286N/A * @param opPos The position of this iterator in the
286N/A * opcode list from the compiler.
286N/A *
286N/A * @throws javax.xml.transform.TransformerException
286N/A */
286N/A protected BasicTestIterator(Compiler compiler, int opPos, int analysis)
286N/A throws javax.xml.transform.TransformerException
286N/A {
286N/A super(compiler, opPos, analysis, false);
286N/A
293N/A int firstStepPos = OpMap.getFirstChildPos(opPos);
286N/A int whatToShow = compiler.getWhatToShow(firstStepPos);
286N/A
286N/A if ((0 == (whatToShow
286N/A & (DTMFilter.SHOW_ATTRIBUTE
286N/A | DTMFilter.SHOW_NAMESPACE
286N/A | DTMFilter.SHOW_ELEMENT
286N/A | DTMFilter.SHOW_PROCESSING_INSTRUCTION)))
286N/A || (whatToShow == DTMFilter.SHOW_ALL))
286N/A initNodeTest(whatToShow);
286N/A else
286N/A {
286N/A initNodeTest(whatToShow, compiler.getStepNS(firstStepPos),
286N/A compiler.getStepLocalName(firstStepPos));
286N/A }
286N/A initPredicateInfo(compiler, firstStepPos);
286N/A }
286N/A
286N/A /**
286N/A * Create a LocPathIterator object, including creation
286N/A * of step walkers from the opcode list, and call back
286N/A * into the Compiler to create predicate expressions.
286N/A *
286N/A * @param compiler The Compiler which is creating
286N/A * this expression.
286N/A * @param opPos The position of this iterator in the
286N/A * opcode list from the compiler.
286N/A * @param shouldLoadWalkers True if walkers should be
286N/A * loaded, or false if this is a derived iterator and
286N/A * it doesn't wish to load child walkers.
286N/A *
286N/A * @throws javax.xml.transform.TransformerException
286N/A */
286N/A protected BasicTestIterator(
286N/A Compiler compiler, int opPos, int analysis, boolean shouldLoadWalkers)
286N/A throws javax.xml.transform.TransformerException
286N/A {
286N/A super(compiler, opPos, analysis, shouldLoadWalkers);
286N/A }
286N/A
286N/A
286N/A /**
286N/A * Get the next node via getNextXXX. Bottlenecked for derived class override.
286N/A * @return The next node on the axis, or DTM.NULL.
286N/A */
286N/A protected abstract int getNextNode();
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 {
286N/A m_lastFetched = DTM.NULL;
286N/A return DTM.NULL;
286N/A }
286N/A
286N/A if(DTM.NULL == m_lastFetched)
286N/A {
286N/A resetProximityPositions();
286N/A }
286N/A
286N/A int next;
286N/A
286N/A com.sun.org.apache.xpath.internal.VariableStack vars;
286N/A int savedStart;
286N/A if (-1 != m_stackFrame)
286N/A {
286N/A vars = m_execContext.getVarStack();
286N/A
286N/A // These three statements need to be combined into one operation.
286N/A savedStart = vars.getStackFrame();
286N/A
286N/A vars.setStackFrame(m_stackFrame);
286N/A }
286N/A else
286N/A {
286N/A // Yuck. Just to shut up the compiler!
286N/A vars = null;
286N/A savedStart = 0;
286N/A }
286N/A
286N/A try
286N/A {
286N/A do
286N/A {
286N/A next = getNextNode();
286N/A
286N/A if (DTM.NULL != next)
286N/A {
286N/A if(DTMIterator.FILTER_ACCEPT == acceptNode(next))
286N/A break;
286N/A else
286N/A continue;
286N/A }
286N/A else
286N/A break;
286N/A }
286N/A while (next != DTM.NULL);
286N/A
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 finally
286N/A {
286N/A if (-1 != m_stackFrame)
286N/A {
286N/A // These two statements need to be combined into one operation.
286N/A vars.setStackFrame(savedStart);
286N/A }
286N/A }
286N/A }
286N/A
286N/A /**
286N/A * Get a cloned Iterator that is reset to the beginning
286N/A * of the query.
286N/A *
286N/A * @return A cloned NodeIterator set of the start of the query.
286N/A *
286N/A * @throws CloneNotSupportedException
286N/A */
286N/A public DTMIterator cloneWithReset() throws CloneNotSupportedException
286N/A {
286N/A
286N/A ChildTestIterator clone = (ChildTestIterator) super.cloneWithReset();
286N/A
286N/A clone.resetProximityPositions();
286N/A
286N/A return clone;
286N/A }
286N/A
286N/A
286N/A}