KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2  *
3  * Bonita
4  * Copyright (C) 1999 Bull S.A.
5  * Bull 68 route de versailles 78434 Louveciennes Cedex France
6  * Further information: bonita@objectweb.org
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21  * USA
22  *
23  *
24 --------------------------------------------------------------------------
25  * $Id: Inscription.java,v 1.3 2004/11/10 17:10:50 mvaldes Exp $
26  *
27 --------------------------------------------------------------------------
28  */

29
30 package hero.client.samples;
31
32 import javax.security.auth.login.LoginContext JavaDoc;
33 import hero.client.test.SimpleCallbackHandler;
34
35 import hero.interfaces.ProjectSession;
36 import hero.interfaces.ProjectSessionHome;
37 import hero.interfaces.ProjectSessionUtil;
38
39 import hero.interfaces.UserSession;
40 import hero.interfaces.UserSessionHome;
41 import hero.interfaces.UserSessionUtil;
42
43 import hero.interfaces.UserRegistration;
44 import hero.interfaces.UserRegistrationHome;
45 import hero.interfaces.UserRegistrationUtil;
46
47 import java.util.*;
48
49 public class Inscription {
50     
51     static public void main(String JavaDoc[] args) throws Exception JavaDoc{
52       // Admin login
53
char[] password={'t','o','t','o'};
54       SimpleCallbackHandler handler = new SimpleCallbackHandler("admin",password);
55       LoginContext JavaDoc lc = new LoginContext JavaDoc("TestClient", handler);
56       lc.login();
57           
58       // Project Session interface instantiation (for admin user)
59
ProjectSessionHome lHome=ProjectSessionUtil.getHome();
60       ProjectSession lProject = lHome.create();
61       String JavaDoc instName = lProject.instantiateProject("e-citizen");
62       
63       // "user1" (e-citizen) creation in Bonita database
64
UserRegistrationHome urHome = UserRegistrationUtil.getHome();
65       UserRegistration userReg=urHome.create();
66       try{
67          userReg.userCreate("user1","user1","miguel.valdes-faura@ext.bull.net");
68       }catch(Exception JavaDoc e){} // Maybe user exists
69
userReg.remove();
70       
71       // "agent1" creation in Bonita database
72
urHome = UserRegistrationUtil.getHome();
73       userReg=urHome.create();
74       try{
75          userReg.userCreate("agent1","agent1","miguel.valdes-faura@ext.bull.net");
76       }catch(Exception JavaDoc e){} // Maybe user exists
77
userReg.remove();
78       
79       // admin user adds "user1" (e-citizen) to this workflow instance
80
lProject.addUser("user1");
81       lProject.addUser("agent1");
82       // admin user adds "InitialRole" to "user1" (e-citizen) for this instance
83
lProject.setUserRole("user1","InitialRole");
84       // admin user adds "agent" role to "agent1" (Agent) for this instance
85
lProject.setUserRole("agent1","agent");
86       // admin user adds "user1" process properties
87
lProject.setProperty("userId","user1");
88       lProject.setProperty("recordId","1111");
89       lProject.setProperty("orderId","0001");
90           
91       // "user1" is logged
92
char[] password2={'u','s','e','r','1'};
93       handler = new SimpleCallbackHandler("user1",password2);
94       lc = new LoginContext JavaDoc("TestClient", handler);
95       lc.login();
96       
97       // user1 creates User Session Bean
98
UserSessionHome uHome=UserSessionUtil.getHome();
99       UserSession uSession = uHome.create();
100       Collection nodes = uSession.getToDoList(instName);
101       Iterator i = nodes.iterator();
102       while (i.hasNext())
103       {
104         String JavaDoc activityName = (String JavaDoc)i.next();
105         uSession.startActivity(instName,activityName);
106         System.out.println("Start application activity... wait for termination");
107         uSession.terminateActivity(instName,activityName);
108         System.out.println("Terminate activity");
109       }
110       
111       // "agent1" is logged
112
char[] password3={'a','g','e','n','t','1'};
113       handler = new SimpleCallbackHandler("agent1",password3);
114       lc = new LoginContext JavaDoc("TestClient", handler);
115       lc.login();
116       
117       // agent1 creates User Session Bean
118
uHome=UserSessionUtil.getHome();
119       UserSession aSession = uHome.create();
120       nodes = aSession.getToDoList(instName);
121       i = nodes.iterator();
122       while (i.hasNext())
123       {
124         String JavaDoc activityName = (String JavaDoc)i.next();
125         // The user data is not correct...
126
ProjectSessionHome lHomeAgent1=ProjectSessionUtil.getHome();
127         ProjectSession lProjectAgent1 = lHome.create();
128         lProjectAgent1.initProject(instName);
129         
130         lProjectAgent1.setNodeProperty(activityName,"correct","nok");
131         aSession.startActivity(instName,activityName);
132         System.out.println("Start application activity... wait for termination");
133         aSession.terminateActivity(instName,activityName);
134         System.out.println("Terminate activity");
135       }
136     }
137 }
138
139
140
Popular Tags