1 17 18 package org.apache.el; 19 20 import java.io.Externalizable ; 21 import java.io.IOException ; 22 import java.io.ObjectInput ; 23 import java.io.ObjectOutput ; 24 25 import javax.el.ELContext; 26 import javax.el.ELException; 27 import javax.el.ELResolver; 28 import javax.el.Expression; 29 import javax.el.ExpressionFactory; 30 import javax.el.FunctionMapper; 31 import javax.el.MethodExpression; 32 import javax.el.MethodInfo; 33 import javax.el.MethodNotFoundException; 34 import javax.el.PropertyNotFoundException; 35 import javax.el.VariableMapper; 36 37 import org.apache.el.lang.ELSupport; 38 import org.apache.el.lang.EvaluationContext; 39 import org.apache.el.lang.ExpressionBuilder; 40 import org.apache.el.parser.Node; 41 import org.apache.el.util.ReflectionUtil; 42 43 44 81 public final class MethodExpressionImpl extends MethodExpression implements 82 Externalizable { 83 84 private Class expectedType; 85 86 private String expr; 87 88 private FunctionMapper fnMapper; 89 90 private VariableMapper varMapper; 91 92 private transient Node node; 93 94 private Class [] paramTypes; 95 96 99 public MethodExpressionImpl() { 100 super(); 101 } 102 103 110 public MethodExpressionImpl(String expr, Node node, 111 FunctionMapper fnMapper, VariableMapper varMapper, 112 Class expectedType, Class [] paramTypes) { 113 super(); 114 this.expr = expr; 115 this.node = node; 116 this.fnMapper = fnMapper; 117 this.varMapper = varMapper; 118 this.expectedType = expectedType; 119 this.paramTypes = paramTypes; 120 } 121 122 149 public boolean equals(Object obj) { 150 return (obj instanceof MethodExpressionImpl && obj.hashCode() == this 151 .hashCode()); 152 } 153 154 175 public String getExpressionString() { 176 return this.expr; 177 } 178 179 201 public MethodInfo getMethodInfo(ELContext context) 202 throws PropertyNotFoundException, MethodNotFoundException, 203 ELException { 204 Node n = this.getNode(); 205 EvaluationContext ctx = new EvaluationContext(context, this.fnMapper, 206 this.varMapper); 207 return n.getMethodInfo(ctx, this.paramTypes); 208 } 209 210 214 private Node getNode() throws ELException { 215 if (this.node == null) { 216 this.node = ExpressionBuilder.createNode(this.expr); 217 } 218 return this.node; 219 } 220 221 238 public int hashCode() { 239 return this.expr.hashCode(); 240 } 241 242 272 public Object invoke(ELContext context, Object [] params) 273 throws PropertyNotFoundException, MethodNotFoundException, 274 ELException { 275 EvaluationContext ctx = new EvaluationContext(context, this.fnMapper, 276 this.varMapper); 277 return this.getNode().invoke(ctx, this.paramTypes, params); 278 } 279 280 285 public void readExternal(ObjectInput in) throws IOException , 286 ClassNotFoundException { 287 this.expr = in.readUTF(); 288 String type = in.readUTF(); 289 if (!"".equals(type)) { 290 this.expectedType = ReflectionUtil.forName(type); 291 } 292 this.paramTypes = ReflectionUtil.toTypeArray(((String []) in 293 .readObject())); 294 this.fnMapper = (FunctionMapper) in.readObject(); 295 this.varMapper = (VariableMapper) in.readObject(); 296 } 297 298 303 public void writeExternal(ObjectOutput out) throws IOException { 304 out.writeUTF(this.expr); 305 out.writeUTF((this.expectedType != null) ? this.expectedType.getName() 306 : ""); 307 out.writeObject(ReflectionUtil.toTypeNameArray(this.paramTypes)); 308 out.writeObject(this.fnMapper); 309 out.writeObject(this.varMapper); 310 } 311 312 public boolean isLiteralText() { 313 return false; 314 } 315 } 316 | Popular Tags |