KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > webflow > engine > impl > FlowExecutionImplFactory


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.impl;
17
18 import java.util.Map JavaDoc;
19
20 import org.springframework.util.Assert;
21 import org.springframework.webflow.core.collection.AttributeMap;
22 import org.springframework.webflow.core.collection.CollectionUtils;
23 import org.springframework.webflow.core.collection.LocalAttributeMap;
24 import org.springframework.webflow.definition.FlowDefinition;
25 import org.springframework.webflow.engine.Flow;
26 import org.springframework.webflow.execution.FlowExecution;
27 import org.springframework.webflow.execution.FlowExecutionFactory;
28 import org.springframework.webflow.execution.FlowExecutionListener;
29 import org.springframework.webflow.execution.factory.FlowExecutionListenerLoader;
30 import org.springframework.webflow.execution.factory.StaticFlowExecutionListenerLoader;
31
32 /**
33  * A factory for instances of the
34  * {@link FlowExecutionImpl default flow execution} implementation.
35  *
36  * @author Keith Donald
37  */

38 public class FlowExecutionImplFactory implements FlowExecutionFactory {
39
40     /**
41      * The strategy for loading listeners that should observe executions of a
42      * flow definition. The default simply loads an empty static listener list.
43      */

44     private FlowExecutionListenerLoader executionListenerLoader = StaticFlowExecutionListenerLoader.EMPTY_INSTANCE;
45
46     /**
47      * System execution attributes that may influence flow execution behavior.
48      * The default is an empty map.
49      */

50     private AttributeMap executionAttributes = CollectionUtils.EMPTY_ATTRIBUTE_MAP;
51     
52     /**
53      * Returns the attributes to apply to flow executions created by this factory.
54      * Execution attributes may affect flow execution behavior.
55      * @return flow execution attributes
56      */

57     public AttributeMap getExecutionAttributes() {
58         return executionAttributes;
59     }
60
61     /**
62      * Sets the attributes to apply to flow executions created by this factory.
63      * Execution attributes may affect flow execution behavior.
64      * @param executionAttributes flow execution system attributes
65      */

66     public void setExecutionAttributes(AttributeMap executionAttributes) {
67         Assert.notNull(executionAttributes, "The execution attributes map is required");
68         this.executionAttributes = executionAttributes;
69     }
70     
71     /**
72      * Sets the attributes to apply to flow executions created by this factory.
73      * Execution attributes may affect flow execution behavior.
74      * <p>
75      * Convenience setter that takes a simple <code>java.util.Map</code> to ease
76      * bean style configuration.
77      * @param executionAttributes flow execution system attributes
78      */

79     public void setExecutionAttributesMap(Map JavaDoc executionAttributes) {
80         Assert.notNull(executionAttributes, "The execution attributes map is required");
81         this.executionAttributes = new LocalAttributeMap(executionAttributes);
82     }
83     
84     /**
85      * Returns the strategy for loading listeners that should observe executions of
86      * a flow definition. Allows full control over what listeners should apply
87      * for executions of a flow definition.
88      */

89     public FlowExecutionListenerLoader getExecutionListenerLoader() {
90         return executionListenerLoader;
91     }
92
93     /**
94      * Sets the strategy for loading listeners that should observe executions of
95      * a flow definition. Allows full control over what listeners should apply
96      * for executions of a flow definition.
97      */

98     public void setExecutionListenerLoader(FlowExecutionListenerLoader listenerLoader) {
99         Assert.notNull(listenerLoader, "The listener loader is required");
100         this.executionListenerLoader = listenerLoader;
101     }
102
103     public FlowExecution createFlowExecution(FlowDefinition flowDefinition) {
104         Assert.isInstanceOf(Flow.class, flowDefinition, "Flow definition is of wrong type: ");
105         FlowExecutionListener[] listeners = executionListenerLoader.getListeners(flowDefinition);
106         return new FlowExecutionImpl((Flow)flowDefinition, listeners, executionAttributes);
107     }
108 }
Popular Tags