001: /*
002: * Copyright 2004-2007 the original author or authors.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.springframework.webflow.engine.impl;
017:
018: import java.util.Map;
019:
020: import org.apache.commons.logging.Log;
021: import org.apache.commons.logging.LogFactory;
022: import org.springframework.util.Assert;
023: import org.springframework.webflow.core.collection.AttributeMap;
024: import org.springframework.webflow.core.collection.CollectionUtils;
025: import org.springframework.webflow.core.collection.LocalAttributeMap;
026: import org.springframework.webflow.definition.FlowDefinition;
027: import org.springframework.webflow.engine.Flow;
028: import org.springframework.webflow.execution.FlowExecution;
029: import org.springframework.webflow.execution.FlowExecutionFactory;
030: import org.springframework.webflow.execution.FlowExecutionListener;
031: import org.springframework.webflow.execution.factory.FlowExecutionListenerLoader;
032: import org.springframework.webflow.execution.factory.StaticFlowExecutionListenerLoader;
033:
034: /**
035: * A factory for instances of the
036: * {@link FlowExecutionImpl default flow execution} implementation.
037: *
038: * @author Keith Donald
039: */
040: public class FlowExecutionImplFactory implements FlowExecutionFactory {
041:
042: private static final Log logger = LogFactory
043: .getLog(FlowExecutionImplFactory.class);
044:
045: /**
046: * The strategy for loading listeners that should observe executions of a
047: * flow definition. The default simply loads an empty static listener list.
048: */
049: private FlowExecutionListenerLoader executionListenerLoader = StaticFlowExecutionListenerLoader.EMPTY_INSTANCE;
050:
051: /**
052: * System execution attributes that may influence flow execution behavior.
053: * The default is an empty map.
054: */
055: private AttributeMap executionAttributes = CollectionUtils.EMPTY_ATTRIBUTE_MAP;
056:
057: /**
058: * Returns the attributes to apply to flow executions created by this factory.
059: * Execution attributes may affect flow execution behavior.
060: * @return flow execution attributes
061: */
062: public AttributeMap getExecutionAttributes() {
063: return executionAttributes;
064: }
065:
066: /**
067: * Sets the attributes to apply to flow executions created by this factory.
068: * Execution attributes may affect flow execution behavior.
069: * @param executionAttributes flow execution system attributes
070: */
071: public void setExecutionAttributes(AttributeMap executionAttributes) {
072: Assert.notNull(executionAttributes,
073: "The execution attributes map is required");
074: this .executionAttributes = executionAttributes;
075: }
076:
077: /**
078: * Sets the attributes to apply to flow executions created by this factory.
079: * Execution attributes may affect flow execution behavior.
080: * <p>
081: * Convenience setter that takes a simple <code>java.util.Map</code> to ease
082: * bean style configuration.
083: * @param executionAttributes flow execution system attributes
084: */
085: public void setExecutionAttributesMap(Map executionAttributes) {
086: Assert.notNull(executionAttributes,
087: "The execution attributes map is required");
088: this .executionAttributes = new LocalAttributeMap(
089: executionAttributes);
090: }
091:
092: /**
093: * Returns the strategy for loading listeners that should observe executions of
094: * a flow definition. Allows full control over what listeners should apply
095: * for executions of a flow definition.
096: */
097: public FlowExecutionListenerLoader getExecutionListenerLoader() {
098: return executionListenerLoader;
099: }
100:
101: /**
102: * Sets the strategy for loading listeners that should observe executions of
103: * a flow definition. Allows full control over what listeners should apply
104: * for executions of a flow definition.
105: */
106: public void setExecutionListenerLoader(
107: FlowExecutionListenerLoader listenerLoader) {
108: Assert.notNull(listenerLoader,
109: "The listener loader is required");
110: this .executionListenerLoader = listenerLoader;
111: }
112:
113: public FlowExecution createFlowExecution(
114: FlowDefinition flowDefinition) {
115: Assert.isInstanceOf(Flow.class, flowDefinition,
116: "Flow definition is of wrong type: ");
117: if (logger.isDebugEnabled()) {
118: logger
119: .debug("Creating flow execution for flow definition with id '"
120: + flowDefinition.getId() + "'");
121: }
122: FlowExecutionListener[] listeners = executionListenerLoader
123: .getListeners(flowDefinition);
124: return new FlowExecutionImpl((Flow) flowDefinition, listeners,
125: executionAttributes);
126: }
127: }
|