KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > graph > def > Event


1 package org.jbpm.graph.def;
2
3 import java.io.Serializable JavaDoc;
4 import java.util.ArrayList JavaDoc;
5 import java.util.List JavaDoc;
6
7 public class Event implements Serializable JavaDoc {
8   
9   private static final long serialVersionUID = 1L;
10
11   public static final String JavaDoc EVENTTYPE_TRANSITION = "transition";
12   public static final String JavaDoc EVENTTYPE_BEFORE_SIGNAL = "before-signal";
13   public static final String JavaDoc EVENTTYPE_AFTER_SIGNAL = "after-signal";
14   public static final String JavaDoc EVENTTYPE_PROCESS_START = "process-start";
15   public static final String JavaDoc EVENTTYPE_PROCESS_END = "process-end";
16   public static final String JavaDoc EVENTTYPE_NODE_ENTER = "node-enter";
17   public static final String JavaDoc EVENTTYPE_NODE_LEAVE = "node-leave";
18   public static final String JavaDoc EVENTTYPE_SUPERSTATE_ENTER = "superstate-enter";
19   public static final String JavaDoc EVENTTYPE_SUPERSTATE_LEAVE = "superstate-leave";
20   public static final String JavaDoc EVENTTYPE_SUBPROCESS_CREATED = "subprocess-created";
21   public static final String JavaDoc EVENTTYPE_SUBPROCESS_END = "subprocess-end";
22   public static final String JavaDoc EVENTTYPE_TASK_CREATE = "task-create";
23   public static final String JavaDoc EVENTTYPE_TASK_ASSIGN = "task-assign";
24   public static final String JavaDoc EVENTTYPE_TASK_START = "task-start";
25   public static final String JavaDoc EVENTTYPE_TASK_END = "task-end";
26   public static final String JavaDoc EVENTTYPE_TIMER = "timer";
27
28   long id = 0;
29   protected String JavaDoc eventType = null;
30   protected GraphElement graphElement = null;
31   protected List JavaDoc actions = null;
32   
33   // constructors /////////////////////////////////////////////////////////////
34

35   public Event() {
36   }
37   
38   public Event(String JavaDoc eventType) {
39     this.eventType = eventType;
40   }
41
42   public Event(GraphElement graphElement, String JavaDoc eventType) {
43     this.graphElement = graphElement;
44     this.eventType = eventType;
45   }
46
47   // actions //////////////////////////////////////////////////////////////////
48

49   /**
50    * is the list of actions associated to this event.
51    * @return an empty list if no actions are associated.
52    */

53   public List JavaDoc getActions() {
54     return actions;
55   }
56
57   public boolean hasActions() {
58     return ( (actions!=null)
59              && (actions.size()>0) );
60   }
61
62   public Action addAction(Action action) {
63     if (action==null) throw new IllegalArgumentException JavaDoc("can't add a null action to an event");
64     if (actions==null) actions = new ArrayList JavaDoc();
65     actions.add(action);
66     action.event = this;
67     return action;
68   }
69
70   public void removeAction(Action action) {
71     if (action==null) throw new IllegalArgumentException JavaDoc("can't remove a null action from an event");
72     if (actions!=null) {
73       if (actions.remove(action)) {
74         action.event=null;
75       }
76     }
77   }
78
79   // behaviour ////////////////////////////////////////////////////////////////
80
/*
81   public void fire(ExecutionContext executionContext) {
82     // create the action context
83     executionContext.setEvent(this);
84
85     // the next instruction merges the actions specified in the process definition with the runtime actions
86     List actions = collectActions(executionContext);
87     
88     // calculate if the event was fired on this element or if it was a propagated event
89     boolean isPropagated = (executionContext.getEventSource()!=graphElement);
90     
91     // loop over all actions of this event
92     Iterator iter = actions.iterator();
93     while (iter.hasNext()) {
94       Action action = (Action) iter.next();
95       executionContext.setAction(action);
96       
97       if ( (!isPropagated)
98            || (action.acceptsPropagatedEvents() ) ) {
99
100         // create action log
101         ActionLog actionLog = new ActionLog(action);
102         executionContext.getToken().startCompositeLog(actionLog);
103
104         try {
105           // execute the action
106           action.execute(executionContext);
107
108         } catch (Throwable exception) {
109           log.error("action threw exception: "+exception.getMessage(), exception);
110           
111           // log the action exception
112           actionLog.setException(exception);
113
114           // if an exception handler is available
115           graphElement.raiseException(exception, executionContext);
116         } finally {
117           executionContext.getToken().endCompositeLog();
118         }
119       }
120     }
121   }
122 */

123   /**
124    * collects static and runtime actions.
125   private List collectActions(ExecutionContext executionContext) {
126     List mergedActions = new ArrayList();
127
128     // first, add all actions
129     if (actions!=null) {
130       mergedActions.addAll(actions);
131     }
132     
133     // then add all runtime actions
134     List runtimeActions = executionContext.getProcessInstance().getRuntimeActions();
135     if (runtimeActions!=null) {
136       Iterator iter = runtimeActions.iterator();
137       while (iter.hasNext()) {
138         RuntimeAction runtimeAction = (RuntimeAction) iter.next();
139         if (this==runtimeAction.getEvent()) {
140           mergedActions.add(runtimeAction.getAction());
141         }
142       }
143     }
144     
145     return mergedActions;
146   }
147    */

148
149   public String JavaDoc toString() {
150     return eventType;
151   }
152
153   // getters and setters //////////////////////////////////////////////////////
154

155   public String JavaDoc getEventType() {
156     return eventType;
157   }
158   public GraphElement getGraphElement() {
159     return graphElement;
160   }
161   public long getId() {
162     return id;
163   }
164   
165   // private static final Log log = LogFactory.getLog(Event.class);
166
}
167
Popular Tags