1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the  "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 *     http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18/*
19 * $Id: SelfIteratorNoPredicate.java 469263 2006-10-30 20:45:40Z minchau $
20 */
21package org.apache.xpath.axes;
22
23import org.apache.xml.dtm.DTM;
24import org.apache.xpath.XPathContext;
25import org.apache.xpath.compiler.Compiler;
26
27/**
28 * This class implements an optimized iterator for
29 * "." patterns, that is, the self axes without any predicates.
30 * @see org.apache.xpath.axes.LocPathIterator
31 * @xsl.usage advanced
32 */
33public class SelfIteratorNoPredicate extends LocPathIterator
34{
35    static final long serialVersionUID = -4226887905279814201L;
36
37  /**
38   * Create a SelfIteratorNoPredicate object.
39   *
40   * @param compiler A reference to the Compiler that contains the op map.
41   * @param opPos The position within the op map, which contains the
42   * location path expression for this itterator.
43   * @param analysis Analysis bits.
44   *
45   * @throws javax.xml.transform.TransformerException
46   */
47  SelfIteratorNoPredicate(Compiler compiler, int opPos, int analysis)
48          throws javax.xml.transform.TransformerException
49  {
50    super(compiler, opPos, analysis, false);
51  }
52
53  /**
54   * Create a SelfIteratorNoPredicate object.
55   *
56   * @throws javax.xml.transform.TransformerException
57   */
58  public SelfIteratorNoPredicate()
59          throws javax.xml.transform.TransformerException
60  {
61    super(null);
62  }
63
64
65  /**
66   *  Returns the next node in the set and advances the position of the
67   * iterator in the set. After a NodeIterator is created, the first call
68   * to nextNode() returns the first node in the set.
69   *
70   * @return  The next <code>Node</code> in the set being iterated over, or
71   *   <code>null</code> if there are no more members in that set.
72   */
73  public int nextNode()
74  {
75    if (m_foundLast)
76      return DTM.NULL;
77
78    int next;
79
80    m_lastFetched = next = (DTM.NULL == m_lastFetched)
81                           ? m_context
82                           : DTM.NULL;
83
84    // m_lastFetched = next;
85    if (DTM.NULL != next)
86    {
87      m_pos++;
88
89      return next;
90    }
91    else
92    {
93      m_foundLast = true;
94
95      return DTM.NULL;
96    }
97  }
98
99  /**
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}
128