01: /*
02: * Copyright 2004-2007 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.springframework.webflow.engine.builder;
17:
18: import org.springframework.webflow.core.collection.AttributeMap;
19: import org.springframework.webflow.definition.registry.FlowDefinitionHolder;
20: import org.springframework.webflow.definition.registry.FlowDefinitionRegistry;
21: import org.springframework.webflow.definition.registry.StaticFlowDefinitionHolder;
22: import org.springframework.webflow.engine.Flow;
23: import org.springframework.webflow.engine.builder.AbstractFlowBuilder;
24: import org.springframework.webflow.engine.builder.AbstractFlowBuildingFlowRegistryFactoryBean;
25: import org.springframework.webflow.engine.builder.FlowAssembler;
26:
27: /**
28: * Base class for factory beans that create flow definition registries containing
29: * flows built using Java based {@link AbstractFlowBuilder flow builders}.
30: * <p>
31: * Subclasses only need to define the {@link #doPopulate(FlowDefinitionRegistry)}
32: * method and use the
33: * {@link #registerFlowDefinition(FlowDefinitionRegistry, String, AbstractFlowBuilder)}
34: * convenience methods provided by this class to register all relevant flows:
35: *
36: * <pre class="code">
37: * public class MyFlowRegistryFactoryBean extends AbstractFlowBuilderFlowRegistryFactoryBean {
38: * protected void doPopulate(FlowDefinitionRegistry registry) {
39: * registerFlowDefinition(registry, "my-flow", new MyFlowBuilder());
40: * registerFlowDefinition(registry, "my-other-flow", new MyOtherFlowBuilder());
41: * }
42: * }
43: * </pre>
44: *
45: * @see AbstractFlowBuilder
46: *
47: * @since 1.0.2
48: *
49: * @author Erwin Vervaet
50: */
51: public abstract class AbstractFlowBuilderFlowRegistryFactoryBean extends
52: AbstractFlowBuildingFlowRegistryFactoryBean {
53:
54: /**
55: * Register the flow built by given flow builder in specified flow
56: * definition registry.
57: * <p>
58: * Note that this method will set the
59: * {@link #getFlowServiceLocator() flow service locator} of this class
60: * on given flow builder.
61: * @param registry the registry to register the flow in
62: * @param flowId the flow id to assign
63: * @param flowBuilder the builder used to build the flow
64: */
65: protected void registerFlowDefinition(
66: FlowDefinitionRegistry registry, String flowId,
67: AbstractFlowBuilder flowBuilder) {
68: registerFlowDefinition(registry, flowId, null, flowBuilder);
69: }
70:
71: /**
72: * Register the flow built by given flow builder in specified flow
73: * definition registry.
74: * <p>
75: * Note that this method will set the
76: * {@link #getFlowServiceLocator() flow service locator} of this class
77: * on given flow builder.
78: * @param registry the registry to register the flow in
79: * @param flowId the flow id to assign
80: * @param flowAttributes externally assigned flow attributes that can affect
81: * flow construction
82: * @param flowBuilder the builder used to build the flow
83: */
84: protected void registerFlowDefinition(
85: FlowDefinitionRegistry registry, String flowId,
86: AttributeMap flowAttributes, AbstractFlowBuilder flowBuilder) {
87: flowBuilder.setFlowServiceLocator(getFlowServiceLocator());
88: Flow flow = new FlowAssembler(flowId, flowAttributes,
89: flowBuilder).assembleFlow();
90: FlowDefinitionHolder flowHolder = new StaticFlowDefinitionHolder(
91: flow);
92: registry.registerFlowDefinition(flowHolder);
93: }
94: }
|