src/java.xml/share/classes/com/sun/org/apache/xpath/internal/functions/Function2Args.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.functions;
7f561c08de6b Initial load
duke
parents:
diff changeset
    23
7f561c08de6b Initial load
duke
parents:
diff changeset
    24
import com.sun.org.apache.xalan.internal.res.XSLMessages;
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.Expression;
7f561c08de6b Initial load
duke
parents:
diff changeset
    27
import com.sun.org.apache.xpath.internal.ExpressionOwner;
7f561c08de6b Initial load
duke
parents:
diff changeset
    28
import com.sun.org.apache.xpath.internal.XPathVisitor;
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
 * Base class for functions that accept two arguments.
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
 * @xsl.usage advanced
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
public class Function2Args extends FunctionOneArg
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
{
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
    static final long serialVersionUID = 5574294996842710641L;
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
  /** The second argument passed to the function (at index 1).
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
   *  @serial  */
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
  Expression m_arg1;
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
   * Return the second argument passed to the function (at index 1).
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
   * @return An expression that represents the second argument passed to the
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
   *         function.
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
  public Expression getArg1()
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
    return m_arg1;
7f561c08de6b Initial load
duke
parents:
diff changeset
    52
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
   * This function is used to fixup variables from QNames to stack frame
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
   * indexes at stylesheet build time.
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
   * @param vars List of QNames that correspond to variables.  This list
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
   * should be searched backwards for the first qualified name that
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
   * corresponds to the variable reference qname.  The position of the
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
   * QName in the vector from the start of the vector will be its position
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
   * in the stack frame (but variables above the globalsTop value will need
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
   * to be offset to the current stack frame).
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
   */
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
    64
  public void fixupVariables(List<QName> vars, int globalsSize)
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
    super.fixupVariables(vars, globalsSize);
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
    if(null != m_arg1)
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
      m_arg1.fixupVariables(vars, globalsSize);
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
   * Set an argument expression for a function.  This method is called by the
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
   * XPath compiler.
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
   * @param arg non-null expression that represents the argument.
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
   * @param argNum The argument number index.
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
   * @throws WrongNumberArgsException If the argNum parameter is greater than 1.
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
  public void setArg(Expression arg, int argNum)
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
          throws WrongNumberArgsException
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
    // System.out.println("argNum: "+argNum);
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
    if (argNum == 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
      super.setArg(arg, argNum);
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
    else if (1 == argNum)
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
      m_arg1 = arg;
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
      arg.exprSetParent(this);
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
                  reportWrongNumberArgs();
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
   * Check that the number of arguments passed to this function is correct.
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
   * @param argNum The number of arguments that is being passed to the function.
7f561c08de6b Initial load
duke
parents:
diff changeset
   102
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
   * @throws WrongNumberArgsException
7f561c08de6b Initial load
duke
parents:
diff changeset
   104
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
  public void checkNumberArgs(int argNum) throws WrongNumberArgsException
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
    if (argNum != 2)
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
      reportWrongNumberArgs();
7f561c08de6b Initial load
duke
parents:
diff changeset
   109
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   110
7f561c08de6b Initial load
duke
parents:
diff changeset
   111
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   112
   * Constructs and throws a WrongNumberArgException with the appropriate
7f561c08de6b Initial load
duke
parents:
diff changeset
   113
   * message for this function object.
7f561c08de6b Initial load
duke
parents:
diff changeset
   114
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   115
   * @throws WrongNumberArgsException
7f561c08de6b Initial load
duke
parents:
diff changeset
   116
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   117
  protected void reportWrongNumberArgs() throws WrongNumberArgsException {
7f561c08de6b Initial load
duke
parents:
diff changeset
   118
      throw new WrongNumberArgsException(XSLMessages.createXPATHMessage("two", null));
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
7f561c08de6b Initial load
duke
parents:
diff changeset
   121
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
   * Tell if this expression or it's subexpressions can traverse outside
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
   * the current subtree.
7f561c08de6b Initial load
duke
parents:
diff changeset
   124
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   125
   * @return true if traversal outside the context node's subtree can occur.
7f561c08de6b Initial load
duke
parents:
diff changeset
   126
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   127
   public boolean canTraverseOutsideSubtree()
7f561c08de6b Initial load
duke
parents:
diff changeset
   128
   {
7f561c08de6b Initial load
duke
parents:
diff changeset
   129
    return super.canTraverseOutsideSubtree()
7f561c08de6b Initial load
duke
parents:
diff changeset
   130
    ? true : m_arg1.canTraverseOutsideSubtree();
7f561c08de6b Initial load
duke
parents:
diff changeset
   131
   }
7f561c08de6b Initial load
duke
parents:
diff changeset
   132
7f561c08de6b Initial load
duke
parents:
diff changeset
   133
  class Arg1Owner implements ExpressionOwner
7f561c08de6b Initial load
duke
parents:
diff changeset
   134
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   135
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   136
     * @see ExpressionOwner#getExpression()
7f561c08de6b Initial load
duke
parents:
diff changeset
   137
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   138
    public Expression getExpression()
7f561c08de6b Initial load
duke
parents:
diff changeset
   139
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   140
      return m_arg1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   141
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   142
7f561c08de6b Initial load
duke
parents:
diff changeset
   143
7f561c08de6b Initial load
duke
parents:
diff changeset
   144
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   145
     * @see ExpressionOwner#setExpression(Expression)
7f561c08de6b Initial load
duke
parents:
diff changeset
   146
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   147
    public void setExpression(Expression exp)
7f561c08de6b Initial load
duke
parents:
diff changeset
   148
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   149
        exp.exprSetParent(Function2Args.this);
7f561c08de6b Initial load
duke
parents:
diff changeset
   150
        m_arg1 = exp;
7f561c08de6b Initial load
duke
parents:
diff changeset
   151
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   152
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   153
7f561c08de6b Initial load
duke
parents:
diff changeset
   154
7f561c08de6b Initial load
duke
parents:
diff changeset
   155
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   156
   * @see com.sun.org.apache.xpath.internal.XPathVisitable#callVisitors(ExpressionOwner, XPathVisitor)
7f561c08de6b Initial load
duke
parents:
diff changeset
   157
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   158
  public void callArgVisitors(XPathVisitor visitor)
7f561c08de6b Initial load
duke
parents:
diff changeset
   159
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   160
        super.callArgVisitors(visitor);
7f561c08de6b Initial load
duke
parents:
diff changeset
   161
        if(null != m_arg1)
7f561c08de6b Initial load
duke
parents:
diff changeset
   162
                m_arg1.callVisitors(new Arg1Owner(), visitor);
7f561c08de6b Initial load
duke
parents:
diff changeset
   163
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   164
7f561c08de6b Initial load
duke
parents:
diff changeset
   165
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   166
   * @see Expression#deepEquals(Expression)
7f561c08de6b Initial load
duke
parents:
diff changeset
   167
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   168
  public boolean deepEquals(Expression expr)
7f561c08de6b Initial load
duke
parents:
diff changeset
   169
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   170
        if(!super.deepEquals(expr))
7f561c08de6b Initial load
duke
parents:
diff changeset
   171
                return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   172
7f561c08de6b Initial load
duke
parents:
diff changeset
   173
        if(null != m_arg1)
7f561c08de6b Initial load
duke
parents:
diff changeset
   174
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   175
                if(null == ((Function2Args)expr).m_arg1)
7f561c08de6b Initial load
duke
parents:
diff changeset
   176
                        return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   177
7f561c08de6b Initial load
duke
parents:
diff changeset
   178
                if(!m_arg1.deepEquals(((Function2Args)expr).m_arg1))
7f561c08de6b Initial load
duke
parents:
diff changeset
   179
                        return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   180
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   181
        else if(null != ((Function2Args)expr).m_arg1)
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
7f561c08de6b Initial load
duke
parents:
diff changeset
   187
}