1 28 package org.objectweb.carol.jndi.spi; 29 30 import java.util.Hashtable ; 31 32 import javax.naming.Context ; 33 import javax.naming.InitialContext ; 34 import javax.naming.NamingException ; 35 import javax.naming.spi.InitialContextFactory ; 36 37 import org.objectweb.carol.util.configuration.CarolDefaultValues; 38 import org.objectweb.carol.util.configuration.ConfigurationRepository; 39 import org.objectweb.carol.util.configuration.Protocol; 40 import org.objectweb.carol.util.configuration.TraceCarol; 41 42 49 public class MultiOrbInitialContextFactory implements InitialContextFactory { 50 51 60 public Context getInitialContext(Hashtable env) throws NamingException { 61 String providerURL = null; 63 if (env != null) { 64 providerURL = (String ) env.get(Context.PROVIDER_URL); 65 } 66 67 if (providerURL == null) { 69 if (TraceCarol.isDebugJndiCarol()) { 70 TraceCarol.debugJndiCarol("No provider URL, use multiprotocol context"); 71 } 72 return new MultiContext(env); 73 } else { 74 if (TraceCarol.isDebugJndiCarol()) { 76 TraceCarol.debugJndiCarol("Use provider URL of the environment '" + providerURL + "'."); 77 } 78 String initFactory = (String ) env.get(Context.INITIAL_CONTEXT_FACTORY); 80 81 if (initFactory != null && initFactory.equals(CarolDefaultValues.MULTI_JNDI)) { 83 initFactory = null; 84 } 85 if (initFactory == null) { 86 String protocolName = CarolDefaultValues.getRMIProtocol(providerURL); 87 Protocol protocol = ConfigurationRepository.getProtocol(protocolName); 89 if (protocol == null) { 90 throw new NamingException ("The protocol '" + protocolName + "' is not available within carol."); 91 } 92 initFactory = protocol.getInitialContextFactoryClassName(); 93 env.put(Context.INITIAL_CONTEXT_FACTORY, initFactory); 94 if (TraceCarol.isDebugJndiCarol()) { 95 TraceCarol.debugJndiCarol("No INITIAL_CONTEXT_FACTORY, use '" + initFactory + "' as InitialContext factory."); 96 } 97 } 98 return new InitialContext (env); 99 } 100 } 101 102 } | Popular Tags |