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.MethodExpression; 28 import javax.el.MethodInfo; 29 30 import org.apache.el.lang.ELSupport; 31 import org.apache.el.util.ReflectionUtil; 32 33 34 public class MethodExpressionLiteral extends MethodExpression implements Externalizable { 35 36 private Class expectedType; 37 38 private String expr; 39 40 private Class [] paramTypes; 41 42 public MethodExpressionLiteral() { 43 } 45 46 public MethodExpressionLiteral(String expr, Class expectedType, Class [] paramTypes) { 47 this.expr = expr; 48 this.expectedType = expectedType; 49 this.paramTypes = paramTypes; 50 } 51 52 public MethodInfo getMethodInfo(ELContext context) throws ELException { 53 return new MethodInfo(this.expr, this.expectedType, this.paramTypes); 54 } 55 56 public Object invoke(ELContext context, Object [] params) throws ELException { 57 if (this.expectedType != null) { 58 return ELSupport.coerceToType(this.expr, this.expectedType); 59 } else { 60 return this.expr; 61 } 62 } 63 64 public String getExpressionString() { 65 return this.expr; 66 } 67 68 public boolean equals(Object obj) { 69 return (obj instanceof MethodExpressionLiteral && this.hashCode() == obj.hashCode()); 70 } 71 72 public int hashCode() { 73 return this.expr.hashCode(); 74 } 75 76 public boolean isLiteralText() { 77 return true; 78 } 79 80 public void readExternal(ObjectInput in) throws IOException , ClassNotFoundException { 81 this.expr = in.readUTF(); 82 String type = in.readUTF(); 83 if (!"".equals(type)) { 84 this.expectedType = ReflectionUtil.forName(type); 85 } 86 this.paramTypes = ReflectionUtil.toTypeArray(((String []) in 87 .readObject())); 88 } 89 90 public void writeExternal(ObjectOutput out) throws IOException { 91 out.writeUTF(this.expr); 92 out.writeUTF((this.expectedType != null) ? this.expectedType.getName() 93 : ""); 94 out.writeObject(ReflectionUtil.toTypeNameArray(this.paramTypes)); 95 } 96 } 97 | Popular Tags |