jaxp/src/com/sun/org/apache/xpath/internal/axes/DescendantIterator.java
author joehw
Tue, 17 Apr 2012 11:17:59 -0700
changeset 12458 d601e4bba306
parent 12457 c348e06f0e82
permissions -rw-r--r--
7160380: Sync JDK8 with JAXP 1.4.5 Summary: bring JDK8 up to date to what we have in 7u4 Reviewed-by: lancea, mullan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     1
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
     2
 * reserved comment block
7f561c08de6b Initial load
duke
parents:
diff changeset
     3
 * DO NOT REMOVE OR ALTER!
7f561c08de6b Initial load
duke
parents:
diff changeset
     4
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
     5
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
     6
 * Copyright 1999-2004 The Apache Software Foundation.
7f561c08de6b Initial load
duke
parents:
diff changeset
     7
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
     8
 * Licensed under the Apache License, Version 2.0 (the "License");
7f561c08de6b Initial load
duke
parents:
diff changeset
     9
 * you may not use this file except in compliance with the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    10
 * You may obtain a copy of the License at
7f561c08de6b Initial load
duke
parents:
diff changeset
    11
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    12
 *     http://www.apache.org/licenses/LICENSE-2.0
7f561c08de6b Initial load
duke
parents:
diff changeset
    13
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    14
 * Unless required by applicable law or agreed to in writing, software
7f561c08de6b Initial load
duke
parents:
diff changeset
    15
 * distributed under the License is distributed on an "AS IS" BASIS,
7f561c08de6b Initial load
duke
parents:
diff changeset
    16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7f561c08de6b Initial load
duke
parents:
diff changeset
    17
 * See the License for the specific language governing permissions and
7f561c08de6b Initial load
duke
parents:
diff changeset
    18
 * limitations under the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    19
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    20
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
    21
 * $Id: DescendantIterator.java,v 1.2.4.2 2005/09/14 19:45:21 jeffsuttor Exp $
7f561c08de6b Initial load
duke
parents:
diff changeset
    22
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    23
package com.sun.org.apache.xpath.internal.axes;
7f561c08de6b Initial load
duke
parents:
diff changeset
    24
7f561c08de6b Initial load
duke
parents:
diff changeset
    25
import com.sun.org.apache.xml.internal.dtm.Axis;
7f561c08de6b Initial load
duke
parents:
diff changeset
    26
import com.sun.org.apache.xml.internal.dtm.DTM;
7f561c08de6b Initial load
duke
parents:
diff changeset
    27
import com.sun.org.apache.xml.internal.dtm.DTMAxisTraverser;
7f561c08de6b Initial load
duke
parents:
diff changeset
    28
import com.sun.org.apache.xml.internal.dtm.DTMFilter;
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
import com.sun.org.apache.xml.internal.dtm.DTMIterator;
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
import com.sun.org.apache.xpath.internal.Expression;
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
import com.sun.org.apache.xpath.internal.XPathContext;
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
import com.sun.org.apache.xpath.internal.compiler.Compiler;
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
import com.sun.org.apache.xpath.internal.compiler.OpCodes;
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
    34
import com.sun.org.apache.xpath.internal.compiler.OpMap;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
import com.sun.org.apache.xpath.internal.patterns.NodeTest;
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
    36
import org.w3c.dom.DOMException;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
 * This class implements an optimized iterator for
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
 * descendant, descendant-or-self, or "//foo" patterns.
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
 * @see com.sun.org.apache.xpath.internal.axes.LocPathIterator
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
 * @xsl.usage advanced
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
public class DescendantIterator extends LocPathIterator
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
{
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
    static final long serialVersionUID = -1190338607743976938L;
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
   * Create a DescendantIterator object.
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
   * @param compiler A reference to the Compiler that contains the op map.
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
   * @param opPos The position within the op map, which contains the
7f561c08de6b Initial load
duke
parents:
diff changeset
    52
   * location path expression for this itterator.
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
   * @throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
  DescendantIterator(Compiler compiler, int opPos, int analysis)
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
          throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
    super(compiler, opPos, analysis, false);
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
    62
    int firstStepPos = OpMap.getFirstChildPos(opPos);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
    int stepType = compiler.getOp(firstStepPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
    boolean orSelf = (OpCodes.FROM_DESCENDANTS_OR_SELF == stepType);
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
    boolean fromRoot = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
    if (OpCodes.FROM_SELF == stepType)
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
      orSelf = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
      // firstStepPos += 8;
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
    else if(OpCodes.FROM_ROOT == stepType)
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
      fromRoot = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
      // Ugly code... will go away when AST work is done.
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
      int nextStepPos = compiler.getNextStepPos(firstStepPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
      if(compiler.getOp(nextStepPos) == OpCodes.FROM_DESCENDANTS_OR_SELF)
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
        orSelf = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
      // firstStepPos += 8;
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
    // Find the position of the last step.
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
    int nextStepPos = firstStepPos;
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
    while(true)
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
      nextStepPos = compiler.getNextStepPos(nextStepPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
      if(nextStepPos > 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
        int stepOp = compiler.getOp(nextStepPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
        if(OpCodes.ENDOP != stepOp)
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
          firstStepPos = nextStepPos;
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
        else
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
          break;
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
      else
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
        break;
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
    // Fix for http://nagoya.apache.org/bugzilla/show_bug.cgi?id=1336
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
    if((analysis & WalkerFactory.BIT_CHILD) != 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
   102
      orSelf = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
7f561c08de6b Initial load
duke
parents:
diff changeset
   104
    if(fromRoot)
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
      if(orSelf)
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
        m_axis = Axis.DESCENDANTSORSELFFROMROOT;
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
      else
7f561c08de6b Initial load
duke
parents:
diff changeset
   109
        m_axis = Axis.DESCENDANTSFROMROOT;
7f561c08de6b Initial load
duke
parents:
diff changeset
   110
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   111
    else if(orSelf)
7f561c08de6b Initial load
duke
parents:
diff changeset
   112
      m_axis = Axis.DESCENDANTORSELF;
7f561c08de6b Initial load
duke
parents:
diff changeset
   113
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
   114
      m_axis = Axis.DESCENDANT;
7f561c08de6b Initial load
duke
parents:
diff changeset
   115
7f561c08de6b Initial load
duke
parents:
diff changeset
   116
    int whatToShow = compiler.getWhatToShow(firstStepPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   117
7f561c08de6b Initial load
duke
parents:
diff changeset
   118
    if ((0 == (whatToShow
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
               & (DTMFilter.SHOW_ATTRIBUTE | DTMFilter.SHOW_ELEMENT
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
                  | DTMFilter.SHOW_PROCESSING_INSTRUCTION))) ||
7f561c08de6b Initial load
duke
parents:
diff changeset
   121
                   (whatToShow == DTMFilter.SHOW_ALL))
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
      initNodeTest(whatToShow);
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
   124
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   125
      initNodeTest(whatToShow, compiler.getStepNS(firstStepPos),
7f561c08de6b Initial load
duke
parents:
diff changeset
   126
                              compiler.getStepLocalName(firstStepPos));
7f561c08de6b Initial load
duke
parents:
diff changeset
   127
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   128
    initPredicateInfo(compiler, firstStepPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   129
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   130
7f561c08de6b Initial load
duke
parents:
diff changeset
   131
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   132
   * Create a DescendantIterator object.
7f561c08de6b Initial load
duke
parents:
diff changeset
   133
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   134
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   135
  public DescendantIterator()
7f561c08de6b Initial load
duke
parents:
diff changeset
   136
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   137
    super(null);
7f561c08de6b Initial load
duke
parents:
diff changeset
   138
    m_axis = Axis.DESCENDANTSORSELFFROMROOT;
7f561c08de6b Initial load
duke
parents:
diff changeset
   139
    int whatToShow = DTMFilter.SHOW_ALL;
7f561c08de6b Initial load
duke
parents:
diff changeset
   140
    initNodeTest(whatToShow);
7f561c08de6b Initial load
duke
parents:
diff changeset
   141
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   142
7f561c08de6b Initial load
duke
parents:
diff changeset
   143
7f561c08de6b Initial load
duke
parents:
diff changeset
   144
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   145
   *  Get a cloned Iterator that is reset to the beginning
7f561c08de6b Initial load
duke
parents:
diff changeset
   146
   *  of the query.
7f561c08de6b Initial load
duke
parents:
diff changeset
   147
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   148
   *  @return A cloned NodeIterator set of the start of the query.
7f561c08de6b Initial load
duke
parents:
diff changeset
   149
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   150
   *  @throws CloneNotSupportedException
7f561c08de6b Initial load
duke
parents:
diff changeset
   151
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   152
  public DTMIterator cloneWithReset() throws CloneNotSupportedException
7f561c08de6b Initial load
duke
parents:
diff changeset
   153
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   154
7f561c08de6b Initial load
duke
parents:
diff changeset
   155
    DescendantIterator clone = (DescendantIterator) super.cloneWithReset();
7f561c08de6b Initial load
duke
parents:
diff changeset
   156
    clone.m_traverser = m_traverser;
7f561c08de6b Initial load
duke
parents:
diff changeset
   157
7f561c08de6b Initial load
duke
parents:
diff changeset
   158
    clone.resetProximityPositions();
7f561c08de6b Initial load
duke
parents:
diff changeset
   159
7f561c08de6b Initial load
duke
parents:
diff changeset
   160
    return clone;
7f561c08de6b Initial load
duke
parents:
diff changeset
   161
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   162
7f561c08de6b Initial load
duke
parents:
diff changeset
   163
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   164
   *  Returns the next node in the set and advances the position of the
7f561c08de6b Initial load
duke
parents:
diff changeset
   165
   * iterator in the set. After a NodeIterator is created, the first call
7f561c08de6b Initial load
duke
parents:
diff changeset
   166
   * to nextNode() returns the first node in the set.
7f561c08de6b Initial load
duke
parents:
diff changeset
   167
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   168
   * @return  The next <code>Node</code> in the set being iterated over, or
7f561c08de6b Initial load
duke
parents:
diff changeset
   169
   *   <code>null</code> if there are no more members in that set.
7f561c08de6b Initial load
duke
parents:
diff changeset
   170
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   171
   * @throws DOMException
7f561c08de6b Initial load
duke
parents:
diff changeset
   172
   *    INVALID_STATE_ERR: Raised if this method is called after the
7f561c08de6b Initial load
duke
parents:
diff changeset
   173
   *   <code>detach</code> method was invoked.
7f561c08de6b Initial load
duke
parents:
diff changeset
   174
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   175
  public int nextNode()
7f561c08de6b Initial load
duke
parents:
diff changeset
   176
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   177
        if(m_foundLast)
7f561c08de6b Initial load
duke
parents:
diff changeset
   178
                return DTM.NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
   179
7f561c08de6b Initial load
duke
parents:
diff changeset
   180
    if(DTM.NULL == m_lastFetched)
7f561c08de6b Initial load
duke
parents:
diff changeset
   181
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   182
      resetProximityPositions();
7f561c08de6b Initial load
duke
parents:
diff changeset
   183
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   184
7f561c08de6b Initial load
duke
parents:
diff changeset
   185
    int next;
7f561c08de6b Initial load
duke
parents:
diff changeset
   186
7f561c08de6b Initial load
duke
parents:
diff changeset
   187
    com.sun.org.apache.xpath.internal.VariableStack vars;
7f561c08de6b Initial load
duke
parents:
diff changeset
   188
    int savedStart;
7f561c08de6b Initial load
duke
parents:
diff changeset
   189
    if (-1 != m_stackFrame)
7f561c08de6b Initial load
duke
parents:
diff changeset
   190
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   191
      vars = m_execContext.getVarStack();
7f561c08de6b Initial load
duke
parents:
diff changeset
   192
7f561c08de6b Initial load
duke
parents:
diff changeset
   193
      // These three statements need to be combined into one operation.
7f561c08de6b Initial load
duke
parents:
diff changeset
   194
      savedStart = vars.getStackFrame();
7f561c08de6b Initial load
duke
parents:
diff changeset
   195
7f561c08de6b Initial load
duke
parents:
diff changeset
   196
      vars.setStackFrame(m_stackFrame);
7f561c08de6b Initial load
duke
parents:
diff changeset
   197
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   198
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
   199
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   200
      // Yuck.  Just to shut up the compiler!
7f561c08de6b Initial load
duke
parents:
diff changeset
   201
      vars = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   202
      savedStart = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   203
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   204
7f561c08de6b Initial load
duke
parents:
diff changeset
   205
    try
7f561c08de6b Initial load
duke
parents:
diff changeset
   206
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   207
      do
7f561c08de6b Initial load
duke
parents:
diff changeset
   208
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   209
        if(0 == m_extendedTypeID)
7f561c08de6b Initial load
duke
parents:
diff changeset
   210
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   211
          next = m_lastFetched = (DTM.NULL == m_lastFetched)
7f561c08de6b Initial load
duke
parents:
diff changeset
   212
                       ? m_traverser.first(m_context)
7f561c08de6b Initial load
duke
parents:
diff changeset
   213
                       : m_traverser.next(m_context, m_lastFetched);
7f561c08de6b Initial load
duke
parents:
diff changeset
   214
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   215
        else
7f561c08de6b Initial load
duke
parents:
diff changeset
   216
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   217
          next = m_lastFetched = (DTM.NULL == m_lastFetched)
7f561c08de6b Initial load
duke
parents:
diff changeset
   218
                       ? m_traverser.first(m_context, m_extendedTypeID)
7f561c08de6b Initial load
duke
parents:
diff changeset
   219
                       : m_traverser.next(m_context, m_lastFetched,
7f561c08de6b Initial load
duke
parents:
diff changeset
   220
                                          m_extendedTypeID);
7f561c08de6b Initial load
duke
parents:
diff changeset
   221
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   222
7f561c08de6b Initial load
duke
parents:
diff changeset
   223
        if (DTM.NULL != next)
7f561c08de6b Initial load
duke
parents:
diff changeset
   224
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   225
          if(DTMIterator.FILTER_ACCEPT == acceptNode(next))
7f561c08de6b Initial load
duke
parents:
diff changeset
   226
            break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   227
          else
7f561c08de6b Initial load
duke
parents:
diff changeset
   228
            continue;
7f561c08de6b Initial load
duke
parents:
diff changeset
   229
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   230
        else
7f561c08de6b Initial load
duke
parents:
diff changeset
   231
          break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   232
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   233
      while (next != DTM.NULL);
7f561c08de6b Initial load
duke
parents:
diff changeset
   234
7f561c08de6b Initial load
duke
parents:
diff changeset
   235
      if (DTM.NULL != next)
7f561c08de6b Initial load
duke
parents:
diff changeset
   236
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   237
        m_pos++;
7f561c08de6b Initial load
duke
parents:
diff changeset
   238
        return next;
7f561c08de6b Initial load
duke
parents:
diff changeset
   239
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   240
      else
7f561c08de6b Initial load
duke
parents:
diff changeset
   241
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   242
        m_foundLast = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   243
7f561c08de6b Initial load
duke
parents:
diff changeset
   244
        return DTM.NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
   245
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   246
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   247
    finally
7f561c08de6b Initial load
duke
parents:
diff changeset
   248
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   249
      if (-1 != m_stackFrame)
7f561c08de6b Initial load
duke
parents:
diff changeset
   250
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   251
        // These two statements need to be combined into one operation.
7f561c08de6b Initial load
duke
parents:
diff changeset
   252
        vars.setStackFrame(savedStart);
7f561c08de6b Initial load
duke
parents:
diff changeset
   253
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   254
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   255
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   256
7f561c08de6b Initial load
duke
parents:
diff changeset
   257
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   258
   * Initialize the context values for this expression
7f561c08de6b Initial load
duke
parents:
diff changeset
   259
   * after it is cloned.
7f561c08de6b Initial load
duke
parents:
diff changeset
   260
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   261
   * @param context The XPath runtime context for this
7f561c08de6b Initial load
duke
parents:
diff changeset
   262
   * transformation.
7f561c08de6b Initial load
duke
parents:
diff changeset
   263
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   264
  public void setRoot(int context, Object environment)
7f561c08de6b Initial load
duke
parents:
diff changeset
   265
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   266
    super.setRoot(context, environment);
7f561c08de6b Initial load
duke
parents:
diff changeset
   267
    m_traverser = m_cdtm.getAxisTraverser(m_axis);
7f561c08de6b Initial load
duke
parents:
diff changeset
   268
7f561c08de6b Initial load
duke
parents:
diff changeset
   269
    String localName = getLocalName();
7f561c08de6b Initial load
duke
parents:
diff changeset
   270
    String namespace = getNamespace();
7f561c08de6b Initial load
duke
parents:
diff changeset
   271
    int what = m_whatToShow;
7f561c08de6b Initial load
duke
parents:
diff changeset
   272
    // System.out.println("what: ");
7f561c08de6b Initial load
duke
parents:
diff changeset
   273
    // NodeTest.debugWhatToShow(what);
7f561c08de6b Initial load
duke
parents:
diff changeset
   274
    if(DTMFilter.SHOW_ALL == what
7f561c08de6b Initial load
duke
parents:
diff changeset
   275
       || NodeTest.WILD.equals(localName)
7f561c08de6b Initial load
duke
parents:
diff changeset
   276
       || NodeTest.WILD.equals(namespace))
7f561c08de6b Initial load
duke
parents:
diff changeset
   277
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   278
      m_extendedTypeID = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   279
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   280
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
   281
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   282
      int type = getNodeTypeTest(what);
7f561c08de6b Initial load
duke
parents:
diff changeset
   283
      m_extendedTypeID = m_cdtm.getExpandedTypeID(namespace, localName, type);
7f561c08de6b Initial load
duke
parents:
diff changeset
   284
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   285
7f561c08de6b Initial load
duke
parents:
diff changeset
   286
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   287
7f561c08de6b Initial load
duke
parents:
diff changeset
   288
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   289
   * Return the first node out of the nodeset, if this expression is
7f561c08de6b Initial load
duke
parents:
diff changeset
   290
   * a nodeset expression.  This is the default implementation for
7f561c08de6b Initial load
duke
parents:
diff changeset
   291
   * nodesets.
7f561c08de6b Initial load
duke
parents:
diff changeset
   292
   * <p>WARNING: Do not mutate this class from this function!</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   293
   * @param xctxt The XPath runtime context.
7f561c08de6b Initial load
duke
parents:
diff changeset
   294
   * @return the first node out of the nodeset, or DTM.NULL.
7f561c08de6b Initial load
duke
parents:
diff changeset
   295
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   296
  public int asNode(XPathContext xctxt)
7f561c08de6b Initial load
duke
parents:
diff changeset
   297
    throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   298
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   299
    if(getPredicateCount() > 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
   300
      return super.asNode(xctxt);
7f561c08de6b Initial load
duke
parents:
diff changeset
   301
7f561c08de6b Initial load
duke
parents:
diff changeset
   302
    int current = xctxt.getCurrentNode();
7f561c08de6b Initial load
duke
parents:
diff changeset
   303
7f561c08de6b Initial load
duke
parents:
diff changeset
   304
    DTM dtm = xctxt.getDTM(current);
7f561c08de6b Initial load
duke
parents:
diff changeset
   305
    DTMAxisTraverser traverser = dtm.getAxisTraverser(m_axis);
7f561c08de6b Initial load
duke
parents:
diff changeset
   306
7f561c08de6b Initial load
duke
parents:
diff changeset
   307
    String localName = getLocalName();
7f561c08de6b Initial load
duke
parents:
diff changeset
   308
    String namespace = getNamespace();
7f561c08de6b Initial load
duke
parents:
diff changeset
   309
    int what = m_whatToShow;
7f561c08de6b Initial load
duke
parents:
diff changeset
   310
7f561c08de6b Initial load
duke
parents:
diff changeset
   311
    // System.out.print(" (DescendantIterator) ");
7f561c08de6b Initial load
duke
parents:
diff changeset
   312
7f561c08de6b Initial load
duke
parents:
diff changeset
   313
    // System.out.println("what: ");
7f561c08de6b Initial load
duke
parents:
diff changeset
   314
    // NodeTest.debugWhatToShow(what);
7f561c08de6b Initial load
duke
parents:
diff changeset
   315
    if(DTMFilter.SHOW_ALL == what
7f561c08de6b Initial load
duke
parents:
diff changeset
   316
       || localName == NodeTest.WILD
7f561c08de6b Initial load
duke
parents:
diff changeset
   317
       || namespace == NodeTest.WILD)
7f561c08de6b Initial load
duke
parents:
diff changeset
   318
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   319
      return traverser.first(current);
7f561c08de6b Initial load
duke
parents:
diff changeset
   320
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   321
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
   322
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   323
      int type = getNodeTypeTest(what);
7f561c08de6b Initial load
duke
parents:
diff changeset
   324
      int extendedType = dtm.getExpandedTypeID(namespace, localName, type);
7f561c08de6b Initial load
duke
parents:
diff changeset
   325
      return traverser.first(current, extendedType);
7f561c08de6b Initial load
duke
parents:
diff changeset
   326
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   327
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   328
7f561c08de6b Initial load
duke
parents:
diff changeset
   329
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   330
   *  Detaches the iterator from the set which it iterated over, releasing
7f561c08de6b Initial load
duke
parents:
diff changeset
   331
   * any computational resources and placing the iterator in the INVALID
7f561c08de6b Initial load
duke
parents:
diff changeset
   332
   * state. After<code>detach</code> has been invoked, calls to
7f561c08de6b Initial load
duke
parents:
diff changeset
   333
   * <code>nextNode</code> or<code>previousNode</code> will raise the
7f561c08de6b Initial load
duke
parents:
diff changeset
   334
   * exception INVALID_STATE_ERR.
7f561c08de6b Initial load
duke
parents:
diff changeset
   335
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   336
  public void detach()
7f561c08de6b Initial load
duke
parents:
diff changeset
   337
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   338
    if (m_allowDetach) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   339
      m_traverser = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   340
      m_extendedTypeID = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   341
7f561c08de6b Initial load
duke
parents:
diff changeset
   342
      // Always call the superclass detach last!
7f561c08de6b Initial load
duke
parents:
diff changeset
   343
      super.detach();
7f561c08de6b Initial load
duke
parents:
diff changeset
   344
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   345
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   346
7f561c08de6b Initial load
duke
parents:
diff changeset
   347
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   348
   * Returns the axis being iterated, if it is known.
7f561c08de6b Initial load
duke
parents:
diff changeset
   349
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   350
   * @return Axis.CHILD, etc., or -1 if the axis is not known or is of multiple
7f561c08de6b Initial load
duke
parents:
diff changeset
   351
   * types.
7f561c08de6b Initial load
duke
parents:
diff changeset
   352
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   353
  public int getAxis()
7f561c08de6b Initial load
duke
parents:
diff changeset
   354
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   355
    return m_axis;
7f561c08de6b Initial load
duke
parents:
diff changeset
   356
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   357
7f561c08de6b Initial load
duke
parents:
diff changeset
   358
7f561c08de6b Initial load
duke
parents:
diff changeset
   359
  /** The traverser to use to navigate over the descendants. */
7f561c08de6b Initial load
duke
parents:
diff changeset
   360
  transient protected DTMAxisTraverser m_traverser;
7f561c08de6b Initial load
duke
parents:
diff changeset
   361
7f561c08de6b Initial load
duke
parents:
diff changeset
   362
  /** The axis that we are traversing. */
7f561c08de6b Initial load
duke
parents:
diff changeset
   363
  protected int m_axis;
7f561c08de6b Initial load
duke
parents:
diff changeset
   364
7f561c08de6b Initial load
duke
parents:
diff changeset
   365
  /** The extended type ID, not set until setRoot. */
7f561c08de6b Initial load
duke
parents:
diff changeset
   366
  protected int m_extendedTypeID;
7f561c08de6b Initial load
duke
parents:
diff changeset
   367
7f561c08de6b Initial load
duke
parents:
diff changeset
   368
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   369
   * @see Expression#deepEquals(Expression)
7f561c08de6b Initial load
duke
parents:
diff changeset
   370
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   371
  public boolean deepEquals(Expression expr)
7f561c08de6b Initial load
duke
parents:
diff changeset
   372
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   373
        if(!super.deepEquals(expr))
7f561c08de6b Initial load
duke
parents:
diff changeset
   374
                return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   375
7f561c08de6b Initial load
duke
parents:
diff changeset
   376
        if(m_axis != ((DescendantIterator)expr).m_axis)
7f561c08de6b Initial load
duke
parents:
diff changeset
   377
                return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   378
7f561c08de6b Initial load
duke
parents:
diff changeset
   379
        return true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   380
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   381
7f561c08de6b Initial load
duke
parents:
diff changeset
   382
7f561c08de6b Initial load
duke
parents:
diff changeset
   383
}