1 26 27 package org.objectweb.openccm.pss.demo1; 28 29 36 public class Client 37 { 38 44 private static Form form = null; 46 47 53 59 65 70 public static void 71 main( String args[] ) 72 { 73 String ns_name = null; 74 75 args = org.objectweb.openccm.corba.TheORB.initialize(args); 77 78 org.omg.CORBA.ORB orb = org.objectweb.openccm.corba.TheORB.getORB(); 80 81 System.out.println("Obtaining the Name Service..."); 83 org.omg.CORBA.Object obj = null; 84 try { 85 obj = orb.resolve_initial_references("NameService"); 86 } catch(org.omg.CORBA.ORBPackage.InvalidName ex) { 87 ex.printStackTrace(); 88 } 89 org.omg.CosNaming.NamingContext nc = org.omg.CosNaming.NamingContextHelper.narrow(obj); 90 91 92 ns_name = "My_PSS_demo1_form"; 94 System.out.println("Obtaining the " + ns_name + " Form instance..."); 95 org.omg.CosNaming.NameComponent [] ncomp = new org.omg.CosNaming.NameComponent [1]; 96 ncomp[0] = new org.omg.CosNaming.NameComponent (ns_name, ""); 97 try { 98 obj = nc.resolve(ncomp); 99 } catch(org.omg.CosNaming.NamingContextPackage.NotFound ex1) { 100 ex1.printStackTrace(); 101 } catch(org.omg.CosNaming.NamingContextPackage.CannotProceed ex2) { 102 ex2.printStackTrace(); 103 } catch(org.omg.CosNaming.NamingContextPackage.InvalidName ex3){ 104 ex3.printStackTrace(); 105 } 106 107 form = FormHelper.narrow( obj ); 109 110 int option = 0; 111 112 boolean stop = false; 113 114 while ( !stop ) 115 { 116 option = menu(); 117 118 switch ( option ) 119 { 120 121 case 0 : 122 stop = true; 123 System.exit(0); 124 break; 125 126 case 1 : 127 createPerson(); 128 break; 129 130 case 2 : 131 removePerson(); 132 break; 133 134 case 3 : 135 displayPerson(); 136 break; 137 } 138 } 139 140 } 141 142 145 public static void 146 createPerson() 147 { 148 try 149 { 150 System.out.println( "[ Create a new person ]" ); 151 System.out.print( "First Name : " ); 152 String first_name = input(); 153 154 System.out.print( "Last Name : " ); 155 String last_name = input(); 156 157 System.out.print( "Age : " ); 158 int age = new Integer ( input() ).intValue(); 159 160 System.out.print( "Address Line1 : " ); 161 String address_line1 = input(); 162 163 System.out.print( "Address Line2 : " ); 164 String address_line2 = input(); 165 166 System.out.print( "Address City : " ); 167 String address_city = input(); 168 169 System.out.print( "Address Zip : " ); 170 String address_zip = input(); 171 172 System.out.println( "" ); 173 174 form.createPerson( first_name, last_name, age, 175 address_line1, address_line2, address_city, address_zip ); 176 } 177 catch ( org.omg.CORBA.SystemException ex ) 178 { 179 System.out.println( "A CORBA System exception has been intercepted" ); 180 ex.printStackTrace(); 181 } 182 } 183 184 187 public static void 188 removePerson() 189 { 190 try 191 { 192 System.out.println( "[ Remove a person ]" ); 193 System.out.print( "First Name : " ); 194 String first_name = input(); 195 196 System.out.print( "Last Name : " ); 197 String last_name = input(); 198 199 System.out.println( "" ); 200 201 form.removePerson( first_name, last_name ); 202 } 203 catch ( org.omg.CORBA.SystemException ex ) 204 { 205 System.out.println( "A CORBA System exception has been intercepted" ); 206 ex.printStackTrace(); 207 } 208 } 209 210 213 public static void 214 displayPerson() 215 { 216 try 217 { 218 System.out.println( "[ Display a person ]" ); 219 System.out.print( "First Name : " ); 220 String first_name = input(); 221 222 System.out.print( "Last Name : " ); 223 String last_name = input(); 224 225 System.out.println( "" ); 226 227 System.out.print( form.showPerson(first_name, last_name) ); 228 } 229 catch ( org.omg.CORBA.SystemException ex ) 230 { 231 System.out.println( "A CORBA System exception has been intercepted" ); 232 ex.printStackTrace(); 233 } 234 } 235 236 241 public static String 242 input() 243 { 244 try 245 { 246 java.io.BufferedReader reader = new java.io.BufferedReader ( new java.io.InputStreamReader ( System.in ) ); 247 248 return reader.readLine(); 249 } 250 catch ( java.lang.Exception ex ) 251 { 252 ex.printStackTrace(); 253 } 254 255 return null; 256 } 257 258 263 public static int menu() 264 { 265 System.out.println( "Select a choice : " ); 266 System.out.println( "\t0. Quit" ); 267 System.out.println( "\t1. Create a new person" ); 268 System.out.println( "\t2. Remove a person" ); 269 System.out.println( "\t3. Display all person's data" ); 270 271 String choice = input(); 272 273 return new Integer ( choice ).intValue(); 274 } 275 } 276 | Popular Tags |