expression parser simplifications

This commit is contained in:
Keith Donald
2008-01-18 07:00:40 +00:00
parent bc5adf803f
commit 87bb511460
5 changed files with 15 additions and 12 deletions

View File

@@ -84,6 +84,7 @@ public abstract class AbstractExpressionParser implements ExpressionParser {
return string.startsWith(expressionPrefix) && string.endsWith(expressionSuffix);
}
// TODO - add back 1.0 and 2.0 m1 semantics
public Expression parseExpression(String expressionString, ParserContext context) throws ParserException {
Assert.notNull(expressionString, "The expression string to parse is required");
Expression[] expressions = parseExpressions(expressionString, context);

View File

@@ -31,7 +31,7 @@ public class ParserContextImpl implements ParserContext {
return (ExpressionVariable[]) expressionVariables.toArray(new ExpressionVariable[expressionVariables.size()]);
}
public ParserContextImpl context(Class contextType) {
public ParserContextImpl eval(Class contextType) {
evaluationContextType = contextType;
return ParserContextImpl.this;
}

View File

@@ -50,7 +50,7 @@ public class ELExpressionParserTests extends TestCase {
public void testParseEvalExpressionWithContextCustomTestBeanResolver() {
String expressionString = "#{specialProperty}";
Expression exp = parser.parseExpression(expressionString, new ParserContextImpl().context(TestBean.class));
Expression exp = parser.parseExpression(expressionString, new ParserContextImpl().eval(TestBean.class));
assertEquals("Custom resolver resolved this special property!", exp.getValue(new TestBean()));
}

View File

@@ -20,6 +20,7 @@ import junit.framework.TestCase;
import org.easymock.EasyMock;
import org.jboss.el.ExpressionFactoryImpl;
import org.springframework.binding.expression.ExpressionParser;
import org.springframework.binding.expression.support.ParserContextImpl;
import org.springframework.webflow.context.ExternalContext;
import org.springframework.webflow.core.collection.AttributeMap;
import org.springframework.webflow.core.collection.LocalAttributeMap;
@@ -68,8 +69,8 @@ public class JsfFinalResponseActionTests extends TestCase {
jsfMock.facesContext().setViewRoot(null);
jsfMock.facesContext().getApplication().setViewHandler(viewHandler);
lifecycle = new TestLifecycle(jsfMock.lifecycle());
factory = new JsfViewFactory(parser.parseExpression("#{'" + VIEW_ID + "'}", RequestContext.class, String.class,
null), null, lifecycle);
factory = new JsfViewFactory(parser.parseExpression("#{'" + VIEW_ID + "'}", new ParserContextImpl().eval(
RequestContext.class).expect(String.class)), null, lifecycle);
finalResponseAction = new JsfFinalResponseAction(factory);
RequestContextHolder.setRequestContext(context);
ExternalContext ext = new MockExternalContext();

View File

@@ -18,6 +18,7 @@ import junit.framework.TestCase;
import org.easymock.EasyMock;
import org.jboss.el.ExpressionFactoryImpl;
import org.springframework.binding.expression.ExpressionParser;
import org.springframework.binding.expression.support.ParserContextImpl;
import org.springframework.webflow.context.ExternalContext;
import org.springframework.webflow.core.collection.AttributeMap;
import org.springframework.webflow.core.collection.LocalAttributeMap;
@@ -80,8 +81,8 @@ public class JsfViewFactoryTests extends TestCase {
public final void testGetView_Create() {
lifecycle = new NoEventLifecycle(jsfMock.lifecycle());
factory = new JsfViewFactory(parser.parseExpression(VIEW_ID, RequestContext.class, String.class, null), null,
lifecycle);
factory = new JsfViewFactory(parser.parseExpression(VIEW_ID, new ParserContextImpl().eval(RequestContext.class)
.expect(String.class)), null, lifecycle);
UIViewRoot newRoot = new UIViewRoot();
newRoot.setViewId(VIEW_ID);
@@ -102,8 +103,8 @@ public class JsfViewFactoryTests extends TestCase {
public final void testGetView_Restore_NoEvent() {
lifecycle = new NoEventLifecycle(jsfMock.lifecycle());
factory = new JsfViewFactory(parser.parseExpression(VIEW_ID, RequestContext.class, String.class, null), null,
lifecycle);
factory = new JsfViewFactory(parser.parseExpression(VIEW_ID, new ParserContextImpl().eval(RequestContext.class)
.expect(String.class)), null, lifecycle);
UIViewRoot existingRoot = new UIViewRoot();
existingRoot.setViewId(VIEW_ID);
@@ -124,8 +125,8 @@ public class JsfViewFactoryTests extends TestCase {
public final void testGetView_Restore_EventSignaled() {
lifecycle = new EventSignalingLifecycle(jsfMock.lifecycle());
factory = new JsfViewFactory(parser.parseExpression(VIEW_ID, RequestContext.class, String.class, null), null,
lifecycle);
factory = new JsfViewFactory(parser.parseExpression(VIEW_ID, new ParserContextImpl().eval(RequestContext.class)
.expect(String.class)), null, lifecycle);
UIViewRoot existingRoot = new UIViewRoot();
existingRoot.setViewId(VIEW_ID);
@@ -176,8 +177,8 @@ public class JsfViewFactoryTests extends TestCase {
public final void testGetView_ExternalViewRoot() {
lifecycle = new NoEventLifecycle(jsfMock.lifecycle());
factory = new JsfViewFactory(parser.parseExpression(VIEW_ID, RequestContext.class, String.class, null), null,
lifecycle);
factory = new JsfViewFactory(parser.parseExpression(VIEW_ID, new ParserContextImpl().eval(RequestContext.class)
.expect(String.class)), null, lifecycle);
UIViewRoot newRoot = new UIViewRoot();
newRoot.setViewId(VIEW_ID);