public class SingletonInitialContext extends Object implements Context
JNDI naming context that can be used in unit tests for code that
looks up objects.
This can be used easily in a unit test by either using one of two methods. The first is using the convenient static
configure method that takes one, two or three name/object pairs:
SingletonInitialContext.register(name, obj); SingletonInitialContext.register(name1, obj1, name2, obj2); SingletonInitialContext.register(name1, obj1, name2, obj2, name3, obj3);
The other approach is to set the system property for the InitialContextFactory:
System.setProperty("java.naming.factory.initial", "org.modeshape.common.mock.SingletonInitialContextFactory");
and then to bind an object.SingletonInitialContextFactoryAPPLET, AUTHORITATIVE, BATCHSIZE, DNS_URL, INITIAL_CONTEXT_FACTORY, LANGUAGE, OBJECT_FACTORIES, PROVIDER_URL, REFERRAL, SECURITY_AUTHENTICATION, SECURITY_CREDENTIALS, SECURITY_PRINCIPAL, SECURITY_PROTOCOL, STATE_FACTORIES, URL_PKG_PREFIXES| Modifier and Type | Method and Description |
|---|---|
Object |
addToEnvironment(String propName,
Object propVal) |
void |
bind(Name name,
Object obj) |
void |
bind(String name,
Object obj) |
void |
close() |
Name |
composeName(Name name,
Name prefix) |
String |
composeName(String name,
String prefix) |
Context |
createSubcontext(Name name) |
Context |
createSubcontext(String name) |
void |
destroySubcontext(Name name) |
void |
destroySubcontext(String name) |
Hashtable<?,?> |
getEnvironment() |
String |
getNameInNamespace() |
NameParser |
getNameParser(Name name) |
NameParser |
getNameParser(String name) |
NamingEnumeration<NameClassPair> |
list(Name name) |
NamingEnumeration<NameClassPair> |
list(String name) |
NamingEnumeration<Binding> |
listBindings(Name name) |
NamingEnumeration<Binding> |
listBindings(String name) |
Object |
lookup(Name name) |
Object |
lookup(String name) |
Object |
lookupLink(Name name) |
Object |
lookupLink(String name) |
void |
rebind(Name name,
Object obj) |
void |
rebind(String name,
Object obj) |
static void |
register(String name,
Object obj)
A convenience method that registers the supplied object with the supplied name.
|
static void |
register(String name1,
Object obj1,
String name2,
Object obj2)
A convenience method that registers the supplied objects with the supplied names.
|
static void |
register(String name1,
Object obj1,
String name2,
Object obj2,
String name3,
Object obj3)
A convenience method that registers the supplied objects with the supplied names.
|
Object |
removeFromEnvironment(String propName) |
void |
rename(Name oldName,
Name newName) |
void |
rename(String oldName,
String newName) |
void |
unbind(Name name) |
void |
unbind(String name) |
public static void register(String name, Object obj)
name - the JNDI nameobj - the object to be registeredpublic static void register(String name1, Object obj1, String name2, Object obj2)
name1 - the JNDI name for the first objectobj1 - the first object to be registeredname2 - the JNDI name for the second objectobj2 - the second object to be registeredpublic static void register(String name1, Object obj1, String name2, Object obj2, String name3, Object obj3)
name1 - the JNDI name for the first objectobj1 - the first object to be registeredname2 - the JNDI name for the second objectobj2 - the second object to be registeredname3 - the JNDI name for the third objectobj3 - the third object to be registeredpublic Object addToEnvironment(String propName, Object propVal)
addToEnvironment in interface Contextpublic Object removeFromEnvironment(String propName)
removeFromEnvironment in interface Contextpublic void bind(Name name, Object obj) throws NamingException
bind in interface ContextNamingExceptionpublic void bind(String name, Object obj) throws NamingException
bind in interface ContextNamingExceptionpublic Object lookup(Name name) throws NamingException
lookup in interface ContextNamingExceptionpublic Object lookup(String name) throws NamingException
lookup in interface ContextNamingExceptionpublic Object lookupLink(String name)
lookupLink in interface Contextpublic Object lookupLink(Name name)
lookupLink in interface Contextpublic Name composeName(Name name, Name prefix)
composeName in interface Contextpublic String composeName(String name, String prefix)
composeName in interface Contextpublic Context createSubcontext(Name name)
createSubcontext in interface Contextpublic Context createSubcontext(String name)
createSubcontext in interface Contextpublic void destroySubcontext(Name name)
destroySubcontext in interface Contextpublic void destroySubcontext(String name)
destroySubcontext in interface Contextpublic Hashtable<?,?> getEnvironment()
getEnvironment in interface Contextpublic String getNameInNamespace()
getNameInNamespace in interface Contextpublic NameParser getNameParser(Name name)
getNameParser in interface Contextpublic NameParser getNameParser(String name)
getNameParser in interface Contextpublic NamingEnumeration<NameClassPair> list(Name name)
public NamingEnumeration<NameClassPair> list(String name)
public NamingEnumeration<Binding> listBindings(Name name)
listBindings in interface Contextpublic NamingEnumeration<Binding> listBindings(String name)
listBindings in interface ContextCopyright © 2008-2014 JBoss, a division of Red Hat. All Rights Reserved.