Author: remy.maucherat(a)jboss.com
Date: 2009-11-08 22:56:49 -0500 (Sun, 08 Nov 2009)
New Revision: 1255
Modified:
trunk/java/javax/el/ValueReference.java
trunk/java/org/apache/el/ExpressionFactoryImpl.java
trunk/java/org/apache/el/ValueExpressionImpl.java
trunk/java/org/apache/el/lang/ELSupport.java
trunk/java/org/apache/el/parser/AstIdentifier.java
trunk/java/org/apache/el/parser/AstValue.java
trunk/java/org/apache/el/parser/Node.java
trunk/java/org/apache/el/parser/SimpleNode.java
Log:
- Various EL fixes.
Modified: trunk/java/javax/el/ValueReference.java
===================================================================
--- trunk/java/javax/el/ValueReference.java 2009-11-08 17:19:30 UTC (rev 1254)
+++ trunk/java/javax/el/ValueReference.java 2009-11-09 03:56:49 UTC (rev 1255)
@@ -13,7 +13,7 @@
private Object base;
private Object property;
- public ValueReference(Object base, Object porperty) {
+ public ValueReference(Object base, Object property) {
this.base = base;
this.property = property;
}
Modified: trunk/java/org/apache/el/ExpressionFactoryImpl.java
===================================================================
--- trunk/java/org/apache/el/ExpressionFactoryImpl.java 2009-11-08 17:19:30 UTC (rev
1254)
+++ trunk/java/org/apache/el/ExpressionFactoryImpl.java 2009-11-09 03:56:49 UTC (rev
1255)
@@ -42,7 +42,7 @@
super();
}
- public Object coerceToType(Object obj, Class type) {
+ public Object coerceToType(Object obj, Class<?> type) {
return ELSupport.coerceToType(obj, type);
}
@@ -59,7 +59,7 @@
}
public ValueExpression createValueExpression(ELContext context,
- String expression, Class expectedType) {
+ String expression, Class<?> expectedType) {
if (expectedType == null) {
throw new NullPointerException(MessageFactory
.get("error.value.expectedType"));
@@ -69,7 +69,7 @@
}
public ValueExpression createValueExpression(Object instance,
- Class expectedType) {
+ Class<?> expectedType) {
if (expectedType == null) {
throw new NullPointerException(MessageFactory
.get("error.value.expectedType"));
Modified: trunk/java/org/apache/el/ValueExpressionImpl.java
===================================================================
--- trunk/java/org/apache/el/ValueExpressionImpl.java 2009-11-08 17:19:30 UTC (rev 1254)
+++ trunk/java/org/apache/el/ValueExpressionImpl.java 2009-11-09 03:56:49 UTC (rev 1255)
@@ -31,6 +31,7 @@
import javax.el.PropertyNotFoundException;
import javax.el.PropertyNotWritableException;
import javax.el.ValueExpression;
+import javax.el.ValueReference;
import javax.el.VariableMapper;
import org.apache.el.lang.ELSupport;
@@ -196,7 +197,15 @@
* @see java.lang.Object#hashCode()
*/
public int hashCode() {
- return this.expr.hashCode();
+ StringBuilder hash = new StringBuilder(getNode().toString());
+ for (int i = 0; i < getNode().jjtGetNumChildren(); i++) {
+ Node child = getNode().jjtGetChild(i);
+ String childToString = child.toString();
+ if (childToString != null) {
+ hash.append('[').append(childToString).append(']');
+ }
+ }
+ return hash.toString().hashCode();
}
/*
@@ -257,6 +266,13 @@
out.writeObject(this.varMapper);
}
+ public ValueReference getValueReference(ELContext context) {
+ System.out.println("Node: " + this.getNode() + " Image: " +
this.getNode().getImage());
+ EvaluationContext ctx = new EvaluationContext(context, this.fnMapper,
+ this.varMapper);
+ return this.getNode().getValueReference(ctx);
+ }
+
public String toString() {
return "ValueExpression["+this.expr+"]";
}
Modified: trunk/java/org/apache/el/lang/ELSupport.java
===================================================================
--- trunk/java/org/apache/el/lang/ELSupport.java 2009-11-08 17:19:30 UTC (rev 1254)
+++ trunk/java/org/apache/el/lang/ELSupport.java 2009-11-09 03:56:49 UTC (rev 1255)
@@ -143,14 +143,19 @@
* @param type
* @return
*/
- public final static Enum coerceToEnum(final Object obj, Class type) {
+ public final static Enum coerceToEnum(final Object obj, Class type)
+ throws ELException {
if (obj == null || "".equals(obj)) {
return null;
}
if (obj.getClass().isEnum()) {
return (Enum) obj;
}
- return Enum.valueOf(type, obj.toString());
+ try {
+ return Enum.valueOf(type, obj.toString());
+ } catch (Exception e) {
+ throw new ELException(e);
+ }
}
/**
@@ -158,7 +163,7 @@
* @return
*/
public final static Boolean coerceToBoolean(final Object obj)
- throws IllegalArgumentException {
+ throws ELException {
if (obj == null || "".equals(obj)) {
return Boolean.FALSE;
}
@@ -169,12 +174,12 @@
return Boolean.valueOf((String) obj);
}
- throw new IllegalArgumentException(MessageFactory.get("error.convert",
+ throw new ELException(MessageFactory.get("error.convert",
obj, obj.getClass(), Boolean.class));
}
public final static Character coerceToCharacter(final Object obj)
- throws IllegalArgumentException {
+ throws ELException {
if (obj == null || "".equals(obj)) {
return new Character((char) 0);
}
@@ -184,12 +189,12 @@
if (ELArithmetic.isNumber(obj)) {
return new Character((char) ((Number) obj).shortValue());
}
- Class objType = obj.getClass();
+ Class<?> objType = obj.getClass();
if (obj instanceof Character) {
return (Character) obj;
}
- throw new IllegalArgumentException(MessageFactory.get("error.convert",
+ throw new ELException(MessageFactory.get("error.convert",
obj, objType, Character.class));
}
@@ -209,7 +214,7 @@
}
protected final static Number coerceToNumber(final Number number,
- final Class type) throws IllegalArgumentException {
+ final Class<?> type) throws ELException {
if (Long.TYPE == type || Long.class.equals(type)) {
return new Long(number.longValue());
}
@@ -247,12 +252,12 @@
return new Float(number.floatValue());
}
- throw new IllegalArgumentException(MessageFactory.get("error.convert",
+ throw new ELException(MessageFactory.get("error.convert",
number, number.getClass(), type));
}
- public final static Number coerceToNumber(final Object obj, final Class type)
- throws IllegalArgumentException {
+ public final static Number coerceToNumber(final Object obj, final Class<?>
type)
+ throws ELException {
if (obj == null || "".equals(obj)) {
return coerceToNumber(ZERO, type);
}
@@ -268,38 +273,43 @@
.charValue()), type);
}
- throw new IllegalArgumentException(MessageFactory.get("error.convert",
+ throw new ELException(MessageFactory.get("error.convert",
obj, obj.getClass(), type));
}
protected final static Number coerceToNumber(final String val,
- final Class type) throws IllegalArgumentException {
- if (Long.TYPE == type || Long.class.equals(type)) {
- return Long.valueOf(val);
+ final Class<?> type) throws ELException {
+ try {
+ if (Long.TYPE == type || Long.class.equals(type)) {
+ return Long.valueOf(val);
+ }
+ if (Integer.TYPE == type || Integer.class.equals(type)) {
+ return Integer.valueOf(val);
+ }
+ if (Double.TYPE == type || Double.class.equals(type)) {
+ return Double.valueOf(val);
+ }
+ if (BigInteger.class.equals(type)) {
+ return new BigInteger(val);
+ }
+ if (BigDecimal.class.equals(type)) {
+ return new BigDecimal(val);
+ }
+ if (Byte.TYPE == type || Byte.class.equals(type)) {
+ return Byte.valueOf(val);
+ }
+ if (Short.TYPE == type || Short.class.equals(type)) {
+ return Short.valueOf(val);
+ }
+ if (Float.TYPE == type || Float.class.equals(type)) {
+ return Float.valueOf(val);
+ }
+ } catch (Exception e) {
+ throw new ELException(MessageFactory.get("error.convert",
+ val, String.class, type), e);
}
- if (Integer.TYPE == type || Integer.class.equals(type)) {
- return Integer.valueOf(val);
- }
- if (Double.TYPE == type || Double.class.equals(type)) {
- return Double.valueOf(val);
- }
- if (BigInteger.class.equals(type)) {
- return new BigInteger(val);
- }
- if (BigDecimal.class.equals(type)) {
- return new BigDecimal(val);
- }
- if (Byte.TYPE == type || Byte.class.equals(type)) {
- return Byte.valueOf(val);
- }
- if (Short.TYPE == type || Short.class.equals(type)) {
- return Short.valueOf(val);
- }
- if (Float.TYPE == type || Float.class.equals(type)) {
- return Float.valueOf(val);
- }
- throw new IllegalArgumentException(MessageFactory.get("error.convert",
+ throw new ELException(MessageFactory.get("error.convert",
val, String.class, type));
}
@@ -319,8 +329,8 @@
}
}
- public final static void checkType(final Object obj, final Class type)
- throws IllegalArgumentException {
+ public final static void checkType(final Object obj, final Class<?> type)
+ throws ELException {
if (String.class.equals(type)) {
coerceToString(obj);
}
@@ -338,8 +348,8 @@
}
}
- public final static Object coerceToType(final Object obj, final Class type)
- throws IllegalArgumentException {
+ public final static Object coerceToType(final Object obj, final Class<?> type)
+ throws ELException {
if (type == null || Object.class.equals(type) ||
(obj != null && type.isAssignableFrom(obj.getClass()))) {
return obj;
@@ -372,7 +382,7 @@
return editor.getValue();
}
}
- throw new IllegalArgumentException(MessageFactory.get("error.convert",
+ throw new ELException(MessageFactory.get("error.convert",
obj, obj.getClass(), type));
}
Modified: trunk/java/org/apache/el/parser/AstIdentifier.java
===================================================================
--- trunk/java/org/apache/el/parser/AstIdentifier.java 2009-11-08 17:19:30 UTC (rev 1254)
+++ trunk/java/org/apache/el/parser/AstIdentifier.java 2009-11-09 03:56:49 UTC (rev 1255)
@@ -22,6 +22,7 @@
import javax.el.MethodExpression;
import javax.el.MethodInfo;
import javax.el.MethodNotFoundException;
+import javax.el.PropertyNotFoundException;
import javax.el.ValueExpression;
import javax.el.VariableMapper;
@@ -46,7 +47,12 @@
}
}
ctx.setPropertyResolved(false);
- return ctx.getELResolver().getType(ctx, null, this.image);
+ Class result = ctx.getELResolver().getType(ctx, null, this.image);
+ if (ctx.isPropertyResolved()) {
+ return result;
+ } else {
+ throw new PropertyNotFoundException("Could not resolve property
'" + this.image + "'");
+ }
}
public Object getValue(EvaluationContext ctx) throws ELException {
@@ -58,7 +64,12 @@
}
}
ctx.setPropertyResolved(false);
- return ctx.getELResolver().getValue(ctx, null, this.image);
+ Object result = ctx.getELResolver().getValue(ctx, null, this.image);
+ if (ctx.isPropertyResolved()) {
+ return result;
+ } else {
+ throw new PropertyNotFoundException("Could not resolve property
'" + this.image + "'");
+ }
}
public boolean isReadOnly(EvaluationContext ctx) throws ELException {
@@ -70,7 +81,12 @@
}
}
ctx.setPropertyResolved(false);
- return ctx.getELResolver().isReadOnly(ctx, null, this.image);
+ boolean result = ctx.getELResolver().isReadOnly(ctx, null, this.image);
+ if (ctx.isPropertyResolved()) {
+ return result;
+ } else {
+ throw new PropertyNotFoundException("Could not resolve property
'" + this.image + "'");
+ }
}
public void setValue(EvaluationContext ctx, Object value)
@@ -85,6 +101,9 @@
}
ctx.setPropertyResolved(false);
ctx.getELResolver().setValue(ctx, null, this.image, value);
+ if (!ctx.isPropertyResolved()) {
+ throw new PropertyNotFoundException("Could not resolve property
'" + this.image + "'");
+ }
}
private final Object invokeTarget(EvaluationContext ctx, Object target,
Modified: trunk/java/org/apache/el/parser/AstValue.java
===================================================================
--- trunk/java/org/apache/el/parser/AstValue.java 2009-11-08 17:19:30 UTC (rev 1254)
+++ trunk/java/org/apache/el/parser/AstValue.java 2009-11-09 03:56:49 UTC (rev 1255)
@@ -25,6 +25,7 @@
import javax.el.ELResolver;
import javax.el.MethodInfo;
import javax.el.PropertyNotFoundException;
+import javax.el.ValueReference;
import org.apache.el.lang.ELSupport;
import org.apache.el.lang.EvaluationContext;
@@ -58,6 +59,14 @@
return ctx.getELResolver().getType(ctx, t.base, t.property);
}
+ public ValueReference getValueReference(EvaluationContext ctx) {
+ try {
+ Target t = getTarget(ctx);
+ return new ValueReference(t.base, t.property);
+ } catch (Exception e) {
+ return null;
+ }
+ }
private final Target getTarget(EvaluationContext ctx) throws ELException {
// evaluate expr-a to value-a
Object base = this.children[0].getValue(ctx);
Modified: trunk/java/org/apache/el/parser/Node.java
===================================================================
--- trunk/java/org/apache/el/parser/Node.java 2009-11-08 17:19:30 UTC (rev 1254)
+++ trunk/java/org/apache/el/parser/Node.java 2009-11-09 03:56:49 UTC (rev 1255)
@@ -21,6 +21,7 @@
import javax.el.ELException;
import javax.el.MethodInfo;
+import javax.el.ValueReference;
import org.apache.el.lang.EvaluationContext;
@@ -62,6 +63,7 @@
public String getImage();
public Object getValue(EvaluationContext ctx) throws ELException;
+ public ValueReference getValueReference(EvaluationContext ctx);
public void setValue(EvaluationContext ctx, Object value) throws ELException;
public Class getType(EvaluationContext ctx) throws ELException;
public boolean isReadOnly(EvaluationContext ctx) throws ELException;
Modified: trunk/java/org/apache/el/parser/SimpleNode.java
===================================================================
--- trunk/java/org/apache/el/parser/SimpleNode.java 2009-11-08 17:19:30 UTC (rev 1254)
+++ trunk/java/org/apache/el/parser/SimpleNode.java 2009-11-09 03:56:49 UTC (rev 1255)
@@ -21,6 +21,7 @@
import javax.el.ELException;
import javax.el.MethodInfo;
import javax.el.PropertyNotWritableException;
+import javax.el.ValueReference;
import org.apache.el.lang.ELSupport;
import org.apache.el.lang.EvaluationContext;
@@ -131,6 +132,10 @@
throw new UnsupportedOperationException();
}
+ public ValueReference getValueReference(EvaluationContext ctx) {
+ return null;
+ }
+
public boolean isReadOnly(EvaluationContext ctx)
throws ELException {
return true;