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.PropertyNotFoundException; 37 import javax.el.PropertyNotWritableException; 38 import javax.el.ValueExpression; 39 import java.util.logging.Logger ; 40 41 44 abstract public class AbstractValueExpression extends ValueExpression 45 { 46 protected static final Logger log 47 = Logger.getLogger(AbstractValueExpression.class.getName()); 48 protected static final L10N L = new L10N(AbstractValueExpression.class); 49 50 protected final Expr _expr; 51 private final String _expressionString; 52 53 protected AbstractValueExpression(Expr expr, 54 String expressionString) 55 { 56 _expr = expr; 57 _expressionString = expressionString; 58 } 59 60 protected AbstractValueExpression(Expr expr) 61 { 62 _expr = expr; 63 _expressionString = _expr.toString(); 64 } 65 66 public boolean isLiteralText() 67 { 68 return _expr.isLiteralText(); 69 } 70 71 public String getExpressionString() 72 { 73 return _expressionString; 74 } 75 76 abstract public Class <?> getExpectedType(); 77 78 public Class <?> getType(ELContext context) 79 throws PropertyNotFoundException, 80 ELException 81 { 82 Object value = getValue(context); 83 84 if (value == null) 85 return null; 86 else 87 return value.getClass(); 88 } 89 90 @Override 91 public Object getValue(ELContext context) 92 throws PropertyNotFoundException, 93 ELException 94 { 95 return _expr.getValue(context); 96 } 97 98 @Override 99 public boolean isReadOnly(ELContext context) 100 throws PropertyNotFoundException, 101 ELException 102 { 103 return _expr.isReadOnly(context); 104 } 105 106 public void setValue(ELContext context, Object value) 107 throws PropertyNotFoundException, 108 PropertyNotWritableException, 109 ELException 110 { 111 _expr.setValue(context, value); 112 } 113 114 public int hashCode() 115 { 116 return _expr.hashCode(); 117 } 118 119 public boolean equals(Object o) 120 { 121 if (this == o) 122 return true; 123 else if (! (o instanceof AbstractValueExpression)) 124 return false; 125 126 AbstractValueExpression expr = (AbstractValueExpression) o; 127 128 return _expr.equals(expr._expr); 129 } 130 131 public String toString() 132 { 133 String name = getClass().getName(); 134 int p = name.lastIndexOf('.'); 135 name = name.substring(p + 1); 136 137 return name + "[" + getExpressionString() + "]"; 138 } 139 } 140 | Popular Tags |