|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.modeshape.common.naming.SingletonInitialContextFactory
public class SingletonInitialContextFactory
An InitialContextFactory
that provides a singleton JNDI naming context
. Because it is a singleton, it
is useful in unit tests that looks up
objects where it can be used within service registration
logic while also being easily accessible in the test case itself.
For example, the following code sample shows how this InitialContextFactory implementation can be specified via the standard "
" property:
java.naming.factory.initial
Hashtable<String, Object> jndiContext = new Hashtable<String, Object>(); jndiContext.put("java.naming.factory.initial", "org.modeshape.common.naming.SingleonInitialContextFactory"); jndiContext.put("java.naming.provider.url", "localhost"); InitialContext initialContext = new InitialContext(jndiContext);while the following sample shows how the same
Context
instance will be subsequently returned from accessed within other
code (e.g., a test case):
Context context = SingletoneInitialContextFactory.create();
Constructor Summary | |
---|---|
SingletonInitialContextFactory()
No-arg constructor |
Method Summary | |
---|---|
Context |
getInitialContext(Hashtable<?,?> environment)
|
static Context |
getInstance()
Return the previously-configured Context singleton instance. |
static Context |
getInstance(Hashtable<?,?> environment)
Return the Context singleton instance. |
static void |
initialize()
Set the Context.INITIAL_CONTEXT_FACTORY system property to the name of this context's
factory class . |
static void |
tearDown()
Release any existing singleton naming context . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public SingletonInitialContextFactory()
Method Detail |
---|
public Context getInitialContext(Hashtable<?,?> environment)
getInitialContext
in interface InitialContextFactory
public static Context getInstance(Hashtable<?,?> environment)
Context
singleton instance. If no such context has been configured, this method will configured the
singletone using the supplied environment.
environment
- the environment for the naming context; may be null or empty
getInitialContext(Hashtable)
,
getInstance(Hashtable)
public static Context getInstance()
Context
singleton instance. If no such context has been configured, this method
throws a SystemFailureException
.
SystemFailureException
- if the singleton context has not yet been configured.getInitialContext(Hashtable)
,
getInstance(Hashtable)
public static void initialize()
Context.INITIAL_CONTEXT_FACTORY
system property to the name of this context's
factory class
.
public static void tearDown()
naming context
. Any subsequent calls to getInstance(Hashtable)
or
getInitialContext(Hashtable)
will return a new singleton instance.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |