KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > mc > formgenerator > bonita > BonitaActivityExecutor


1 /*
2  * Created on 3 mai 2004
3  *
4  */

5 package mc.formgenerator.bonita;
6
7 import hero.interfaces.ProjectSession;
8 import hero.interfaces.ProjectSessionHome;
9 import hero.interfaces.ProjectSessionUtil;
10 import hero.interfaces.UserSession;
11 import hero.interfaces.UserSessionHome;
12 import hero.interfaces.UserSessionUtil;
13
14 import java.util.*;
15
16 import org.w3c.dom.Document JavaDoc;
17
18 /**
19  * @author delfourr
20  */

21 public class BonitaActivityExecutor {
22
23
24
25     /**
26      * Default constructor
27      */

28     public BonitaActivityExecutor() {
29         
30     }
31     
32     
33     
34     /**
35      * Allows to find, initialise and terminate an activity.
36      * @param document Document with the activity information (name, attributes and project name).
37      * @param mode the application mode: consumer or exploitant
38      * @throws LoginException
39      */

40     public void actOnActivity(Document JavaDoc document, String JavaDoc mode){
41         
42         //'parse' transforms a Document
43
DocumentParser parse = new DocumentParser();
44
45         DataActivity data = parse.parseActivity(document);
46         
47                 
48         //get the project name to wich it belongs
49
String JavaDoc projectName = data.getProcessName();
50
51
52         //get the activity name
53
String JavaDoc activityName = data.getActivityName();
54
55
56         //get the process properties
57
HashMap table = data.getProcessProperties();
58         
59         //terminate the activity thanks to its name and properties
60
this.startActivity(activityName, projectName, table, mode);
61     }
62     
63     
64     
65     
66     
67     /**
68      * Thanks to its name, the activity is found and stopped.
69      * Before, its attributes are set with the HashMap values.
70      * @param activityName Name of the activity to stop.
71      * @param projectName Name of the project to which it belongs.
72      * @param table HashMap with the activity attributes associated to their values
73      * @param mode the application mode: consumer or exploitant
74      * @throws LoginException
75      */

76     private void startActivity(String JavaDoc activityName, String JavaDoc projectName, HashMap table, String JavaDoc mode) {
77
78         //The local home
79
ProjectSessionHome projecth = null;
80
81         //The bean
82
ProjectSession project = null;
83
84         try {
85             //Getting local home by using JNDI
86
projecth = ProjectSessionUtil.getHome();
87
88             //Creation of the project
89
project = projecth.create();
90                 
91             project.initProject(projectName);
92                 
93
94             //**************************************************************************
95
// SET THE ACTIVITY PROPERTIES
96
//**************************************************************************
97

98             //All the keys are saved in a set
99
Set collec = table.keySet();
100
101             //Set properties if they exist
102
if (collec.size() > 0) {
103
104                 //For all the keys we have to retrieve the associated value
105
Iterator it = collec.iterator();
106
107                 //variable which will stock the property name
108
String JavaDoc cle="";
109
110                 while (it.hasNext()) {
111
112                     //Getting the values
113
cle = (String JavaDoc) it.next();
114
115                     //Set the current process property
116
project.setNodeProperty(activityName, cle, (String JavaDoc) table.get(cle));
117                 }
118             }
119             
120             //**************************************************************************
121
// START THE ACTIVITY
122
//**************************************************************************
123

124             //The local home
125
UserSessionHome userh = UserSessionUtil.getHome();
126
127             //The bean
128
UserSession user = userh.create();
129             //the session starts the activity
130
user.startActivity(projectName, activityName);
131             
132             //the session terminate the activity
133
user.terminateActivity(projectName, activityName);
134             
135             // test if the instance is termined
136
boolean isTerminated = project.isTerminated();
137             if (isTerminated)
138             {
139                 user.terminate(projectName);
140             }
141             //**************************************************************************
142
// STOP THE ACTIVITY
143
//**************************************************************************
144

145             //if(mode.equals("consumer"))
146
//this.endActivity(activityName, projectName);
147

148         } catch (Exception JavaDoc e) {
149             System.out.println(e.getMessage());
150         }
151     }
152
153     
154     
155
156
157     public void endActivity (String JavaDoc activityName, String JavaDoc projectName) {
158         try {
159             
160             //The local home
161
UserSessionHome userh = UserSessionUtil.getHome();
162         
163             //The bean
164
UserSession user = userh.create();
165             
166             
167             //the session terminates the activity
168
user.terminateActivity( projectName, activityName);
169             
170         } catch (Exception JavaDoc e) {
171             System.out.println(e.getMessage());
172         }
173     }
174     
175 }
176
Popular Tags