From f63b5907eb28601356c2e9dcf38308cf8ba74fc7 Mon Sep 17 00:00:00 2001 From: Jeremy Grelle Date: Thu, 21 Feb 2008 19:41:18 +0000 Subject: [PATCH] SWF-403 - Define custom expression parser inside flow-builder-services element. --- ...owBuilderServicesBeanDefinitionParser.java | 63 ++ .../config/FlowRegistryFactoryBean.java | 3 + .../config/WebFlowConfigNamespaceHandler.java | 2 + .../config/spring-webflow-config-2.0.xsd | 630 ++++++++++-------- .../el/WebFlowELExpressionParser.java | 4 + 5 files changed, 410 insertions(+), 292 deletions(-) create mode 100644 spring-webflow/src/main/java/org/springframework/webflow/config/FlowBuilderServicesBeanDefinitionParser.java diff --git a/spring-webflow/src/main/java/org/springframework/webflow/config/FlowBuilderServicesBeanDefinitionParser.java b/spring-webflow/src/main/java/org/springframework/webflow/config/FlowBuilderServicesBeanDefinitionParser.java new file mode 100644 index 00000000..e3e2cc12 --- /dev/null +++ b/spring-webflow/src/main/java/org/springframework/webflow/config/FlowBuilderServicesBeanDefinitionParser.java @@ -0,0 +1,63 @@ +package org.springframework.webflow.config; + +import org.springframework.beans.factory.support.BeanDefinitionBuilder; +import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser; +import org.springframework.beans.factory.xml.BeanDefinitionParser; +import org.springframework.util.StringUtils; +import org.springframework.webflow.engine.builder.support.FlowBuilderServices; +import org.springframework.webflow.mvc.MvcViewFactoryCreator; +import org.w3c.dom.Element; + +/** + * {@link BeanDefinitionParser} for the <flow-builder-services> tag. + * + * @author Jeremy Grelle + */ +public class FlowBuilderServicesBeanDefinitionParser extends AbstractSingleBeanDefinitionParser { + + private static final String EXPRESSION_PARSER_ATTRIBUTE = "expression-parser"; + + private static final String EXPRESSION_PARSER_PROPERTY = "expressionParser"; + + private static final String VIEW_FACTORY_CREATOR_ATTRIBUTE = "view-factory-creator"; + + private static final String VIEW_FACTORY_CREATOR_PROPERTY = "viewFactoryCreator"; + + private static final String CONVERSION_SERVICE_ATTRIBUTE = "conversion-service"; + + private static final String CONVERSION_SERVICE_PROPERTY = "conversionService"; + + protected Class getBeanClass(Element element) { + return FlowBuilderServices.class; + } + + protected void doParse(Element element, BeanDefinitionBuilder definitionBuilder) { + parseExpressionParser(element, definitionBuilder); + parseViewFactoryCreator(element, definitionBuilder); + parseConversionService(element, definitionBuilder); + } + + private void parseConversionService(Element element, BeanDefinitionBuilder definitionBuilder) { + String conversionService = element.getAttribute(CONVERSION_SERVICE_ATTRIBUTE); + if (StringUtils.hasText(conversionService)) { + definitionBuilder.addPropertyReference(CONVERSION_SERVICE_PROPERTY, conversionService); + } + } + + private void parseViewFactoryCreator(Element element, BeanDefinitionBuilder definitionBuilder) { + String viewFactoryCreator = element.getAttribute(VIEW_FACTORY_CREATOR_ATTRIBUTE); + if (StringUtils.hasText(viewFactoryCreator)) { + definitionBuilder.addPropertyReference(VIEW_FACTORY_CREATOR_PROPERTY, viewFactoryCreator); + } else { + definitionBuilder.addPropertyValue(VIEW_FACTORY_CREATOR_PROPERTY, new MvcViewFactoryCreator()); + } + } + + private void parseExpressionParser(Element element, BeanDefinitionBuilder definitionBuilder) { + String expressionParser = element.getAttribute(EXPRESSION_PARSER_ATTRIBUTE); + if (StringUtils.hasText(expressionParser)) { + definitionBuilder.addPropertyReference(EXPRESSION_PARSER_PROPERTY, expressionParser); + } + } + +} diff --git a/spring-webflow/src/main/java/org/springframework/webflow/config/FlowRegistryFactoryBean.java b/spring-webflow/src/main/java/org/springframework/webflow/config/FlowRegistryFactoryBean.java index 50895b73..4c46c278 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/config/FlowRegistryFactoryBean.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/config/FlowRegistryFactoryBean.java @@ -28,6 +28,7 @@ import org.springframework.webflow.engine.builder.RefreshableFlowDefinitionHolde import org.springframework.webflow.engine.builder.support.FlowBuilderContextImpl; import org.springframework.webflow.engine.builder.support.FlowBuilderServices; import org.springframework.webflow.engine.builder.xml.XmlFlowBuilder; +import org.springframework.webflow.mvc.MvcViewFactoryCreator; /** * A factory for a flow definition registry. Is a Spring FactoryBean, for provision by the flow definition registry bean @@ -35,6 +36,7 @@ import org.springframework.webflow.engine.builder.xml.XmlFlowBuilder; * higher-level webflow-config Spring 2.x configuration namespace. * * @author Keith Donald + * @author Jeremy Grelle */ class FlowRegistryFactoryBean implements FactoryBean, ResourceLoaderAware, BeanFactoryAware, InitializingBean { @@ -206,5 +208,6 @@ class FlowRegistryFactoryBean implements FactoryBean, ResourceLoaderAware, BeanF flowBuilderServices = new FlowBuilderServices(); flowBuilderServices.setResourceLoader(resourceLoader); flowBuilderServices.setBeanFactory(beanFactory); + flowBuilderServices.setViewFactoryCreator(new MvcViewFactoryCreator()); } } \ No newline at end of file diff --git a/spring-webflow/src/main/java/org/springframework/webflow/config/WebFlowConfigNamespaceHandler.java b/spring-webflow/src/main/java/org/springframework/webflow/config/WebFlowConfigNamespaceHandler.java index 232118c8..612d1039 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/config/WebFlowConfigNamespaceHandler.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/config/WebFlowConfigNamespaceHandler.java @@ -22,12 +22,14 @@ import org.springframework.beans.factory.xml.NamespaceHandlerSupport; * * @author Keith Donald * @author Ben Hale + * @author Jeremy Grelle */ public class WebFlowConfigNamespaceHandler extends NamespaceHandlerSupport { public void init() { registerBeanDefinitionParser("flow-executor", new FlowExecutorBeanDefinitionParser()); registerBeanDefinitionParser("flow-execution-listeners", new FlowExecutionListenerLoaderBeanDefinitionParser()); registerBeanDefinitionParser("flow-registry", new FlowRegistryBeanDefinitionParser()); + registerBeanDefinitionParser("flow-builder-services", new FlowBuilderServicesBeanDefinitionParser()); registerBeanDefinitionParser("enable-flow-scopes", new EnableFlowScopesBeanDefinitionParser()); } } \ No newline at end of file diff --git a/spring-webflow/src/main/java/org/springframework/webflow/config/spring-webflow-config-2.0.xsd b/spring-webflow/src/main/java/org/springframework/webflow/config/spring-webflow-config-2.0.xsd index 7f4b09e9..afd58abc 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/config/spring-webflow-config-2.0.xsd +++ b/spring-webflow/src/main/java/org/springframework/webflow/config/spring-webflow-config-2.0.xsd @@ -1,63 +1,63 @@ - - - - - - -Provides an easy way to configure a flow executor and an XML flow definition registry. -]]> - - - - - - - - - -Each flow definition registered in this registry is assigned a unique identifier. By default, -this identifier is the name of the externalized resource minus its file extension. For example, -a registry containing flow definitions built from the files "orderitem-flow.xml" and "shipping-flow.xml" -would index those definitions by "orderitem-flow" and "shipping-flow" by default. -
-A flow registry is used by a flow executor at runtime to launch new executions of flow definitions. -]]> -
-
+ + + + + + +Provides an easy way to configure a flow executor and an XML flow definition registry. +]]> + + + + + + + + + +Each flow definition registered in this registry is assigned a unique identifier. By default, +this identifier is the name of the externalized resource minus its file extension. For example, +a registry containing flow definitions built from the files "orderitem-flow.xml" and "shipping-flow.xml" +would index those definitions by "orderitem-flow" and "shipping-flow" by default. +
+A flow registry is used by a flow executor at runtime to launch new executions of flow definitions. +]]> +
+
- - - - - -Individual paths such as: -
-	/WEB-INF/booking.xml
-
-... are supported as well as wildcard paths such as: -
-	/WEB-INF/flows/**/*-flow.xml
-
-]]> -
-
+ + + + + +Individual paths such as: +
+	/WEB-INF/booking.xml
+
+... are supported as well as wildcard paths such as: +
+	/WEB-INF/flows/**/*-flow.xml
+
+]]> +
+
@@ -67,7 +67,7 @@ Specifies a flow builder implementation to register in the registry. ]]> - +
@@ -79,10 +79,10 @@ The idref of the flow builder services instance this flow definition registry sh
-
-
-
- + + +
+ @@ -94,30 +94,30 @@ Attributes to assign to the flow definition that may influence flow execution. - - - - - - - - - - - - - - + + + + + + + - + + + + + + + + @@ -150,64 +150,64 @@ The fully qualified class name of the flow builder implementation. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -218,51 +218,97 @@ Allows access to the Spring Web Flow scopes (request, flash, flow, conversation) ]]> - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -308,81 +354,81 @@ constant throughout the life of the execution. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -399,34 +445,34 @@ An attribute's type may be specified using the 'type' attribute. - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + +
\ No newline at end of file diff --git a/spring-webflow/src/main/java/org/springframework/webflow/core/expression/el/WebFlowELExpressionParser.java b/spring-webflow/src/main/java/org/springframework/webflow/core/expression/el/WebFlowELExpressionParser.java index 60cf5eb6..e556444f 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/core/expression/el/WebFlowELExpressionParser.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/core/expression/el/WebFlowELExpressionParser.java @@ -29,6 +29,10 @@ public class WebFlowELExpressionParser extends ELExpressionParser { putContextFactory(MutableAttributeMap.class, new AttributeMapELContextFactory()); } + public WebFlowELExpressionParser() { + this(ExpressionFactory.newInstance()); + } + private static class RequestContextELContextFactory implements ELContextFactory { public ELContext getELContext(Object target) { List customResolvers = new ArrayList();