1 45 package org.exolab.jms.server; 46 47 import java.util.Hashtable ; 48 49 import javax.naming.Context ; 50 import javax.naming.CommunicationException ; 51 import javax.naming.Name ; 52 import javax.naming.NameParser ; 53 import javax.naming.NamingException ; 54 55 import org.codehaus.spice.jndikit.DefaultNameParser; 56 import org.codehaus.spice.jndikit.Namespace; 57 import org.codehaus.spice.jndikit.NamingProvider; 58 import org.codehaus.spice.jndikit.RemoteContext; 59 import org.codehaus.spice.jndikit.StandardNamespace; 60 import org.codehaus.spice.jndikit.memory.MemoryContext; 61 import org.codehaus.spice.jndikit.rmi.server.RMINamingProviderImpl; 62 63 public class EmbeddedNameService { 64 65 68 private Context _root; 69 70 73 private NamingProvider _provider; 74 75 78 private static EmbeddedNameService _instance = new EmbeddedNameService(); 79 80 81 84 private EmbeddedNameService() { 85 DefaultNameParser parser = new DefaultNameParser(); 86 Namespace namespace = createNamespace(parser); 87 Context context = new MemoryContext(namespace, null, null); 88 _provider = new RMINamingProviderImpl(context); 89 } 90 91 96 public static EmbeddedNameService getInstance() { 97 return _instance; 98 } 99 100 106 public Context getInitialContext() throws NamingException { 107 Hashtable environment = new Hashtable (); 108 Namespace namespace; 109 try { 110 namespace = createNamespace(_provider.getNameParser()); 111 } catch (NamingException exception) { 112 throw exception; 113 } catch (Exception exception) { 114 throw new CommunicationException (exception.toString()); 115 } 116 117 environment.put(RemoteContext.NAMING_PROVIDER, _provider); 118 environment.put(RemoteContext.NAMESPACE, namespace); 119 120 final Name baseName = namespace.getNameParser().parse(""); 121 return new RemoteContext(environment, baseName); 122 } 123 124 129 public NamingProvider getNamingProvider() { 130 return _provider; 131 } 132 133 139 private Namespace createNamespace(NameParser parser) { 140 return new StandardNamespace(parser); 141 } 142 } 143 | Popular Tags |