01 package org.jbpm.gop;
02
03 import java.util.List;
04
05 /** one path of execution */
06 public class Execution {
07
08 /** pointer to the current node */
09 public Node node = null;
10
11 /** an execution always starts in a given node */
12 public Execution(Node node) {
13 this.node = node;
14 }
15
16 /** executes the current node's actions and takes the event's transition */
17 public void event(String event) {
18 System.out.println(this+" received event '"+event+"' on "+node);
19 fire(event);
20 if (node.transitions.containsKey(event)) {
21 System.out.println(this+" leaves "+node);
22 fire("leave-node");
23 take(node.transitions.get(event));
24 }
25 }
26
27 /** take a transition */
28 void take(Transition transition) {
29 System.out.println(this+" takes transition to "+transition.destination);
30 node = transition.destination;
31 enter(transition.destination);
32 }
33
34 /** enter the next node */
35 void enter(Node node) {
36 System.out.println(this+" enters "+node);
37 fire("enter-node");
38 node.execute(this);
39 }
40
41 /** fires the actions of a node for a specific event */
42 void fire(String event) {
43 List<Action> eventActions = node.actions.get(event);
44 if (eventActions!=null) {
45 System.out.println(this+" fires actions for event '"+event);
46 for (Action action : eventActions)
47 action.execute(this);
48 }
49 }
50
51 public String toString() {return "execution";}
52 }
|