KickJava   Java API By Example, From Geeks To Geeks.

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


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

24
25
26 import javax.security.auth.login.LoginContext JavaDoc;
27 import hero.client.test.SimpleCallbackHandler;
28
29 import hero.interfaces.UserSession;
30 import hero.interfaces.UserSessionHome;
31 import hero.interfaces.UserSessionUtil;
32
33 import hero.interfaces.Constants;
34
35 import java.util.*;
36
37 public class SampleUserApi {
38     
39     static public void main(String JavaDoc[] args) throws Exception JavaDoc{
40     
41           // User Admin login
42
char[] password={'t','o','t','o'};
43           SimpleCallbackHandler handler = new SimpleCallbackHandler("admin",password);
44           LoginContext JavaDoc lc = new LoginContext JavaDoc("TestClient", handler);
45           lc.login();
46
47          // User Session Bean Creation using Remote Interface
48
UserSessionHome usrHome= (UserSessionHome) UserSessionUtil.getHome();
49           UserSession usrSession = usrHome.create();
50     
51           //***************************************************************/
52
//************** API Documentation - Sample 6 ***************/
53
//************** Users and Activities *****************/
54
//***************************************************************/
55

56       System.out.println("Current User Name/Passwd : " + usrSession.getUser() + "/" + usrSession.getUserPassword());
57
58       usrSession.setUserProperty("Language","Spanish");
59
60       System.out.println("Getting Current User properties values" );
61           Collection properties = usrSession.getUserProperties() ;
62           Iterator i = properties.iterator();
63           while (i.hasNext())
64           {
65                 hero.interfaces.BnUserPropertyValue property = (hero.interfaces.BnUserPropertyValue)i.next();
66                 try {
67                         String JavaDoc propertyKeyName = property.getTheKey();
68                         String JavaDoc propertyValue = (String JavaDoc)property.getTheValue();
69                         System.out.println("Property (Key, Value) : " + propertyKeyName + "/" + propertyValue);
70                 } catch(Exception JavaDoc e) {System.out.println(e);} //Maybe there is a problem
71
}
72
73       System.out.println("\n Getting project names for this user");
74       try {
75             Collection prjNames = usrSession.getProjectListNames() ;
76             Iterator j = prjNames.iterator();
77             while (j.hasNext())
78             {
79                 String JavaDoc prjName = (String JavaDoc)j.next();
80                 System.out.println(" --> Project : " + prjName ); }
81       } catch(Exception JavaDoc e) {System.out.println(" --> " + e);} //Maybe something is wrong
82

83
84       System.out.println("\n Starting & terminating Activities available for this user");
85       try {
86             Collection instNames = usrSession.getInstancesListNames() ;
87             Iterator j = instNames.iterator();
88             while (j.hasNext())
89             {
90                 String JavaDoc instName = (String JavaDoc)j.next();
91                 System.out.println("--> INSTANCE : " + instName );
92
93           System.out.println("Getting ToDo list for this instance");
94               Collection activityNames = usrSession.getToDoList(instName) ;
95               Iterator k = activityNames.iterator();
96               while (k.hasNext())
97               {
98                 String JavaDoc activityName = (String JavaDoc)k.next();
99                 System.out.println(" --> activity : " + activityName );
100         try {
101             usrSession.startActivity(instName,activityName) ;
102                     System.out.println(" --> activity started" );
103         } catch(Exception JavaDoc e) {System.out.println(" --> " + e);} //Maybe something is wrong
104
} // End ToDo list
105

106           System.out.println("Getting the activity List (executing or anticipating) for the user");
107               activityNames = usrSession.getActivityList(instName) ;
108               k = activityNames.iterator();
109               while (k.hasNext())
110               {
111                 String JavaDoc activityName = (String JavaDoc)k.next();
112                 System.out.println(" --> activity : " + activityName );
113         try {
114             usrSession.terminateActivity(instName,activityName) ;
115                     System.out.println(" --> activity terminated" );
116         } catch(Exception JavaDoc e) {System.out.println(" --> " + e);} //Maybe something is wrong
117
} // End ToDo list
118

119         } // End Intances List
120

121       } catch(Exception JavaDoc e) {System.out.println(" --> " + e);} //Maybe something is wrong
122

123     } //End Main
124

125 } // End SampleProjectApi Class
126

127
Popular Tags