expression parser updates
This commit is contained in:
@@ -50,10 +50,6 @@ public final class DefaultExpressionParserFactory {
|
||||
// this prevents the default OGNL-based parser from being initialized until it is actually used
|
||||
// which allows OGNL to be an optional dependency if the expression parser wrapper is replaced and never used
|
||||
return new ExpressionParser() {
|
||||
public boolean isDelimitedExpression(String string) {
|
||||
return getDefaultExpressionParser().isDelimitedExpression(string);
|
||||
}
|
||||
|
||||
public Expression parseExpression(String expressionString, ParserContext context) throws ParserException {
|
||||
return getDefaultExpressionParser().parseExpression(expressionString, context);
|
||||
}
|
||||
|
||||
@@ -30,31 +30,28 @@ public class WebFlowELExpressionParser extends ELExpressionParser {
|
||||
}
|
||||
|
||||
private static class RequestContextELContextFactory implements ELContextFactory {
|
||||
public ELContext getELContext(Object target, VariableMapper variableMapper) {
|
||||
public ELContext getELContext(Object target) {
|
||||
List customResolvers = new ArrayList();
|
||||
customResolvers.add(new RequestContextELResolver());
|
||||
customResolvers.add(new ScopeSearchingELResolver());
|
||||
ELResolver resolver = new DefaultELResolver(target, customResolvers);
|
||||
return new WebFlowELContext(resolver, variableMapper);
|
||||
return new WebFlowELContext(resolver);
|
||||
}
|
||||
}
|
||||
|
||||
private static class AttributeMapELContextFactory implements ELContextFactory {
|
||||
public ELContext getELContext(Object target, VariableMapper variableMapper) {
|
||||
public ELContext getELContext(Object target) {
|
||||
ELResolver resolver = new DefaultELResolver(target, null);
|
||||
return new WebFlowELContext(resolver, variableMapper);
|
||||
return new WebFlowELContext(resolver);
|
||||
}
|
||||
}
|
||||
|
||||
private static class WebFlowELContext extends ELContext {
|
||||
|
||||
VariableMapper variableMapper;
|
||||
private ELResolver resolver;
|
||||
|
||||
ELResolver resolver;
|
||||
|
||||
public WebFlowELContext(ELResolver resolver, VariableMapper variableMapper) {
|
||||
public WebFlowELContext(ELResolver resolver) {
|
||||
this.resolver = resolver;
|
||||
this.variableMapper = variableMapper;
|
||||
}
|
||||
|
||||
public ELResolver getELResolver() {
|
||||
@@ -66,7 +63,7 @@ public class WebFlowELExpressionParser extends ELExpressionParser {
|
||||
}
|
||||
|
||||
public VariableMapper getVariableMapper() {
|
||||
return variableMapper;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import org.springframework.binding.convert.support.AbstractConverter;
|
||||
import org.springframework.binding.expression.Expression;
|
||||
import org.springframework.binding.expression.ExpressionParser;
|
||||
import org.springframework.binding.expression.ExpressionVariable;
|
||||
import org.springframework.binding.expression.ognl.OgnlExpressionParser;
|
||||
import org.springframework.binding.expression.support.ParserContextImpl;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.webflow.engine.TransitionCriteria;
|
||||
@@ -84,16 +85,21 @@ class TextToTransitionCriteria extends AbstractConverter {
|
||||
if (!StringUtils.hasText(encodedCriteria)
|
||||
|| WildcardTransitionCriteria.WILDCARD_EVENT_ID.equals(encodedCriteria)) {
|
||||
return WildcardTransitionCriteria.INSTANCE;
|
||||
} else if (parser.isDelimitedExpression(encodedCriteria)) {
|
||||
Expression expression = parser.parseExpression(encodedCriteria, new ParserContextImpl().eval(
|
||||
RequestContext.class).expect(Boolean.class).variable(
|
||||
new ExpressionVariable("result", "lastEvent.id")));
|
||||
return createBooleanExpressionTransitionCriteria(expression);
|
||||
} else if (encodedCriteria.startsWith(BEAN_PREFIX)) {
|
||||
return flowBuilderContext.getBeanFactory().getBean(encodedCriteria.substring(BEAN_PREFIX.length()),
|
||||
TransitionCriteria.class);
|
||||
} else {
|
||||
return createEventIdTransitionCriteria(encodedCriteria);
|
||||
if (parser instanceof OgnlExpressionParser) {
|
||||
// 1.0 compatability
|
||||
OgnlExpressionParser ognl = (OgnlExpressionParser) parser;
|
||||
if (ognl.isTemplateExpression(encodedCriteria)) {
|
||||
return createBooleanExpressionTransitionCriteria(encodedCriteria, parser);
|
||||
} else {
|
||||
return createEventIdTransitionCriteria(encodedCriteria);
|
||||
}
|
||||
} else {
|
||||
return createBooleanExpressionTransitionCriteria(encodedCriteria, parser);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,12 +116,15 @@ class TextToTransitionCriteria extends AbstractConverter {
|
||||
/**
|
||||
* Hook method subclasses can override to return a specialized expression evaluating transition criteria
|
||||
* implementation.
|
||||
* @param expression the expression to evaluate
|
||||
* @param encodedCriteria the encoded transition criteria expression
|
||||
* @param parser the parser that should parse the expression
|
||||
* @return the transition criteria object
|
||||
* @throws ConversionException when something goes wrong
|
||||
*/
|
||||
protected TransitionCriteria createBooleanExpressionTransitionCriteria(Expression expression)
|
||||
throws ConversionException {
|
||||
protected TransitionCriteria createBooleanExpressionTransitionCriteria(String encodedCriteria,
|
||||
ExpressionParser parser) throws ConversionException {
|
||||
Expression expression = parser.parseExpression(encodedCriteria, new ParserContextImpl().eval(
|
||||
RequestContext.class).variable(new ExpressionVariable("result", "lastEvent.id")));
|
||||
return new BooleanExpressionTransitionCriteria(expression);
|
||||
}
|
||||
}
|
||||
@@ -46,7 +46,12 @@ public class BooleanExpressionTransitionCriteria implements TransitionCriteria {
|
||||
}
|
||||
|
||||
public boolean test(RequestContext context) {
|
||||
return ((Boolean) booleanExpression.getValue(context)).booleanValue();
|
||||
Object result = booleanExpression.getValue(context);
|
||||
if (result instanceof Boolean) {
|
||||
return ((Boolean) result).booleanValue();
|
||||
} else {
|
||||
return context.getLastEvent().getId().equals(String.valueOf(result));
|
||||
}
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
|
||||
Reference in New Issue
Block a user