Making DefaultELResolver more flexible.

This commit is contained in:
Jeremy Grelle
2007-09-28 22:31:32 +00:00
parent c1b68c5c15
commit b9513cd42b
4 changed files with 23 additions and 48 deletions

View File

@@ -6,10 +6,11 @@ import javax.el.CompositeELResolver;
import javax.el.ELContext;
import javax.el.ListELResolver;
import javax.el.MapELResolver;
import javax.el.PropertyNotFoundException;
import javax.el.PropertyNotWritableException;
import javax.el.ResourceBundleELResolver;
import org.springframework.binding.collection.MapAdaptable;
import org.springframework.util.Assert;
/**
* A generic ELResolver to be used as a default when no other ELResolvers have been configured by the client
@@ -35,21 +36,27 @@ public class DefaultELResolver extends CompositeELResolver {
}
public Object getValue(ELContext context, Object base, Object property) {
Assert.notNull(target, "The DefaultELResolver must have a target base property set.");
if (base == null) {
return super.getValue(context, target, property);
} else {
return super.getValue(context, adaptIfNecessary(base), property);
try {
return super.getValue(context, target, property);
} catch (PropertyNotFoundException ex) {
context.setPropertyResolved(false);
}
}
return super.getValue(context, adaptIfNecessary(base), property);
}
public void setValue(ELContext context, Object base, Object property, Object val) {
Assert.notNull(target, "The DefaultELResolver must have a target base property set.");
if (base == null) {
super.setValue(context, target, property, val);
} else {
super.setValue(context, adaptIfNecessary(base), property, val);
try {
super.setValue(context, target, property, val);
if (context.isPropertyResolved())
return;
} catch (PropertyNotWritableException ex) {
context.setPropertyResolved(false);
}
}
super.setValue(context, adaptIfNecessary(base), property, val);
}
public Object getTarget() {

View File

@@ -84,35 +84,16 @@ public class ELExpressionParser implements ExpressionParser {
}
public final Expression parseExpression(String expressionString) throws ParserException {
if (!isDelimitedExpression(expressionString)) {
expressionString = expressionPrefix + expressionString + expressionSuffix;
}
return doParseExpression(expressionString);
return parseSettableExpression(expressionString);
}
/**
* Parses the expression string into an EL value expression.
* @param expressionString
* @throws ParserException
*/
public final SettableExpression parseSettableExpression(String expressionString) throws ParserException,
UnsupportedOperationException {
if (!isDelimitedExpression(expressionString)) {
expressionString = expressionPrefix + expressionString + expressionSuffix;
}
return doParseSettableExpression(expressionString);
}
/**
* Parses the expression string into an EL value expression.
* @param expressionString
* @throws ParserException
*/
protected Expression doParseExpression(String expressionString) throws ParserException {
return doParseSettableExpression(expressionString);
}
/**
* Parses the expression string into an EL value expression.
* @param expressionString
* @throws ParserException
*/
protected SettableExpression doParseSettableExpression(String expressionString) throws ParserException {
ELContext ctx = contextFactory.getParseContext();
try {
return new ELExpression(contextFactory, expressionFactory.createValueExpression(ctx, expressionString,