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: SelfIteratorNoPredicate.java,v 1.14 2005/01/23 01:02:11 mcnamara Exp $
018: */
019: package org.apache.xpath.axes;
020:
021: import org.apache.xml.dtm.DTM;
022: import org.apache.xpath.XPathContext;
023: import org.apache.xpath.compiler.Compiler;
024:
025: /**
026: * This class implements an optimized iterator for
027: * "." patterns, that is, the self axes without any predicates.
028: * @see org.apache.xpath.axes.LocPathIterator
029: * @xsl.usage advanced
030: */
031: public class SelfIteratorNoPredicate extends LocPathIterator {
032: static final long serialVersionUID = -4226887905279814201L;
033:
034: /**
035: * Create a SelfIteratorNoPredicate object.
036: *
037: * @param compiler A reference to the Compiler that contains the op map.
038: * @param opPos The position within the op map, which contains the
039: * location path expression for this itterator.
040: * @param analysis Analysis bits.
041: *
042: * @throws javax.xml.transform.TransformerException
043: */
044: SelfIteratorNoPredicate(Compiler compiler, int opPos, int analysis)
045: throws javax.xml.transform.TransformerException {
046: super (compiler, opPos, analysis, false);
047: }
048:
049: /**
050: * Create a SelfIteratorNoPredicate object.
051: *
052: * @throws javax.xml.transform.TransformerException
053: */
054: public SelfIteratorNoPredicate()
055: throws javax.xml.transform.TransformerException {
056: super (null);
057: }
058:
059: /**
060: * Returns the next node in the set and advances the position of the
061: * iterator in the set. After a NodeIterator is created, the first call
062: * to nextNode() returns the first node in the set.
063: *
064: * @return The next <code>Node</code> in the set being iterated over, or
065: * <code>null</code> if there are no more members in that set.
066: */
067: public int nextNode() {
068: if (m_foundLast)
069: return DTM.NULL;
070:
071: int next;
072: DTM dtm = m_cdtm;
073:
074: m_lastFetched = next = (DTM.NULL == m_lastFetched) ? m_context
075: : DTM.NULL;
076:
077: // m_lastFetched = next;
078: if (DTM.NULL != next) {
079: m_pos++;
080:
081: return next;
082: } else {
083: m_foundLast = true;
084:
085: return DTM.NULL;
086: }
087: }
088:
089: /**
090: * Return the first node out of the nodeset, if this expression is
091: * a nodeset expression. This is the default implementation for
092: * nodesets. Derived classes should try and override this and return a
093: * value without having to do a clone operation.
094: * @param xctxt The XPath runtime context.
095: * @return the first node out of the nodeset, or DTM.NULL.
096: */
097: public int asNode(XPathContext xctxt)
098: throws javax.xml.transform.TransformerException {
099: return xctxt.getCurrentNode();
100: }
101:
102: /**
103: * Get the index of the last node that can be itterated to.
104: * This probably will need to be overridded by derived classes.
105: *
106: * @param xctxt XPath runtime context.
107: *
108: * @return the index of the last node that can be itterated to.
109: */
110: public int getLastPos(XPathContext xctxt) {
111: return 1;
112: }
113:
114: }
|