001: package hero.client.samples;
002:
003: /*
004: *
005: * Inscription.java -
006: * Copyright (C) 2004 Ecoo Team
007: * Anne.Geron@bull.net
008: *
009: *
010: * This program is free software; you can redistribute it and/or
011: * modify it under the terms of the GNU Lesser General Public License
012: * as published by the Free Software Foundation; either version 2
013: * of the License, or (at your option) any later version.
014: *
015: * This program is distributed in the hope that it will be useful,
016: * but WITHOUT ANY WARRANTY; without even the implied warranty of
017: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
018: * GNU Lesser General Public License for more details.
019: *
020: * You should have received a copy of the GNU Lesser General Public License
021: * along with this program; if not, write to the Free Software
022: * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
023: */
024:
025: import javax.security.auth.login.LoginContext;
026: import hero.client.test.SimpleCallbackHandler;
027:
028: import hero.interfaces.UserSession;
029: import hero.interfaces.UserSessionHome;
030: import hero.interfaces.UserSessionUtil;
031:
032: import hero.interfaces.Constants;
033:
034: import java.util.*;
035:
036: public class SampleUserApi {
037:
038: static public void main(String[] args) throws Exception {
039:
040: // User Admin login
041: char[] password = { 't', 'o', 't', 'o' };
042: SimpleCallbackHandler handler = new SimpleCallbackHandler(
043: "admin", password);
044: LoginContext lc = new LoginContext("TestClient", handler);
045: lc.login();
046:
047: // User Session Bean Creation using Remote Interface
048: UserSessionHome usrHome = (UserSessionHome) UserSessionUtil
049: .getHome();
050: UserSession usrSession = usrHome.create();
051:
052: //***************************************************************/
053: //************** API Documentation - Sample 6 ***************/
054: //************** Users and Activities *****************/
055: //***************************************************************/
056:
057: System.out.println("Current User Name/Passwd : "
058: + usrSession.getUser() + "/"
059: + usrSession.getUserPassword());
060:
061: usrSession.setUserProperty("Language", "Spanish");
062:
063: System.out.println("Getting Current User properties values");
064: Collection properties = usrSession.getUserProperties();
065: Iterator i = properties.iterator();
066: while (i.hasNext()) {
067: hero.interfaces.BnUserPropertyValue property = (hero.interfaces.BnUserPropertyValue) i
068: .next();
069: try {
070: String propertyKeyName = property.getTheKey();
071: String propertyValue = (String) property.getTheValue();
072: System.out.println("Property (Key, Value) : "
073: + propertyKeyName + "/" + propertyValue);
074: } catch (Exception e) {
075: System.out.println(e);
076: } //Maybe there is a problem
077: }
078:
079: System.out.println("\n Getting project names for this user");
080: try {
081: Collection prjNames = usrSession.getProjectListNames();
082: Iterator j = prjNames.iterator();
083: while (j.hasNext()) {
084: String prjName = (String) j.next();
085: System.out.println(" --> Project : " + prjName);
086: }
087: } catch (Exception e) {
088: System.out.println(" --> " + e);
089: } //Maybe something is wrong
090:
091: System.out
092: .println("\n Starting & terminating Activities available for this user");
093: try {
094: Collection instNames = usrSession.getInstancesListNames();
095: Iterator j = instNames.iterator();
096: while (j.hasNext()) {
097: String instName = (String) j.next();
098: System.out.println("--> INSTANCE : " + instName);
099:
100: System.out
101: .println("Getting ToDo list for this instance");
102: Collection activityNames = usrSession
103: .getToDoList(instName);
104: Iterator k = activityNames.iterator();
105: while (k.hasNext()) {
106: String activityName = (String) k.next();
107: System.out.println(" --> activity : "
108: + activityName);
109: try {
110: usrSession
111: .startActivity(instName, activityName);
112: System.out.println(" --> activity started");
113: } catch (Exception e) {
114: System.out.println(" --> " + e);
115: } //Maybe something is wrong
116: } // End ToDo list
117:
118: System.out
119: .println("Getting the activity List (executing or anticipating) for the user");
120: activityNames = usrSession.getActivityList(instName);
121: k = activityNames.iterator();
122: while (k.hasNext()) {
123: String activityName = (String) k.next();
124: System.out.println(" --> activity : "
125: + activityName);
126: try {
127: usrSession.terminateActivity(instName,
128: activityName);
129: System.out
130: .println(" --> activity terminated");
131: } catch (Exception e) {
132: System.out.println(" --> " + e);
133: } //Maybe something is wrong
134: } // End ToDo list
135:
136: } // End Intances List
137:
138: } catch (Exception e) {
139: System.out.println(" --> " + e);
140: } //Maybe something is wrong
141:
142: } //End Main
143:
144: } // End SampleProjectApi Class
|