src/java.xml/share/classes/com/sun/org/apache/xpath/internal/functions/Function3Args.java
changeset 47216 71c04702a3d5
parent 44797 8b3b3b911b8a
child 47359 e1a6c0168741
equal deleted inserted replaced
47215:4ebc2e2fb97c 47216:71c04702a3d5
       
     1 /*
       
     2  * reserved comment block
       
     3  * DO NOT REMOVE OR ALTER!
       
     4  */
       
     5 /*
       
     6  * Licensed to the Apache Software Foundation (ASF) under one or more
       
     7  * contributor license agreements.  See the NOTICE file distributed with
       
     8  * this work for additional information regarding copyright ownership.
       
     9  * The ASF licenses this file to You under the Apache License, Version 2.0
       
    10  * (the "License"); you may not use this file except in compliance with
       
    11  * the License.  You may obtain a copy of the License at
       
    12  *
       
    13  *      http://www.apache.org/licenses/LICENSE-2.0
       
    14  *
       
    15  * Unless required by applicable law or agreed to in writing, software
       
    16  * distributed under the License is distributed on an "AS IS" BASIS,
       
    17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       
    18  * See the License for the specific language governing permissions and
       
    19  * limitations under the License.
       
    20  */
       
    21 
       
    22 package com.sun.org.apache.xpath.internal.functions;
       
    23 
       
    24 import com.sun.org.apache.xalan.internal.res.XSLMessages;
       
    25 import com.sun.org.apache.xpath.internal.Expression;
       
    26 import com.sun.org.apache.xpath.internal.ExpressionOwner;
       
    27 import com.sun.org.apache.xpath.internal.XPathVisitor;
       
    28 
       
    29 /**
       
    30  * Base class for functions that accept three arguments.
       
    31  * @xsl.usage advanced
       
    32  */
       
    33 public class Function3Args extends Function2Args
       
    34 {
       
    35     static final long serialVersionUID = 7915240747161506646L;
       
    36 
       
    37   /** The third argument passed to the function (at index 2).
       
    38    *  @serial  */
       
    39   Expression m_arg2;
       
    40 
       
    41   /**
       
    42    * Return the third argument passed to the function (at index 2).
       
    43    *
       
    44    * @return An expression that represents the third argument passed to the
       
    45    *         function.
       
    46    */
       
    47   public Expression getArg2()
       
    48   {
       
    49     return m_arg2;
       
    50   }
       
    51 
       
    52   /**
       
    53    * This function is used to fixup variables from QNames to stack frame
       
    54    * indexes at stylesheet build time.
       
    55    * @param vars List of QNames that correspond to variables.  This list
       
    56    * should be searched backwards for the first qualified name that
       
    57    * corresponds to the variable reference qname.  The position of the
       
    58    * QName in the vector from the start of the vector will be its position
       
    59    * in the stack frame (but variables above the globalsTop value will need
       
    60    * to be offset to the current stack frame).
       
    61    */
       
    62   public void fixupVariables(java.util.Vector vars, int globalsSize)
       
    63   {
       
    64     super.fixupVariables(vars, globalsSize);
       
    65     if(null != m_arg2)
       
    66       m_arg2.fixupVariables(vars, globalsSize);
       
    67   }
       
    68 
       
    69   /**
       
    70    * Set an argument expression for a function.  This method is called by the
       
    71    * XPath compiler.
       
    72    *
       
    73    * @param arg non-null expression that represents the argument.
       
    74    * @param argNum The argument number index.
       
    75    *
       
    76    * @throws WrongNumberArgsException If the argNum parameter is greater than 2.
       
    77    */
       
    78   public void setArg(Expression arg, int argNum)
       
    79           throws WrongNumberArgsException
       
    80   {
       
    81 
       
    82     if (argNum < 2)
       
    83       super.setArg(arg, argNum);
       
    84     else if (2 == argNum)
       
    85     {
       
    86       m_arg2 = arg;
       
    87       arg.exprSetParent(this);
       
    88     }
       
    89     else
       
    90                   reportWrongNumberArgs();
       
    91   }
       
    92 
       
    93   /**
       
    94    * Check that the number of arguments passed to this function is correct.
       
    95    *
       
    96    *
       
    97    * @param argNum The number of arguments that is being passed to the function.
       
    98    *
       
    99    * @throws WrongNumberArgsException
       
   100    */
       
   101   public void checkNumberArgs(int argNum) throws WrongNumberArgsException
       
   102   {
       
   103     if (argNum != 3)
       
   104       reportWrongNumberArgs();
       
   105   }
       
   106 
       
   107   /**
       
   108    * Constructs and throws a WrongNumberArgException with the appropriate
       
   109    * message for this function object.
       
   110    *
       
   111    * @throws WrongNumberArgsException
       
   112    */
       
   113   protected void reportWrongNumberArgs() throws WrongNumberArgsException {
       
   114       throw new WrongNumberArgsException(XSLMessages.createXPATHMessage("three", null));
       
   115   }
       
   116 
       
   117   /**
       
   118    * Tell if this expression or it's subexpressions can traverse outside
       
   119    * the current subtree.
       
   120    *
       
   121    * @return true if traversal outside the context node's subtree can occur.
       
   122    */
       
   123    public boolean canTraverseOutsideSubtree()
       
   124    {
       
   125     return super.canTraverseOutsideSubtree()
       
   126     ? true : m_arg2.canTraverseOutsideSubtree();
       
   127    }
       
   128 
       
   129   class Arg2Owner implements ExpressionOwner
       
   130   {
       
   131     /**
       
   132      * @see ExpressionOwner#getExpression()
       
   133      */
       
   134     public Expression getExpression()
       
   135     {
       
   136       return m_arg2;
       
   137     }
       
   138 
       
   139 
       
   140     /**
       
   141      * @see ExpressionOwner#setExpression(Expression)
       
   142      */
       
   143     public void setExpression(Expression exp)
       
   144     {
       
   145         exp.exprSetParent(Function3Args.this);
       
   146         m_arg2 = exp;
       
   147     }
       
   148   }
       
   149 
       
   150 
       
   151   /**
       
   152    * @see com.sun.org.apache.xpath.internal.XPathVisitable#callVisitors(ExpressionOwner, XPathVisitor)
       
   153    */
       
   154   public void callArgVisitors(XPathVisitor visitor)
       
   155   {
       
   156         super.callArgVisitors(visitor);
       
   157         if(null != m_arg2)
       
   158                 m_arg2.callVisitors(new Arg2Owner(), visitor);
       
   159   }
       
   160 
       
   161   /**
       
   162    * @see Expression#deepEquals(Expression)
       
   163    */
       
   164   public boolean deepEquals(Expression expr)
       
   165   {
       
   166         if(!super.deepEquals(expr))
       
   167                 return false;
       
   168 
       
   169         if(null != m_arg2)
       
   170         {
       
   171                 if(null == ((Function3Args)expr).m_arg2)
       
   172                         return false;
       
   173 
       
   174                 if(!m_arg2.deepEquals(((Function3Args)expr).m_arg2))
       
   175                         return false;
       
   176         }
       
   177         else if (null != ((Function3Args)expr).m_arg2)
       
   178                 return false;
       
   179 
       
   180         return true;
       
   181   }
       
   182 
       
   183 
       
   184 }