/*
* This example is from the book "Java Enterprise in a Nutshell".
* Copyright (c) 1999 by O'Reilly & Associates.
* You may distribute this source code for non-commercial purposes only.
* You may study, modify, and use this example for any purpose, as long as
* this notice is retained. Note that this example is provided "as is",
* WITHOUT WARRANTY of any kind either expressed or implied.
*/
import org.omg.CORBA.*;
import org.omg.CORBA.ORBPackage.*;
import org.omg.CosNaming.*;
import java.util.*;
public class ServerClient {
public static void main(String argv[]) {
ORB orb = ORB.init(argv, null);
org.omg.CORBA.Object ref = null;
try {
ref = orb.resolve_initial_references("NameService");
}
catch (InvalidName invN) {
System.out.println("No primary NameService available.");
System.exit(1);
}
NamingContext nameContext = NamingContextHelper.narrow(ref);
NameComponent comp = new NameComponent("ThisOrThatServer", "");
NameComponent path[] = {comp};
try {
org.omg.CORBA.Object ref2 = nameContext.resolve(path);
ThisOrThatServer server = ThisOrThatServerHelper.narrow(ref2);
System.out.println("Got server, calling methods...");
server.doThis("something");
server.doThat("something else");
}
catch (Exception e) {
System.out.println("Failed to access server.");
e.printStackTrace();
}
}
}
|