KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SOFA > Util > CORBAAccess


1 /* $Id: CORBAAccess.java,v 1.2 2004/05/20 14:23:53 bures Exp $ */
2 package SOFA.Util;
3
4 import org.omg.CORBA.ORB JavaDoc;
5 import org.omg.CosNaming.NamingContext JavaDoc;
6 import org.omg.CosNaming.NamingContextHelper JavaDoc;
7 import org.omg.PortableServer.POA JavaDoc;
8 import org.omg.PortableServer.POAHelper JavaDoc;
9 import org.omg.PortableServer.Servant JavaDoc;
10
11 /** Contains reference to ORB, naming,...
12   *
13   * @author Petr Hnetynka
14   */

15 public class CORBAAccess {
16  
17   
18   public static ORB JavaDoc orb;
19   public static NamingContext JavaDoc ncRef;
20   private static POA JavaDoc rootpoa;
21
22
23   public CORBAAccess() throws CORBAAccessException {
24  
25     try {
26       String JavaDoc orbport = System.getProperty("sofa.orbport","900");
27       String JavaDoc orbhost = System.getProperty("sofa.orbhost","localhost");
28       String JavaDoc[] args = new String JavaDoc [4];
29       args[0] = "-ORBInitialPort";
30       args[1] = orbport;
31       args[2] = "-ORBInitialHost";
32       args[3] = orbhost;
33       
34       orb = ORB.init(args, null);
35
36       rootpoa=POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
37       rootpoa.the_POAManager().activate();
38
39       org.omg.CORBA.Object JavaDoc objRef = orb.resolve_initial_references("NameService");
40       ncRef = NamingContextHelper.narrow(objRef);
41
42     }
43     catch (Exception JavaDoc e) {
44       throw new CORBAAccessException("Can't initialize ORB.", e);
45     }
46   }
47
48   public static org.omg.CORBA.Object JavaDoc activate_object(Servant JavaDoc o) throws Exception JavaDoc {
49     return rootpoa.servant_to_reference(o);
50   }
51
52   public static String JavaDoc object_to_string(org.omg.CORBA.Object JavaDoc o) throws Exception JavaDoc {
53
54     return orb.object_to_string((org.omg.CORBA.Object JavaDoc)o);
55   }
56
57   public void run() {
58     orb.run();
59   }
60 }
61
Popular Tags