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