1 25 package com.sun.el; 26 27 import java.io.Externalizable ; 28 import java.io.IOException ; 29 import java.io.ObjectInput ; 30 import java.io.ObjectOutput ; 31 32 import javax.el.ELContext; 33 import javax.el.ELException; 34 import javax.el.ELResolver; 35 import javax.el.Expression; 36 import javax.el.ExpressionFactory; 37 import javax.el.FunctionMapper; 38 import javax.el.MethodExpression; 39 import javax.el.MethodInfo; 40 import javax.el.MethodNotFoundException; 41 import javax.el.PropertyNotFoundException; 42 import javax.el.VariableMapper; 43 44 import com.sun.el.lang.ELSupport; 45 import com.sun.el.lang.EvaluationContext; 46 import com.sun.el.lang.ExpressionBuilder; 47 import com.sun.el.parser.Node; 48 import com.sun.el.util.ReflectionUtil; 49 50 87 public final class MethodExpressionImpl extends MethodExpression implements 88 Externalizable { 89 90 private Class expectedType; 91 92 private String expr; 93 94 private FunctionMapper fnMapper; 95 96 private VariableMapper varMapper; 97 98 private transient Node node; 99 100 private Class [] paramTypes; 101 102 105 public MethodExpressionImpl() { 106 super(); 107 } 108 109 116 public MethodExpressionImpl(String expr, Node node, 117 FunctionMapper fnMapper, VariableMapper varMapper, 118 Class expectedType, Class [] paramTypes) { 119 super(); 120 this.expr = expr; 121 this.node = node; 122 this.fnMapper = fnMapper; 123 this.varMapper = varMapper; 124 this.expectedType = expectedType; 125 this.paramTypes = paramTypes; 126 } 127 128 155 public boolean equals(Object obj) { 156 return (obj instanceof MethodExpressionImpl && obj.hashCode() == this 157 .hashCode()); 158 } 159 160 181 public String getExpressionString() { 182 return this.expr; 183 } 184 185 207 public MethodInfo getMethodInfo(ELContext context) 208 throws PropertyNotFoundException, MethodNotFoundException, 209 ELException { 210 Node n = this.getNode(); 211 EvaluationContext ctx = new EvaluationContext(context, this.fnMapper, 212 this.varMapper); 213 return n.getMethodInfo(ctx, this.paramTypes); 214 } 215 216 220 private Node getNode() throws ELException { 221 if (this.node == null) { 222 this.node = ExpressionBuilder.createNode(this.expr); 223 } 224 return this.node; 225 } 226 227 244 public int hashCode() { 245 return this.expr.hashCode(); 246 } 247 248 278 public Object invoke(ELContext context, Object [] params) 279 throws PropertyNotFoundException, MethodNotFoundException, 280 ELException { 281 EvaluationContext ctx = new EvaluationContext(context, this.fnMapper, 282 this.varMapper); 283 return this.getNode().invoke(ctx, this.paramTypes, params); 284 } 285 286 291 public void readExternal(ObjectInput in) throws IOException , 292 ClassNotFoundException { 293 this.expr = in.readUTF(); 294 String type = in.readUTF(); 295 if (!"".equals(type)) { 296 this.expectedType = ReflectionUtil.forName(type); 297 } 298 this.paramTypes = ReflectionUtil.toTypeArray(((String []) in 299 .readObject())); 300 this.fnMapper = (FunctionMapper) in.readObject(); 301 this.varMapper = (VariableMapper) in.readObject(); 302 } 303 304 309 public void writeExternal(ObjectOutput out) throws IOException { 310 out.writeUTF(this.expr); 311 out.writeUTF((this.expectedType != null) ? this.expectedType.getName() 312 : ""); 313 out.writeObject(ReflectionUtil.toTypeNameArray(this.paramTypes)); 314 out.writeObject(this.fnMapper); 315 out.writeObject(this.varMapper); 316 } 317 318 public boolean isLiteralText() { 319 return false; 320 } 321 } 322 | Popular Tags |