1 2 package SOFA.Util; 3 4 import org.omg.CORBA.ORB ; 5 import org.omg.CosNaming.NamingContext ; 6 import org.omg.CosNaming.NamingContextHelper ; 7 import org.omg.PortableServer.POA ; 8 import org.omg.PortableServer.POAHelper ; 9 import org.omg.PortableServer.Servant ; 10 11 15 public class CORBAAccess { 16 17 18 public static ORB orb; 19 public static NamingContext ncRef; 20 private static POA rootpoa; 21 22 23 public CORBAAccess() throws CORBAAccessException { 24 25 try { 26 String orbport = System.getProperty("sofa.orbport","900"); 27 String orbhost = System.getProperty("sofa.orbhost","localhost"); 28 String [] args = new String [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 objRef = orb.resolve_initial_references("NameService"); 40 ncRef = NamingContextHelper.narrow(objRef); 41 42 } 43 catch (Exception e) { 44 throw new CORBAAccessException("Can't initialize ORB.", e); 45 } 46 } 47 48 public static org.omg.CORBA.Object activate_object(Servant o) throws Exception { 49 return rootpoa.servant_to_reference(o); 50 } 51 52 public static String object_to_string(org.omg.CORBA.Object o) throws Exception { 53 54 return orb.object_to_string((org.omg.CORBA.Object )o); 55 } 56 57 public void run() { 58 orb.run(); 59 } 60 } 61 | Popular Tags |