FileDocCategorySizeDatePackage
ContextBindings.javaAPI DocApache Tomcat 6.0.1410490Fri Jul 20 04:20:36 BST 2007org.apache.naming

ContextBindings

public class ContextBindings extends Object
Handles the associations :
  • Catalina context name with the NamingContext
  • Calling thread with the NamingContext
author
Remy Maucherat
version
$Revision: 467222 $ $Date: 2006-10-24 05:17:11 +0200 (mar., 24 oct. 2006) $

Fields Summary
private static Hashtable
contextNameBindings
Bindings name - naming context. Keyed by name.
private static Hashtable
threadBindings
Bindings thread - naming context. Keyed by thread id.
private static Hashtable
threadNameBindings
Bindings thread - name. Keyed by thread id.
private static Hashtable
clBindings
Bindings class loader - naming context. Keyed by CL id.
private static Hashtable
clNameBindings
Bindings class loader - name. Keyed by CL id.
protected static StringManager
sm
The string manager for this package.
Constructors Summary
Methods Summary
public static voidbindClassLoader(java.lang.Object name)
Binds a naming context to a class loader.

param
name Name of the context

        bindClassLoader(name, null);
    
public static voidbindClassLoader(java.lang.Object name, java.lang.Object token)
Binds a naming context to a thread.

param
name Name of the context
param
token Security token

        bindClassLoader
            (name, token, Thread.currentThread().getContextClassLoader());
    
public static voidbindClassLoader(java.lang.Object name, java.lang.Object token, java.lang.ClassLoader classLoader)
Binds a naming context to a thread.

param
name Name of the context
param
token Security token

        if (ContextAccessController.checkSecurityToken(name, token)) {
            Context context = (Context) contextNameBindings.get(name);
            if (context == null)
                throw new NamingException
                    (sm.getString("contextBindings.unknownContext", name));
            clBindings.put(classLoader, context);
            clNameBindings.put(classLoader, name);
        }
    
public static voidbindContext(java.lang.Object name, javax.naming.Context context)
Binds a context name.

param
name Name of the context
param
context Associated naming context instance



    // --------------------------------------------------------- Public Methods


                          
           
        bindContext(name, context, null);
    
public static voidbindContext(java.lang.Object name, javax.naming.Context context, java.lang.Object token)
Binds a context name.

param
name Name of the context
param
context Associated naming context instance
param
token Security token

        if (ContextAccessController.checkSecurityToken(name, token))
            contextNameBindings.put(name, context);
    
public static voidbindThread(java.lang.Object name)
Binds a naming context to a thread.

param
name Name of the context

        bindThread(name, null);
    
public static voidbindThread(java.lang.Object name, java.lang.Object token)
Binds a naming context to a thread.

param
name Name of the context
param
token Security token

        if (ContextAccessController.checkSecurityToken(name, token)) {
            Context context = (Context) contextNameBindings.get(name);
            if (context == null)
                throw new NamingException
                    (sm.getString("contextBindings.unknownContext", name));
            threadBindings.put(Thread.currentThread(), context);
            threadNameBindings.put(Thread.currentThread(), name);
        }
    
public static javax.naming.ContextgetClassLoader()
Retrieves the naming context bound to a class loader.

        ClassLoader cl = Thread.currentThread().getContextClassLoader();
        Context context = null;
        do {
            context = (Context) clBindings.get(cl);
            if (context != null) {
                return context;
            }
        } while ((cl = cl.getParent()) != null);
        throw new NamingException
            (sm.getString("contextBindings.noContextBoundToCL"));
    
static java.lang.ObjectgetClassLoaderName()
Retrieves the naming context name bound to a class loader.

        ClassLoader cl = Thread.currentThread().getContextClassLoader();
        Object name = null;
        do {
            name = clNameBindings.get(cl);
            if (name != null) {
                return name;
            }
        } while ((cl = cl.getParent()) != null);
        throw new NamingException
            (sm.getString("contextBindings.noContextBoundToCL"));
    
static javax.naming.ContextgetContext(java.lang.Object name)
Retrieve a naming context.

param
name Name of the context

        return (Context) contextNameBindings.get(name);
    
public static javax.naming.ContextgetThread()
Retrieves the naming context bound to a thread.

        Context context = 
            (Context) threadBindings.get(Thread.currentThread());
        if (context == null)
            throw new NamingException
                (sm.getString("contextBindings.noContextBoundToThread"));
        return context;
    
static java.lang.ObjectgetThreadName()
Retrieves the naming context name bound to a thread.

        Object name = threadNameBindings.get(Thread.currentThread());
        if (name == null)
            throw new NamingException
                (sm.getString("contextBindings.noContextBoundToThread"));
        return name;
    
public static booleanisClassLoaderBound()
Tests if current class loader is bound to a context.

        ClassLoader cl = Thread.currentThread().getContextClassLoader();
        do {
            if (clBindings.containsKey(cl)) {
                return true;
            }
        } while ((cl = cl.getParent()) != null);
        return false;
    
public static booleanisThreadBound()
Tests if current thread is bound to a context.

        return (threadBindings.containsKey(Thread.currentThread()));
    
public static voidunbindClassLoader(java.lang.Object name)
Unbinds a naming context to a class loader.

param
name Name of the context

        unbindClassLoader(name, null);
    
public static voidunbindClassLoader(java.lang.Object name, java.lang.Object token)
Unbinds a naming context to a class loader.

param
name Name of the context
param
token Security token

        unbindClassLoader(name, token, 
                          Thread.currentThread().getContextClassLoader());
    
public static voidunbindClassLoader(java.lang.Object name, java.lang.Object token, java.lang.ClassLoader classLoader)
Unbinds a naming context to a class loader.

param
name Name of the context
param
token Security token

        if (ContextAccessController.checkSecurityToken(name, token)) {
            Object n = clNameBindings.get(classLoader);
            if ((n==null) || !(n.equals(name))) {
                return;
            }
            clBindings.remove(classLoader);
            clNameBindings.remove(classLoader);
        }
    
public static voidunbindContext(java.lang.Object name)
Unbind context name.

param
name Name of the context

        unbindContext(name, null);
    
public static voidunbindContext(java.lang.Object name, java.lang.Object token)
Unbind context name.

param
name Name of the context
param
token Security token

        if (ContextAccessController.checkSecurityToken(name, token))
            contextNameBindings.remove(name);
    
public static voidunbindThread(java.lang.Object name)
Unbinds a naming context to a thread.

param
name Name of the context

        unbindThread(name, null);
    
public static voidunbindThread(java.lang.Object name, java.lang.Object token)
Unbinds a naming context to a thread.

param
name Name of the context
param
token Security token

        if (ContextAccessController.checkSecurityToken(name, token)) {
            threadBindings.remove(Thread.currentThread());
            threadNameBindings.remove(Thread.currentThread());
        }