import HelloApp.*; import java.io.*; import org.omg.CosNaming.*; import org.omg.CosNaming.NamingContextPackage.*; import org.omg.CORBA.*; import org.omg.PortableServer.*; import org.omg.PortableServer.POA; import java.util.Properties; /** * The server serving a Hello CORBA object * *@author donsez *@version 16/06/2003 */ public class HelloServer { /** * 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 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); // get reference to rootpoa & activate the POAManager POA rootpoa = POAHelper.narrow(orb.resolve_initial_references("RootPOA")); rootpoa.the_POAManager().activate(); // create servant and register it with the ORB HelloServant helloServant = new HelloServant(); helloServant.setORB(orb); // get object reference from the servant org.omg.CORBA.Object ref = rootpoa.servant_to_reference(helloServant); Hello href = HelloHelper.narrow(ref); if (args[0].equals("-name")) { String bindingname = args[1]; // get the root naming context org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService"); // Use NamingContextExt which is part of the Interoperable // Naming Service (INS) specification. NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef); // bind the Object Reference in Naming NameComponent path[] = ncRef.to_name(bindingname); ncRef.rebind(path, href); } else if (args[0].equals("-iorfile")) { String iorfilename = args[1]; // get the ior from the servant String ior = orb.object_to_string(ref); // save the ior string in a file PrintWriter ps = new PrintWriter(new FileOutputStream(iorfilename)); ps.print(ior); ps.close(); } else { usage(); return; } System.out.println("HelloServer ready and waiting ..."); // wait for invocations from clients orb.run(); } catch (Exception e) { System.err.println("ERROR: " + e); e.printStackTrace(System.out); } System.out.println("HelloServer Exiting ..."); } /** * Print usage of this application */ static void usage() { System.err.println("Usage: HelloServer -name "); System.err.println("Usage: HelloServer -iorfile "); } }