KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > webflow > engine > builder > BaseFlowBuilder


1 /*
2  * Copyright 2002-2006 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.binding.convert.ConversionException;
19 import org.springframework.binding.convert.ConversionExecutor;
20 import org.springframework.util.Assert;
21 import org.springframework.webflow.core.collection.AttributeMap;
22 import org.springframework.webflow.engine.Flow;
23
24 /**
25  * Abstract base implementation of a flow builder defining common functionality
26  * needed by most concrete flow builder implementations. This class implements
27  * all optional parts of the FlowBuilder process as no-op methods. Subclasses
28  * are only required to implement {@link #init(String, AttributeMap)} and
29  * {@link #buildStates()}.
30  * <p>
31  * This class also provides a {@link FlowServiceLocator} for use by
32  * subclasses in the flow construction process.
33  *
34  * @see org.springframework.webflow.engine.builder.FlowServiceLocator
35  *
36  * @author Keith Donald
37  * @author Erwin Vervaet
38  */

39 public abstract class BaseFlowBuilder implements FlowBuilder {
40
41     /**
42      * The <code>Flow</code> built by this builder.
43      */

44     private Flow flow;
45
46     /**
47      * Locates actions, attribute mappers, and other artifacts needed by the
48      * flow built by this builder.
49      */

50     private FlowServiceLocator flowServiceLocator;
51
52     /**
53      * Default constructor for subclassing. Sets up use of a {@link BaseFlowServiceLocator}.
54      * @see #setFlowServiceLocator(FlowServiceLocator)
55      */

56     protected BaseFlowBuilder() {
57         setFlowServiceLocator(new BaseFlowServiceLocator());
58     }
59
60     /**
61      * Creates a flow builder using the given locator to link in artifacts.
62      * @param flowServiceLocator the locator for services needed by this builder to build its Flow
63      */

64     protected BaseFlowBuilder(FlowServiceLocator flowServiceLocator) {
65         setFlowServiceLocator(flowServiceLocator);
66     }
67
68     /**
69      * Returns the configured flow service locator.
70      */

71     public FlowServiceLocator getFlowServiceLocator() {
72         return flowServiceLocator;
73     }
74
75     /**
76      * Sets the flow service locator to use. Defaults to {@link BaseFlowServiceLocator}.
77      */

78     public void setFlowServiceLocator(FlowServiceLocator flowServiceLocator) {
79         Assert.notNull(flowServiceLocator, "The flow service locator is required");
80         this.flowServiceLocator = flowServiceLocator;
81     }
82
83     /**
84      * Set the flow being built by this builder. Typically called during
85      * initialization to set the initial flow reference returned by
86      * {@link #getFlow()} after building.
87      */

88     protected void setFlow(Flow flow) {
89         this.flow = flow;
90     }
91
92     public abstract void init(String JavaDoc flowId, AttributeMap attributes) throws FlowBuilderException;
93
94     public void buildVariables() throws FlowBuilderException {
95     }
96
97     public void buildInputMapper() throws FlowBuilderException {
98     }
99
100     public void buildStartActions() throws FlowBuilderException {
101     }
102
103     public void buildInlineFlows() throws FlowBuilderException {
104     }
105
106     public abstract void buildStates() throws FlowBuilderException;
107
108     public void buildGlobalTransitions() throws FlowBuilderException {
109     }
110
111     public void buildEndActions() throws FlowBuilderException {
112     }
113
114     public void buildOutputMapper() throws FlowBuilderException {
115     }
116
117     public void buildExceptionHandlers() throws FlowBuilderException {
118     }
119
120     /**
121      * Get the flow (result) built by this builder.
122      */

123     public Flow getFlow() {
124         return flow;
125     }
126
127     public void dispose() {
128         setFlow(null);
129     }
130     
131     // helpers for use in subclasses
132

133     /**
134      * Returns a conversion executor capable of converting string objects to the
135      * target class aliased by the provided alias.
136      * @param targetAlias the target class alias, e.g. "long" or "float"
137      * @return the conversion executor, or <code>null</code> if no suitable
138      * converter exists for given alias
139      */

140     protected ConversionExecutor fromStringTo(String JavaDoc targetAlias) {
141         return getFlowServiceLocator().getConversionService().getConversionExecutorByTargetAlias(String JavaDoc.class, targetAlias);
142     }
143
144     /**
145      * Returns a converter capable of converting a string value to the given
146      * type.
147      * @param targetType the type you wish to convert to (from a string)
148      * @return the converter
149      * @throws ConversionException when the converter cannot be found
150      */

151     protected ConversionExecutor fromStringTo(Class JavaDoc targetType) throws ConversionException {
152         return getFlowServiceLocator().getConversionService().getConversionExecutor(String JavaDoc.class, targetType);
153     }
154 }
Popular Tags