src/java.xml/share/classes/com/sun/org/apache/xpath/internal/axes/UnionChildIterator.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.DTMIterator;
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
    25
import com.sun.org.apache.xml.internal.utils.QName;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    26
import com.sun.org.apache.xpath.internal.XPathContext;
7f561c08de6b Initial load
duke
parents:
diff changeset
    27
import com.sun.org.apache.xpath.internal.objects.XObject;
7f561c08de6b Initial load
duke
parents:
diff changeset
    28
import com.sun.org.apache.xpath.internal.patterns.NodeTest;
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
    29
import java.util.List;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
 * This class defines a simplified type of union iterator that only
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
 * tests along the child axes.  If the conditions are right, it is
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
 * much faster than using a UnionPathIterator.
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
public class UnionChildIterator extends ChildTestIterator
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
{
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
    static final long serialVersionUID = 3500298482193003495L;
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
   * Even though these may hold full LocPathIterators, this array does
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
   * not have to be cloned, since only the node test and predicate
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
   * portion are used, and these only need static information.  However,
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
   * also note that index predicates can not be used!
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
  private PredicatedNodeTest[] m_nodeTests = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
   * Constructor for UnionChildIterator
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
  public UnionChildIterator()
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
    52
    super(null);
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
   * Add a node test to the union list.
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
   * @param test reference to a NodeTest, which will be added
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
   * directly to the list of node tests (in other words, it will
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
   * not be cloned).  The parent of this test will be set to
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
   * this object.
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
  public void addNodeTest(PredicatedNodeTest test)
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
    // Increase array size by only 1 at a time.  Fix this
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
    // if it looks to be a problem.
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
    if (null == m_nodeTests)
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
      m_nodeTests = new PredicatedNodeTest[1];
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
      m_nodeTests[0] = test;
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
      PredicatedNodeTest[] tests = m_nodeTests;
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
      int len = m_nodeTests.length;
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
      m_nodeTests = new PredicatedNodeTest[len + 1];
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
      System.arraycopy(tests, 0, m_nodeTests, 0, len);
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
      m_nodeTests[len] = test;
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
    test.exprSetParent(this);
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
   * This function is used to fixup variables from QNames to stack frame
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
   * indexes at stylesheet build time.
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
   * @param vars List of QNames that correspond to variables.  This list
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
   * should be searched backwards for the first qualified name that
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
   * corresponds to the variable reference qname.  The position of the
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
   * QName in the vector from the start of the vector will be its position
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
   * in the stack frame (but variables above the globalsTop value will need
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
   * to be offset to the current stack frame).
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
   */
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
    97
  public void fixupVariables(List<QName> vars, int globalsSize)
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
    super.fixupVariables(vars, globalsSize);
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
    if (m_nodeTests != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
      for (int i = 0; i < m_nodeTests.length; i++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   102
        m_nodeTests[i].fixupVariables(vars, globalsSize);
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   104
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
   * Test whether a specified node is visible in the logical view of a
7f561c08de6b Initial load
duke
parents:
diff changeset
   109
   * TreeWalker or NodeIterator. This function will be called by the
7f561c08de6b Initial load
duke
parents:
diff changeset
   110
   * implementation of TreeWalker and NodeIterator; it is not intended to
7f561c08de6b Initial load
duke
parents:
diff changeset
   111
   * be called directly from user code.
7f561c08de6b Initial load
duke
parents:
diff changeset
   112
   * @param n  The node to check to see if it passes the filter or not.
7f561c08de6b Initial load
duke
parents:
diff changeset
   113
   * @return  a constant to determine whether the node is accepted,
7f561c08de6b Initial load
duke
parents:
diff changeset
   114
   *   rejected, or skipped, as defined  above .
7f561c08de6b Initial load
duke
parents:
diff changeset
   115
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   116
  public short acceptNode(int n)
7f561c08de6b Initial load
duke
parents:
diff changeset
   117
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   118
    XPathContext xctxt = getXPathContext();
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
    try
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   121
      xctxt.pushCurrentNode(n);
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
      for (int i = 0; i < m_nodeTests.length; i++)
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   124
        PredicatedNodeTest pnt = m_nodeTests[i];
7f561c08de6b Initial load
duke
parents:
diff changeset
   125
        XObject score = pnt.execute(xctxt, n);
7f561c08de6b Initial load
duke
parents:
diff changeset
   126
        if (score != NodeTest.SCORE_NONE)
7f561c08de6b Initial load
duke
parents:
diff changeset
   127
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   128
          // Note that we are assuming there are no positional predicates!
7f561c08de6b Initial load
duke
parents:
diff changeset
   129
          if (pnt.getPredicateCount() > 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
   130
          {
7f561c08de6b Initial load
duke
parents:
diff changeset
   131
            if (pnt.executePredicates(n, xctxt))
7f561c08de6b Initial load
duke
parents:
diff changeset
   132
              return DTMIterator.FILTER_ACCEPT;
7f561c08de6b Initial load
duke
parents:
diff changeset
   133
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
   134
          else
7f561c08de6b Initial load
duke
parents:
diff changeset
   135
            return DTMIterator.FILTER_ACCEPT;
7f561c08de6b Initial load
duke
parents:
diff changeset
   136
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
    catch (javax.xml.transform.TransformerException se)
7f561c08de6b Initial load
duke
parents:
diff changeset
   141
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   142
7f561c08de6b Initial load
duke
parents:
diff changeset
   143
      // TODO: Fix this.
7f561c08de6b Initial load
duke
parents:
diff changeset
   144
      throw new RuntimeException(se.getMessage());
7f561c08de6b Initial load
duke
parents:
diff changeset
   145
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   146
    finally
7f561c08de6b Initial load
duke
parents:
diff changeset
   147
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   148
      xctxt.popCurrentNode();
7f561c08de6b Initial load
duke
parents:
diff changeset
   149
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   150
    return DTMIterator.FILTER_SKIP;
7f561c08de6b Initial load
duke
parents:
diff changeset
   151
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   152
7f561c08de6b Initial load
duke
parents:
diff changeset
   153
}