src/java.xml/share/classes/com/sun/org/apache/xpath/internal/axes/UnionPathIterator.java
author joehw
Wed, 18 Oct 2017 13:25:49 -0700
changeset 47359 e1a6c0168741
parent 47216 71c04702a3d5
child 48409 5ab69533994b
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
/*
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
     2
 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
     3
 * @LastModified: Oct 2017
6
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.DTMIterator;
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
    27
import com.sun.org.apache.xml.internal.utils.QName;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    28
import com.sun.org.apache.xpath.internal.Expression;
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
import com.sun.org.apache.xpath.internal.ExpressionOwner;
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
import com.sun.org.apache.xpath.internal.XPathVisitor;
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;
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
    34
import java.util.List;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
 * This class extends NodeSetDTM, which implements DTMIterator,
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
 * and fetches nodes one at a time in document order based on a XPath
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
 * <a href="http://www.w3.org/TR/xpath#NT-UnionExpr">UnionExpr</a>.
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
 * As each node is iterated via nextNode(), the node is also stored
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
 * in the NodeVector, so that previousNode() can easily be done.
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 UnionPathIterator extends LocPathIterator
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
        implements Cloneable, DTMIterator, java.io.Serializable, PathComponent
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
{
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
    static final long serialVersionUID = -3910351546843826781L;
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
   * Constructor to create an instance which you can add location paths to.
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    52
  public UnionPathIterator()
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
    super();
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
    // m_mutable = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
    // m_cacheNodes = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
    m_iterators = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
    m_exprs = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
   * Initialize the context values for this expression
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
   * after it is cloned.
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
   * @param context The XPath runtime context for this
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
   * transformation.
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
  public void setRoot(int context, Object environment)
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
    super.setRoot(context, environment);
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
    try
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
      if (null != m_exprs)
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
        int n = m_exprs.length;
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
        DTMIterator newIters[] = new DTMIterator[n];
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
        for (int i = 0; i < n; i++)
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
          DTMIterator iter = m_exprs[i].asIterator(m_execContext, context);
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
          newIters[i] = iter;
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
          iter.nextNode();
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
        m_iterators = newIters;
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
    catch(Exception e)
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
      throw new com.sun.org.apache.xml.internal.utils.WrappedRuntimeException(e);
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
   * Add an iterator to the union list.
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
   * @param expr non-null reference to a location path iterator.
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
  public void addIterator(DTMIterator expr)
7f561c08de6b Initial load
duke
parents:
diff changeset
   102
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
7f561c08de6b Initial load
duke
parents:
diff changeset
   104
    // Increase array size by only 1 at a time.  Fix this
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
    // if it looks to be a problem.
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
    if (null == m_iterators)
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
      m_iterators = new DTMIterator[1];
7f561c08de6b Initial load
duke
parents:
diff changeset
   109
      m_iterators[0] = expr;
7f561c08de6b Initial load
duke
parents:
diff changeset
   110
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   111
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
   112
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   113
      DTMIterator[] exprs = m_iterators;
7f561c08de6b Initial load
duke
parents:
diff changeset
   114
      int len = m_iterators.length;
7f561c08de6b Initial load
duke
parents:
diff changeset
   115
7f561c08de6b Initial load
duke
parents:
diff changeset
   116
      m_iterators = new DTMIterator[len + 1];
7f561c08de6b Initial load
duke
parents:
diff changeset
   117
7f561c08de6b Initial load
duke
parents:
diff changeset
   118
      System.arraycopy(exprs, 0, m_iterators, 0, len);
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
      m_iterators[len] = expr;
7f561c08de6b Initial load
duke
parents:
diff changeset
   121
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
    expr.nextNode();
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
    if(expr instanceof Expression)
7f561c08de6b Initial load
duke
parents:
diff changeset
   124
        ((Expression)expr).exprSetParent(this);
7f561c08de6b Initial load
duke
parents:
diff changeset
   125
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   126
7f561c08de6b Initial load
duke
parents:
diff changeset
   127
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   128
   *  Detaches the iterator from the set which it iterated over, releasing
7f561c08de6b Initial load
duke
parents:
diff changeset
   129
   * any computational resources and placing the iterator in the INVALID
7f561c08de6b Initial load
duke
parents:
diff changeset
   130
   * state. After<code>detach</code> has been invoked, calls to
7f561c08de6b Initial load
duke
parents:
diff changeset
   131
   * <code>nextNode</code> or<code>previousNode</code> will raise the
7f561c08de6b Initial load
duke
parents:
diff changeset
   132
   * exception INVALID_STATE_ERR.
7f561c08de6b Initial load
duke
parents:
diff changeset
   133
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   134
  public void detach()
7f561c08de6b Initial load
duke
parents:
diff changeset
   135
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   136
          if(m_allowDetach && null != m_iterators){
7f561c08de6b Initial load
duke
parents:
diff changeset
   137
                  int n = m_iterators.length;
7f561c08de6b Initial load
duke
parents:
diff changeset
   138
                  for(int i = 0; i < n; i++)
7f561c08de6b Initial load
duke
parents:
diff changeset
   139
                  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   140
                          m_iterators[i].detach();
7f561c08de6b Initial load
duke
parents:
diff changeset
   141
                  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   142
                  m_iterators = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   143
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
   144
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   145
7f561c08de6b Initial load
duke
parents:
diff changeset
   146
7f561c08de6b Initial load
duke
parents:
diff changeset
   147
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   148
   * Create a UnionPathIterator object, including creation
7f561c08de6b Initial load
duke
parents:
diff changeset
   149
   * of location path iterators from the opcode list, and call back
7f561c08de6b Initial load
duke
parents:
diff changeset
   150
   * into the Compiler to create predicate expressions.
7f561c08de6b Initial load
duke
parents:
diff changeset
   151
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   152
   * @param compiler The Compiler which is creating
7f561c08de6b Initial load
duke
parents:
diff changeset
   153
   * this expression.
7f561c08de6b Initial load
duke
parents:
diff changeset
   154
   * @param opPos The position of this iterator in the
7f561c08de6b Initial load
duke
parents:
diff changeset
   155
   * opcode list from the compiler.
7f561c08de6b Initial load
duke
parents:
diff changeset
   156
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   157
   * @throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   158
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   159
  public UnionPathIterator(Compiler compiler, int opPos)
7f561c08de6b Initial load
duke
parents:
diff changeset
   160
          throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   161
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   162
7f561c08de6b Initial load
duke
parents:
diff changeset
   163
    super();
7f561c08de6b Initial load
duke
parents:
diff changeset
   164
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   165
    opPos = OpMap.getFirstChildPos(opPos);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   166
7f561c08de6b Initial load
duke
parents:
diff changeset
   167
    loadLocationPaths(compiler, opPos, 0);
7f561c08de6b Initial load
duke
parents:
diff changeset
   168
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   169
7f561c08de6b Initial load
duke
parents:
diff changeset
   170
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   171
   * This will return an iterator capable of handling the union of paths given.
7f561c08de6b Initial load
duke
parents:
diff changeset
   172
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   173
   * @param compiler The Compiler which is creating
7f561c08de6b Initial load
duke
parents:
diff changeset
   174
   * this expression.
7f561c08de6b Initial load
duke
parents:
diff changeset
   175
   * @param opPos The position of this iterator in the
7f561c08de6b Initial load
duke
parents:
diff changeset
   176
   * opcode list from the compiler.
7f561c08de6b Initial load
duke
parents:
diff changeset
   177
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   178
   * @return Object that is derived from LocPathIterator.
7f561c08de6b Initial load
duke
parents:
diff changeset
   179
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   180
   * @throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   181
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   182
  public static LocPathIterator createUnionIterator(Compiler compiler, int opPos)
7f561c08de6b Initial load
duke
parents:
diff changeset
   183
          throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   184
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   185
        // For the moment, I'm going to first create a full UnionPathIterator, and
7f561c08de6b Initial load
duke
parents:
diff changeset
   186
        // then see if I can reduce it to a UnionChildIterator.  It would obviously
7f561c08de6b Initial load
duke
parents:
diff changeset
   187
        // be more effecient to just test for the conditions for a UnionChildIterator,
7f561c08de6b Initial load
duke
parents:
diff changeset
   188
        // and then create that directly.
7f561c08de6b Initial load
duke
parents:
diff changeset
   189
        UnionPathIterator upi = new UnionPathIterator(compiler, opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   190
        int nPaths = upi.m_exprs.length;
7f561c08de6b Initial load
duke
parents:
diff changeset
   191
        boolean isAllChildIterators = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   192
        for(int i = 0; i < nPaths; i++)
7f561c08de6b Initial load
duke
parents:
diff changeset
   193
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   194
                LocPathIterator lpi = upi.m_exprs[i];
7f561c08de6b Initial load
duke
parents:
diff changeset
   195
7f561c08de6b Initial load
duke
parents:
diff changeset
   196
                if(lpi.getAxis() != Axis.CHILD)
7f561c08de6b Initial load
duke
parents:
diff changeset
   197
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
   198
                        isAllChildIterators = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   199
                        break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   200
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   201
                else
7f561c08de6b Initial load
duke
parents:
diff changeset
   202
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
   203
                        // check for positional predicates or position function, which won't work.
7f561c08de6b Initial load
duke
parents:
diff changeset
   204
                        if(HasPositionalPredChecker.check(lpi))
7f561c08de6b Initial load
duke
parents:
diff changeset
   205
                        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   206
                                isAllChildIterators = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   207
                                break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   208
                        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   209
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   210
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   211
        if(isAllChildIterators)
7f561c08de6b Initial load
duke
parents:
diff changeset
   212
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   213
                UnionChildIterator uci = new UnionChildIterator();
7f561c08de6b Initial load
duke
parents:
diff changeset
   214
7f561c08de6b Initial load
duke
parents:
diff changeset
   215
                for(int i = 0; i < nPaths; i++)
7f561c08de6b Initial load
duke
parents:
diff changeset
   216
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
   217
                        PredicatedNodeTest lpi = upi.m_exprs[i];
7f561c08de6b Initial load
duke
parents:
diff changeset
   218
                        // I could strip the lpi down to a pure PredicatedNodeTest, but
7f561c08de6b Initial load
duke
parents:
diff changeset
   219
                        // I don't think it's worth it.  Note that the test can be used
7f561c08de6b Initial load
duke
parents:
diff changeset
   220
                        // as a static object... so it doesn't have to be cloned.
7f561c08de6b Initial load
duke
parents:
diff changeset
   221
                        uci.addNodeTest(lpi);
7f561c08de6b Initial load
duke
parents:
diff changeset
   222
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   223
                return uci;
7f561c08de6b Initial load
duke
parents:
diff changeset
   224
7f561c08de6b Initial load
duke
parents:
diff changeset
   225
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   226
        else
7f561c08de6b Initial load
duke
parents:
diff changeset
   227
                return upi;
7f561c08de6b Initial load
duke
parents:
diff changeset
   228
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   229
7f561c08de6b Initial load
duke
parents:
diff changeset
   230
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   231
   * Get the analysis bits for this walker, as defined in the WalkerFactory.
7f561c08de6b Initial load
duke
parents:
diff changeset
   232
   * @return One of WalkerFactory#BIT_DESCENDANT, etc.
7f561c08de6b Initial load
duke
parents:
diff changeset
   233
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   234
  public int getAnalysisBits()
7f561c08de6b Initial load
duke
parents:
diff changeset
   235
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   236
    int bits = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   237
7f561c08de6b Initial load
duke
parents:
diff changeset
   238
    if (m_exprs != null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   239
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   240
      int n = m_exprs.length;
7f561c08de6b Initial load
duke
parents:
diff changeset
   241
7f561c08de6b Initial load
duke
parents:
diff changeset
   242
      for (int i = 0; i < n; i++)
7f561c08de6b Initial load
duke
parents:
diff changeset
   243
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   244
        int bit = m_exprs[i].getAnalysisBits();
7f561c08de6b Initial load
duke
parents:
diff changeset
   245
        bits |= bit;
7f561c08de6b Initial load
duke
parents:
diff changeset
   246
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   247
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   248
7f561c08de6b Initial load
duke
parents:
diff changeset
   249
    return bits;
7f561c08de6b Initial load
duke
parents:
diff changeset
   250
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   251
7f561c08de6b Initial load
duke
parents:
diff changeset
   252
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   253
   * Read the object from a serialization stream.
7f561c08de6b Initial load
duke
parents:
diff changeset
   254
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   255
   * @param stream Input stream to read from
7f561c08de6b Initial load
duke
parents:
diff changeset
   256
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   257
   * @throws java.io.IOException
7f561c08de6b Initial load
duke
parents:
diff changeset
   258
   * @throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   259
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   260
  private void readObject(java.io.ObjectInputStream stream)
7f561c08de6b Initial load
duke
parents:
diff changeset
   261
          throws java.io.IOException, javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   262
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   263
    try
7f561c08de6b Initial load
duke
parents:
diff changeset
   264
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   265
      stream.defaultReadObject();
7f561c08de6b Initial load
duke
parents:
diff changeset
   266
      m_clones =  new IteratorPool(this);
7f561c08de6b Initial load
duke
parents:
diff changeset
   267
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   268
    catch (ClassNotFoundException cnfe)
7f561c08de6b Initial load
duke
parents:
diff changeset
   269
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   270
      throw new javax.xml.transform.TransformerException(cnfe);
7f561c08de6b Initial load
duke
parents:
diff changeset
   271
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   272
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   273
7f561c08de6b Initial load
duke
parents:
diff changeset
   274
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   275
   * Get a cloned LocPathIterator that holds the same
7f561c08de6b Initial load
duke
parents:
diff changeset
   276
   * position as this iterator.
7f561c08de6b Initial load
duke
parents:
diff changeset
   277
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   278
   * @return A clone of this iterator that holds the same node position.
7f561c08de6b Initial load
duke
parents:
diff changeset
   279
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   280
   * @throws CloneNotSupportedException
7f561c08de6b Initial load
duke
parents:
diff changeset
   281
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   282
  public Object clone() throws CloneNotSupportedException
7f561c08de6b Initial load
duke
parents:
diff changeset
   283
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   284
7f561c08de6b Initial load
duke
parents:
diff changeset
   285
    UnionPathIterator clone = (UnionPathIterator) super.clone();
7f561c08de6b Initial load
duke
parents:
diff changeset
   286
    if (m_iterators != null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   287
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   288
      int n = m_iterators.length;
7f561c08de6b Initial load
duke
parents:
diff changeset
   289
7f561c08de6b Initial load
duke
parents:
diff changeset
   290
      clone.m_iterators = new DTMIterator[n];
7f561c08de6b Initial load
duke
parents:
diff changeset
   291
7f561c08de6b Initial load
duke
parents:
diff changeset
   292
      for (int i = 0; i < n; i++)
7f561c08de6b Initial load
duke
parents:
diff changeset
   293
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   294
        clone.m_iterators[i] = (DTMIterator)m_iterators[i].clone();
7f561c08de6b Initial load
duke
parents:
diff changeset
   295
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   296
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   297
7f561c08de6b Initial load
duke
parents:
diff changeset
   298
    return clone;
7f561c08de6b Initial load
duke
parents:
diff changeset
   299
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   300
7f561c08de6b Initial load
duke
parents:
diff changeset
   301
7f561c08de6b Initial load
duke
parents:
diff changeset
   302
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   303
   * Create a new location path iterator.
7f561c08de6b Initial load
duke
parents:
diff changeset
   304
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   305
   * @param compiler The Compiler which is creating
7f561c08de6b Initial load
duke
parents:
diff changeset
   306
   * this expression.
7f561c08de6b Initial load
duke
parents:
diff changeset
   307
   * @param opPos The position of this iterator in the
7f561c08de6b Initial load
duke
parents:
diff changeset
   308
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   309
   * @return New location path iterator.
7f561c08de6b Initial load
duke
parents:
diff changeset
   310
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   311
   * @throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   312
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   313
  protected LocPathIterator createDTMIterator(
7f561c08de6b Initial load
duke
parents:
diff changeset
   314
          Compiler compiler, int opPos) throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   315
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   316
    LocPathIterator lpi = (LocPathIterator)WalkerFactory.newDTMIterator(compiler, opPos,
7f561c08de6b Initial load
duke
parents:
diff changeset
   317
                                      (compiler.getLocationPathDepth() <= 0));
7f561c08de6b Initial load
duke
parents:
diff changeset
   318
    return lpi;
7f561c08de6b Initial load
duke
parents:
diff changeset
   319
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   320
7f561c08de6b Initial load
duke
parents:
diff changeset
   321
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   322
   * Initialize the location path iterators.  Recursive.
7f561c08de6b Initial load
duke
parents:
diff changeset
   323
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   324
   * @param compiler The Compiler which is creating
7f561c08de6b Initial load
duke
parents:
diff changeset
   325
   * this expression.
7f561c08de6b Initial load
duke
parents:
diff changeset
   326
   * @param opPos The position of this iterator in the
7f561c08de6b Initial load
duke
parents:
diff changeset
   327
   * opcode list from the compiler.
7f561c08de6b Initial load
duke
parents:
diff changeset
   328
   * @param count The insert position of the iterator.
7f561c08de6b Initial load
duke
parents:
diff changeset
   329
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   330
   * @throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   331
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   332
  protected void loadLocationPaths(Compiler compiler, int opPos, int count)
7f561c08de6b Initial load
duke
parents:
diff changeset
   333
          throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   334
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   335
7f561c08de6b Initial load
duke
parents:
diff changeset
   336
    // TODO: Handle unwrapped FilterExpr
7f561c08de6b Initial load
duke
parents:
diff changeset
   337
    int steptype = compiler.getOp(opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   338
7f561c08de6b Initial load
duke
parents:
diff changeset
   339
    if (steptype == OpCodes.OP_LOCATIONPATH)
7f561c08de6b Initial load
duke
parents:
diff changeset
   340
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   341
      loadLocationPaths(compiler, compiler.getNextOpPos(opPos), count + 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
   342
7f561c08de6b Initial load
duke
parents:
diff changeset
   343
      m_exprs[count] = createDTMIterator(compiler, opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   344
      m_exprs[count].exprSetParent(this);
7f561c08de6b Initial load
duke
parents:
diff changeset
   345
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   346
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
   347
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   348
7f561c08de6b Initial load
duke
parents:
diff changeset
   349
      // Have to check for unwrapped functions, which the LocPathIterator
7f561c08de6b Initial load
duke
parents:
diff changeset
   350
      // doesn't handle.
7f561c08de6b Initial load
duke
parents:
diff changeset
   351
      switch (steptype)
7f561c08de6b Initial load
duke
parents:
diff changeset
   352
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   353
      case OpCodes.OP_VARIABLE :
7f561c08de6b Initial load
duke
parents:
diff changeset
   354
      case OpCodes.OP_EXTFUNCTION :
7f561c08de6b Initial load
duke
parents:
diff changeset
   355
      case OpCodes.OP_FUNCTION :
7f561c08de6b Initial load
duke
parents:
diff changeset
   356
      case OpCodes.OP_GROUP :
7f561c08de6b Initial load
duke
parents:
diff changeset
   357
        loadLocationPaths(compiler, compiler.getNextOpPos(opPos), count + 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
   358
7f561c08de6b Initial load
duke
parents:
diff changeset
   359
        WalkingIterator iter =
7f561c08de6b Initial load
duke
parents:
diff changeset
   360
          new WalkingIterator(compiler.getNamespaceContext());
7f561c08de6b Initial load
duke
parents:
diff changeset
   361
        iter.exprSetParent(this);
7f561c08de6b Initial load
duke
parents:
diff changeset
   362
7f561c08de6b Initial load
duke
parents:
diff changeset
   363
        if(compiler.getLocationPathDepth() <= 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
   364
          iter.setIsTopLevel(true);
7f561c08de6b Initial load
duke
parents:
diff changeset
   365
7f561c08de6b Initial load
duke
parents:
diff changeset
   366
        iter.m_firstWalker = new com.sun.org.apache.xpath.internal.axes.FilterExprWalker(iter);
7f561c08de6b Initial load
duke
parents:
diff changeset
   367
7f561c08de6b Initial load
duke
parents:
diff changeset
   368
        iter.m_firstWalker.init(compiler, opPos, steptype);
7f561c08de6b Initial load
duke
parents:
diff changeset
   369
7f561c08de6b Initial load
duke
parents:
diff changeset
   370
        m_exprs[count] = iter;
7f561c08de6b Initial load
duke
parents:
diff changeset
   371
        break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   372
      default :
7f561c08de6b Initial load
duke
parents:
diff changeset
   373
        m_exprs = new LocPathIterator[count];
7f561c08de6b Initial load
duke
parents:
diff changeset
   374
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   375
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   376
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   377
7f561c08de6b Initial load
duke
parents:
diff changeset
   378
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   379
   *  Returns the next node in the set and advances the position of the
7f561c08de6b Initial load
duke
parents:
diff changeset
   380
   * iterator in the set. After a DTMIterator is created, the first call
7f561c08de6b Initial load
duke
parents:
diff changeset
   381
   * to nextNode() returns the first node in the set.
7f561c08de6b Initial load
duke
parents:
diff changeset
   382
   * @return  The next <code>Node</code> in the set being iterated over, or
7f561c08de6b Initial load
duke
parents:
diff changeset
   383
   *   <code>null</code> if there are no more members in that set.
7f561c08de6b Initial load
duke
parents:
diff changeset
   384
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   385
  public int nextNode()
7f561c08de6b Initial load
duke
parents:
diff changeset
   386
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   387
        if(m_foundLast)
7f561c08de6b Initial load
duke
parents:
diff changeset
   388
                return DTM.NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
   389
7f561c08de6b Initial load
duke
parents:
diff changeset
   390
    // Loop through the iterators getting the current fetched
7f561c08de6b Initial load
duke
parents:
diff changeset
   391
    // node, and get the earliest occuring in document order
7f561c08de6b Initial load
duke
parents:
diff changeset
   392
    int earliestNode = DTM.NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
   393
7f561c08de6b Initial load
duke
parents:
diff changeset
   394
    if (null != m_iterators)
7f561c08de6b Initial load
duke
parents:
diff changeset
   395
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   396
      int n = m_iterators.length;
7f561c08de6b Initial load
duke
parents:
diff changeset
   397
      int iteratorUsed = -1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   398
7f561c08de6b Initial load
duke
parents:
diff changeset
   399
      for (int i = 0; i < n; i++)
7f561c08de6b Initial load
duke
parents:
diff changeset
   400
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   401
        int node = m_iterators[i].getCurrentNode();
7f561c08de6b Initial load
duke
parents:
diff changeset
   402
7f561c08de6b Initial load
duke
parents:
diff changeset
   403
        if (DTM.NULL == node)
7f561c08de6b Initial load
duke
parents:
diff changeset
   404
          continue;
7f561c08de6b Initial load
duke
parents:
diff changeset
   405
        else if (DTM.NULL == earliestNode)
7f561c08de6b Initial load
duke
parents:
diff changeset
   406
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   407
          iteratorUsed = i;
7f561c08de6b Initial load
duke
parents:
diff changeset
   408
          earliestNode = node;
7f561c08de6b Initial load
duke
parents:
diff changeset
   409
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   410
        else
7f561c08de6b Initial load
duke
parents:
diff changeset
   411
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   412
          if (node == earliestNode)
7f561c08de6b Initial load
duke
parents:
diff changeset
   413
          {
7f561c08de6b Initial load
duke
parents:
diff changeset
   414
7f561c08de6b Initial load
duke
parents:
diff changeset
   415
            // Found a duplicate, so skip past it.
7f561c08de6b Initial load
duke
parents:
diff changeset
   416
            m_iterators[i].nextNode();
7f561c08de6b Initial load
duke
parents:
diff changeset
   417
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
   418
          else
7f561c08de6b Initial load
duke
parents:
diff changeset
   419
          {
7f561c08de6b Initial load
duke
parents:
diff changeset
   420
            DTM dtm = getDTM(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
   421
7f561c08de6b Initial load
duke
parents:
diff changeset
   422
            if (dtm.isNodeAfter(node, earliestNode))
7f561c08de6b Initial load
duke
parents:
diff changeset
   423
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
   424
              iteratorUsed = i;
7f561c08de6b Initial load
duke
parents:
diff changeset
   425
              earliestNode = node;
7f561c08de6b Initial load
duke
parents:
diff changeset
   426
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   427
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
   428
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   429
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   430
7f561c08de6b Initial load
duke
parents:
diff changeset
   431
      if (DTM.NULL != earliestNode)
7f561c08de6b Initial load
duke
parents:
diff changeset
   432
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   433
        m_iterators[iteratorUsed].nextNode();
7f561c08de6b Initial load
duke
parents:
diff changeset
   434
7f561c08de6b Initial load
duke
parents:
diff changeset
   435
        incrementCurrentPos();
7f561c08de6b Initial load
duke
parents:
diff changeset
   436
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   437
      else
7f561c08de6b Initial load
duke
parents:
diff changeset
   438
        m_foundLast = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   439
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   440
7f561c08de6b Initial load
duke
parents:
diff changeset
   441
    m_lastFetched = earliestNode;
7f561c08de6b Initial load
duke
parents:
diff changeset
   442
7f561c08de6b Initial load
duke
parents:
diff changeset
   443
    return earliestNode;
7f561c08de6b Initial load
duke
parents:
diff changeset
   444
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   445
7f561c08de6b Initial load
duke
parents:
diff changeset
   446
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   447
   * This function is used to fixup variables from QNames to stack frame
7f561c08de6b Initial load
duke
parents:
diff changeset
   448
   * indexes at stylesheet build time.
7f561c08de6b Initial load
duke
parents:
diff changeset
   449
   * @param vars List of QNames that correspond to variables.  This list
7f561c08de6b Initial load
duke
parents:
diff changeset
   450
   * should be searched backwards for the first qualified name that
7f561c08de6b Initial load
duke
parents:
diff changeset
   451
   * corresponds to the variable reference qname.  The position of the
7f561c08de6b Initial load
duke
parents:
diff changeset
   452
   * QName in the vector from the start of the vector will be its position
7f561c08de6b Initial load
duke
parents:
diff changeset
   453
   * in the stack frame (but variables above the globalsTop value will need
7f561c08de6b Initial load
duke
parents:
diff changeset
   454
   * to be offset to the current stack frame).
7f561c08de6b Initial load
duke
parents:
diff changeset
   455
   */
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   456
  public void fixupVariables(List<QName> vars, int globalsSize)
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   457
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   458
    for (int i = 0; i < m_exprs.length; i++)
7f561c08de6b Initial load
duke
parents:
diff changeset
   459
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   460
      m_exprs[i].fixupVariables(vars, globalsSize);
7f561c08de6b Initial load
duke
parents:
diff changeset
   461
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   462
7f561c08de6b Initial load
duke
parents:
diff changeset
   463
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   464
7f561c08de6b Initial load
duke
parents:
diff changeset
   465
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   466
   * The location path iterators, one for each
7f561c08de6b Initial load
duke
parents:
diff changeset
   467
   * <a href="http://www.w3.org/TR/xpath#NT-LocationPath">location
7f561c08de6b Initial load
duke
parents:
diff changeset
   468
   * path</a> contained in the union expression.
7f561c08de6b Initial load
duke
parents:
diff changeset
   469
   * @serial
7f561c08de6b Initial load
duke
parents:
diff changeset
   470
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   471
  protected LocPathIterator[] m_exprs;
7f561c08de6b Initial load
duke
parents:
diff changeset
   472
7f561c08de6b Initial load
duke
parents:
diff changeset
   473
7f561c08de6b Initial load
duke
parents:
diff changeset
   474
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   475
   * The location path iterators, one for each
7f561c08de6b Initial load
duke
parents:
diff changeset
   476
   * <a href="http://www.w3.org/TR/xpath#NT-LocationPath">location
7f561c08de6b Initial load
duke
parents:
diff changeset
   477
   * path</a> contained in the union expression.
7f561c08de6b Initial load
duke
parents:
diff changeset
   478
   * @serial
7f561c08de6b Initial load
duke
parents:
diff changeset
   479
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   480
  protected DTMIterator[] m_iterators;
7f561c08de6b Initial load
duke
parents:
diff changeset
   481
7f561c08de6b Initial load
duke
parents:
diff changeset
   482
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   483
   * Returns the axis being iterated, if it is known.
7f561c08de6b Initial load
duke
parents:
diff changeset
   484
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   485
   * @return Axis.CHILD, etc., or -1 if the axis is not known or is of multiple
7f561c08de6b Initial load
duke
parents:
diff changeset
   486
   * types.
7f561c08de6b Initial load
duke
parents:
diff changeset
   487
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   488
  public int getAxis()
7f561c08de6b Initial load
duke
parents:
diff changeset
   489
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   490
    // Could be smarter.
7f561c08de6b Initial load
duke
parents:
diff changeset
   491
    return -1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   492
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   493
7f561c08de6b Initial load
duke
parents:
diff changeset
   494
  class iterOwner implements ExpressionOwner
7f561c08de6b Initial load
duke
parents:
diff changeset
   495
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   496
        int m_index;
7f561c08de6b Initial load
duke
parents:
diff changeset
   497
7f561c08de6b Initial load
duke
parents:
diff changeset
   498
        iterOwner(int index)
7f561c08de6b Initial load
duke
parents:
diff changeset
   499
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   500
                m_index = index;
7f561c08de6b Initial load
duke
parents:
diff changeset
   501
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   502
7f561c08de6b Initial load
duke
parents:
diff changeset
   503
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   504
     * @see ExpressionOwner#getExpression()
7f561c08de6b Initial load
duke
parents:
diff changeset
   505
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   506
    public Expression getExpression()
7f561c08de6b Initial load
duke
parents:
diff changeset
   507
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   508
      return m_exprs[m_index];
7f561c08de6b Initial load
duke
parents:
diff changeset
   509
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   510
7f561c08de6b Initial load
duke
parents:
diff changeset
   511
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   512
     * @see ExpressionOwner#setExpression(Expression)
7f561c08de6b Initial load
duke
parents:
diff changeset
   513
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   514
    public void setExpression(Expression exp)
7f561c08de6b Initial load
duke
parents:
diff changeset
   515
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   516
7f561c08de6b Initial load
duke
parents:
diff changeset
   517
        if(!(exp instanceof LocPathIterator))
7f561c08de6b Initial load
duke
parents:
diff changeset
   518
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   519
                // Yuck.  Need FilterExprIter.  Or make it so m_exprs can be just
7f561c08de6b Initial load
duke
parents:
diff changeset
   520
                // plain expressions?
7f561c08de6b Initial load
duke
parents:
diff changeset
   521
                WalkingIterator wi = new WalkingIterator(getPrefixResolver());
7f561c08de6b Initial load
duke
parents:
diff changeset
   522
                FilterExprWalker few = new FilterExprWalker(wi);
7f561c08de6b Initial load
duke
parents:
diff changeset
   523
                wi.setFirstWalker(few);
7f561c08de6b Initial load
duke
parents:
diff changeset
   524
                few.setInnerExpression(exp);
7f561c08de6b Initial load
duke
parents:
diff changeset
   525
                wi.exprSetParent(UnionPathIterator.this);
7f561c08de6b Initial load
duke
parents:
diff changeset
   526
                few.exprSetParent(wi);
7f561c08de6b Initial load
duke
parents:
diff changeset
   527
                exp.exprSetParent(few);
7f561c08de6b Initial load
duke
parents:
diff changeset
   528
                exp = wi;
7f561c08de6b Initial load
duke
parents:
diff changeset
   529
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   530
        else
7f561c08de6b Initial load
duke
parents:
diff changeset
   531
                exp.exprSetParent(UnionPathIterator.this);
7f561c08de6b Initial load
duke
parents:
diff changeset
   532
        m_exprs[m_index] = (LocPathIterator)exp;
7f561c08de6b Initial load
duke
parents:
diff changeset
   533
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   534
7f561c08de6b Initial load
duke
parents:
diff changeset
   535
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   536
7f561c08de6b Initial load
duke
parents:
diff changeset
   537
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   538
   * @see com.sun.org.apache.xpath.internal.XPathVisitable#callVisitors(ExpressionOwner, XPathVisitor)
7f561c08de6b Initial load
duke
parents:
diff changeset
   539
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   540
  public void callVisitors(ExpressionOwner owner, XPathVisitor visitor)
7f561c08de6b Initial load
duke
parents:
diff changeset
   541
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   542
                if(visitor.visitUnionPath(owner, this))
7f561c08de6b Initial load
duke
parents:
diff changeset
   543
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
   544
                        if(null != m_exprs)
7f561c08de6b Initial load
duke
parents:
diff changeset
   545
                        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   546
                                int n = m_exprs.length;
7f561c08de6b Initial load
duke
parents:
diff changeset
   547
                                for(int i = 0; i < n; i++)
7f561c08de6b Initial load
duke
parents:
diff changeset
   548
                                {
7f561c08de6b Initial load
duke
parents:
diff changeset
   549
                                        m_exprs[i].callVisitors(new iterOwner(i), visitor);
7f561c08de6b Initial load
duke
parents:
diff changeset
   550
                                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   551
                        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   552
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   553
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   554
7f561c08de6b Initial load
duke
parents:
diff changeset
   555
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   556
     * @see Expression#deepEquals(Expression)
7f561c08de6b Initial load
duke
parents:
diff changeset
   557
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   558
    public boolean deepEquals(Expression expr)
7f561c08de6b Initial load
duke
parents:
diff changeset
   559
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   560
      if (!super.deepEquals(expr))
7f561c08de6b Initial load
duke
parents:
diff changeset
   561
            return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   562
7f561c08de6b Initial load
duke
parents:
diff changeset
   563
      UnionPathIterator upi = (UnionPathIterator) expr;
7f561c08de6b Initial load
duke
parents:
diff changeset
   564
7f561c08de6b Initial load
duke
parents:
diff changeset
   565
      if (null != m_exprs)
7f561c08de6b Initial load
duke
parents:
diff changeset
   566
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   567
        int n = m_exprs.length;
7f561c08de6b Initial load
duke
parents:
diff changeset
   568
7f561c08de6b Initial load
duke
parents:
diff changeset
   569
        if((null == upi.m_exprs) || (upi.m_exprs.length != n))
7f561c08de6b Initial load
duke
parents:
diff changeset
   570
                return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   571
7f561c08de6b Initial load
duke
parents:
diff changeset
   572
        for (int i = 0; i < n; i++)
7f561c08de6b Initial load
duke
parents:
diff changeset
   573
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   574
          if(!m_exprs[i].deepEquals(upi.m_exprs[i]))
7f561c08de6b Initial load
duke
parents:
diff changeset
   575
                return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   576
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   577
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   578
      else if (null != upi.m_exprs)
7f561c08de6b Initial load
duke
parents:
diff changeset
   579
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   580
          return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   581
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   582
7f561c08de6b Initial load
duke
parents:
diff changeset
   583
      return true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   584
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   585
7f561c08de6b Initial load
duke
parents:
diff changeset
   586
7f561c08de6b Initial load
duke
parents:
diff changeset
   587
}