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