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