1 package hero.client.samples; 2 3 24 25 26 import javax.security.auth.login.LoginContext ; 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 [] args) throws Exception { 40 41 char[] password={'t','o','t','o'}; 43 SimpleCallbackHandler handler = new SimpleCallbackHandler("admin",password); 44 LoginContext lc = new LoginContext ("TestClient", handler); 45 lc.login(); 46 47 UserSessionHome usrHome= (UserSessionHome) UserSessionUtil.getHome(); 49 UserSession usrSession = usrHome.create(); 50 51 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 propertyKeyName = property.getTheKey(); 68 String propertyValue = (String )property.getTheValue(); 69 System.out.println("Property (Key, Value) : " + propertyKeyName + "/" + propertyValue); 70 } catch(Exception e) {System.out.println(e);} } 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 prjName = (String )j.next(); 80 System.out.println(" --> Project : " + prjName ); } 81 } catch(Exception e) {System.out.println(" --> " + e);} 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 instName = (String )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 activityName = (String )k.next(); 99 System.out.println(" --> activity : " + activityName ); 100 try { 101 usrSession.startActivity(instName,activityName) ; 102 System.out.println(" --> activity started" ); 103 } catch(Exception e) {System.out.println(" --> " + e);} } 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 activityName = (String )k.next(); 112 System.out.println(" --> activity : " + activityName ); 113 try { 114 usrSession.terminateActivity(instName,activityName) ; 115 System.out.println(" --> activity terminated" ); 116 } catch(Exception e) {System.out.println(" --> " + e);} } 119 } 121 } catch(Exception e) {System.out.println(" --> " + e);} 123 } 125 } 127 | Popular Tags |