You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by re...@locus.apache.org on 2000/11/11 02:47:48 UTC
cvs commit: jakarta-tomcat-4.0/catalina/src/share/org/apache/naming ContextBindings.java LocalStrings.properties SelectorContext.java
remm 00/11/10 17:47:48
Modified: catalina/src/share/org/apache/naming ContextBindings.java
LocalStrings.properties SelectorContext.java
Log:
- Adds the capability to bind the class loader associated with the current
thread to a Context.
- The current thread binding will still be checked first.
Revision Changes Path
1.2 +112 -7 jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/ContextBindings.java
Index: ContextBindings.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/ContextBindings.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ContextBindings.java 2000/11/02 06:14:16 1.1
+++ ContextBindings.java 2000/11/11 01:47:47 1.2
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/ContextBindings.java,v 1.1 2000/11/02 06:14:16 remm Exp $
- * $Revision: 1.1 $
- * $Date: 2000/11/02 06:14:16 $
+ * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/ContextBindings.java,v 1.2 2000/11/11 01:47:47 remm Exp $
+ * $Revision: 1.2 $
+ * $Date: 2000/11/11 01:47:47 $
*
* ====================================================================
*
@@ -76,7 +76,7 @@
* </ul>
*
* @author Remy Maucherat
- * @version $Revision: 1.1 $ $Date: 2000/11/02 06:14:16 $
+ * @version $Revision: 1.2 $ $Date: 2000/11/11 01:47:47 $
*/
public class ContextBindings {
@@ -86,7 +86,7 @@
/**
- * Bindings Catalina context name - naming context. Keyed by context name.
+ * Bindings name - naming context. Keyed by name.
*/
private static Hashtable contextNameBindings = new Hashtable();
@@ -104,6 +104,18 @@
/**
+ * Bindings class loader - naming context. Keyed by CL id.
+ */
+ private static Hashtable clBindings = new Hashtable();
+
+
+ /**
+ * Bindings class loader - name. Keyed by CL id.
+ */
+ private static Hashtable clNameBindings = new Hashtable();
+
+
+ /**
* The string manager for this package.
*/
protected static StringManager sm =
@@ -174,7 +186,6 @@
* Binds a naming context to a thread.
*
* @param name Name of the context
- * @param token Security token
*/
public static void bindThread(String name)
throws NamingException {
@@ -186,6 +197,7 @@
* Binds a naming context to a thread.
*
* @param name Name of the context
+ * @param token Security token
*/
public static void bindThread(String name, Object token)
throws NamingException {
@@ -193,8 +205,7 @@
Context context = (Context) contextNameBindings.get(name);
if (context == null)
throw new NamingException
- (sm.getString("contextBindings.unknownContext",
- name));
+ (sm.getString("contextBindings.unknownContext", name));
threadBindings.put(Thread.currentThread(), context);
threadNameBindings.put(Thread.currentThread(), name);
}
@@ -258,6 +269,100 @@
*/
public static boolean isThreadBound() {
return (threadBindings.containsKey(Thread.currentThread()));
+ }
+
+
+ /**
+ * Binds a naming context to a class loader.
+ *
+ * @param name Name of the context
+ */
+ public static void bindClassLoader(String name)
+ throws NamingException {
+ bindClassLoader(name, null);
+ }
+
+
+ /**
+ * Binds a naming context to a thread.
+ *
+ * @param name Name of the context
+ * @param token Security token
+ */
+ public static void bindClassLoader(String name, Object token)
+ throws NamingException {
+ if (ContextAccessController.checkSecurityToken(name, token)) {
+ Context context = (Context) contextNameBindings.get(name);
+ if (context == null)
+ throw new NamingException
+ (sm.getString("contextBindings.unknownContext", name));
+ clBindings.put(Thread.currentThread().getContextClassLoader(),
+ context);
+ clNameBindings.put(Thread.currentThread().getContextClassLoader(),
+ name);
+ }
+ }
+
+
+ /**
+ * Unbinds a naming context to a class loader.
+ *
+ * @param name Name of the context
+ */
+ public static void unbindClassLoader(String name) {
+ unbindClassLoader(null);
+ }
+
+
+ /**
+ * Unbinds a naming context to a class loader.
+ *
+ * @param name Name of the context
+ * @param token Security token
+ */
+ public static void unbindClassLoader(String name, Object token) {
+ if (ContextAccessController.checkSecurityToken(name, token)) {
+ clBindings.remove(Thread.currentThread().getContextClassLoader());
+ clNameBindings.remove
+ (Thread.currentThread().getContextClassLoader());
+ }
+ }
+
+
+ /**
+ * Retrieves the naming context bound to a class loader.
+ */
+ public static Context getClassLoader()
+ throws NamingException {
+ Context context = (Context) clBindings.get
+ (Thread.currentThread().getContextClassLoader());
+ if (context == null)
+ throw new NamingException
+ (sm.getString("contextBindings.noContextBoundToCL"));
+ return context;
+ }
+
+
+ /**
+ * Retrieves the naming context name bound to a class loader.
+ */
+ public static String getClassLoaderName()
+ throws NamingException {
+ String name = (String) clNameBindings.get
+ (Thread.currentThread().getContextClassLoader());
+ if (name == null)
+ throw new NamingException
+ (sm.getString("contextBindings.noContextBoundToCL"));
+ return name;
+ }
+
+
+ /**
+ * Tests if current class loader is bound to a context.
+ */
+ public static boolean isClassLoaderBound() {
+ return (clBindings.containsKey
+ (Thread.currentThread().getContextClassLoader()));
}
1.2 +1 -0 jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/LocalStrings.properties
Index: LocalStrings.properties
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/LocalStrings.properties,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- LocalStrings.properties 2000/11/02 06:14:16 1.1
+++ LocalStrings.properties 2000/11/11 01:47:47 1.2
@@ -1,5 +1,6 @@
contextBindings.unknownContext=Unknown context name : {0}
contextBindings.noContextBoundToThread=No naming context bound to this thread
+contextBindings.noContextBoundToCL=No naming context bound to this class loader
selectorContext.noJavaUrl=This context must be accessed throught a java: URL
namingContext.contextExpected=Name is not bound to a Context
namingContext.nameNotBound=Name {0} is not bound in this Context
1.2 +20 -6 jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/SelectorContext.java
Index: SelectorContext.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/SelectorContext.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SelectorContext.java 2000/11/02 06:14:16 1.1
+++ SelectorContext.java 2000/11/11 01:47:47 1.2
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/SelectorContext.java,v 1.1 2000/11/02 06:14:16 remm Exp $
- * $Revision: 1.1 $
- * $Date: 2000/11/02 06:14:16 $
+ * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/SelectorContext.java,v 1.2 2000/11/11 01:47:47 remm Exp $
+ * $Revision: 1.2 $
+ * $Date: 2000/11/11 01:47:47 $
*
* ====================================================================
*
@@ -75,7 +75,7 @@
* Catalina JNDI Context implementation.
*
* @author Remy Maucherat
- * @version $Revision: 1.1 $ $Date: 2000/11/02 06:14:16 $
+ * @version $Revision: 1.2 $ $Date: 2000/11/11 01:47:47 $
*/
public class SelectorContext implements Context {
@@ -96,6 +96,12 @@
public static final int prefixLength = prefix.length();
+ /**
+ * Initial context prefix.
+ */
+ public static final String IC_PREFIX = "IC_";
+
+
// ----------------------------------------------------------- Constructors
@@ -657,8 +663,12 @@
throws NamingException {
if (initialContext) {
- String ICName =
- "IC_" + ContextBindings.getThreadName();
+ String ICName = IC_PREFIX;
+ if (ContextBindings.isThreadBound()) {
+ ICName += ContextBindings.getThreadName();
+ } else if (ContextBindings.isClassLoaderBound()) {
+ ICName += ContextBindings.getClassLoaderName();
+ }
Context initialContext = ContextBindings.getContext(ICName);
if (initialContext == null) {
// Allocating a new context and binding it to the appropriate
@@ -668,7 +678,11 @@
}
return initialContext;
} else {
- return ContextBindings.getThread();
+ if (ContextBindings.isThreadBound()) {
+ return ContextBindings.getThread();
+ } else {
+ return ContextBindings.getClassLoader();
+ }
}
}