src/java.xml/share/classes/com/sun/org/apache/xpath/internal/axes/WalkingIteratorSorted.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.utils.PrefixResolver;
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
    26
import com.sun.org.apache.xml.internal.utils.QName;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    27
import com.sun.org.apache.xpath.internal.compiler.Compiler;
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
    28
import java.util.List;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
 * This class iterates over set of nodes that needs to be sorted.
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
 * @xsl.usage internal
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
public class WalkingIteratorSorted extends WalkingIterator
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
{
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
    static final long serialVersionUID = -4512512007542368213L;
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
//  /** True if the nodes will be found in document order */
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
//  protected boolean m_inNaturalOrder = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
  /** True if the nodes will be found in document order, and this can
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
   * be determined statically. */
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
  protected boolean m_inNaturalOrderStatic = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
   * Create a WalkingIteratorSorted object.
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
   * @param nscontext The namespace context for this iterator,
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
   * should be OK if null.
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
  public WalkingIteratorSorted(PrefixResolver nscontext)
7f561c08de6b Initial load
duke
parents:
diff changeset
    52
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
    super(nscontext);
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
   * Create a WalkingIterator iterator, including creation
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
   * of step walkers from the opcode list, and call back
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
   * into the Compiler to create predicate expressions.
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
   * @param compiler The Compiler which is creating
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
   * this expression.
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
   * @param opPos The position of this iterator in the
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
   * opcode list from the compiler.
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
   * @param shouldLoadWalkers True if walkers should be
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
   * loaded, or false if this is a derived iterator and
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
   * it doesn't wish to load child walkers.
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
   * @throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
  WalkingIteratorSorted(
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
          Compiler compiler, int opPos, int analysis, boolean shouldLoadWalkers)
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
            throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
    super(compiler, opPos, analysis, shouldLoadWalkers);
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
   * Returns true if all the nodes in the iteration well be returned in document
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
   * order.
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
   * @return true as a default.
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
  public boolean isDocOrdered()
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
    return m_inNaturalOrderStatic;
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
   * Tell if the nodeset can be walked in doc order, via static analysis.
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
   * @return true if the nodeset can be walked in doc order, without sorting.
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
  boolean canBeWalkedInNaturalDocOrderStatic()
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
    if (null != m_firstWalker)
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
      AxesWalker walker = m_firstWalker;
7f561c08de6b Initial load
duke
parents:
diff changeset
   102
      int prevAxis = -1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
      boolean prevIsSimpleDownAxis = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   104
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
      for(int i = 0; null != walker; i++)
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
        int axis = walker.getAxis();
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
7f561c08de6b Initial load
duke
parents:
diff changeset
   109
        if(walker.isDocOrdered())
7f561c08de6b Initial load
duke
parents:
diff changeset
   110
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   111
          boolean isSimpleDownAxis = ((axis == Axis.CHILD)
7f561c08de6b Initial load
duke
parents:
diff changeset
   112
                                   || (axis == Axis.SELF)
7f561c08de6b Initial load
duke
parents:
diff changeset
   113
                                   || (axis == Axis.ROOT));
7f561c08de6b Initial load
duke
parents:
diff changeset
   114
          // Catching the filtered list here is only OK because
7f561c08de6b Initial load
duke
parents:
diff changeset
   115
          // FilterExprWalker#isDocOrdered() did the right thing.
7f561c08de6b Initial load
duke
parents:
diff changeset
   116
          if(isSimpleDownAxis || (axis == -1))
7f561c08de6b Initial load
duke
parents:
diff changeset
   117
            walker = walker.getNextWalker();
7f561c08de6b Initial load
duke
parents:
diff changeset
   118
          else
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
          {
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
            boolean isLastWalker = (null == walker.getNextWalker());
7f561c08de6b Initial load
duke
parents:
diff changeset
   121
            if(isLastWalker)
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
              if(walker.isDocOrdered() && (axis == Axis.DESCENDANT ||
7f561c08de6b Initial load
duke
parents:
diff changeset
   124
                 axis == Axis.DESCENDANTORSELF || axis == Axis.DESCENDANTSFROMROOT
7f561c08de6b Initial load
duke
parents:
diff changeset
   125
                 || axis == Axis.DESCENDANTSORSELFFROMROOT) || (axis == Axis.ATTRIBUTE))
7f561c08de6b Initial load
duke
parents:
diff changeset
   126
                return true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   127
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   128
            return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   129
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
   130
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   131
        else
7f561c08de6b Initial load
duke
parents:
diff changeset
   132
          return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   133
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   134
      return true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   135
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   136
    return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   137
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   138
7f561c08de6b Initial load
duke
parents:
diff changeset
   139
7f561c08de6b Initial load
duke
parents:
diff changeset
   140
//  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   141
//   * NEEDSDOC Method canBeWalkedInNaturalDocOrder
7f561c08de6b Initial load
duke
parents:
diff changeset
   142
//   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   143
//   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   144
//   * NEEDSDOC (canBeWalkedInNaturalDocOrder) @return
7f561c08de6b Initial load
duke
parents:
diff changeset
   145
//   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   146
//  boolean canBeWalkedInNaturalDocOrder()
7f561c08de6b Initial load
duke
parents:
diff changeset
   147
//  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   148
//
7f561c08de6b Initial load
duke
parents:
diff changeset
   149
//    if (null != m_firstWalker)
7f561c08de6b Initial load
duke
parents:
diff changeset
   150
//    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   151
//      AxesWalker walker = m_firstWalker;
7f561c08de6b Initial load
duke
parents:
diff changeset
   152
//      int prevAxis = -1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   153
//      boolean prevIsSimpleDownAxis = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   154
//
7f561c08de6b Initial load
duke
parents:
diff changeset
   155
//      for(int i = 0; null != walker; i++)
7f561c08de6b Initial load
duke
parents:
diff changeset
   156
//      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   157
//        int axis = walker.getAxis();
7f561c08de6b Initial load
duke
parents:
diff changeset
   158
//
7f561c08de6b Initial load
duke
parents:
diff changeset
   159
//        if(walker.isDocOrdered())
7f561c08de6b Initial load
duke
parents:
diff changeset
   160
//        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   161
//          boolean isSimpleDownAxis = ((axis == Axis.CHILD)
7f561c08de6b Initial load
duke
parents:
diff changeset
   162
//                                   || (axis == Axis.SELF)
7f561c08de6b Initial load
duke
parents:
diff changeset
   163
//                                   || (axis == Axis.ROOT));
7f561c08de6b Initial load
duke
parents:
diff changeset
   164
//          // Catching the filtered list here is only OK because
7f561c08de6b Initial load
duke
parents:
diff changeset
   165
//          // FilterExprWalker#isDocOrdered() did the right thing.
7f561c08de6b Initial load
duke
parents:
diff changeset
   166
//          if(isSimpleDownAxis || (axis == -1))
7f561c08de6b Initial load
duke
parents:
diff changeset
   167
//            walker = walker.getNextWalker();
7f561c08de6b Initial load
duke
parents:
diff changeset
   168
//          else
7f561c08de6b Initial load
duke
parents:
diff changeset
   169
//          {
7f561c08de6b Initial load
duke
parents:
diff changeset
   170
//            boolean isLastWalker = (null == walker.getNextWalker());
7f561c08de6b Initial load
duke
parents:
diff changeset
   171
//            if(isLastWalker)
7f561c08de6b Initial load
duke
parents:
diff changeset
   172
//            {
7f561c08de6b Initial load
duke
parents:
diff changeset
   173
//              if(walker.isDocOrdered() && (axis == Axis.DESCENDANT ||
7f561c08de6b Initial load
duke
parents:
diff changeset
   174
//                 axis == Axis.DESCENDANTORSELF || axis == Axis.DESCENDANTSFROMROOT
7f561c08de6b Initial load
duke
parents:
diff changeset
   175
//                 || axis == Axis.DESCENDANTSORSELFFROMROOT) || (axis == Axis.ATTRIBUTE))
7f561c08de6b Initial load
duke
parents:
diff changeset
   176
//                return true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   177
//            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   178
//            return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   179
//          }
7f561c08de6b Initial load
duke
parents:
diff changeset
   180
//        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   181
//        else
7f561c08de6b Initial load
duke
parents:
diff changeset
   182
//          return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   183
//      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   184
//      return true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   185
//    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   186
//    return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   187
//  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   188
7f561c08de6b Initial load
duke
parents:
diff changeset
   189
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   190
   * This function is used to perform some extra analysis of the iterator.
7f561c08de6b Initial load
duke
parents:
diff changeset
   191
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   192
   * @param vars List of QNames that correspond to variables.  This list
7f561c08de6b Initial load
duke
parents:
diff changeset
   193
   * should be searched backwards for the first qualified name that
7f561c08de6b Initial load
duke
parents:
diff changeset
   194
   * corresponds to the variable reference qname.  The position of the
7f561c08de6b Initial load
duke
parents:
diff changeset
   195
   * QName in the vector from the start of the vector will be its position
7f561c08de6b Initial load
duke
parents:
diff changeset
   196
   * in the stack frame (but variables above the globalsTop value will need
7f561c08de6b Initial load
duke
parents:
diff changeset
   197
   * to be offset to the current stack frame).
7f561c08de6b Initial load
duke
parents:
diff changeset
   198
   */
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   199
  public void fixupVariables(List<QName> vars, int globalsSize)
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   200
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   201
    super.fixupVariables(vars, globalsSize);
7f561c08de6b Initial load
duke
parents:
diff changeset
   202
7f561c08de6b Initial load
duke
parents:
diff changeset
   203
    int analysis = getAnalysisBits();
7f561c08de6b Initial load
duke
parents:
diff changeset
   204
    if(WalkerFactory.isNaturalDocOrder(analysis))
7f561c08de6b Initial load
duke
parents:
diff changeset
   205
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   206
        m_inNaturalOrderStatic = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   207
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   208
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
   209
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   210
        m_inNaturalOrderStatic = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   211
        // System.out.println("Setting natural doc order to false: "+
7f561c08de6b Initial load
duke
parents:
diff changeset
   212
        //    WalkerFactory.getAnalysisString(analysis));
7f561c08de6b Initial load
duke
parents:
diff changeset
   213
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   214
7f561c08de6b Initial load
duke
parents:
diff changeset
   215
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   216
7f561c08de6b Initial load
duke
parents:
diff changeset
   217
}