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