1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.rice.kew.engine.transition;
18
19 import org.kuali.rice.kew.engine.RouteContext;
20 import org.kuali.rice.kew.engine.RouteHelper;
21 import org.kuali.rice.kew.engine.node.Node;
22 import org.kuali.rice.kew.engine.node.ProcessResult;
23 import org.kuali.rice.kew.engine.node.RouteNode;
24 import org.kuali.rice.kew.engine.node.RouteNodeInstance;
25
26 import java.util.ArrayList;
27 import java.util.List;
28
29
30
31
32
33
34
35
36 public abstract class TransitionEngine {
37
38 private RouteHelper helper;
39
40 public RouteNodeInstance transitionTo(RouteNodeInstance nextNodeInstance, RouteContext context) throws Exception {
41 return nextNodeInstance;
42 }
43
44
45
46
47
48
49
50
51
52 public abstract ProcessResult isComplete(RouteContext context) throws Exception;
53
54 public Transition transitionFrom(RouteContext context, ProcessResult processResult) throws Exception {
55 return new Transition(resolveNextNodeInstances(context.getNodeInstance()));
56 }
57
58 protected void setRouteHelper(RouteHelper helper) {
59 this.helper = helper;
60 }
61
62 protected RouteHelper getRouteHelper() {
63 return helper;
64 }
65
66 protected Node getNode(RouteNode routeNode, Class nodeClass) throws Exception {
67 return helper.getNode(routeNode);
68 }
69
70
71
72
73
74
75
76
77
78 protected List<RouteNodeInstance> resolveNextNodeInstances(RouteNodeInstance nodeInstance, List<RouteNode> nextRouteNodes) {
79 List<RouteNodeInstance> nextNodeInstances = new ArrayList<RouteNodeInstance>();
80 for (RouteNode nextRouteNode : nextRouteNodes)
81 {
82 RouteNode nextNode = (RouteNode) nextRouteNode;
83 RouteNodeInstance nextNodeInstance = getRouteHelper().getNodeFactory().createRouteNodeInstance(nodeInstance.getDocumentId(), nextNode);
84 nextNodeInstance.setBranch(nodeInstance.getBranch());
85 nextNodeInstance.setProcess(nodeInstance.getProcess());
86 nextNodeInstances.add(nextNodeInstance);
87 }
88 return nextNodeInstances;
89 }
90
91 protected List<RouteNodeInstance> resolveNextNodeInstances(RouteNodeInstance nodeInstance) {
92 return resolveNextNodeInstances(nodeInstance, nodeInstance.getRouteNode().getNextNodes());
93 }
94
95 }