ContextBindings (Apache Tomcat 11.0.5 API Documentation)
Description: declaration: package: org.apache.naming, class: ContextBindings

# Class ContextBindings

java.lang.Object
org.apache.naming.ContextBindings

public class ContextBindings extends Object
Handles the associations :

- Object with a NamingContext
- Calling thread with a NamingContext
- Calling thread with object bound to the same naming context
- Thread context class loader with a NamingContext
- Thread context class loader with object bound to the same NamingContext

The objects are typically Catalina Server or Context objects.

Author:
  Remy Maucherat

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected static final StringManager`
  `sm`
  The string manager for this package.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ContextBindings()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static void`
  `bindClassLoader(Object obj, Object token, ClassLoader classLoader)`
  Binds a naming context to a class loader.
  `static void`
  `bindContext(Object obj, Context context)`
  Binds an object and a naming context.
  `static void`
  `bindContext(Object obj, Context context, Object token)`
  Binds an object and a naming context.
  `static void`
  `bindThread(Object obj, Object token)`
  Binds a naming context to a thread.
  `static Context`
  `getClassLoader()`
  Retrieves the naming context bound to a class loader.
  `static Context`
  `getThread()`
  Retrieves the naming context bound to the current thread.
  `static boolean`
  `isClassLoaderBound()`
  Tests if the thread context class loader is bound to a context.
  `static boolean`
  `isThreadBound()`
  Tests if current thread is bound to a naming context.
  `static void`
  `unbindClassLoader(Object obj, Object token, ClassLoader classLoader)`
  Unbinds a naming context and a class loader.
  `static void`
  `unbindContext(Object obj, Object token)`
  Unbinds an object and a naming context.
  `static void`
  `unbindThread(Object obj, Object token)`
  Unbinds a thread and a naming context.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### sm

    protected static final StringManager sm
    The string manager for this package.

- ## Constructor Details

  - ### ContextBindings

    public ContextBindings()

- ## Method Details

  - ### bindContext

    public static void bindContext(Object obj, Context context)
    Binds an object and a naming context.
    Parameters:
      `obj` - Object to bind with naming context
      `context` - Associated naming context instance

  - ### bindContext

    public static void bindContext(Object obj, Context context, Object token)
    Binds an object and a naming context.
    Parameters:
      `obj` - Object to bind with naming context
      `context` - Associated naming context instance
      `token` - Security token

  - ### unbindContext

    public static void unbindContext(Object obj, Object token)
    Unbinds an object and a naming context.
    Parameters:
      `obj` - Object to unbind
      `token` - Security token

  - ### bindThread

    public static void bindThread(Object obj, Object token) throws NamingException
    Binds a naming context to a thread.
    Parameters:
      `obj` - Object bound to the required naming context
      `token` - Security token
    Throws:
      `NamingException` - If no naming context is bound to the provided object

  - ### unbindThread

    public static void unbindThread(Object obj, Object token)
    Unbinds a thread and a naming context.
    Parameters:
      `obj` - Object bound to the required naming context
      `token` - Security token

  - ### getThread

    public static Context getThread() throws NamingException
    Retrieves the naming context bound to the current thread.
    Returns:
      The naming context bound to the current thread.
    Throws:
      `NamingException` - If no naming context is bound to the current thread

  - ### isThreadBound

    public static boolean isThreadBound()
    Tests if current thread is bound to a naming context.
    Returns:
      `true` if the current thread is bound to a naming context, otherwise `false`

  - ### bindClassLoader

    public static void bindClassLoader(Object obj, Object token, ClassLoader classLoader) throws NamingException
    Binds a naming context to a class loader.
    Parameters:
      `obj` - Object bound to the required naming context
      `token` - Security token
      `classLoader` - The class loader to bind to the naming context
    Throws:
      `NamingException` - If no naming context is bound to the provided object

  - ### unbindClassLoader

    public static void unbindClassLoader(Object obj, Object token, ClassLoader classLoader)
    Unbinds a naming context and a class loader.
    Parameters:
      `obj` - Object bound to the required naming context
      `token` - Security token
      `classLoader` - The class loader bound to the naming context

  - ### getClassLoader

    public static Context getClassLoader() throws NamingException
    Retrieves the naming context bound to a class loader.
    Returns:
      the naming context bound to current class loader or one of its parents
    Throws:
      `NamingException` - If no naming context was bound

  - ### isClassLoaderBound

    public static boolean isClassLoaderBound()
    Tests if the thread context class loader is bound to a context.
    Returns:
      `true` if the thread context class loader or one of its parents is bound to a naming context, otherwise `false`