|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.mockejb.jndi.MockContextFactory
Creates MockContext
. In case if delegate
environment was provided, obtains delegate InitialContext.
Delegate context is used by MockContext for unresolved lookups.
Constructor Summary | |
MockContextFactory()
|
Method Summary | |
javax.naming.Context |
getInitialContext(java.util.Hashtable environment)
Singleton for initial context. |
static void |
revertSetAsInitial()
Restores the properties changed by 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. |
static void |
setAsInitial()
Sets the MockContextFactory as the initial context factory. |
static void |
setDelegateContext(javax.naming.Context ctx)
Sets the delegate context. |
static void |
setDelegateEnvironment(java.util.Hashtable env)
Sets the environment of the delegate JNDI context. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public MockContextFactory()
Method Detail |
public javax.naming.Context getInitialContext(java.util.Hashtable environment) throws javax.naming.NamingException
MockContext
object that
will be used as starting point for all naming operations.
MockContext
is then used by javax.naming.InitialContext
object.
It also creates the delegate context if the delegate environment is set. MockContextFactory
caches the delegate context once it's created.
getInitialContext
in interface javax.naming.spi.InitialContextFactory
MockContext
object
javax.naming.NamingException
InitialContextFactory.getInitialContext(java.util.Hashtable)
public static void setDelegateEnvironment(java.util.Hashtable env)
MockContext
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(javax.naming.Context ctx)
MockContext
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:
MockContextFactory.setDelegateContext( new InitialContext() );
ctx
- delegate contextpublic static void setAsInitial() throws javax.naming.NamingException
MockContextFactory
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.mockejb.jndi.MockContextFactory java.naming.factory.url.pkgs=org.mockejb.jndi
javax.naming.NamingException
public 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.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |