KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > graph > node > StartState


1 package org.jbpm.graph.node;
2
3 import java.util.Map JavaDoc;
4
5 import org.dom4j.Element;
6 import org.jbpm.graph.def.Event;
7 import org.jbpm.graph.def.Node;
8 import org.jbpm.graph.def.Transition;
9 import org.jbpm.graph.exe.ExecutionContext;
10 import org.jbpm.jpdl.xml.JpdlXmlReader;
11 import org.jbpm.security.Authentication;
12 import org.jbpm.taskmgmt.def.Swimlane;
13 import org.jbpm.taskmgmt.def.TaskMgmtDefinition;
14 import org.jbpm.taskmgmt.exe.SwimlaneInstance;
15
16 public class StartState extends Node {
17   
18   private static final long serialVersionUID = 1L;
19   
20   // initiatorSwimlane of a start-state serves to capture the authenticate user
21
// that starts the process as the initiator.
22
public Swimlane initiatorSwimlane = null;
23
24   public StartState() {
25   }
26
27   public StartState(String JavaDoc name) {
28     super(name);
29   }
30
31   // event types //////////////////////////////////////////////////////////////
32

33   public static final String JavaDoc[] supportedEventTypes = new String JavaDoc[]{
34     Event.EVENTTYPE_NODE_LEAVE,
35     Event.EVENTTYPE_AFTER_SIGNAL
36   };
37   public String JavaDoc[] getSupportedEventTypes() {
38     return supportedEventTypes;
39   }
40
41   // xml //////////////////////////////////////////////////////////////////////
42

43   public void read(Element startStateElement, JpdlXmlReader jpdlReader) {
44     String JavaDoc swimlaneName = startStateElement.attributeValue("swimlane");
45     if (swimlaneName!=null) {
46       TaskMgmtDefinition taskMgmtDefinition = jpdlReader.getProcessDefinition().getTaskMgmtDefinition();
47       initiatorSwimlane = taskMgmtDefinition.getSwimlane(swimlaneName);
48     }
49     
50     // if the start-state has a task specified,
51
Element startTaskElement = startStateElement.element("task");
52     if (startTaskElement!=null) {
53       // delegate the parsing of the start-state task to the jpdlReader
54
jpdlReader.readStartStateTask(startTaskElement, this);
55     }
56   }
57
58   public void write(Element nodeElement) {
59   }
60   
61   public void leave(ExecutionContext executionContext, Transition transition) {
62     // if this start-state is associated with a initiatorSwimlane
63
if (initiatorSwimlane!=null) {
64       // get the initiator swimlane instance
65
SwimlaneInstance initiatorSwimlaneInstance = executionContext.getTaskMgmtInstance().getSwimlaneInstance(initiatorSwimlane.getName());
66       // then capture the authenticated user
67
String JavaDoc initiatorActorId = Authentication.getAuthenticatedActorId();
68       // then store the currently authenticated user as the actor in the initiator swimlane instance
69
initiatorSwimlaneInstance.setActorId(initiatorActorId);
70     }
71     
72     // leave this node as usual
73
super.leave(executionContext, transition);
74   }
75   
76   public void execute(ExecutionContext executionContext) {
77     throw new UnsupportedOperationException JavaDoc( "illegal operation : its not possible to arrive in a start-state" );
78   }
79   
80   public Transition addArrivingTransition(Transition t) {
81     throw new UnsupportedOperationException JavaDoc( "illegal operation : its not possible to add a transition that is arriving in a start state" );
82   }
83   
84   public void setArrivingTransitions(Map JavaDoc arrivingTransitions) {
85     if ( (arrivingTransitions!=null)
86          && (arrivingTransitions.size()>0)) {
87       throw new UnsupportedOperationException JavaDoc( "illegal operation : its not possible to set a non-empty map in the arriving transitions of a start state" );
88     }
89   }
90 }
91
Popular Tags