Added AbstractFlowBuilderFlowRegistryFactoryBean for easy setup of a flow registry containing flows built using AbstractFlowBuilders.

This commit is contained in:
Erwin Vervaet
2007-03-27 19:15:22 +00:00
parent a5070b92f0
commit 67d69ecc6b
11 changed files with 99 additions and 121 deletions

View File

@@ -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));

View File

@@ -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());
}
}

View File

@@ -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());
}
}

View File

@@ -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();

View File

@@ -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));

View File

@@ -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());
}
}

View File

@@ -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());
}
}

View File

@@ -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();

View File

@@ -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

View File

@@ -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).
* <p>
* Concrete subclasses are expected to derive from this class to provide

View File

@@ -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}.
* <p>
* 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:
*
* <pre class="code">
* public class MyFlowRegistryFactoryBean extends AbstractFlowBuilderFlowRegistryFactoryBean {
* protected void doPopulate(FlowDefinitionRegistry registry) {
* registerFlowDefinition(registry, "my-flow", new MyFlowBuilder());
* registerFlowDefinition(registry, "my-other-flow", new MyOtherFlowBuilder());
* }
* }
* </pre>
*
* @see AbstractFlowBuilder
*
* @author Erwin Vervaet
*/
public abstract class AbstractFlowBuilderFlowRegistryFactoryBean extends
AbstractFlowBuildingFlowRegistryFactoryBean {
/**
* Register the flow built by given flow builder in specified flow
* definition registry.
* <p>
* 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.
* <p>
* 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);
}
}