1 16 package org.springframework.webflow.engine.builder; 17 18 import org.springframework.binding.mapping.AttributeMapper; 19 import org.springframework.webflow.core.collection.AttributeMap; 20 import org.springframework.webflow.engine.ActionState; 21 import org.springframework.webflow.engine.DecisionState; 22 import org.springframework.webflow.engine.EndState; 23 import org.springframework.webflow.engine.Flow; 24 import org.springframework.webflow.engine.FlowAttributeMapper; 25 import org.springframework.webflow.engine.FlowExecutionExceptionHandler; 26 import org.springframework.webflow.engine.State; 27 import org.springframework.webflow.engine.SubflowState; 28 import org.springframework.webflow.engine.TargetStateResolver; 29 import org.springframework.webflow.engine.Transition; 30 import org.springframework.webflow.engine.TransitionCriteria; 31 import org.springframework.webflow.engine.TransitionableState; 32 import org.springframework.webflow.engine.ViewSelector; 33 import org.springframework.webflow.engine.ViewState; 34 import org.springframework.webflow.execution.Action; 35 36 47 public class FlowArtifactFactory { 48 49 65 public Flow createFlow(String id, AttributeMap attributes) throws FlowArtifactLookupException { 66 Flow flow = new Flow(id); 67 flow.getAttributeMap().putAll(attributes); 68 return flow; 69 } 70 71 92 public State createViewState(String id, Flow flow, Action[] entryActions, ViewSelector viewSelector, 93 Action[] renderActions, Transition[] transitions, FlowExecutionExceptionHandler[] exceptionHandlers, 94 Action[] exitActions, AttributeMap attributes) throws FlowArtifactLookupException { 95 ViewState viewState = new ViewState(flow, id); 96 if (viewSelector != null) { 97 viewState.setViewSelector(viewSelector); 98 } 99 viewState.getRenderActionList().addAll(renderActions); 100 configureCommonProperties(viewState, entryActions, transitions, exceptionHandlers, exitActions, attributes); 101 return viewState; 102 } 103 104 124 public State createActionState(String id, Flow flow, Action[] entryActions, Action[] actions, 125 Transition[] transitions, FlowExecutionExceptionHandler[] exceptionHandlers, Action[] exitActions, 126 AttributeMap attributes) throws FlowArtifactLookupException { 127 ActionState actionState = new ActionState(flow, id); 128 actionState.getActionList().addAll(actions); 129 configureCommonProperties(actionState, entryActions, transitions, exceptionHandlers, exitActions, attributes); 130 return actionState; 131 } 132 133 151 public State createDecisionState(String id, Flow flow, Action[] entryActions, Transition[] transitions, 152 FlowExecutionExceptionHandler[] exceptionHandlers, Action[] exitActions, AttributeMap attributes) 153 throws FlowArtifactLookupException { 154 DecisionState decisionState = new DecisionState(flow, id); 155 configureCommonProperties(decisionState, entryActions, transitions, exceptionHandlers, exitActions, attributes); 156 return decisionState; 157 } 158 159 180 public State createSubflowState(String id, Flow flow, Action[] entryActions, Flow subflow, 181 FlowAttributeMapper attributeMapper, Transition[] transitions, 182 FlowExecutionExceptionHandler[] exceptionHandlers, Action[] exitActions, AttributeMap attributes) 183 throws FlowArtifactLookupException { 184 SubflowState subflowState = new SubflowState(flow, id, subflow); 185 if (attributeMapper != null) { 186 subflowState.setAttributeMapper(attributeMapper); 187 } 188 configureCommonProperties(subflowState, entryActions, transitions, exceptionHandlers, exitActions, attributes); 189 return subflowState; 190 } 191 192 211 public State createEndState(String id, Flow flow, Action[] entryActions, ViewSelector viewSelector, 212 AttributeMapper outputMapper, FlowExecutionExceptionHandler[] exceptionHandlers, AttributeMap attributes) 213 throws FlowArtifactLookupException { 214 EndState endState = new EndState(flow, id); 215 if (viewSelector != null) { 216 endState.setViewSelector(viewSelector); 217 } 218 if (outputMapper != null) { 219 endState.setOutputMapper(outputMapper); 220 } 221 configureCommonProperties(endState, entryActions, exceptionHandlers, attributes); 222 return endState; 223 } 224 225 241 public Transition createTransition(TargetStateResolver targetStateResolver, TransitionCriteria matchingCriteria, 242 TransitionCriteria executionCriteria, AttributeMap attributes) throws FlowArtifactLookupException { 243 Transition transition = new Transition(targetStateResolver); 244 if (matchingCriteria != null) { 245 transition.setMatchingCriteria(matchingCriteria); 246 } 247 if (executionCriteria != null) { 248 transition.setExecutionCriteria(executionCriteria); 249 } 250 transition.getAttributeMap().putAll(attributes); 251 return transition; 252 } 253 254 256 259 private void configureCommonProperties(TransitionableState state, Action[] entryActions, Transition[] transitions, 260 FlowExecutionExceptionHandler[] exceptionHandlers, Action[] exitActions, AttributeMap attributes) { 261 configureCommonProperties(state, entryActions, exceptionHandlers, attributes); 262 state.getTransitionSet().addAll(transitions); 263 state.getExitActionList().addAll(exitActions); 264 } 265 266 269 private void configureCommonProperties(State state, Action[] entryActions, 270 FlowExecutionExceptionHandler[] exceptionHandlers, AttributeMap attributes) { 271 state.getEntryActionList().addAll(entryActions); 272 state.getExceptionHandlerSet().addAll(exceptionHandlers); 273 state.getAttributeMap().putAll(attributes); 274 } 275 } | Popular Tags |