From 48d6697070cdf2c84752884af5575178ff7da7a7 Mon Sep 17 00:00:00 2001 From: Keith Donald Date: Wed, 5 Mar 2008 00:30:25 +0000 Subject: [PATCH] updated for core.el move and new resolvers --- ...owBuilderServicesBeanDefinitionParser.java | 2 +- .../CompositeFlowPropertyResolver.java | 4 +- .../CompositeFlowVariableResolver.java | 5 +- .../ImplicitFlowVariableELResolver.java | 116 ------------------ .../LegacyJSFELExpressionParser.java | 10 +- ...lderServicesBeanDefinitionParserTests.java | 2 +- .../ImplicitFlowVariableELResolverTests.java | 47 ------- .../webflow/JsfFinalResponseActionTests.java | 2 +- .../faces/webflow/JsfViewFactoryTests.java | 2 +- 9 files changed, 16 insertions(+), 174 deletions(-) delete mode 100644 spring-faces/src/main/java/org/springframework/faces/expression/ImplicitFlowVariableELResolver.java delete mode 100644 spring-faces/src/test/java/org/springframework/faces/expression/ImplicitFlowVariableELResolverTests.java diff --git a/spring-faces/src/main/java/org/springframework/faces/config/FacesFlowBuilderServicesBeanDefinitionParser.java b/spring-faces/src/main/java/org/springframework/faces/config/FacesFlowBuilderServicesBeanDefinitionParser.java index c357f663..82ab2d86 100644 --- a/spring-faces/src/main/java/org/springframework/faces/config/FacesFlowBuilderServicesBeanDefinitionParser.java +++ b/spring-faces/src/main/java/org/springframework/faces/config/FacesFlowBuilderServicesBeanDefinitionParser.java @@ -7,8 +7,8 @@ import org.springframework.faces.expression.LegacyJSFELExpressionParser; import org.springframework.faces.model.converter.FacesConversionService; import org.springframework.faces.webflow.JsfViewFactoryCreator; import org.springframework.util.StringUtils; -import org.springframework.webflow.core.expression.el.WebFlowELExpressionParser; import org.springframework.webflow.engine.builder.support.FlowBuilderServices; +import org.springframework.webflow.expression.el.WebFlowELExpressionParser; import org.w3c.dom.Element; public class FacesFlowBuilderServicesBeanDefinitionParser extends AbstractSingleBeanDefinitionParser implements diff --git a/spring-faces/src/main/java/org/springframework/faces/expression/CompositeFlowPropertyResolver.java b/spring-faces/src/main/java/org/springframework/faces/expression/CompositeFlowPropertyResolver.java index 50e017e2..b113ccf9 100644 --- a/spring-faces/src/main/java/org/springframework/faces/expression/CompositeFlowPropertyResolver.java +++ b/spring-faces/src/main/java/org/springframework/faces/expression/CompositeFlowPropertyResolver.java @@ -4,8 +4,8 @@ import javax.el.CompositeELResolver; import javax.faces.el.PropertyResolver; import org.springframework.binding.expression.el.MapAdaptableELResolver; -import org.springframework.webflow.core.expression.el.RequestContextELResolver; -import org.springframework.webflow.core.expression.el.ScopeSearchingELResolver; +import org.springframework.webflow.expression.el.RequestContextELResolver; +import org.springframework.webflow.expression.el.ScopeSearchingELResolver; /** * Assembles {@link RequestContextELResolver} and {@link ScopeSearchingELResolver} into a composite that may be used diff --git a/spring-faces/src/main/java/org/springframework/faces/expression/CompositeFlowVariableResolver.java b/spring-faces/src/main/java/org/springframework/faces/expression/CompositeFlowVariableResolver.java index 2c173346..ff3c6d22 100644 --- a/spring-faces/src/main/java/org/springframework/faces/expression/CompositeFlowVariableResolver.java +++ b/spring-faces/src/main/java/org/springframework/faces/expression/CompositeFlowVariableResolver.java @@ -4,8 +4,9 @@ import javax.el.CompositeELResolver; import javax.faces.el.VariableResolver; import org.springframework.binding.expression.el.MapAdaptableELResolver; -import org.springframework.webflow.core.expression.el.RequestContextELResolver; -import org.springframework.webflow.core.expression.el.ScopeSearchingELResolver; +import org.springframework.webflow.expression.el.ImplicitFlowVariableELResolver; +import org.springframework.webflow.expression.el.RequestContextELResolver; +import org.springframework.webflow.expression.el.ScopeSearchingELResolver; /** * Assembles {@link RequestContextELResolver} and {@link ScopeSearchingELResolver} into a composite that may be used diff --git a/spring-faces/src/main/java/org/springframework/faces/expression/ImplicitFlowVariableELResolver.java b/spring-faces/src/main/java/org/springframework/faces/expression/ImplicitFlowVariableELResolver.java deleted file mode 100644 index 9fb435b3..00000000 --- a/spring-faces/src/main/java/org/springframework/faces/expression/ImplicitFlowVariableELResolver.java +++ /dev/null @@ -1,116 +0,0 @@ -package org.springframework.faces.expression; - -import java.util.Iterator; - -import javax.el.ELContext; -import javax.el.ELResolver; -import javax.el.PropertyNotFoundException; -import javax.el.PropertyNotWritableException; - -import org.springframework.core.enums.StaticLabeledEnum; -import org.springframework.core.enums.StaticLabeledEnumResolver; -import org.springframework.webflow.execution.RequestContext; -import org.springframework.webflow.execution.RequestContextHolder; - -public class ImplicitFlowVariableELResolver extends ELResolver { - - public Class getCommonPropertyType(ELContext context, Object base) { - return Object.class; - } - - public Iterator getFeatureDescriptors(ELContext context, Object base) { - return null; - } - - public Class getType(ELContext context, Object base, Object property) { - if (base == null) { - Object resolved = resolveVariable(property.toString()); - if (resolved != null) { - context.setPropertyResolved(true); - return resolved.getClass(); - } - } - return null; - } - - public Object getValue(ELContext context, Object base, Object property) { - if (base == null) { - Object resolved = resolveVariable(property.toString()); - if (resolved != null) { - context.setPropertyResolved(true); - return resolved; - } - } - return null; - } - - public boolean isReadOnly(ELContext context, Object base, Object property) { - if (base == null) { - Object resolved = resolveVariable(property.toString()); - if (resolved != null) { - context.setPropertyResolved(true); - return true; - } - } - return false; - } - - public void setValue(ELContext context, Object base, Object property, Object value) { - if (base == null) { - Object resolved = resolveVariable(property.toString()); - if (resolved != null) { - context.setPropertyResolved(true); - throw new PropertyNotWritableException("The implicit flow variable " + property - + " cannot be overwritten."); - } - } - } - - private Object resolveVariable(String variable) { - try { - ImplicitFlowVariable flowVariable = (ImplicitFlowVariable) StaticLabeledEnumResolver.instance() - .getLabeledEnumByLabel(ImplicitFlowVariable.class, variable); - return flowVariable.resolve(); - } catch (IllegalArgumentException ex) { - return null; - } - } - - public abstract static class ImplicitFlowVariable extends StaticLabeledEnum { - - private ImplicitFlowVariable(int code, String label) { - super(code, label); - } - - public static final ImplicitFlowVariable FLASH_SCOPE = new ImplicitFlowVariable(1, "flashScope") { - public Object doResolve(RequestContext context) { - return context.getFlashScope(); - } - }; - - public static final ImplicitFlowVariable FLOW_SCOPE = new ImplicitFlowVariable(2, "flowScope") { - public Object doResolve(RequestContext context) { - return context.getFlowScope(); - } - }; - - public static final ImplicitFlowVariable CONVERSATION_SCOPE = new ImplicitFlowVariable(3, "conversationScope") { - public Object doResolve(RequestContext context) { - return context.getConversationScope(); - } - }; - - public Object resolve() { - RequestContext context = RequestContextHolder.getRequestContext(); - if (context != null) { - return doResolve(context); - } else { - throw new PropertyNotFoundException("Implicit flow variable " + this.getLabel() - + " could not be resolved. No active flow found."); - } - } - - public abstract Object doResolve(RequestContext context); - } - -} diff --git a/spring-faces/src/main/java/org/springframework/faces/expression/LegacyJSFELExpressionParser.java b/spring-faces/src/main/java/org/springframework/faces/expression/LegacyJSFELExpressionParser.java index 03ac35a4..9ba37a21 100644 --- a/spring-faces/src/main/java/org/springframework/faces/expression/LegacyJSFELExpressionParser.java +++ b/spring-faces/src/main/java/org/springframework/faces/expression/LegacyJSFELExpressionParser.java @@ -13,10 +13,12 @@ import org.springframework.binding.expression.el.DefaultELResolver; import org.springframework.binding.expression.el.ELContextFactory; import org.springframework.binding.expression.el.ELExpressionParser; import org.springframework.webflow.core.collection.MutableAttributeMap; -import org.springframework.webflow.core.expression.el.RequestContextELResolver; -import org.springframework.webflow.core.expression.el.ScopeSearchingELResolver; -import org.springframework.webflow.core.expression.el.SpringBeanWebFlowELResolver; import org.springframework.webflow.execution.RequestContext; +import org.springframework.webflow.expression.el.ActionMethodELResolver; +import org.springframework.webflow.expression.el.ImplicitFlowVariableELResolver; +import org.springframework.webflow.expression.el.RequestContextELResolver; +import org.springframework.webflow.expression.el.ScopeSearchingELResolver; +import org.springframework.webflow.expression.el.SpringBeanWebFlowELResolver; /** * A JSF-specific ExpressionParser that allows beans managed by either JSF, Spring, or Web Flow referenced in @@ -47,7 +49,9 @@ public class LegacyJSFELExpressionParser extends ELExpressionParser { public ELContext getELContext(Object target) { List customResolvers = new ArrayList(); customResolvers.add(new RequestContextELResolver()); + customResolvers.add(new ImplicitFlowVariableELResolver()); customResolvers.add(new SpringBeanWebFlowELResolver()); + customResolvers.add(new ActionMethodELResolver()); customResolvers.add(new ScopeSearchingELResolver()); customResolvers.add(new LegacyJSFBeanResolver()); ELResolver resolver = new DefaultELResolver(target, customResolvers); diff --git a/spring-faces/src/test/java/org/springframework/faces/config/FacesFlowBuilderServicesBeanDefinitionParserTests.java b/spring-faces/src/test/java/org/springframework/faces/config/FacesFlowBuilderServicesBeanDefinitionParserTests.java index 1dad5b5f..7edc747d 100644 --- a/spring-faces/src/test/java/org/springframework/faces/config/FacesFlowBuilderServicesBeanDefinitionParserTests.java +++ b/spring-faces/src/test/java/org/springframework/faces/config/FacesFlowBuilderServicesBeanDefinitionParserTests.java @@ -7,8 +7,8 @@ import org.springframework.faces.expression.LegacyJSFELExpressionParser; import org.springframework.faces.model.converter.FacesConversionService; import org.springframework.faces.webflow.JSFMockHelper; import org.springframework.faces.webflow.JsfViewFactoryCreator; -import org.springframework.webflow.core.expression.el.WebFlowELExpressionParser; import org.springframework.webflow.engine.builder.support.FlowBuilderServices; +import org.springframework.webflow.expression.el.WebFlowELExpressionParser; public class FacesFlowBuilderServicesBeanDefinitionParserTests extends TestCase { diff --git a/spring-faces/src/test/java/org/springframework/faces/expression/ImplicitFlowVariableELResolverTests.java b/spring-faces/src/test/java/org/springframework/faces/expression/ImplicitFlowVariableELResolverTests.java deleted file mode 100644 index 677cbfdc..00000000 --- a/spring-faces/src/test/java/org/springframework/faces/expression/ImplicitFlowVariableELResolverTests.java +++ /dev/null @@ -1,47 +0,0 @@ -package org.springframework.faces.expression; - -import javax.el.ELContext; - -import junit.framework.TestCase; - -import org.springframework.binding.expression.el.DefaultELContext; -import org.springframework.webflow.execution.RequestContext; -import org.springframework.webflow.execution.RequestContextHolder; -import org.springframework.webflow.test.MockRequestContext; - -public class ImplicitFlowVariableELResolverTests extends TestCase { - - RequestContext requestContext = new MockRequestContext(); - ELContext elContext = new DefaultELContext(new ImplicitFlowVariableELResolver(), null, null); - - public void setUp() { - RequestContextHolder.setRequestContext(requestContext); - } - - public void testGetValue_UnknownVariable() { - Object result = elContext.getELResolver().getValue(elContext, null, "foo"); - assertNull(result); - assertFalse(elContext.isPropertyResolved()); - } - - public void testGetValue_FlashScope() { - Object result = elContext.getELResolver().getValue(elContext, null, "flashScope"); - assertNotNull(result); - assertTrue(elContext.isPropertyResolved()); - assertSame(requestContext.getFlashScope(), result); - } - - public void testGetValue_FlowScope() { - Object result = elContext.getELResolver().getValue(elContext, null, "flowScope"); - assertNotNull(result); - assertTrue(elContext.isPropertyResolved()); - assertSame(requestContext.getFlowScope(), result); - } - - public void testGetValue_ConversationScope() { - Object result = elContext.getELResolver().getValue(elContext, null, "conversationScope"); - assertNotNull(result); - assertTrue(elContext.isPropertyResolved()); - assertSame(requestContext.getConversationScope(), result); - } -} diff --git a/spring-faces/src/test/java/org/springframework/faces/webflow/JsfFinalResponseActionTests.java b/spring-faces/src/test/java/org/springframework/faces/webflow/JsfFinalResponseActionTests.java index 1a61c97c..3597fabb 100644 --- a/spring-faces/src/test/java/org/springframework/faces/webflow/JsfFinalResponseActionTests.java +++ b/spring-faces/src/test/java/org/springframework/faces/webflow/JsfFinalResponseActionTests.java @@ -27,9 +27,9 @@ import org.springframework.mock.web.MockServletContext; import org.springframework.webflow.core.collection.AttributeMap; import org.springframework.webflow.core.collection.LocalAttributeMap; import org.springframework.webflow.core.collection.LocalParameterMap; -import org.springframework.webflow.core.expression.el.WebFlowELExpressionParser; import org.springframework.webflow.execution.RequestContext; import org.springframework.webflow.execution.RequestContextHolder; +import org.springframework.webflow.expression.el.WebFlowELExpressionParser; import org.springframework.webflow.test.MockExternalContext; public class JsfFinalResponseActionTests extends TestCase { diff --git a/spring-faces/src/test/java/org/springframework/faces/webflow/JsfViewFactoryTests.java b/spring-faces/src/test/java/org/springframework/faces/webflow/JsfViewFactoryTests.java index 252c8f48..cbd1b6f9 100644 --- a/spring-faces/src/test/java/org/springframework/faces/webflow/JsfViewFactoryTests.java +++ b/spring-faces/src/test/java/org/springframework/faces/webflow/JsfViewFactoryTests.java @@ -23,13 +23,13 @@ import org.springframework.faces.ui.AjaxViewRoot; import org.springframework.webflow.core.collection.AttributeMap; import org.springframework.webflow.core.collection.LocalAttributeMap; import org.springframework.webflow.core.collection.LocalParameterMap; -import org.springframework.webflow.core.expression.el.WebFlowELExpressionParser; import org.springframework.webflow.definition.FlowDefinition; import org.springframework.webflow.definition.StateDefinition; import org.springframework.webflow.execution.RequestContext; import org.springframework.webflow.execution.RequestContextHolder; import org.springframework.webflow.execution.View; import org.springframework.webflow.execution.ViewFactory; +import org.springframework.webflow.expression.el.WebFlowELExpressionParser; import org.springframework.webflow.test.MockExternalContext; public class JsfViewFactoryTests extends TestCase {