KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hero > client > samples > Sample1RunningSession


1 package hero.client.samples;
2
3
4 /*
5 *
6 * Inscription.java -
7 * Copyright (C) 2004 Ecoo Team
8 * miguel.valdes-faura@ext.bull.net
9 *
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 */

25
26 /* This class implements the third part of the Business Process example described in the
27 * "BONITA workflow cooperative System Users's Guide
28 * jack : Custumer
29 * john : Custumer Service employee
30 */

31
32
33 import javax.security.auth.login.LoginContext JavaDoc;
34 import hero.client.test.SimpleCallbackHandler;
35
36 import hero.interfaces.ProjectSession;
37 import hero.interfaces.ProjectSessionHome;
38 import hero.interfaces.ProjectSessionUtil;
39
40 import hero.interfaces.UserSession;
41 import hero.interfaces.UserSessionHome;
42 import hero.interfaces.UserSessionUtil;
43
44 import hero.interfaces.UserRegistration;
45 import hero.interfaces.UserRegistrationHome;
46 import hero.interfaces.UserRegistrationUtil;
47
48 import java.util.*;
49
50 public class Sample1RunningSession {
51     
52     static public void main(String JavaDoc[] args) throws Exception JavaDoc{
53     
54       // jackOrderProcessing
55
// "jack" is logged
56
char[] passwordJack={'j','a','c','k'};
57       SimpleCallbackHandler handlerJack = new SimpleCallbackHandler("jack",passwordJack);
58       LoginContext JavaDoc lcJack = new LoginContext JavaDoc("TestClient", handlerJack);
59       lcJack.login();
60       
61           
62       // jack creates User Session Bean (Activity running)
63
UserSessionHome userHome=UserSessionUtil.getHome();
64       UserSession userSession = userHome.create();
65       
66       Collection names = userSession.getProjectInstancesNames("Order Processing");
67       Iterator i = names.iterator() ;
68       String JavaDoc instNameOP = (String JavaDoc) i.next();
69       
70       // ProjectSessionBean needed (Activity properties setting )
71
ProjectSessionHome prjHome=ProjectSessionUtil.getHome();
72       ProjectSession prjSession = prjHome.create();
73       
74       
75       System.out.println("SessionBean created");
76           
77      // Verifying roles
78
try {
79         prjSession.initProject(instNameOP) ;
80      } catch(Exception JavaDoc e){System.out.println("initProject : exception raised") ;}
81         
82      try {
83      Collection roleNames = prjSession.getUserRolesInProject("jack") ;
84      Iterator j = roleNames.iterator();
85      while (j.hasNext())
86      {
87         System.out.println("user jack : rôle : "+ j.next());
88      }
89     } catch(Exception JavaDoc e){System.out.println("getUserRolesInProject : exception raised : " + e) ;}
90     
91     
92     // Activity to be started :
93
String JavaDoc activityName = "Receive Order" ;
94     
95     // etat de l'activité avant lancement
96
int state = 0 ;
97       try {
98         state = prjSession.getNodeState(activityName);
99       } catch(Exception JavaDoc e){System.out.println("getNodeState : exception raised") ;}
100   
101       System.out.println("Verification : Node State : " + state);
102     
103        
104       try {
105         userSession.startActivity(instNameOP,activityName);
106         System.out.println("(Jack) Activity started : "+ activityName);
107      } catch(Exception JavaDoc e){System.out.println("startActivity : exception raised : "+ e) ;} // Maybe instance or activity does not exists
108

109        
110       try {
111         state = prjSession.getNodeState(activityName);
112       } catch(Exception JavaDoc e){System.out.println("getNodeState : exception raised") ;}
113   
114       System.out.println("Verification : Node State : " + state);
115     
116
117      // Now He has to set the Order Data : setting the values for the properties associated to this activities
118
try {
119         prjSession.setNodeProperty(activityName,"customer_name","jack",true) ;
120         prjSession.setNodeProperty(activityName,"product_name","tv",true) ;
121         prjSession.setNodeProperty(activityName,"items","1",true) ;
122      } catch(Exception JavaDoc e){System.out.println("setNodeProperty : exception raised : "+ e) ;} // maybe it raises some exception
123

124      System.out.println("properties set");
125      
126      try {
127      Collection Properties = prjSession.getNodeProperties(activityName) ;
128      Iterator k = Properties.iterator();
129      while (k.hasNext())
130      {
131         System.out.println("Activity "+ activityName +" property : "+ k.next());
132      }
133     } catch(Exception JavaDoc e){System.out.println("getNodeProperties : exception raised : " + e) ;}
134     
135       
136        try {
137         userSession.terminateActivity(instNameOP,activityName);
138         System.out.println("(Jack) Activity terminated : " + activityName);
139      } catch(Exception JavaDoc e){System.out.println("terminateActivity : exception raised : "+ e) ;} // Maybe instance or activity does not exists
140

141 // johnStartAcceptOrder
142
// "john" is logged
143
char[] passwordJohn ={'j','o','h','n'};
144       SimpleCallbackHandler handlerJohn = new SimpleCallbackHandler("john",passwordJohn);
145       LoginContext JavaDoc lcJohn = new LoginContext JavaDoc("TestClient", handlerJohn);
146       lcJohn.login();
147
148       names = userSession.getProjectInstancesNames("Accept Order");
149       i = names.iterator() ;
150       String JavaDoc instNameAO = (String JavaDoc) i.next();;
151
152       
153       // Activity to be started :
154
activityName = instNameAO ;
155       
156     try {
157         userSession.startActivity(instNameOP,activityName);
158         System.out.println("(John) Activity started : "+ activityName);
159      } catch(Exception JavaDoc e){System.out.println("startActivity : exception raised : "+ e) ;} // Maybe instance or activity does not exists
160

161 // jackStartAskCustomer
162
// Jack context
163
lcJack.login();
164
165     // Session bean already created
166
// Activity to be started :
167
activityName = "Ask Customer" ;
168       
169     try {
170         userSession.startActivity(instNameAO,activityName);
171         System.out.println("(Jack) Activity started : "+ activityName);
172      } catch(Exception JavaDoc e){System.out.println("startActivity : exception raised : "+ e) ;} // Maybe instance or activity does not exists
173

174        try {
175         userSession.terminateActivity(instNameAO,activityName);
176         System.out.println("(Jack) Activity terminated : "+ activityName);
177      } catch(Exception JavaDoc e){System.out.println("terminateActivity : exception raised : "+ e) ;} // Maybe instance or activity does not exists
178

179      //johnTermAcceptOrder
180
// John context
181
lcJohn.login();
182
183     // Session bean already created
184

185     // John starts and terminates "Notify Sales"
186
activityName = "Notify Sales" ;
187     try {
188         userSession.startActivity(instNameAO,activityName);
189         System.out.println("(John) Activity started : "+ activityName);
190      } catch(Exception JavaDoc e){System.out.println("startActivity : exception raised : "+ e) ;} // Maybe instance or activity does not exists
191

192      try {
193         userSession.terminateActivity(instNameAO,activityName);
194         System.out.println("(John) Activity terminated : "+ activityName);
195      } catch(Exception JavaDoc e){System.out.println("terminateActivity : exception raised : "+ e) ;} // Maybe instance or activity does not exists
196

197     // John terminates "Accept Order"
198
try {
199         userSession.terminateActivity(instNameOP,instNameAO);
200         System.out.println("(John) Activity terminated : "+ instNameAO);
201      } catch(Exception JavaDoc e){System.out.println("terminateActivity : exception raised : "+ e) ;} // Maybe instance or activity does not exists
202

203     System.out.println(" ");
204     System.out.println(" ------------------------------------------");
205     System.out.println(" First Iteration terminated");
206     System.out.println(" Play other iterations with Bonita manager tool (jack and john users)");
207     System.out.println(" To stop : just use Bonita Web admin page (admin user) and ") ;
208     System.out.println(" position the once_more property to KO for the Accept Order_Instance1 SUB PROJECT ") ;
209     System.out.println("(and not activity) before terminating the Notify Sales activity ");
210     System.out.println(" ------------------------------------------");
211
212     }
213
214
215
216
217 }
218
219
220
Popular Tags