null resolution support

This commit is contained in:
Keith Donald
2008-04-11 15:53:31 +00:00
parent ab3d438119
commit a1b336d93d
6 changed files with 30 additions and 67 deletions

View File

@@ -44,9 +44,14 @@ public class ELExpression implements Expression {
try {
Object result = valueExpression.getValue(ctx);
if (result == null && !ctx.isPropertyResolved()) {
EvaluationAttempt attempt = new EvaluationAttempt(this, context);
throw new EvaluationException(attempt, attempt
+ " failed: the expression path did not resolve--is the base variable incorrect?", null);
if (getExpressionString().equals("null")) {
// special case for handling reserved null keyword
return null;
} else {
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) {

View File

@@ -1,60 +0,0 @@
package org.springframework.binding.expression.el;
import java.util.Iterator;
import javax.el.ELContext;
import javax.el.ELResolver;
import javax.el.PropertyNotWritableException;
/**
* Resolves the special 'null' variable, indicating a null value.
*
* @author Keith Donald
*/
public class NullELResolver extends ELResolver {
private static final String NULL_VARIABLE_NAME = "null";
public Class getCommonPropertyType(ELContext context, Object base) {
return null;
}
public Iterator getFeatureDescriptors(ELContext context, Object base) {
return null;
}
public Class getType(ELContext context, Object base, Object property) {
if (base == null && NULL_VARIABLE_NAME.equals(property)) {
context.setPropertyResolved(true);
return null;
} else {
return null;
}
}
public Object getValue(ELContext context, Object base, Object property) {
if (base == null && NULL_VARIABLE_NAME.equals(property)) {
context.setPropertyResolved(true);
return null;
} else {
return null;
}
}
public boolean isReadOnly(ELContext context, Object base, Object property) {
if (base == null && NULL_VARIABLE_NAME.equals(property)) {
context.setPropertyResolved(true);
return true;
} else {
return false;
}
}
public void setValue(ELContext context, Object base, Object property, Object value) {
if (base == null && NULL_VARIABLE_NAME.equals(property)) {
context.setPropertyResolved(true);
throw new PropertyNotWritableException("The 'null' value cannot be set");
}
}
}