KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > webflow > definition > registry > AbstractFlowDefinitionRegistryFactoryBean


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.definition.registry;
17
18 import org.springframework.beans.factory.FactoryBean;
19 import org.springframework.beans.factory.InitializingBean;
20
21 /**
22  * A base class for factory beans that create populated flow definition registries.
23  * Subclasses should override the {@link #doPopulate(FlowDefinitionRegistry)} method
24  * to perform the registry population logic, typically delegating to a
25  * {@link FlowDefinitionRegistrar} strategy to perform the population.
26  *
27  * @author Keith Donald
28  */

29 public abstract class AbstractFlowDefinitionRegistryFactoryBean implements FactoryBean, InitializingBean {
30
31     /**
32      * The registry to register flow definitions in.
33      */

34     private FlowDefinitionRegistry registry = createFlowDefinitionRegistry();
35
36     /**
37      * Sets the parent registry of the registry constructed by this factory
38      * bean.
39      * <p>
40      * A child registry will delegate to its parent if it cannot fulfill a
41      * request to locate a flow definition itself.
42      * @param parent the parent flow definition registry
43      */

44     public void setParent(FlowDefinitionRegistry parent) {
45         registry.setParent(parent);
46     }
47
48     // implementing InitializingBean
49

50     public final void afterPropertiesSet() throws Exception JavaDoc {
51         init();
52         doPopulate(registry);
53     }
54
55     // implementing FactoryBean
56

57     public Class JavaDoc getObjectType() {
58         return FlowDefinitionRegistry.class;
59     }
60
61     public boolean isSingleton() {
62         return true;
63     }
64
65     public Object JavaDoc getObject() throws Exception JavaDoc {
66         // the registry is populated by the time this is called
67
return getRegistry();
68     }
69
70     /**
71      * Returns the flow definition registry constructed by the factory bean.
72      */

73     public FlowDefinitionRegistry getRegistry() {
74         return registry;
75     }
76
77     // subclassing hooks
78

79     /**
80      * Create the flow definition registry to be populated in
81      * {@link #doPopulate(FlowDefinitionRegistry)}. Subclasses can override
82      * this method if they want to use a custom flow definition registry
83      * implementation.
84      */

85     protected FlowDefinitionRegistry createFlowDefinitionRegistry() {
86         return new FlowDefinitionRegistryImpl();
87     }
88     
89     /**
90      * Template method subclasses may override to perform factory bean initialization
91      * logic before registry population. Will be called before
92      * {@link #doPopulate(FlowDefinitionRegistry)}. The default implementation
93      * is empty.
94      */

95     protected void init() {
96     }
97     
98     /**
99      * Template method subclasses must override to perform registry population.
100      * @param registry the flow definition registry to populate
101      */

102     protected abstract void doPopulate(FlowDefinitionRegistry registry);
103
104 }
Popular Tags