1 25 package org.objectweb.carol.jndi.spi; 26 27 import java.util.Hashtable ; 28 29 import javax.naming.Context ; 30 import javax.naming.NamingException ; 31 import javax.naming.spi.InitialContextFactory ; 32 33 import org.omg.CORBA.ORB ; 34 import org.omg.PortableServer.POA ; 35 36 import org.objectweb.carol.jndi.ns.JacORBCosNaming; 37 import org.objectweb.carol.rmi.exception.NamingExceptionHelper; 38 import org.objectweb.carol.util.configuration.CarolDefaultValues; 39 import org.objectweb.carol.util.csiv2.SasComponent; 40 41 48 public class JacORBIIOPContextWrapperFactory extends AbsInitialContextFactory implements InitialContextFactory { 49 50 53 public static final String SAS_COMPONENT = "org.objectweb.carol.util.csiv2.SasComponent"; 54 55 56 59 public static final String REFERENCING_FACTORY = "com.sun.jndi.cosnaming.CNCtxFactory"; 60 61 64 protected String getReferencingFactory() { 65 return REFERENCING_FACTORY; 66 } 67 68 71 protected Class getWrapperClass() { 72 return JacORBIIOPContext.class; 73 } 74 75 78 private static ORB orb = null; 79 80 83 private static boolean orbStarted = false; 84 85 88 private static POA rootPOA = null; 89 90 94 protected void addExtraConfInEnvironment(Hashtable environment) { 95 environment.put("java.naming.corba.orb", orb); 96 } 97 98 102 protected void init() throws NamingException { 103 if (orb == null) { 105 orb = JacORBCosNaming.getOrb(); 106 } 107 108 if (!orbStarted && System.getProperty(CarolDefaultValues.SERVER_MODE, "false").equalsIgnoreCase("true")) { 109 new Thread (new Runnable () { 111 112 public void run() { 113 orb.run(); 114 } 115 }).start(); 116 orbStarted = true; 117 } 118 119 if (rootPOA == null) { 120 try { 121 rootPOA = org.omg.PortableServer.POAHelper.narrow(orb.resolve_initial_references("RootPOA")); 122 rootPOA.the_POAManager().activate(); 123 } catch (Exception e) { 124 throw NamingExceptionHelper.create("Cannot get a single instance of rootPOA : " + e.getMessage(), e); 125 } 126 } 127 128 } 129 130 131 135 protected String getKey(Hashtable environment) { 136 String key = null; 137 SasComponent sasComponent = null; 138 if (environment != null) { 139 key = (String ) environment.get(Context.PROVIDER_URL); 140 sasComponent = (SasComponent) environment.get(SAS_COMPONENT); 141 } 142 if (sasComponent == null) { 144 return key; 145 } else { 146 return null; 147 } 148 } 149 } | Popular Tags |