public class NamingContextFactory extends Object implements InitialContextFactory
NamingContext. In case a delegate
environment was provided, obtains delegate InitialContext.
Delegate context is used by NamingContext for unresolved lookups.| Constructor and Description |
|---|
NamingContextFactory() |
| Modifier and Type | Method and Description |
|---|---|
Context |
getInitialContext(Hashtable<?,?> environment)
Singleton for initial context.
|
static void |
install()
Same as
setAsInitial() but it use strong types (avoiding reflection)
to install the naming context factory. |
static void |
revertSetAsInitial()
Restores the properties changed by
setAsInitial(). |
static void |
setAsInitial()
Sets the
NamingContextFactory as the initial context factory. |
static void |
setDelegateContext(Context ctx)
Sets the delegate context.
|
static void |
setDelegateEnvironment(Hashtable<?,?> env)
Sets the environment of the delegate JNDI context.
|
public Context getInitialContext(Hashtable<?,?> environment) throws NamingException
NamingContext object that
will be used as starting point for all naming operations.
NamingContext is then used by javax.naming.InitialContext object.
It also creates the delegate context if the delegate environment is set. NamingContextFactory
caches the delegate context once it's created.getInitialContext in interface InitialContextFactoryNamingContext objectNamingExceptionInitialContextFactory.getInitialContext(java.util.Hashtable)public static void setDelegateEnvironment(Hashtable<?,?> env)
NamingContext first tries to look up the object in its local tree.
If the object is not found, it will look in the delegate context.env - JNDI properties of the delegate environmentpublic static void setDelegateContext(Context ctx)
NamingContext first tries to look up the object in its local tree.
If the object is not found, it will look in the delegate context.
Example:
NamingContextFactory.setDelegateContext(new InitialContext());
ctx - delegate contextpublic static void setAsInitial()
NamingContextFactory as the initial context factory.
This helper method sets the Context.INITIAL_CONTEXT_FACTORY
and Context.URL_PKG_PREFIXES system properties. The second one is needed to
be able to handle java:comp context correctly.
The method also saves the current values of these properties so they can be
restored later on using revertSetAsInitial.
This method is normally called from setUp
You can also set these properties directly:
java.naming.factory.initial=org.nuxeo.common.jndi.NamingContextFactory
java.naming.factory.url.pkgs=org.nuxeo.common.jndi
NamingExceptionpublic static void install()
throws NamingException
setAsInitial() but it use strong types (avoiding reflection)
to install the naming context factory.
This is preferable in frameworks that doesn't work well with the current thread context class loader like OSGi.
NamingExceptionpublic static void revertSetAsInitial()
setAsInitial().
This method should be called in tearDown() to clean up
all changes to the environment in case if the test is running in the app
server.
This method also cleans the initial context.
Copyright © 2011 Nuxeo SA. All Rights Reserved.