KickJava   Java API By Example, From Geeks To Geeks.

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


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.beans.factory.BeanFactory;
19 import org.springframework.beans.factory.BeanFactoryAware;
20 import org.springframework.binding.convert.ConversionService;
21 import org.springframework.binding.expression.ExpressionParser;
22 import org.springframework.context.ResourceLoaderAware;
23 import org.springframework.core.io.ResourceLoader;
24 import org.springframework.webflow.action.BeanInvokingActionFactory;
25 import org.springframework.webflow.definition.registry.AbstractFlowDefinitionRegistryFactoryBean;
26 import org.springframework.webflow.definition.registry.FlowDefinitionRegistry;
27 import org.springframework.webflow.engine.Flow;
28 import org.springframework.webflow.engine.State;
29 import org.springframework.webflow.execution.Action;
30
31 /**
32  * A base class for factory beans that create populated registries of flow
33  * definitions built using a {@link FlowBuilder}, typically a {@link BaseFlowBuilder}
34  * subclass. This base class will setup a {@link FlowServiceLocator} for
35  * use by the flow builder.
36  * <p>
37  * Subclasses should override the {@link #doPopulate(FlowDefinitionRegistry)}
38  * template method to perform the registry population logic, typically delegating to a
39  * {@link org.springframework.webflow.definition.registry.FlowDefinitionRegistrar}
40  * strategy.
41  *
42  * @see org.springframework.webflow.definition.registry.FlowDefinitionRegistry
43  * @see org.springframework.webflow.definition.registry.FlowDefinitionRegistrar
44  *
45  * @author Keith Donald
46  */

47 public abstract class AbstractFlowBuildingFlowRegistryFactoryBean extends AbstractFlowDefinitionRegistryFactoryBean
48         implements BeanFactoryAware, ResourceLoaderAware {
49
50     /**
51      * The locator of services needed by the flows built for inclusion in the
52      * registry.
53      */

54     private FlowServiceLocator flowServiceLocator;
55
56     /**
57      * The factory encapsulating the creation of central Flow artifacts such as
58      * {@link Flow flows} and {@link State states}.
59      */

60     private FlowArtifactFactory flowArtifactFactory;
61
62     /**
63      * The factory encapsulating the creation of bean invoking actions, actions
64      * that adapt methods on objects to the {@link Action} interface.
65      */

66     private BeanInvokingActionFactory beanInvokingActionFactory;
67
68     /**
69      * The parser for parsing expression strings into evaluatable expression
70      * objects.
71      */

72     private ExpressionParser expressionParser;
73
74     /**
75      * A conversion service that can convert between types.
76      */

77     private ConversionService conversionService;
78
79     /**
80      * A resource loader that can load resources.
81      */

82     private ResourceLoader resourceLoader;
83
84     /**
85      * The Spring bean factory that manages configured flow artifacts.
86      */

87     private BeanFactory beanFactory;
88
89     /**
90      * Returns the factory encapsulating the creation of central Flow artifacts
91      * such as {@link Flow flows} and {@link State states}.
92      */

93     protected FlowArtifactFactory getFlowArtifactFactory() {
94         return flowArtifactFactory;
95     }
96     
97     /**
98      * Sets the factory encapsulating the creation of central Flow artifacts
99      * such as {@link Flow flows} and {@link State states}.
100      */

101     public void setFlowArtifactFactory(FlowArtifactFactory flowArtifactFactory) {
102         this.flowArtifactFactory = flowArtifactFactory;
103     }
104     
105     /**
106      * Returns the factory for creating bean invoking actions, actions that adapt
107      * methods on objects to the {@link Action} interface.
108      */

109     protected BeanInvokingActionFactory getBeanInvokingActionFactory() {
110         return beanInvokingActionFactory;
111     }
112
113     /**
114      * Sets the factory for creating bean invoking actions, actions that adapt
115      * methods on objects to the {@link Action} interface.
116      */

117     public void setBeanInvokingActionFactory(BeanInvokingActionFactory beanInvokingActionFactory) {
118         this.beanInvokingActionFactory = beanInvokingActionFactory;
119     }
120     
121     /**
122      * Returns the expression parser responsible for parsing expression strings into
123      * evaluatable expression objects.
124      */

125     protected ExpressionParser getExpressionParser() {
126         return expressionParser;
127     }
128
129     /**
130      * Set the expression parser responsible for parsing expression strings into
131      * evaluatable expression objects.
132      */

133     public void setExpressionParser(ExpressionParser expressionParser) {
134         this.expressionParser = expressionParser;
135     }
136     
137     /**
138      * Returns the conversion service to use to convert between types; typically
139      * from string to a rich object type.
140      */

141     protected ConversionService getConversionService() {
142         return conversionService;
143     }
144
145     /**
146      * Set the conversion service to use to convert between types; typically
147      * from string to a rich object type.
148      */

149     public void setConversionService(ConversionService conversionService) {
150         this.conversionService = conversionService;
151     }
152     
153     // implementing ResourceLoaderAware
154

155     /**
156      * Returns the injected resource loader.
157      */

158     protected ResourceLoader getResourceLoader() {
159         return resourceLoader;
160     }
161
162     public void setResourceLoader(ResourceLoader resourceLoader) {
163         this.resourceLoader = resourceLoader;
164     }
165     
166     // implementing BeanFactoryAware
167

168     /**
169      * Returns the bean factory managing this bean.
170      */

171     protected BeanFactory getBeanFactory() {
172         return beanFactory;
173     }
174
175     public void setBeanFactory(BeanFactory beanFactory) {
176         this.beanFactory = beanFactory;
177     }
178
179     protected final void init() {
180         flowServiceLocator = createFlowServiceLocator();
181         init(flowServiceLocator);
182     }
183
184     // subclassing hooks
185

186     /**
187      * Factory method for creating the service locator used to locate webflow
188      * services during flow assembly. Subclasses may override to customize the
189      * instantiation and configuration of the locator returned.
190      * @return the service locator
191      */

192     protected FlowServiceLocator createFlowServiceLocator() {
193         DefaultFlowServiceLocator serviceLocator = new DefaultFlowServiceLocator(getRegistry(), beanFactory);
194         if (flowArtifactFactory != null) {
195             serviceLocator.setFlowArtifactFactory(flowArtifactFactory);
196         }
197         if (beanInvokingActionFactory != null) {
198             serviceLocator.setBeanInvokingActionFactory(beanInvokingActionFactory);
199         }
200         if (expressionParser != null) {
201             serviceLocator.setExpressionParser(expressionParser);
202         }
203         if (conversionService != null) {
204             serviceLocator.setConversionService(conversionService);
205         }
206         if (resourceLoader != null) {
207             serviceLocator.setResourceLoader(resourceLoader);
208         }
209         return serviceLocator;
210     }
211
212     /**
213      * Called after properties have been set on the service locator, but before
214      * registry population. Subclasses may override to perform custom initialization
215      * of the flow service locator.
216      * @param flowServiceLocator the flow service locator to use to locate externally managed
217      * services needed during flow building and assembly, typically used by a
218      * {@link org.springframework.webflow.definition.registry.FlowDefinitionRegistrar}
219      */

220     protected void init(FlowServiceLocator flowServiceLocator) {
221     }
222
223     /**
224      * Returns the strategy for locating dependent artifacts when a flow is
225      * being built. May be called by subclasses during
226      * {@link #doPopulate(FlowDefinitionRegistry) registry population} to wire
227      * in the service locator needed for flow assembly.
228      */

229     protected FlowServiceLocator getFlowServiceLocator() {
230         return flowServiceLocator;
231     }
232
233     protected abstract void doPopulate(FlowDefinitionRegistry registry);
234 }
Popular Tags