001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements. See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership. The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the "License");
007 * you may not use this file except in compliance with the License.
008 * You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018 /*
019 * $Id: SelfIteratorNoPredicate.java 469263 2006-10-30 20:45:40Z minchau $
020 */
021 package org.apache.xpath.axes;
022
023 import org.apache.xml.dtm.DTM;
024 import org.apache.xpath.XPathContext;
025 import org.apache.xpath.compiler.Compiler;
026
027 /**
028 * This class implements an optimized iterator for
029 * "." patterns, that is, the self axes without any predicates.
030 * @see org.apache.xpath.axes.LocPathIterator
031 * @xsl.usage advanced
032 */
033 public class SelfIteratorNoPredicate extends LocPathIterator
034 {
035 static final long serialVersionUID = -4226887905279814201L;
036
037 /**
038 * Create a SelfIteratorNoPredicate object.
039 *
040 * @param compiler A reference to the Compiler that contains the op map.
041 * @param opPos The position within the op map, which contains the
042 * location path expression for this itterator.
043 * @param analysis Analysis bits.
044 *
045 * @throws javax.xml.transform.TransformerException
046 */
047 SelfIteratorNoPredicate(Compiler compiler, int opPos, int analysis)
048 throws javax.xml.transform.TransformerException
049 {
050 super(compiler, opPos, analysis, false);
051 }
052
053 /**
054 * Create a SelfIteratorNoPredicate object.
055 *
056 * @throws javax.xml.transform.TransformerException
057 */
058 public SelfIteratorNoPredicate()
059 throws javax.xml.transform.TransformerException
060 {
061 super(null);
062 }
063
064
065 /**
066 * Returns the next node in the set and advances the position of the
067 * iterator in the set. After a NodeIterator is created, the first call
068 * to nextNode() returns the first node in the set.
069 *
070 * @return The next <code>Node</code> in the set being iterated over, or
071 * <code>null</code> if there are no more members in that set.
072 */
073 public int nextNode()
074 {
075 if (m_foundLast)
076 return DTM.NULL;
077
078 int next;
079
080 m_lastFetched = next = (DTM.NULL == m_lastFetched)
081 ? m_context
082 : DTM.NULL;
083
084 // m_lastFetched = next;
085 if (DTM.NULL != next)
086 {
087 m_pos++;
088
089 return next;
090 }
091 else
092 {
093 m_foundLast = true;
094
095 return DTM.NULL;
096 }
097 }
098
099 /**
100 * Return the first node out of the nodeset, if this expression is
101 * a nodeset expression. This is the default implementation for
102 * nodesets. Derived classes should try and override this and return a
103 * value without having to do a clone operation.
104 * @param xctxt The XPath runtime context.
105 * @return the first node out of the nodeset, or DTM.NULL.
106 */
107 public int asNode(XPathContext xctxt)
108 throws javax.xml.transform.TransformerException
109 {
110 return xctxt.getCurrentNode();
111 }
112
113 /**
114 * Get the index of the last node that can be itterated to.
115 * This probably will need to be overridded by derived classes.
116 *
117 * @param xctxt XPath runtime context.
118 *
119 * @return the index of the last node that can be itterated to.
120 */
121 public int getLastPos(XPathContext xctxt)
122 {
123 return 1;
124 }
125
126
127 }