package training.corba; import java.io.*; import org.omg.CORBA.*; import org.omg.PortableServer.*; import org.omg.CosNaming.*; import org.omg.CosNaming.NamingContextPackage.*; public class HelloClient { public static void main(String args[]) { // ORB org.omg.CORBA.ORB orb = null; // IOR reference to a POA org.omg.PortableServer.POA refRootPOA = null; // IOR reference to a Naming service org.omg.CosNaming.NamingContext refNS = null; // IOR reference to a distributed Corba object org.omg.CORBA.Object obj = null; // IOR reference to a distributed object of interface hello Hello refHello = null; // create ORB java.util.Properties props = System.getProperties(); // configure the orb // Example : ORBACUS //props.put("org.omg.CORBA.ORBClass", "com.ooc.CORBA.ORB"); //props.put("org.omg.CORBA.ORBSingletonClass", "com.ooc.CORBA.ORBSingleton"); //props.put("ooc.orb.id", "Hello-Client"); orb = org.omg.CORBA.ORB.init(args, props); try { obj = orb.resolve_initial_references("RootPOA"); } catch (org.omg.CORBA.ORBPackage.InvalidName e) { System.out.println("HelloClient : got an exception " + e); } // Get the reference of the default POA refRootPOA = org.omg.PortableServer.POAHelper.narrow(obj); // Get the reference of the naming service try { java.io.BufferedReader in = new java.io.BufferedReader( new java.io.FileReader("Naming.ior")); String ref = in.readLine(); obj = orb.string_to_object(ref); } catch(IOException e) { System.out.println(e); System.exit(1); } // obj = orb.string_to_object("relfile:/Naming.ref"); if(obj == null){ System.err.println("example.HelloServer: cannot read IOR from Naming.ref"); System.exit(1); } /* try { obj = orb.resolve_initial_references("NameService"); } catch(org.omg.CORBA.ORBPackage.InvalidName e) { System.out.println("HelloServer: can't resolve 'NameService' " + e); System.exit(1); } */ refNS = org.omg.CosNaming.NamingContextHelper.narrow(obj); try { // get hello's reference NameComponent[] name = new NameComponent[1]; name[0] = new NameComponent(); name[0].id = "hello"; // context name[0].kind = ""; obj = refNS.resolve(name); } catch(NotFound e) { System.err.print("HelloClient: got a `NotFound' exception " + e); System.exit(1) ; } catch(CannotProceed e) { System.err.println("HelloClient: got a `CannotProceed' exception" + e); System.exit(1) ; } catch(InvalidName e) { System.err.println("HelloClient: got an `InvalidName' exception" + e); System.exit(1) ; } try { // Call a method on hello object refHello = HelloHelper.narrow(obj); refHello.print("hello "); refHello.print("world "); refHello.print("!"); } catch (Exception e) { System.err.println("HelloClient: got an exception " + e); } } }