KickJava   Java API By Example, From Geeks To Geeks.

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


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: Sample1AdminWF.java,v 1.3 2005/03/18 14:50:41 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 Sample1AdminWF{
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       // User registration interface creation
59
UserRegistrationHome urHome = UserRegistrationUtil.getHome();
60       UserRegistration userReg=urHome.create();
61       
62       // User "jack" (customer) creation in Bonita database
63
try{
64          userReg.userCreate("jack","jack","miguel.valdes-faura@ext.bull.net");
65       }catch(Exception JavaDoc e){System.out.println(e) ;} // Maybe user exists
66

67       
68       // User "john" (service customer) creation in Bonita database
69
try{
70          userReg.userCreate("john","john","miguel.valdes-faura@ext.bull.net");
71       }catch(Exception JavaDoc e){System.out.println(e) ;} // Maybe user exists
72

73       userReg.remove();
74       
75       // Project Session interface instantiation (for admin user)
76
// And user registration in Order Processing Project instance
77
ProjectSessionHome prjSessionHome=ProjectSessionUtil.getHome();
78       ProjectSession prjSession = prjSessionHome.create();
79       
80       try {
81       String JavaDoc instName = prjSession.instantiateProject("Order Processing");
82       }catch(Exception JavaDoc e){System.out.println(e) ;} // Maybe project does not exists
83

84       // User Session interface instanciation (for admin user)
85
// and User registration in "Accept Order" Project instance
86
// For this we need to get the Accpet Order instance
87
UserSessionHome usHome=UserSessionUtil.getHome();
88       UserSession uSession = usHome.create();
89       
90       try {
91       Collection names = uSession.getProjectInstancesNames("Order Processing");
92       Iterator i = names.iterator() ;
93       prjSession.initProject((String JavaDoc) i.next());
94           
95       // admin user adds "jack" (customer) and "john" (customer service) to this workflow instance
96
prjSession.addUser("jack");
97       prjSession.addUser("john");
98                
99           // admin user sets "customer" role to "miguel" for this instance
100
prjSession.setUserRole("jack","customer");
101       // admin user sets "agent" role to "john" (Customer Service) for this instance
102
prjSession.setUserRole("john","agent");
103       
104      //}
105
}catch(Exception JavaDoc e){e.printStackTrace();}
106      
107       prjSession.remove() ;
108     }
109
110     
111 }
112
113
114
Popular Tags