1 16 19 package org.apache.xpath.functions; 20 21 import org.apache.xalan.res.XSLMessages; 22 import org.apache.xpath.Expression; 23 import org.apache.xpath.ExpressionOwner; 24 import org.apache.xpath.XPathVisitor; 25 import org.apache.xpath.res.XPATHErrorResources; 26 27 32 public class FunctionMultiArgs extends Function3Args 33 { 34 35 37 Expression[] m_args; 38 39 44 public Expression[] getArgs() 45 { 46 return m_args; 47 } 48 49 59 public void setArg(Expression arg, int argNum) 60 throws WrongNumberArgsException 61 { 62 63 if (argNum < 3) 64 super.setArg(arg, argNum); 65 else 66 { 67 if (null == m_args) 68 { 69 m_args = new Expression[1]; 70 m_args[0] = arg; 71 } 72 else 73 { 74 75 Expression[] args = new Expression[m_args.length + 1]; 77 78 System.arraycopy(m_args, 0, args, 0, m_args.length); 79 80 args[m_args.length] = arg; 81 m_args = args; 82 } 83 arg.exprSetParent(this); 84 } 85 } 86 87 97 public void fixupVariables(java.util.Vector vars, int globalsSize) 98 { 99 super.fixupVariables(vars, globalsSize); 100 if(null != m_args) 101 { 102 for (int i = 0; i < m_args.length; i++) 103 { 104 m_args[i].fixupVariables(vars, globalsSize); 105 } 106 } 107 } 108 109 117 public void checkNumberArgs(int argNum) throws WrongNumberArgsException{} 118 119 126 protected void reportWrongNumberArgs() throws WrongNumberArgsException { 127 String fMsg = XSLMessages.createXPATHMessage( 128 XPATHErrorResources.ER_INCORRECT_PROGRAMMER_ASSERTION, 129 new Object []{ "Programmer's assertion: the method FunctionMultiArgs.reportWrongNumberArgs() should never be called." }); 130 131 throw new RuntimeException (fMsg); 132 } 133 134 140 public boolean canTraverseOutsideSubtree() 141 { 142 143 if (super.canTraverseOutsideSubtree()) 144 return true; 145 else 146 { 147 int n = m_args.length; 148 149 for (int i = 0; i < n; i++) 150 { 151 if (m_args[i].canTraverseOutsideSubtree()) 152 return true; 153 } 154 155 return false; 156 } 157 } 158 159 class ArgMultiOwner implements ExpressionOwner 160 { 161 int m_argIndex; 162 163 ArgMultiOwner(int index) 164 { 165 m_argIndex = index; 166 } 167 168 171 public Expression getExpression() 172 { 173 return m_args[m_argIndex]; 174 } 175 176 177 180 public void setExpression(Expression exp) 181 { 182 exp.exprSetParent(FunctionMultiArgs.this); 183 m_args[m_argIndex] = exp; 184 } 185 } 186 187 188 191 public void callArgVisitors(XPathVisitor visitor) 192 { 193 super.callArgVisitors(visitor); 194 if (null != m_args) 195 { 196 int n = m_args.length; 197 for (int i = 0; i < n; i++) 198 { 199 m_args[i].callVisitors(new ArgMultiOwner(i), visitor); 200 } 201 } 202 } 203 204 207 public boolean deepEquals(Expression expr) 208 { 209 if (!super.deepEquals(expr)) 210 return false; 211 212 FunctionMultiArgs fma = (FunctionMultiArgs) expr; 213 if (null != m_args) 214 { 215 int n = m_args.length; 216 if ((null == fma) || (fma.m_args.length != n)) 217 return false; 218 219 for (int i = 0; i < n; i++) 220 { 221 if (!m_args[i].deepEquals(fma.m_args[i])) 222 return false; 223 } 224 225 } 226 else if (null != fma.m_args) 227 { 228 return false; 229 } 230 231 return true; 232 } 233 } 234 | Popular Tags |