KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > omg > mof > Model > Server


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