diff --git a/spring-webflow-samples/phonebook-portlet/src/main/java/org/springframework/webflow/samples/phonebook/webflow/PersonDetailFlowBuilder.java b/spring-webflow-samples/phonebook-portlet/src/main/java/org/springframework/webflow/samples/phonebook/webflow/PersonDetailFlowBuilder.java index 3ef31ae1..0b246f12 100644 --- a/spring-webflow-samples/phonebook-portlet/src/main/java/org/springframework/webflow/samples/phonebook/webflow/PersonDetailFlowBuilder.java +++ b/spring-webflow-samples/phonebook-portlet/src/main/java/org/springframework/webflow/samples/phonebook/webflow/PersonDetailFlowBuilder.java @@ -20,7 +20,6 @@ import org.springframework.binding.mapping.Mapping; import org.springframework.webflow.engine.Transition; import org.springframework.webflow.engine.builder.AbstractFlowBuilder; import org.springframework.webflow.engine.builder.FlowBuilderException; -import org.springframework.webflow.engine.builder.FlowServiceLocator; import org.springframework.webflow.engine.support.ConfigurableFlowAttributeMapper; /** @@ -34,10 +33,6 @@ import org.springframework.webflow.engine.support.ConfigurableFlowAttributeMappe */ class PersonDetailFlowBuilder extends AbstractFlowBuilder { - public PersonDetailFlowBuilder(FlowServiceLocator flowServiceLocator) { - super(flowServiceLocator); - } - public void buildInputMapper() throws FlowBuilderException { Mapping idMapping = mapping().source("id").target("flowScope.id").value(); getFlow().setInputMapper(new DefaultAttributeMapper().addMapping(idMapping)); diff --git a/spring-webflow-samples/phonebook-portlet/src/main/java/org/springframework/webflow/samples/phonebook/webflow/PhonebookFlowRegistrar.java b/spring-webflow-samples/phonebook-portlet/src/main/java/org/springframework/webflow/samples/phonebook/webflow/PhonebookFlowRegistrar.java deleted file mode 100644 index 3b849df7..00000000 --- a/spring-webflow-samples/phonebook-portlet/src/main/java/org/springframework/webflow/samples/phonebook/webflow/PhonebookFlowRegistrar.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2004-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.webflow.samples.phonebook.webflow; - -import org.springframework.webflow.definition.registry.FlowDefinitionHolder; -import org.springframework.webflow.definition.registry.FlowDefinitionRegistrar; -import org.springframework.webflow.definition.registry.FlowDefinitionRegistry; -import org.springframework.webflow.definition.registry.StaticFlowDefinitionHolder; -import org.springframework.webflow.engine.builder.FlowAssembler; -import org.springframework.webflow.engine.builder.FlowBuilder; -import org.springframework.webflow.engine.builder.FlowServiceLocator; - -/** - * Demonstrates how to register flows programatically. - * - * @author Keith Donald - */ -class PhonebookFlowRegistrar implements FlowDefinitionRegistrar { - - private FlowServiceLocator serviceLocator; - - public PhonebookFlowRegistrar(FlowServiceLocator serviceLocator) { - this.serviceLocator = serviceLocator; - } - - public void registerFlowDefinitions(FlowDefinitionRegistry registry) { - registry.registerFlowDefinition(assemble("detail-flow", new PersonDetailFlowBuilder(serviceLocator))); - registry.registerFlowDefinition(assemble("search-flow", new SearchPersonFlowBuilder(serviceLocator))); - } - - private FlowDefinitionHolder assemble(String flowId, FlowBuilder flowBuilder) { - return new StaticFlowDefinitionHolder(new FlowAssembler(flowId, flowBuilder).assembleFlow()); - } -} \ No newline at end of file diff --git a/spring-webflow-samples/phonebook-portlet/src/main/java/org/springframework/webflow/samples/phonebook/webflow/PhonebookFlowRegistryFactoryBean.java b/spring-webflow-samples/phonebook-portlet/src/main/java/org/springframework/webflow/samples/phonebook/webflow/PhonebookFlowRegistryFactoryBean.java index 5c6372bc..4e199be7 100644 --- a/spring-webflow-samples/phonebook-portlet/src/main/java/org/springframework/webflow/samples/phonebook/webflow/PhonebookFlowRegistryFactoryBean.java +++ b/spring-webflow-samples/phonebook-portlet/src/main/java/org/springframework/webflow/samples/phonebook/webflow/PhonebookFlowRegistryFactoryBean.java @@ -16,16 +16,17 @@ package org.springframework.webflow.samples.phonebook.webflow; import org.springframework.webflow.definition.registry.FlowDefinitionRegistry; -import org.springframework.webflow.engine.builder.AbstractFlowBuildingFlowRegistryFactoryBean; +import org.springframework.webflow.engine.builder.AbstractFlowBuilderFlowRegistryFactoryBean; /** * Demonstrates how to populate a flow registry programatically. * * @author Keith Donald */ -public class PhonebookFlowRegistryFactoryBean extends AbstractFlowBuildingFlowRegistryFactoryBean { +public class PhonebookFlowRegistryFactoryBean extends AbstractFlowBuilderFlowRegistryFactoryBean { protected void doPopulate(FlowDefinitionRegistry registry) { - new PhonebookFlowRegistrar(getFlowServiceLocator()).registerFlowDefinitions(registry); + registerFlowDefinition(registry, "detail-flow", new PersonDetailFlowBuilder()); + registerFlowDefinition(registry, "search-flow", new SearchPersonFlowBuilder()); } } diff --git a/spring-webflow-samples/phonebook-portlet/src/main/java/org/springframework/webflow/samples/phonebook/webflow/SearchPersonFlowBuilder.java b/spring-webflow-samples/phonebook-portlet/src/main/java/org/springframework/webflow/samples/phonebook/webflow/SearchPersonFlowBuilder.java index 88689f2f..b4148584 100644 --- a/spring-webflow-samples/phonebook-portlet/src/main/java/org/springframework/webflow/samples/phonebook/webflow/SearchPersonFlowBuilder.java +++ b/spring-webflow-samples/phonebook-portlet/src/main/java/org/springframework/webflow/samples/phonebook/webflow/SearchPersonFlowBuilder.java @@ -20,7 +20,6 @@ import org.springframework.webflow.action.MultiAction; import org.springframework.webflow.engine.Transition; import org.springframework.webflow.engine.builder.AbstractFlowBuilder; import org.springframework.webflow.engine.builder.FlowBuilderException; -import org.springframework.webflow.engine.builder.FlowServiceLocator; import org.springframework.webflow.engine.support.ConfigurableFlowAttributeMapper; import org.springframework.webflow.execution.ScopeType; import org.springframework.webflow.samples.phonebook.SearchCriteria; @@ -39,10 +38,6 @@ import org.springframework.webflow.samples.phonebook.SearchCriteriaValidator; */ class SearchPersonFlowBuilder extends AbstractFlowBuilder { - public SearchPersonFlowBuilder(FlowServiceLocator flowServiceLocator) { - super(flowServiceLocator); - } - public void buildStates() throws FlowBuilderException { // view search criteria MultiAction searchFormAction = createSearchFormAction(); diff --git a/spring-webflow-samples/phonebook/src/main/java/org/springframework/webflow/samples/phonebook/webflow/PersonDetailFlowBuilder.java b/spring-webflow-samples/phonebook/src/main/java/org/springframework/webflow/samples/phonebook/webflow/PersonDetailFlowBuilder.java index 3ef31ae1..0b246f12 100644 --- a/spring-webflow-samples/phonebook/src/main/java/org/springframework/webflow/samples/phonebook/webflow/PersonDetailFlowBuilder.java +++ b/spring-webflow-samples/phonebook/src/main/java/org/springframework/webflow/samples/phonebook/webflow/PersonDetailFlowBuilder.java @@ -20,7 +20,6 @@ import org.springframework.binding.mapping.Mapping; import org.springframework.webflow.engine.Transition; import org.springframework.webflow.engine.builder.AbstractFlowBuilder; import org.springframework.webflow.engine.builder.FlowBuilderException; -import org.springframework.webflow.engine.builder.FlowServiceLocator; import org.springframework.webflow.engine.support.ConfigurableFlowAttributeMapper; /** @@ -34,10 +33,6 @@ import org.springframework.webflow.engine.support.ConfigurableFlowAttributeMappe */ class PersonDetailFlowBuilder extends AbstractFlowBuilder { - public PersonDetailFlowBuilder(FlowServiceLocator flowServiceLocator) { - super(flowServiceLocator); - } - public void buildInputMapper() throws FlowBuilderException { Mapping idMapping = mapping().source("id").target("flowScope.id").value(); getFlow().setInputMapper(new DefaultAttributeMapper().addMapping(idMapping)); diff --git a/spring-webflow-samples/phonebook/src/main/java/org/springframework/webflow/samples/phonebook/webflow/PhonebookFlowRegistrar.java b/spring-webflow-samples/phonebook/src/main/java/org/springframework/webflow/samples/phonebook/webflow/PhonebookFlowRegistrar.java deleted file mode 100644 index 3b849df7..00000000 --- a/spring-webflow-samples/phonebook/src/main/java/org/springframework/webflow/samples/phonebook/webflow/PhonebookFlowRegistrar.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2004-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.webflow.samples.phonebook.webflow; - -import org.springframework.webflow.definition.registry.FlowDefinitionHolder; -import org.springframework.webflow.definition.registry.FlowDefinitionRegistrar; -import org.springframework.webflow.definition.registry.FlowDefinitionRegistry; -import org.springframework.webflow.definition.registry.StaticFlowDefinitionHolder; -import org.springframework.webflow.engine.builder.FlowAssembler; -import org.springframework.webflow.engine.builder.FlowBuilder; -import org.springframework.webflow.engine.builder.FlowServiceLocator; - -/** - * Demonstrates how to register flows programatically. - * - * @author Keith Donald - */ -class PhonebookFlowRegistrar implements FlowDefinitionRegistrar { - - private FlowServiceLocator serviceLocator; - - public PhonebookFlowRegistrar(FlowServiceLocator serviceLocator) { - this.serviceLocator = serviceLocator; - } - - public void registerFlowDefinitions(FlowDefinitionRegistry registry) { - registry.registerFlowDefinition(assemble("detail-flow", new PersonDetailFlowBuilder(serviceLocator))); - registry.registerFlowDefinition(assemble("search-flow", new SearchPersonFlowBuilder(serviceLocator))); - } - - private FlowDefinitionHolder assemble(String flowId, FlowBuilder flowBuilder) { - return new StaticFlowDefinitionHolder(new FlowAssembler(flowId, flowBuilder).assembleFlow()); - } -} \ No newline at end of file diff --git a/spring-webflow-samples/phonebook/src/main/java/org/springframework/webflow/samples/phonebook/webflow/PhonebookFlowRegistryFactoryBean.java b/spring-webflow-samples/phonebook/src/main/java/org/springframework/webflow/samples/phonebook/webflow/PhonebookFlowRegistryFactoryBean.java index 5c6372bc..4e199be7 100644 --- a/spring-webflow-samples/phonebook/src/main/java/org/springframework/webflow/samples/phonebook/webflow/PhonebookFlowRegistryFactoryBean.java +++ b/spring-webflow-samples/phonebook/src/main/java/org/springframework/webflow/samples/phonebook/webflow/PhonebookFlowRegistryFactoryBean.java @@ -16,16 +16,17 @@ package org.springframework.webflow.samples.phonebook.webflow; import org.springframework.webflow.definition.registry.FlowDefinitionRegistry; -import org.springframework.webflow.engine.builder.AbstractFlowBuildingFlowRegistryFactoryBean; +import org.springframework.webflow.engine.builder.AbstractFlowBuilderFlowRegistryFactoryBean; /** * Demonstrates how to populate a flow registry programatically. * * @author Keith Donald */ -public class PhonebookFlowRegistryFactoryBean extends AbstractFlowBuildingFlowRegistryFactoryBean { +public class PhonebookFlowRegistryFactoryBean extends AbstractFlowBuilderFlowRegistryFactoryBean { protected void doPopulate(FlowDefinitionRegistry registry) { - new PhonebookFlowRegistrar(getFlowServiceLocator()).registerFlowDefinitions(registry); + registerFlowDefinition(registry, "detail-flow", new PersonDetailFlowBuilder()); + registerFlowDefinition(registry, "search-flow", new SearchPersonFlowBuilder()); } } diff --git a/spring-webflow-samples/phonebook/src/main/java/org/springframework/webflow/samples/phonebook/webflow/SearchPersonFlowBuilder.java b/spring-webflow-samples/phonebook/src/main/java/org/springframework/webflow/samples/phonebook/webflow/SearchPersonFlowBuilder.java index 88689f2f..b4148584 100644 --- a/spring-webflow-samples/phonebook/src/main/java/org/springframework/webflow/samples/phonebook/webflow/SearchPersonFlowBuilder.java +++ b/spring-webflow-samples/phonebook/src/main/java/org/springframework/webflow/samples/phonebook/webflow/SearchPersonFlowBuilder.java @@ -20,7 +20,6 @@ import org.springframework.webflow.action.MultiAction; import org.springframework.webflow.engine.Transition; import org.springframework.webflow.engine.builder.AbstractFlowBuilder; import org.springframework.webflow.engine.builder.FlowBuilderException; -import org.springframework.webflow.engine.builder.FlowServiceLocator; import org.springframework.webflow.engine.support.ConfigurableFlowAttributeMapper; import org.springframework.webflow.execution.ScopeType; import org.springframework.webflow.samples.phonebook.SearchCriteria; @@ -39,10 +38,6 @@ import org.springframework.webflow.samples.phonebook.SearchCriteriaValidator; */ class SearchPersonFlowBuilder extends AbstractFlowBuilder { - public SearchPersonFlowBuilder(FlowServiceLocator flowServiceLocator) { - super(flowServiceLocator); - } - public void buildStates() throws FlowBuilderException { // view search criteria MultiAction searchFormAction = createSearchFormAction(); diff --git a/spring-webflow/changelog.txt b/spring-webflow/changelog.txt index 5c6ac611..52e51f0a 100644 --- a/spring-webflow/changelog.txt +++ b/spring-webflow/changelog.txt @@ -36,6 +36,8 @@ Package org.springframework.webflow.engine * The XmlFlowBuilder now also supports OGNL expressions in the "to" attribute of a transition when using the "on-exception" attribute (SWF-269). * The XmlFlowBuilder now consistently uses "fromStringTo(Class.class)" to resolve types (SWF-268). +* Added AbstractFlowBuilderFlowRegistryFactoryBean for easy setup of a flow registry containing + flows built using AbstractFlowBuilders. Package org.springframework.webflow.execution * Added FlowExecutionListener.sessionCreated(RequestContext, FlowSession) callback, useful for diff --git a/spring-webflow/src/main/java/org/springframework/webflow/definition/registry/ExternalizedFlowDefinitionRegistrar.java b/spring-webflow/src/main/java/org/springframework/webflow/definition/registry/ExternalizedFlowDefinitionRegistrar.java index be26c900..f2f8b486 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/definition/registry/ExternalizedFlowDefinitionRegistrar.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/definition/registry/ExternalizedFlowDefinitionRegistrar.java @@ -26,7 +26,7 @@ import org.springframework.core.style.ToStringCreator; /** * A flow definition registrar that populates a flow definition registry from * flow definitions defined within externalized resources. Encapsulates - * registration behaivior common to all externalized registrars and is not tied + * registration behavior common to all externalized registrars and is not tied * to a specific flow definition format (e.g. xml). *
* Concrete subclasses are expected to derive from this class to provide diff --git a/spring-webflow/src/main/java/org/springframework/webflow/engine/builder/AbstractFlowBuilderFlowRegistryFactoryBean.java b/spring-webflow/src/main/java/org/springframework/webflow/engine/builder/AbstractFlowBuilderFlowRegistryFactoryBean.java new file mode 100644 index 00000000..a89ee600 --- /dev/null +++ b/spring-webflow/src/main/java/org/springframework/webflow/engine/builder/AbstractFlowBuilderFlowRegistryFactoryBean.java @@ -0,0 +1,88 @@ +/* + * Copyright 2004-2007 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.webflow.engine.builder; + +import org.springframework.webflow.core.collection.AttributeMap; +import org.springframework.webflow.definition.registry.FlowDefinitionHolder; +import org.springframework.webflow.definition.registry.FlowDefinitionRegistry; +import org.springframework.webflow.definition.registry.StaticFlowDefinitionHolder; +import org.springframework.webflow.engine.Flow; +import org.springframework.webflow.engine.builder.AbstractFlowBuilder; +import org.springframework.webflow.engine.builder.AbstractFlowBuildingFlowRegistryFactoryBean; +import org.springframework.webflow.engine.builder.FlowAssembler; + +/** + * Base class for factory beans that create flow definition registries containing + * flows built using Java based {@link AbstractFlowBuilder flow builders}. + *
+ * Subclasses only need to define the {@link #doPopulate(FlowDefinitionRegistry)} + * method and use the + * {@link #registerFlowDefinition(FlowDefinitionRegistry, String, AbstractFlowBuilder)} + * convenience methods provided by this class to register all relevant flows: + * + *
+ * public class MyFlowRegistryFactoryBean extends AbstractFlowBuilderFlowRegistryFactoryBean {
+ * protected void doPopulate(FlowDefinitionRegistry registry) {
+ * registerFlowDefinition(registry, "my-flow", new MyFlowBuilder());
+ * registerFlowDefinition(registry, "my-other-flow", new MyOtherFlowBuilder());
+ * }
+ * }
+ *
+ *
+ * @see AbstractFlowBuilder
+ *
+ * @author Erwin Vervaet
+ */
+public abstract class AbstractFlowBuilderFlowRegistryFactoryBean extends
+ AbstractFlowBuildingFlowRegistryFactoryBean {
+
+ /**
+ * Register the flow built by given flow builder in specified flow
+ * definition registry.
+ * + * Note that this method will set the + * {@link #getFlowServiceLocator() flow service locator} of this class + * on given flow builder. + * @param registry the registry to register the flow in + * @param flowId the flow id to assign + * @param flowBuilder the builder used to build the flow + */ + protected void registerFlowDefinition( + FlowDefinitionRegistry registry, String flowId, AbstractFlowBuilder flowBuilder) { + registerFlowDefinition(registry, flowId, null, flowBuilder); + } + + /** + * Register the flow built by given flow builder in specified flow + * definition registry. + *
+ * Note that this method will set the + * {@link #getFlowServiceLocator() flow service locator} of this class + * on given flow builder. + * @param registry the registry to register the flow in + * @param flowId the flow id to assign + * @param flowAttributes externally assigned flow attributes that can affect + * flow construction + * @param flowBuilder the builder used to build the flow + */ + protected void registerFlowDefinition( + FlowDefinitionRegistry registry, String flowId, AttributeMap flowAttributes, AbstractFlowBuilder flowBuilder) { + flowBuilder.setFlowServiceLocator(getFlowServiceLocator()); + Flow flow = new FlowAssembler(flowId, flowAttributes, flowBuilder).assembleFlow(); + FlowDefinitionHolder flowHolder = new StaticFlowDefinitionHolder(flow); + registry.registerFlowDefinition(flowHolder); + } +}