import HelloApp.*; import org.omg.CosNaming.*; import org.omg.CosNaming.NamingContextPackage.*; import org.omg.CORBA.*; import java.io.*; /** * a simple client using dynamic invocation * *@author donsez *@created 16 juin 2003 *@link http://developer.netscape.com/docs/manuals/enterprise/javapg/dii.htm */ public class DIIHelloClient { /** * The main() Method * *@param args command arguments */ public static void main(String args[]) { if (args.length < 2) { usage(); return; } try { // Set or load the ORB properties java.util.Properties props = null; // Properties props = new Properties(); // props.put("org.omg.CORBA.ORBInitialPort", "1050"); // props.put("org.omg.CORBA.ORBInitialHost", "MyHost"); // create and initialize the ORB ORB orb = ORB.init(args, props); org.omg.CORBA.Object objRef; if (args[0].equals("-name")) { String bindingname = args[1]; // get the root naming context org.omg.CORBA.Object ncobjRef = orb.resolve_initial_references("NameService"); // Use NamingContextExt instead of NamingContext. This is // part of the Interoperable naming Service. NamingContextExt ncRef = NamingContextExtHelper.narrow(ncobjRef); // resolve the Object Reference in Naming objRef = ncRef.resolve_str(bindingname); } else if (args[0].equals("-iorfile")) { String iorfilename = args[1]; FileInputStream fis = new FileInputStream(iorfilename); java.io.DataInputStream dis = new java.io.DataInputStream(fis); String ior = dis.readLine(); dis.close(); objRef = orb.string_to_object(ior); } else if (args[0].equals("-ior")) { String ior = args[1]; objRef = orb.string_to_object(ior); } else { usage(); return; } // Dynamic Invocation for result=hello.sayHello(param) String param = "World"; Request sayHelloReq = objRef._request("sayHello"); sayHelloReq.add_in_arg().insert_string(param); sayHelloReq.set_return_type(orb.get_primitive_tc(TCKind.tk_string)); sayHelloReq.invoke(); String result = sayHelloReq.result().value().extract_string(); System.out.println(result); // Dynamic Invocation for hello.shutdown(); Request shutdownReq = objRef._request("shutdown"); shutdownReq.invoke(); } catch (Exception e) { System.out.println("ERROR : " + e); e.printStackTrace(System.out); } } /** * Print usage of this application */ static void usage() { System.err.println("Usage: HelloClient -name "); System.err.println("Usage: HelloClient -ior "); System.err.println("Usage: HelloClient -iorfile "); } }