AbstractExpressionParser now has a doParseSettableExpression() template method
This commit is contained in:
@@ -111,8 +111,16 @@ public abstract class AbstractExpressionParser implements ExpressionParser {
|
||||
}
|
||||
}
|
||||
|
||||
public abstract SettableExpression parseSettableExpression(String expressionString) throws ParserException,
|
||||
UnsupportedOperationException;
|
||||
public final SettableExpression parseSettableExpression(String expressionString)
|
||||
throws ParserException, UnsupportedOperationException {
|
||||
expressionString = expressionString.trim();
|
||||
// a settable expression should just be a single expression
|
||||
if (expressionString.startsWith(getExpressionPrefix()) && expressionString.endsWith(getExpressionSuffix())) {
|
||||
expressionString = expressionString.substring(getExpressionPrefix().length(),
|
||||
expressionString.length() - getExpressionSuffix().length());
|
||||
}
|
||||
return doParseSettableExpression(expressionString);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper that parses given expression string using the configured parser.
|
||||
@@ -183,13 +191,28 @@ public abstract class AbstractExpressionParser implements ExpressionParser {
|
||||
}
|
||||
return (Expression[]) expressions.toArray(new Expression[expressions.size()]);
|
||||
}
|
||||
|
||||
// template methods
|
||||
|
||||
/**
|
||||
* Template method for parsing a filtered expression string. Subclasses should
|
||||
* override.
|
||||
* @param expressionString the expression string
|
||||
* @return the parsed expression
|
||||
* @throws ParserException an exception occured during parsing
|
||||
*/
|
||||
protected abstract Expression doParseExpression(String expressionString);
|
||||
protected abstract Expression doParseExpression(String expressionString) throws ParserException;
|
||||
|
||||
/**
|
||||
* Template method for parsing a filtered settable expression string. Subclasses
|
||||
* should override.
|
||||
* @param expressionString the expression string
|
||||
* @return the parsed expression
|
||||
* @throws ParserException an exception occured during parsing
|
||||
* @throws UnsupportedOperationException this parser does not support
|
||||
* settable expressions
|
||||
*/
|
||||
protected abstract SettableExpression doParseSettableExpression(String expressionString)
|
||||
throws ParserException, UnsupportedOperationException;
|
||||
|
||||
}
|
||||
@@ -22,7 +22,7 @@ import org.springframework.binding.expression.SettableExpression;
|
||||
/**
|
||||
* An expression parser that parses bean wrapper expressions.
|
||||
*
|
||||
* @author Keith
|
||||
* @author Keith Donald
|
||||
*/
|
||||
public class BeanWrapperExpressionParser extends AbstractExpressionParser {
|
||||
|
||||
@@ -30,7 +30,7 @@ public class BeanWrapperExpressionParser extends AbstractExpressionParser {
|
||||
return parseSettableExpression(expressionString);
|
||||
}
|
||||
|
||||
public SettableExpression parseSettableExpression(String expressionString) throws ParserException {
|
||||
public SettableExpression doParseSettableExpression(String expressionString) throws ParserException {
|
||||
return new BeanWrapperExpression(expressionString);
|
||||
}
|
||||
}
|
||||
@@ -60,8 +60,7 @@ class OgnlExpression implements SettableExpression {
|
||||
if (!(o instanceof OgnlExpression)) {
|
||||
return false;
|
||||
}
|
||||
// as late as Ognl 2.6.7, their expression objects don't implement
|
||||
// equals
|
||||
// as late as Ognl 2.6.7, their expression objects don't implement equals
|
||||
// so this always returns false
|
||||
OgnlExpression other = (OgnlExpression) o;
|
||||
return expression.equals(other.expression);
|
||||
|
||||
@@ -35,7 +35,7 @@ public class OgnlExpressionParser extends AbstractExpressionParser {
|
||||
return parseSettableExpression(expressionString);
|
||||
}
|
||||
|
||||
public SettableExpression parseSettableExpression(String expressionString) throws ParserException {
|
||||
public SettableExpression doParseSettableExpression(String expressionString) throws ParserException {
|
||||
try {
|
||||
return new OgnlExpression(Ognl.parseExpression(expressionString));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user