null resolution support
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user