Yurttas/PL/OOL/Java/F/08/02/00/00/HelloServer00.java
Jump to navigation
Jump to search
1import Hello00.*;
2
3import org.omg.CosNaming.*;
4import org.omg.CosNaming.NamingContextPackage.*;
5import org.omg.CORBA.*;
6import org.omg.PortableServer.*;
7import org.omg.PortableServer.POA;
8
9import java.util.Properties;
10
11public class HelloServer00 {
12
13 public static void main(String args[]) {
14 try {
15 // create and initialize the ORB
16 ORB orb = ORB.init(args, null);
17
18 // get reference to rootpoa & activate the POAManager
19 POA rootpoa = POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
20 rootpoa.the_POAManager().activate();
21
22 // create servant and register it with the ORB
23 HelloImp00 helloImp = new HelloImp00();
24 helloImp.setORB(orb);
25
26 // get object reference from the servant
27 org.omg.CORBA.Object ref = rootpoa.servant_to_reference(helloImp);
28 Hello href = HelloHelper.narrow(ref);
29
30 // get the root naming context
31 org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService");
32 // Use NamingContextExt which is part of the Interoperable
33 // Naming Service (INS) specification.
34 NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);
35
36 // bind the Object Reference in Naming
37 String name = "Hello";
38 NameComponent path[] = ncRef.to_name( name );
39 ncRef.rebind(path, href);
40
41 System.out.println("HelloServer ready and waiting ...");
42
43 // wait for invocations from clients
44 orb.run();
45 }
46 catch(Exception e) {
47 System.err.println("ERROR: " + e);
48 e.printStackTrace(System.out);
49 }
50
51 System.out.println("HelloServer Exiting ...");
52 }
53
54}