KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > winstone > jndi > java > javaURLContextFactory


1 /*
2  * Copyright 2003-2006 Rick Knowles <winstone-devel at lists sourceforge net>
3  * Distributed under the terms of either:
4  * - the common development and distribution license (CDDL), v1.0; or
5  * - the GNU Lesser General Public License, v2.1 or later
6  */

7 package winstone.jndi.java;
8
9 import java.util.Hashtable JavaDoc;
10
11 import javax.naming.Context JavaDoc;
12 import javax.naming.Name JavaDoc;
13 import javax.naming.NamingException JavaDoc;
14 import javax.naming.spi.InitialContextFactory JavaDoc;
15 import javax.naming.spi.ObjectFactory JavaDoc;
16
17 import winstone.jndi.WinstoneContext;
18
19 /**
20  * Creates the initial instance of the Winstone JNDI context (corresponds to
21  * java:/ urls)
22  *
23  * @author <a HREF="mailto:rick_knowles@hotmail.com">Rick Knowles</a>
24  * @version $Id: javaURLContextFactory.java,v 1.4 2006/02/28 07:32:49 rickknowles Exp $
25  */

26 public class javaURLContextFactory implements InitialContextFactory JavaDoc,
27         ObjectFactory JavaDoc {
28 // private static final WinstoneResourceBundle resources = new WinstoneResourceBundle("winstone.jndi.LocalStrings");
29

30 // private static Map rootContexts;
31
// static {
32
// rootContexts = new Hashtable();
33
// }
34
//
35
// /**
36
// * Gets a context using the thread context class loader as a key. This allows us
37
// * to return different jndi spaces for each webapp, since the context class loader
38
// * is unique for each
39
// */
40
// public Context getInitialContext(Hashtable env) throws NamingException {
41
//
42
// synchronized (rootContexts) {
43
// // Check for a context matching this thread context class loader, and
44
// // recurse back to the root CL until a match is found
45
// ClassLoader cl = Thread.currentThread().getContextClassLoader();
46
// ClassLoader loopIndex = cl;
47
// while (loopIndex != null) {
48
// Logger.log(Logger.FULL_DEBUG, resources, "javaURLContextFactory.TryingForClassLoader",
49
// loopIndex.toString());
50
// Context rootContext = (Context) rootContexts.get(loopIndex);
51
// if (rootContext != null) {
52
// return (Context) rootContext.lookup("");
53
// } else {
54
// loopIndex = loopIndex.getParent();
55
// }
56
// }
57
//
58
// // If no match, create a new context
59
// Logger.log(Logger.FULL_DEBUG, resources, "javaURLContextFactory.NewContext",
60
// cl.toString());
61
// Context rootContext = new WinstoneContext(env, null, "java:/comp/env",
62
// new Boolean(true));
63
// rootContexts.put(cl, rootContext);
64
// return (Context) rootContext.lookup("");
65
//
66
// }
67
// }
68

69     private static Context JavaDoc rootContext;
70     private Object JavaDoc lock = new Boolean JavaDoc(true);
71
72     public Context JavaDoc getInitialContext(Hashtable JavaDoc env) throws NamingException JavaDoc {
73         synchronized (lock) {
74             if (rootContext == null)
75                 rootContext = new WinstoneContext(env, null, "java:/comp/env",
76                         new Boolean JavaDoc(true));
77         }
78         return (Context JavaDoc) rootContext.lookup("");
79     }
80     
81     public Object JavaDoc getObjectInstance(Object JavaDoc object, Name JavaDoc name, Context JavaDoc context,
82             Hashtable JavaDoc env) {
83         return null;
84     }
85 }
86
Popular Tags