1 16 package org.springframework.webflow.engine.impl; 17 18 import java.io.Externalizable ; 19 import java.io.IOException ; 20 import java.io.ObjectInput ; 21 import java.io.ObjectOutput ; 22 23 import org.springframework.core.style.ToStringCreator; 24 import org.springframework.util.Assert; 25 import org.springframework.webflow.core.collection.LocalAttributeMap; 26 import org.springframework.webflow.core.collection.MutableAttributeMap; 27 import org.springframework.webflow.definition.FlowDefinition; 28 import org.springframework.webflow.definition.StateDefinition; 29 import org.springframework.webflow.engine.Flow; 30 import org.springframework.webflow.engine.State; 31 import org.springframework.webflow.execution.FlowSession; 32 import org.springframework.webflow.execution.FlowSessionStatus; 33 34 45 class FlowSessionImpl implements FlowSession, Externalizable { 46 47 53 private transient Flow flow; 54 55 59 private String flowId; 60 61 67 private transient State state; 68 69 73 private String stateId; 74 75 79 private FlowSessionStatus status = FlowSessionStatus.CREATED; 80 81 84 private MutableAttributeMap scope = new LocalAttributeMap(); 85 86 89 private MutableAttributeMap flashMap = new LocalAttributeMap(); 90 91 95 private FlowSessionImpl parent; 96 97 101 public FlowSessionImpl() { 102 } 103 104 109 public FlowSessionImpl(Flow flow, FlowSessionImpl parent) { 110 setFlow(flow); 111 this.parent = parent; 112 } 113 114 116 public FlowDefinition getDefinition() { 117 return flow; 118 } 119 120 public StateDefinition getState() { 121 return state; 122 } 123 124 public FlowSessionStatus getStatus() { 125 return status; 126 } 127 128 public MutableAttributeMap getScope() { 129 return scope; 130 } 131 132 public MutableAttributeMap getFlashMap() { 133 return flashMap; 134 } 135 136 public FlowSession getParent() { 137 return parent; 138 } 139 140 public boolean isRoot() { 141 return parent == null; 142 } 143 144 146 public void readExternal(ObjectInput in) throws IOException , ClassNotFoundException { 147 flowId = (String )in.readObject(); 148 stateId = (String )in.readObject(); 149 status = (FlowSessionStatus)in.readObject(); 150 scope = (MutableAttributeMap)in.readObject(); 151 flashMap = (MutableAttributeMap)in.readObject(); 152 parent = (FlowSessionImpl)in.readObject(); 153 } 154 155 public void writeExternal(ObjectOutput out) throws IOException { 156 out.writeObject(flowId); 157 out.writeObject(stateId); 158 out.writeObject(status); 159 out.writeObject(scope); 160 out.writeObject(flashMap); 161 out.writeObject(parent); 162 } 163 164 167 172 void setFlow(Flow flow) { 173 Assert.notNull(flow, "The flow is required"); 174 this.flow = flow; 175 this.flowId = flow.getId(); 176 } 177 178 184 void setState(State state) { 185 Assert.notNull(state, "The state is required"); 186 Assert.isTrue(flow == state.getOwner(), 187 "The state does not belong to the flow associated with this flow session"); 188 this.state = state; 189 this.stateId = state.getId(); 190 } 191 192 196 void setStatus(FlowSessionStatus status) { 197 Assert.notNull(status, "The flow session status is requred"); 198 this.status = status; 199 } 200 201 204 String getFlowId() { 205 return flowId; 206 } 207 208 211 String getStateId() { 212 return stateId; 213 } 214 215 public String toString() { 216 return new ToStringCreator(this).append("flow", flowId).append("state", stateId).append("scope", scope).append( 217 "flashMap", flashMap).append("status", status).toString(); 218 } 219 } | Popular Tags |