1 29 30 package com.caucho.el; 31 32 import com.caucho.util.L10N; 33 34 import javax.el.ELContext; 35 import javax.el.ELException; 36 import javax.el.MethodExpression; 37 import javax.el.MethodInfo; 38 import javax.el.MethodNotFoundException; 39 import javax.el.PropertyNotFoundException; 40 import java.util.logging.Logger ; 41 42 45 public class MethodExpressionImpl extends MethodExpression 46 { 47 protected static final Logger log 48 = Logger.getLogger(MethodExpressionImpl.class.getName()); 49 protected static final L10N L = new L10N(MethodExpressionImpl.class); 50 51 private final String _expressionString; 52 private final Expr _expr; 53 private final Class _expectedType; 54 private final Class []_expectedArgs; 55 56 public MethodExpressionImpl(Expr expr, 57 String expressionString, 58 Class <?> expectedType, 59 Class <?> []expectedArgs) 60 { 61 _expr = expr; 62 _expressionString = expressionString; 63 _expectedType = expectedType; 64 _expectedArgs = expectedArgs; 65 } 66 67 public boolean isLiteralText() 68 { 69 return _expr.isLiteralText(); 70 } 71 72 public String getExpressionString() 73 { 74 return _expressionString; 75 } 76 77 public MethodInfo getMethodInfo(ELContext context) 78 throws PropertyNotFoundException, 79 MethodNotFoundException, 80 ELException 81 { 82 return _expr.getMethodInfo(context, _expectedType, _expectedArgs); 83 } 84 85 public Object invoke(ELContext context, 86 Object []params) 87 throws PropertyNotFoundException, 88 MethodNotFoundException, 89 ELException 90 { 91 if (params == null && _expectedArgs.length != 0 92 || params != null && params.length != _expectedArgs.length) { 93 throw new IllegalArgumentException (L.l("expected arguments do not match actual arguments for '{0}'", _expr.toString())); 94 } 95 96 Object value = _expr.invoke(context, _expectedArgs, params); 97 98 return Expr.coerceToType(value, _expectedType); 99 } 100 101 public int hashCode() 102 { 103 return _expr.hashCode(); 104 } 105 106 public boolean equals(Object o) 107 { 108 if (this == o) 109 return true; 110 else if (! (o instanceof MethodExpressionImpl)) 111 return false; 112 113 MethodExpressionImpl expr = (MethodExpressionImpl) o; 114 115 return _expr.equals(expr._expr); 116 } 117 118 public String toString() 119 { 120 return "MethodExpressionImpl[" + getExpressionString() + "]"; 121 } 122 } 123 | Popular Tags |