本文整理匯總了Java中javax.naming.spi.NamingManager.getInitialContext方法的典型用法代碼示例。如果您正苦於以下問題:Java NamingManager.getInitialContext方法的具體用法?Java NamingManager.getInitialContext怎麽用?Java NamingManager.getInitialContext使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.naming.spi.NamingManager
的用法示例。
在下文中一共展示了NamingManager.getInitialContext方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: myTestGetInitialContext_HasBuilder_Normal
import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
/**
* Test the normal condition when factory builder is properly set.
*/
public void myTestGetInitialContext_HasBuilder_Normal()
throws NamingException {
log.setMethod("myTestGetInitialContext_HasBuilder_Normal");
Context context = NamingManager.getInitialContext(null);
assertTrue(context instanceof MockContext);
assertEquals(context, new MockContext(null));
Hashtable<Object, Object> env = new Hashtable<Object, Object>();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"dazzle.jndi.testing.spi.DazzleContextFactory");
context = NamingManager.getInitialContext(env);
assertTrue(context instanceof MockContext);
assertEquals(context, new MockContext(env));
}
示例2: myTestGetInitialContext_HasBuilder_BuilderNullPointerException
import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
/**
* Test the behavior when factory builder throws NullPointerException.
*/
public void myTestGetInitialContext_HasBuilder_BuilderNullPointerException()
throws NamingException {
log
.setMethod("myTestGetInitialContext_HasBuilder_BuilderNullPointerException");
Hashtable<Object, Object> env = new Hashtable<Object, Object>();
NamingManagerTest.indicateNullPointerException(env, 1);
env.put(Context.INITIAL_CONTEXT_FACTORY,
"dazzle.jndi.testing.spi.DazzleContextFactory");
try {
NamingManager.getInitialContext(env);
fail("Should throw NullPointerException.");
} catch (NullPointerException e) {
// log.log(e);
}
}
示例3: myTestGetInitialContext_HasBuilder_BuilderNamingException
import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
/**
* Test the behavior when factory builder throws NamingException.
*/
public void myTestGetInitialContext_HasBuilder_BuilderNamingException()
throws NamingException {
log
.setMethod("myTestGetInitialContext_HasBuilder_BuilderNamingException");
Hashtable<Object, Object> env = new Hashtable<Object, Object>();
NamingManagerTest.indicateNamingException(env, 1);
env.put(Context.INITIAL_CONTEXT_FACTORY,
"dazzle.jndi.testing.spi.DazzleContextFactory");
try {
NamingManager.getInitialContext(env);
fail("Should throw NamingException.");
} catch (NamingException e) {
// log.log(e);
}
}
示例4: myTestGetInitialContext_HasBuilder_FactoryRuntimeException
import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
/**
* Test the behavior when factory throws RuntimeException.
*/
public void myTestGetInitialContext_HasBuilder_FactoryRuntimeException()
throws NamingException {
log
.setMethod("myTestGetInitialContext_HasBuilder_FactoryRuntimeException");
Hashtable<Object, Object> env = new Hashtable<Object, Object>();
NamingManagerTest.indicateRuntimeException(env, 2);
env.put(Context.INITIAL_CONTEXT_FACTORY,
"dazzle.jndi.testing.spi.DazzleContextFactory");
try {
NamingManager.getInitialContext(env);
fail("Should throw RuntimeException.");
} catch (RuntimeException e) {
// log.log(e);
}
}
示例5: myTestGetInitialContext_HasBuilder_FactoryNamingException
import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
/**
* Test the behavior when factory throws NamingException.
*/
public void myTestGetInitialContext_HasBuilder_FactoryNamingException()
throws NamingException {
log
.setMethod("myTestGetInitialContext_HasBuilder_FactoryNamingException");
Hashtable<Object, Object> env = new Hashtable<Object, Object>();
NamingManagerTest.indicateNamingException(env, 2);
env.put(Context.INITIAL_CONTEXT_FACTORY,
"dazzle.jndi.testing.spi.DazzleContextFactory");
try {
NamingManager.getInitialContext(env);
fail("Should throw NamingException.");
} catch (NamingException e) {
// log.log(e);
}
}
示例6: getDefaultInitCtx
import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
/**
* Retrieves the initial context by calling
* <code>NamingManager.getInitialContext()</code>
* and cache it in defaultInitCtx.
* Set <code>gotDefault</code> so that we know we've tried this before.
* @return The non-null cached initial context.
* @exception NoInitialContextException If cannot find an initial context.
* @exception NamingException If a naming exception was encountered.
*/
protected Context getDefaultInitCtx() throws NamingException{
if (!gotDefault) {
defaultInitCtx = NamingManager.getInitialContext(myProps);
gotDefault = true;
}
if (defaultInitCtx == null)
throw new NoInitialContextException();
return defaultInitCtx;
}
示例7: CibetRemoteContext
import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
public CibetRemoteContext(Hashtable<?, ?> env) throws NamingException {
if (env == null) {
throw new IllegalArgumentException(
"Failed to create CibetRemoteContext: Constructor parameter env must not be null");
}
environment = env;
nativeEnv = (Hashtable<String, Object>) env.clone();
String nativeContextClassname = (String) nativeEnv.get(NATIVE_INITIAL_CONTEXT_FACTORY);
if (nativeContextClassname != null) {
log.info("create native initial context with " + nativeContextClassname);
nativeEnv.put(Context.INITIAL_CONTEXT_FACTORY, nativeContextClassname);
}
String nativePrefixes = (String) environment.get(CibetRemoteContext.NATIVE_URL_PKG_PREFIXES);
if (nativePrefixes != null) {
nativeEnv.put(Context.URL_PKG_PREFIXES, nativePrefixes);
}
if (log.isDebugEnabled()) {
for (Entry<?, ?> e : nativeEnv.entrySet()) {
log.debug(e);
}
}
defaultNativeContext = NamingManager.getInitialContext(nativeEnv);
log.debug("CibetRemoteContext initialised");
}
示例8: getDefaultInitCtx
import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
/**
* Get the default initial context. If {@link #gotDefault} == false, this
* method obtains the initial context from the naming manager and sets
* gotDefault to true. Otherwise the cached value ({@link #defaultInitCtx} is
* returned.
*
* @return the default initial context
* @throws NamingException
*/
protected Context getDefaultInitCtx() throws NamingException
{
if (! gotDefault)
{
defaultInitCtx = NamingManager.getInitialContext(myProps);
gotDefault = true;
}
return defaultInitCtx;
}
示例9: getDefaultInitCtx
import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
/**
* Get the default initial context. If {@link #gotDefault} == false, this
* method obtains the initial context from the naming manager and sets
* gotDefault to true. Otherwise the cached value ({@link #defaultInitCtx} is
* returned.
*
* @return the default initial context
* @throws NamingException
*/
protected Context getDefaultInitCtx() throws NamingException
{
if (! gotDefault)
{
defaultInitCtx = NamingManager.getInitialContext(myProps);
gotDefault = true;
}
return defaultInitCtx;
}
示例10: initializeDefaultInitCtx
import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
private void initializeDefaultInitCtx() throws NamingException {
if (!this.gotDefault) {
this.defaultInitCtx = NamingManager.getInitialContext(myProps);
if (null == this.defaultInitCtx) {
throw new NoInitialContextException(
"Failed to create an initial context."); //$NON-NLS-1$
}
this.gotDefault = true;
}
}
示例11: myTestGetInitialContext_HasBuilder_BuilderReturnNull
import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
/**
* Test the behavior when factory builder is set but the factory builder
* returns null.
*/
public void myTestGetInitialContext_HasBuilder_BuilderReturnNull()
throws NamingException {
log.setMethod("myTestGetInitialContext_HasBuilder_BuilderReturnNull");
Hashtable<Object, Object> env = new Hashtable<Object, Object>();
NamingManagerTest.indicateReturnNull(env, 1);
env.put(Context.INITIAL_CONTEXT_FACTORY,
"dazzle.jndi.testing.spi.DazzleContextFactory");
try {
NamingManager.getInitialContext(env);
fail("Should throw NullPointerException.");
} catch (NullPointerException e) {
// log.log(e);
}
}
示例12: myTestGetInitialContext_HasBuilder_FactoryReturnNull
import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
/**
* Test the behavior when factory builder is set but the factory returns
* null.
*/
public void myTestGetInitialContext_HasBuilder_FactoryReturnNull()
throws NamingException {
log.setMethod("myTestGetInitialContext_HasBuilder_FactoryReturnNull");
Hashtable<Object, Object> env = new Hashtable<Object, Object>();
NamingManagerTest.indicateReturnNull(env, 2);
env.put(Context.INITIAL_CONTEXT_FACTORY,
"dazzle.jndi.testing.spi.DazzleContextFactory");
Context context = NamingManager.getInitialContext(env);
assertNull(context);
}
示例13: testGetInitialContext_NoBuilder_NullFactory
import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
/**
* Test the behavior when the class name is null before factory builder is
* set.
*/
public void testGetInitialContext_NoBuilder_NullFactory()
throws NamingException {
log.setMethod("testGetInitialContext_NoBuilder_NullFactory()");
Hashtable<String, String> envWithNoFac = new Hashtable<String, String>();
try {
NamingManager.getInitialContext(envWithNoFac);
fail("Should throw NoInitialContextException.");
} catch (NoInitialContextException e) {
}
}
示例14: testGetInitialContext_NoBuilder_EmptyFactory
import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
/**
* Test the behavior when the class name is empty before factory builder is
* set.
*/
public void testGetInitialContext_NoBuilder_EmptyFactory()
throws NamingException {
log.setMethod("testGetInitialContext_NoBuilder_EmptyFactory()");
Hashtable<String, String> envWithEmptyFac = new Hashtable<String, String>();
envWithEmptyFac.put(Context.INITIAL_CONTEXT_FACTORY, "");
try {
NamingManager.getInitialContext(envWithEmptyFac);
fail("Should throw NoInitialContextException.");
} catch (NoInitialContextException e) {
}
}
示例15: testGetInitialContext_NoBuilder_InvalidFactory
import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
/**
* Test the behavior when the class name is invalid before factory builder
* is set.
*/
public void testGetInitialContext_NoBuilder_InvalidFactory()
throws NamingException {
log.setMethod("testGetInitialContext_NoBuilder_InvalidFactory()");
Hashtable<String, String> envWithInvalidFac = new Hashtable<String, String>();
envWithInvalidFac.put(Context.INITIAL_CONTEXT_FACTORY, "junk.Factory");
try {
NamingManager.getInitialContext(envWithInvalidFac);
fail("Should throw NoInitialContextException.");
} catch (NoInitialContextException e) {
}
}