add EventAttributeELResolver

improved invalid variable ex message
This commit is contained in:
Keith Donald
2008-04-11 15:24:55 +00:00
parent a5a5c8e4cd
commit ab3d438119
7 changed files with 131 additions and 9 deletions

View File

@@ -25,6 +25,7 @@ import org.springframework.core.style.ToStringCreator;
public class EvaluationAttempt {
private Expression expression;
private Object context;
/**

View File

@@ -15,19 +15,17 @@
*/
package org.springframework.binding.expression;
import org.springframework.core.NestedRuntimeException;
/**
* Indicates an expression evaluation failed.
*
* @author Keith Donald
*/
public class EvaluationException extends NestedRuntimeException {
public class EvaluationException extends RuntimeException {
/**
* The evaluation attempt that failed. Transient because an EvaluationAttempt is not serializable.
*/
private transient EvaluationAttempt evaluationAttempt;
private EvaluationAttempt evaluationAttempt;
/**
* Creates a new evaluation exception.
@@ -35,7 +33,17 @@ public class EvaluationException extends NestedRuntimeException {
* @param cause the underlying cause of this exception
*/
public EvaluationException(EvaluationAttempt evaluationAttempt, Throwable cause) {
super(evaluationAttempt + " failed - make sure the expression is evaluatable in the context provided", cause);
this(evaluationAttempt, evaluationAttempt
+ " failed - make sure the expression is evaluatable in the context provided", cause);
}
/**
* Creates a new evaluation exception.
* @param evaluationAttempt the evaluation attempt that failed
* @param cause the underlying cause of this exception
*/
public EvaluationException(EvaluationAttempt evaluationAttempt, String message, Throwable cause) {
super(message, cause);
this.evaluationAttempt = evaluationAttempt;
}

View File

@@ -44,7 +44,9 @@ public class ELExpression implements Expression {
try {
Object result = valueExpression.getValue(ctx);
if (result == null && !ctx.isPropertyResolved()) {
throw new EvaluationException(new EvaluationAttempt(this, context), null);
EvaluationAttempt attempt = new EvaluationAttempt(this, context);
throw new EvaluationException(attempt, attempt
+ " failed: the expression path did not resolve--is the base variable incorrect?", null);
}
return result;
} catch (javax.el.PropertyNotFoundException e) {
@@ -59,7 +61,9 @@ public class ELExpression implements Expression {
try {
valueExpression.setValue(ctx, value);
if (!ctx.isPropertyResolved()) {
throw new EvaluationException(new SetValueAttempt(this, context, value), null);
SetValueAttempt attempt = new SetValueAttempt(this, context, value);
throw new EvaluationException(attempt, attempt
+ " failed: the expression path did not resolve--is the base variable incorrect?", null);
}
} catch (javax.el.PropertyNotFoundException e) {
throw new PropertyNotFoundException(new EvaluationAttempt(this, context), e);