1 16 19 package com.sun.org.apache.xpath.internal.functions; 20 21 import java.util.Vector ; 22 23 import com.sun.org.apache.xalan.internal.res.XSLMessages; 24 import com.sun.org.apache.xpath.internal.Expression; 25 import com.sun.org.apache.xpath.internal.ExpressionNode; 26 import com.sun.org.apache.xpath.internal.ExpressionOwner; 27 import com.sun.org.apache.xpath.internal.ExtensionsProvider; 28 import com.sun.org.apache.xpath.internal.XPathContext; 29 import com.sun.org.apache.xpath.internal.XPathVisitor; 30 import com.sun.org.apache.xpath.internal.objects.XNull; 31 import com.sun.org.apache.xpath.internal.objects.XObject; 32 import com.sun.org.apache.xpath.internal.res.XPATHErrorResources; 33 34 40 public class FuncExtFunction extends Function 41 { 42 43 48 String m_namespace; 49 50 54 String m_extensionName; 55 56 61 Object m_methodKey; 62 63 68 Vector m_argVec = new Vector (); 69 70 81 public void fixupVariables(java.util.Vector vars, int globalsSize) 82 { 83 84 if (null != m_argVec) 85 { 86 int nArgs = m_argVec.size(); 87 88 for (int i = 0; i < nArgs; i++) 89 { 90 Expression arg = (Expression) m_argVec.elementAt(i); 91 92 arg.fixupVariables(vars, globalsSize); 93 } 94 } 95 } 96 97 102 public String getNamespace() 103 { 104 return m_namespace; 105 } 106 107 112 public String getFunctionName() 113 { 114 return m_extensionName; 115 } 116 117 122 public Object getMethodKey() 123 { 124 return m_methodKey; 125 } 126 127 133 public Expression getArg(int n) { 134 if (n >= 0 && n < m_argVec.size()) 135 return (Expression) m_argVec.elementAt(n); 136 else 137 return null; 138 } 139 140 146 public int getArgCount() { 147 return m_argVec.size(); 148 } 149 150 161 public FuncExtFunction(java.lang.String namespace, 162 java.lang.String extensionName, Object methodKey) 163 { 164 m_namespace = namespace; 166 m_extensionName = extensionName; 167 m_methodKey = methodKey; 168 } 169 170 178 public XObject execute(XPathContext xctxt) 179 throws javax.xml.transform.TransformerException 180 { 181 182 XObject result; 183 Vector argVec = new Vector (); 184 int nArgs = m_argVec.size(); 185 186 for (int i = 0; i < nArgs; i++) 187 { 188 Expression arg = (Expression) m_argVec.elementAt(i); 189 190 XObject xobj = arg.execute(xctxt); 191 194 xobj.allowDetachToRelease(false); 195 argVec.addElement(xobj); 196 } 197 ExtensionsProvider extProvider = (ExtensionsProvider)xctxt.getOwnerObject(); 199 Object val = extProvider.extFunction(this, argVec); 200 201 if (null != val) 202 { 203 result = XObject.create(val, xctxt); 204 } 205 else 206 { 207 result = new XNull(); 208 } 209 210 return result; 211 } 212 213 223 public void setArg(Expression arg, int argNum) 224 throws WrongNumberArgsException 225 { 226 m_argVec.addElement(arg); 227 } 228 229 237 public void checkNumberArgs(int argNum) throws WrongNumberArgsException{} 238 239 240 class ArgExtOwner implements ExpressionOwner 241 { 242 243 Expression m_exp; 244 245 ArgExtOwner(Expression exp) 246 { 247 m_exp = exp; 248 } 249 250 253 public Expression getExpression() 254 { 255 return m_exp; 256 } 257 258 259 262 public void setExpression(Expression exp) 263 { 264 exp.exprSetParent(FuncExtFunction.this); 265 m_exp = exp; 266 } 267 } 268 269 270 273 public void callArgVisitors(XPathVisitor visitor) 274 { 275 for (int i = 0; i < m_argVec.size(); i++) 276 { 277 Expression exp = (Expression)m_argVec.elementAt(i); 278 exp.callVisitors(new ArgExtOwner(exp), visitor); 279 } 280 281 } 282 283 290 public void exprSetParent(ExpressionNode n) 291 { 292 293 super.exprSetParent(n); 294 295 int nArgs = m_argVec.size(); 296 297 for (int i = 0; i < nArgs; i++) 298 { 299 Expression arg = (Expression) m_argVec.elementAt(i); 300 301 arg.exprSetParent(n); 302 } 303 } 304 305 312 protected void reportWrongNumberArgs() throws WrongNumberArgsException { 313 String fMsg = XSLMessages.createXPATHMessage( 314 XPATHErrorResources.ER_INCORRECT_PROGRAMMER_ASSERTION, 315 new Object []{ "Programmer's assertion: the method FunctionMultiArgs.reportWrongNumberArgs() should never be called." }); 316 317 throw new RuntimeException (fMsg); 318 } 319 } 320 | Popular Tags |