1 16 package org.springframework.webflow.engine.impl; 17 18 import java.util.ListIterator ; 19 import java.util.Map ; 20 21 import org.springframework.util.Assert; 22 import org.springframework.webflow.core.collection.AttributeMap; 23 import org.springframework.webflow.core.collection.CollectionUtils; 24 import org.springframework.webflow.core.collection.LocalAttributeMap; 25 import org.springframework.webflow.core.collection.MutableAttributeMap; 26 import org.springframework.webflow.definition.registry.FlowDefinitionLocator; 27 import org.springframework.webflow.engine.Flow; 28 import org.springframework.webflow.execution.FlowExecution; 29 import org.springframework.webflow.execution.factory.FlowExecutionListenerLoader; 30 import org.springframework.webflow.execution.factory.StaticFlowExecutionListenerLoader; 31 import org.springframework.webflow.execution.repository.support.FlowExecutionStateRestorer; 32 33 39 public class FlowExecutionImplStateRestorer implements FlowExecutionStateRestorer { 40 41 44 private FlowDefinitionLocator definitionLocator; 45 46 49 private FlowExecutionListenerLoader executionListenerLoader = StaticFlowExecutionListenerLoader.EMPTY_INSTANCE; 50 51 54 private AttributeMap executionAttributes = CollectionUtils.EMPTY_ATTRIBUTE_MAP; 55 56 60 public FlowExecutionImplStateRestorer(FlowDefinitionLocator definitionLocator) { 61 Assert.notNull(definitionLocator, "The flow definition locator is required"); 62 this.definitionLocator = definitionLocator; 63 } 64 65 70 public void setExecutionAttributes(AttributeMap executionAttributes) { 71 Assert.notNull(executionAttributes, "The execution attributes map is required"); 72 this.executionAttributes = executionAttributes; 73 } 74 75 83 public void setExecutionAttributesMap(Map executionAttributes) { 84 Assert.notNull(executionAttributes, "The execution attributes map is required"); 85 this.executionAttributes = new LocalAttributeMap(executionAttributes); 86 } 87 88 93 public void setExecutionListenerLoader(FlowExecutionListenerLoader executionListenerLoader) { 94 Assert.notNull(executionListenerLoader, "The listener loader is required"); 95 this.executionListenerLoader = executionListenerLoader; 96 } 97 98 public FlowExecution restoreState(FlowExecution flowExecution, MutableAttributeMap conversationScope) { 99 FlowExecutionImpl impl = (FlowExecutionImpl)flowExecution; 100 Flow flow = (Flow)definitionLocator.getFlowDefinition(impl.getFlowId()); 102 impl.setFlow(flow); 103 if (impl.hasSessions()) { 104 FlowSessionImpl root = impl.getRootSession(); 105 root.setFlow(flow); 106 root.setState(flow.getStateInstance(root.getStateId())); 107 if (impl.hasSubflowSessions()) { 108 Flow parent = flow; 109 for (ListIterator it = impl.getSubflowSessionIterator(); it.hasNext();) { 110 FlowSessionImpl subflow = (FlowSessionImpl)it.next(); 111 Flow definition; 112 if (parent.containsInlineFlow(subflow.getFlowId())) { 113 definition = parent.getInlineFlow(subflow.getFlowId()); 115 } else { 116 definition = (Flow)definitionLocator.getFlowDefinition(subflow.getFlowId()); 118 } 119 subflow.setFlow(definition); 120 subflow.setState(definition.getStateInstance(subflow.getStateId())); 121 parent = definition; 122 } 123 } 124 } 125 if (conversationScope == null) { 126 conversationScope = new LocalAttributeMap(); 127 } 128 impl.setConversationScope(conversationScope); 129 impl.setListeners(new FlowExecutionListeners(executionListenerLoader.getListeners(flow))); 130 impl.setAttributes(executionAttributes); 131 return flowExecution; 132 } 133 } | Popular Tags |