KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > naming > test > BootstrapNamingContextFactory


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.naming.test;
23
24 import java.util.Hashtable JavaDoc;
25 import javax.naming.Context JavaDoc;
26 import javax.naming.NamingException JavaDoc;
27 import javax.naming.InitialContext JavaDoc;
28 import javax.naming.spi.InitialContextFactory JavaDoc;
29
30 import org.jnp.interfaces.Naming;
31 import org.jnp.interfaces.NamingContext;
32 import org.jboss.logging.Logger;
33
34 /** A naming provider InitialContextFactory implementation that obtains a
35  Naming proxy from a JNDI binding using the default InitialContext. This
36  is only useful for testing secondary naming services.
37
38  @see InitialContextFactory
39
40  @author Scott.Stark@jboss.org
41  @version $Revision: 37406 $
42  */

43 public class BootstrapNamingContextFactory
44    implements InitialContextFactory JavaDoc
45 {
46    static Logger log = Logger.getLogger(BootstrapNamingContextFactory.class);
47
48    // InitialContextFactory implementation --------------------------
49
public Context JavaDoc getInitialContext(Hashtable JavaDoc env)
50       throws NamingException JavaDoc
51    {
52       Naming namingServer = null;
53       try
54       {
55          Hashtable JavaDoc env2 = (Hashtable JavaDoc) env.clone();
56          env2.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
57          // Retrieve the Naming interface
58
String JavaDoc location = (String JavaDoc) env.get("bootstrap-binding");
59          namingServer = (Naming) new InitialContext JavaDoc(env2).lookup(location);
60          log.debug("Found naming proxy:"+namingServer);
61       }
62       catch(Exception JavaDoc e)
63       {
64          log.debug("Lookup failed", e);
65          NamingException JavaDoc ex = new NamingException JavaDoc("Failed to retrieve Naming interface");
66          ex.setRootCause(e);
67          throw ex;
68       }
69
70       // Copy the context env
71
env = (Hashtable JavaDoc) env.clone();
72       return new NamingContext(env, null, namingServer);
73    }
74 }
75
Popular Tags