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