01: /*
02: * Created on Nov 23, 2005
03: */
04: package uk.org.ponder.rsf.flow.lite;
05:
06: import java.util.Iterator;
07:
08: public class FlowUtil {
09:
10: public static void validateFlow(Flow flow) {
11: if (flow.id == null) {
12: throw new IllegalArgumentException("Flow has no defined id");
13: }
14: if (flow.startstate == null
15: || flow.stateFor(flow.startstate) == null) {
16: throw new IllegalArgumentException("Flow with ID "
17: + flow.id + " has no valid start state: "
18: + flow.startstate);
19: }
20: for (Iterator it = flow.getStates().iterator(); it.hasNext();) {
21: State state = (State) it.next();
22: if (state instanceof ViewState) {
23: validateTransitions(flow,
24: ((ViewState) state).transitions,
25: ViewState.class);
26: } else if (state instanceof ActionState) {
27: validateTransitions(flow,
28: ((ActionState) state).transitions,
29: ActionState.class);
30: }
31: }
32: }
33:
34: private static void validateTransitions(Flow flow,
35: TransitionList list, Class source) {
36: for (int i = 0; i < list.size(); ++i) {
37: String to = list.transitionAt(i).to;
38: State tostate = flow.stateFor(to);
39: if (tostate == null) {
40: throw new IllegalArgumentException("Target state " + to
41: + " of transition not found");
42: }
43:
44: }
45: }
46: }
|