org.apache.naming
Class ContextBindings

java.lang.Object
  extended byorg.apache.naming.ContextBindings

public class ContextBindings
extends java.lang.Object

Maintains bindings associating user-defined names, NamingContexts, threads and classloaders. User-defined names are bound to contexts using bindContext. Threads and classloaders are bound to NamingContexts indirectly, using bindXxx methods that take user-defined context names as parameters. The currently executing thread and the context classloaders of the current thread are implicit arguments to the thread and classloader binding methods -- that is, it is only possible to bind the current thread and its context classloader.

If a context name has a security token associated with it (set using ContextAccessController.setSecurityToken(Object,Object)), this token must be supplied to bind and unbind methods.

KeyValueBind methodsLookup method
User-defined nameNamingContext bindContext(Object,Context), bindContext(Object,Context,Object) none
ThreadNamingContext bindThread(Object), bindThread(Object, Object) getThread()
ClassLoaderNamingContext bindClassLoader(Object, Object), bindClassLoader(Object,Object, ClassLoader) getClassLoader()

Also includes unbind methods and methods for determining whether or not classloaders and threads are bound to contexts.

Version:
$Rev: 124742 $ $Date$
Author:
Remy Maucherat

Field Summary
protected static StringManager sm
          The string manager for this package.
 
Constructor Summary
ContextBindings()
           
 
Method Summary
static void bindClassLoader(java.lang.Object name)
          Binds a naming context to the context ClassLoader for the currently executing thread.
static void bindClassLoader(java.lang.Object name, java.lang.Object token)
          Binds a naming context to the context ClassLoader for the currently executing thread.
static void bindClassLoader(java.lang.Object name, java.lang.Object token, java.lang.ClassLoader classLoader)
          Binds a naming context to a ClassLoader.
static void bindContext(java.lang.Object name, javax.naming.Context context)
          Binds a context name.
static void bindContext(java.lang.Object name, javax.naming.Context context, java.lang.Object token)
          Binds a context name.
static void bindThread(java.lang.Object name)
          Binds a naming context to the currently executing thread.
static void bindThread(java.lang.Object name, java.lang.Object token)
          Binds a naming context to the currently executing thread.
static javax.naming.Context getClassLoader()
          Retrieves the naming context bound to the context ClassLoader for the currently executing thread, if that ClassLoader is bound.
static javax.naming.Context getThread()
          Retrieves the naming context bound to the currently executing thread.
static boolean isClassLoaderBound()
          Tests if current class loader is bound to a context.
static boolean isThreadBound()
          Tests if current thread is bound to a context.
static void unbindClassLoader(java.lang.Object name)
          Unbinds a naming context from the context ClassLoader for the currently executing thread.
static void unbindClassLoader(java.lang.Object name, java.lang.Object token)
          Unbinds a naming context from the context ClassLoader for the currently executing thread.
static void unbindClassLoader(java.lang.Object name, java.lang.Object token, java.lang.ClassLoader classLoader)
          Unbinds a naming context from a class loader.
static void unbindContext(java.lang.Object name)
          Unbinds a context name.
static void unbindContext(java.lang.Object name, java.lang.Object token)
          Unbinds a context name.
static void unbindThread(java.lang.Object name)
          Unbinds a naming context from the currently executing thread.
static void unbindThread(java.lang.Object name, java.lang.Object token)
          Unbinds a naming context from the currently executing thread.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sm

protected static StringManager sm
The string manager for this package.

Constructor Detail

ContextBindings

public ContextBindings()
Method Detail

bindContext

public static void bindContext(java.lang.Object name,
                               javax.naming.Context context)
Binds a context name. Overwrites any existing binding using name.

Parameters:
name - Name of the context
context - Associated naming context instance

bindContext

public static void bindContext(java.lang.Object name,
                               javax.naming.Context context,
                               java.lang.Object token)
Binds a context name. Checks the security token first and does nothing if the check fails. Overwrites any existing binding using name.

Parameters:
name - Name of the context
context - Associated naming context instance
token - Security token associated with the context

unbindContext

public static void unbindContext(java.lang.Object name)
Unbinds a context name.

Parameters:
name - Name of the context

unbindContext

public static void unbindContext(java.lang.Object name,
                                 java.lang.Object token)
Unbinds a context name. Checks the security token first and does nothing if the check fails.

Parameters:
name - Name of the context
token - Security token

bindThread

public static void bindThread(java.lang.Object name)
                       throws javax.naming.NamingException
Binds a naming context to the currently executing thread. The name must have been previously bound to a NamingContext using bindContext(Object, Context); otherwise a NamingException is thrown. Overwrites any existing binding for the currently executing thread.

Parameters:
name - Name of the context
Throws:
javax.naming.NamingException - if name is not bound to a context

bindThread

public static void bindThread(java.lang.Object name,
                              java.lang.Object token)
                       throws javax.naming.NamingException
Binds a naming context to the currently executing thread. The name must have been previously bound to a NamingContext using bindContext(Object, Context, Object); otherwise a NamingException is thrown. Checks the security token first and does nothing if the check fails. Overwrites any existing binding for the currently executing thread.

Parameters:
name - Name of the context
token - Security token
Throws:
javax.naming.NamingException - if name is not bound to a context

unbindThread

public static void unbindThread(java.lang.Object name)
Unbinds a naming context from the currently executing thread. Does nothing if name is not bound to a context.

Parameters:
name - Name of the context

unbindThread

public static void unbindThread(java.lang.Object name,
                                java.lang.Object token)
Unbinds a naming context from the currently executing thread. Checks the security token first and does nothing if the check fails or if name is not bound to a context.

Parameters:
name - Name of the context
token - Security token

getThread

public static javax.naming.Context getThread()
                                      throws javax.naming.NamingException
Retrieves the naming context bound to the currently executing thread. Throws a NamingException if the current thread is not bound to a context.

Returns:
context bound to the current thread
Throws:
javax.naming.NamingException - if the current thread is not bound
See Also:
bindThread(Object)

isThreadBound

public static boolean isThreadBound()
Tests if current thread is bound to a context.

Returns:
true if the current thread is bound

bindClassLoader

public static void bindClassLoader(java.lang.Object name)
                            throws javax.naming.NamingException
Binds a naming context to the context ClassLoader for the currently executing thread. The name must have been previously bound to a NamingContext using bindContext(Object, Context, Object); otherwise a NamingException is thrown.

Note: this method does not overwrite existing bindings. If the ClassLoader is already bound to a context, activating this method with a new context name does nothing.

Parameters:
name - Name of the context
Throws:
javax.naming.NamingException - if the current thread is not bound
java.lang.SecurityException - if a security manager exists and its checkPermission method doesn't allow getting the context ClassLoader

bindClassLoader

public static void bindClassLoader(java.lang.Object name,
                                   java.lang.Object token)
                            throws javax.naming.NamingException
Binds a naming context to the context ClassLoader for the currently executing thread. The name must have been previously bound to a NamingContext using bindContext(Object, Context, Object); otherwise a NamingException is thrown. Checks the security token and does nothing if the check fails.

Note: this method does not overwrite existing bindings. If the ClassLoader is already bound to a context, activating this method with a new context name does nothing.

Parameters:
name - Name of the context
token - Security token associated with the name
Throws:
javax.naming.NamingException - if the current thread is not bound
java.lang.SecurityException - if a security manager exists and its checkPermission method doesn't allow getting the context ClassLoader

bindClassLoader

public static void bindClassLoader(java.lang.Object name,
                                   java.lang.Object token,
                                   java.lang.ClassLoader classLoader)
                            throws javax.naming.NamingException
Binds a naming context to a ClassLoader. The name must have been previously bound to a NamingContext using bindContext(Object, Context, Object); otherwise a NamingException is thrown. Checks the security token and does nothing if the check fails.

Note: this method does not overwrite existing bindings. If the ClassLoader is already bound to a context, activating this method with a new context name does nothing.

Parameters:
name - Name of the context
token - Security token
classLoader - ClassLoader to bind
Throws:
javax.naming.NamingException - if the name is not bound to a context

unbindClassLoader

public static void unbindClassLoader(java.lang.Object name)
Unbinds a naming context from the context ClassLoader for the currently executing thread.

Parameters:
name - Name of the context
Throws:
java.lang.SecurityException - if a security manager exists and its checkPermission method doesn't allow getting the context ClassLoader

unbindClassLoader

public static void unbindClassLoader(java.lang.Object name,
                                     java.lang.Object token)
Unbinds a naming context from the context ClassLoader for the currently executing thread. Checks the security token first and does nothing if the check fails.

Parameters:
name - Name of the context
token - Security token
Throws:
java.lang.SecurityException - if a security manager exists and its checkPermission method doesn't allow getting the context ClassLoader

unbindClassLoader

public static void unbindClassLoader(java.lang.Object name,
                                     java.lang.Object token,
                                     java.lang.ClassLoader classLoader)
Unbinds a naming context from a class loader. Checks the security token first and does nothing if the check fails.

Parameters:
name - Name of the context
token - Security token
classLoader - ClassLoader to unbind

getClassLoader

public static javax.naming.Context getClassLoader()
                                           throws javax.naming.NamingException
Retrieves the naming context bound to the context ClassLoader for the currently executing thread, if that ClassLoader is bound. If the context ClassLoader is not bound, the ClassLoader bindings table is queried for parent ClassLoaders, moving up the hierarchy until a bound ClassLoader is found. Throws a NamingException if no ClassLoader in the hierarchy is bound to a context.

Returns:
context bound to the first bound ClassLoader found
Throws:
javax.naming.NamingException - if no bound ClassLoader is found
java.lang.SecurityException - if a security manager exists and its checkPermission blocks access to a ClassLoader
See Also:
bindClassLoader(Object)

isClassLoaderBound

public static boolean isClassLoaderBound()
Tests if current class loader is bound to a context.

Returns:
true if the context ClassLoader for the current thread is bound


Copyright © 2003-2007 Apache Software Foundation. All Rights Reserved.