Class ContextFactory
- All Implemented Interfaces:
ObjectFactory
This is an object factory that produces a jndi naming context based on a classloader.
It is used for the java:comp
context.
This object factory is bound at java:comp
. When a
lookup arrives for java:comp, this object factory
is invoked and will return a context specific to
the caller's environment (so producing the java:comp/env
specific to a webapp).
The context selected is based on classloaders. First we try looking at the thread context classloader if it is set, and walk its hierarchy, creating a context if none is found. If the thread context classloader is not set, then we use the classloader associated with the current Context.
If there is no current context, or no classloader, we return null.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic ClassLoader
associateClassLoader
(ClassLoader loader) static Context
associateContext
(Context ctx) Associate the given Context with the current thread.static void
static void
static void
dump
(Appendable out, String indent) getContextForClassLoader
(ClassLoader loader) Find the naming Context for the given classloadergetObjectInstance
(Object obj, Name name, Context nameCtx, Hashtable env) Find or create a context which pertains to a classloader.newNamingContext
(Object obj, ClassLoader loader, Hashtable env, Name name, Context parentCtx) Create a new NamingContext.
-
Constructor Details
-
ContextFactory
public ContextFactory()
-
-
Method Details
-
getObjectInstance
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable env) throws Exception Find or create a context which pertains to a classloader.If the thread context classloader is set, we try to find an already-created naming context for it. If one does not exist, we walk its classloader hierarchy until one is found, or we run out of parent classloaders. In the latter case, we will create a new naming context associated with the original thread context classloader.
If the thread context classloader is not set, we obtain the classloader from the current jetty Context, and look for an already-created naming context.
If there is no current jetty Context, or it has no associated classloader, we return null.
- Specified by:
getObjectInstance
in interfaceObjectFactory
- Throws:
Exception
- See Also:
-
newNamingContext
public NamingContext newNamingContext(Object obj, ClassLoader loader, Hashtable env, Name name, Context parentCtx) throws Exception Create a new NamingContext.- Parameters:
obj
- the object to createloader
- the classloader for the naming contextenv
- the jndi env for the entryname
- the name of the entryparentCtx
- the parent context of the entry- Returns:
- the newly created naming context
- Throws:
Exception
- if unable to create a new naming context
-
getContextForClassLoader
Find the naming Context for the given classloader- Parameters:
loader
- the classloader for the context- Returns:
- the context for the classloader
-
associateContext
Associate the given Context with the current thread. disassociate method should be called to reset the context.- Parameters:
ctx
- the context to associate to the current thread.- Returns:
- the previous context associated on the thread (can be null)
-
disassociateContext
-
associateClassLoader
-
disassociateClassLoader
public static void disassociateClassLoader() -
dump
- Throws:
IOException
-