本文整理匯總了Java中javax.naming.spi.NamingManager.getURLContext方法的典型用法代碼示例。如果您正苦於以下問題:Java NamingManager.getURLContext方法的具體用法?Java NamingManager.getURLContext怎麽用?Java NamingManager.getURLContext使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.naming.spi.NamingManager
的用法示例。
在下文中一共展示了NamingManager.getURLContext方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getNativeURLOrDefaultInitCtx
import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
protected Context getNativeURLOrDefaultInitCtx(Name name) throws NamingException {
if (NamingManager.hasInitialContextFactoryBuilder()) {
return defaultNativeContext;
}
if (name.size() > 0) {
String first = name.get(0);
String scheme = getURLScheme(first);
if (scheme != null) {
Context ctx = NamingManager.getURLContext(scheme, nativeEnv);
if (ctx != null) {
return ctx;
}
}
}
return defaultNativeContext;
}
示例2: getURLOrDefaultInitCtx
import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
/**
* Obtains the context for resolving the given name. If the first component of
* the name is the URL string, this method tries to find the corressponding
* URL naming context. If it is not an URL string, or the URL context is not
* found, the default initial context is returned.
*
* @param name the name, for that it is required to obtain the context.
* @return the context for resolving the name.
* @throws NamingException
*/
protected Context getURLOrDefaultInitCtx(String name) throws NamingException
{
String scheme = null;
if (NamingManager.hasInitialContextFactoryBuilder())
return getDefaultInitCtx();
int colon = name.indexOf(':');
int slash = name.indexOf('/');
if (colon > 0 && (slash == - 1 || colon < slash))
scheme = name.substring(0, colon);
if (scheme != null)
{
Context context = NamingManager.getURLContext(scheme, myProps);
if (context != null)
return context;
}
return getDefaultInitCtx();
}
示例3: getURLOrDefaultInitCtx
import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
/**
* Obtains the context for resolving the given name. If the first component of
* the name is the URL string, this method tries to find the corressponding
* URL naming context. If it is not an URL string, or the URL context is not
* found, the default initial context is returned.
*
* @param name the name, for that it is required to obtain the context.
* @return the context for resolving the name.
* @throws NamingException
*/
protected Context getURLOrDefaultInitCtx(String name) throws NamingException
{
String scheme = null;
if (NamingManager.hasInitialContextFactoryBuilder())
return getDefaultInitCtx();
int colon = name.indexOf(':');
int slash = name.indexOf('/');
if (colon > 0 && (slash == - 1 || colon < slash))
scheme = name.substring(0, colon);
if (scheme != null)
{
Context context = NamingManager.getURLContext(scheme, myProps);
if (context != null)
return context;
}
return getDefaultInitCtx();
}
示例4: testGetURLContext_http_f1Success
import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
public void testGetURLContext_http_f1Success() {
log.setMethod("testGetURLContext_http_f1Success()");
String schema = "http";
Hashtable<String, String> h = new Hashtable<String, String>();
h.put(Context.URL_PKG_PREFIXES,
"org.apache.harmony.jndi.tests.javax.naming.spi.mocksuccess");
try {
Context ctx = NamingManager.getURLContext(schema, h);
assertNull(ctx.getEnvironment().get("o"));
assertNull(ctx.getEnvironment().get("n"));
assertNull(ctx.getEnvironment().get("c"));
assertSame(h, ctx.getEnvironment().get("h"));
} catch (Throwable e) {
log.log(e);
fail();
}
}
示例5: testGetURLContext_http_f1BadClassName_f2Success
import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
public void testGetURLContext_http_f1BadClassName_f2Success() {
log.setMethod("testGetURLContext_http_f1BadClassName_f2Success()");
String schema = "http";
Hashtable<String, String> h = new Hashtable<String, String>();
h.put(Context.URL_PKG_PREFIXES,
"bad.class.name:org.apache.harmony.jndi.tests.javax.naming.spi.mocksuccess");
try {
Context ctx = NamingManager.getURLContext(schema, h);
assertNull(ctx.getEnvironment().get("o"));
assertNull(ctx.getEnvironment().get("n"));
assertNull(ctx.getEnvironment().get("c"));
assertSame(h, ctx.getEnvironment().get("h"));
} catch (Throwable e) {
log.log(e);
fail();
}
}
示例6: testGetURLContext_http_f1ReturnNull_f2Success
import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
public void testGetURLContext_http_f1ReturnNull_f2Success() {
log.setMethod("testGetURLContext_http_f1ReturnNull_f2Success()");
String schema = "http";
Hashtable<Object, Object> h = new Hashtable<Object, Object>();
h
.put(Context.URL_PKG_PREFIXES,
"org.apache.harmony.jndi.tests.javax.naming.spi.mock:org.apache.harmony.jndi.tests.javax.naming.spi.mocksuccess");
indicateReturnNull(h);
try {
Context ctx = NamingManager.getURLContext(schema, h);
assertNull(ctx);
} catch (Throwable e) {
log.log(e);
fail();
}
}
示例7: testGetURLContext_http_f1ReturnNull_f2ReturnNull
import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
public void testGetURLContext_http_f1ReturnNull_f2ReturnNull() {
log.setMethod("testGetURLContext_http_f1ReturnNull_f2ReturnNull()");
String schema = "http";
Hashtable<Object, Object> h = new Hashtable<Object, Object>();
h
.put(Context.URL_PKG_PREFIXES,
"org.apache.harmony.jndi.tests.javax.naming.spi.mock:org.apache.harmony.jndi.tests.javax.naming.spi.mock");
indicateReturnNull(h);
try {
Context ctx = NamingManager.getURLContext(schema, h);
assertNull(ctx);
} catch (Throwable e) {
log.log(e);
fail();
}
}
示例8: testFactoryBuilder_name
import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
public void testFactoryBuilder_name() throws IllegalStateException,
SecurityException, NamingException {
// log.setMethod("testFactoryBuilder_name");
if (!NamingManager.hasInitialContextFactoryBuilder()) {
InitialContextFactoryBuilder contextFactoryBuilder = MockInitialContextFactoryBuilder
.getInstance();
NamingManager
.setInitialContextFactoryBuilder(contextFactoryBuilder);
}
Hashtable<Object, Object> env = new Hashtable<Object, Object>();
env.put(Context.URL_PKG_PREFIXES, "org.apache.harmony.jndi.tests.javax.naming.spi.mock");
MyInitialContext context = new MyInitialContext(env);
// log.log(context.getEnvironment().toString());
// log.log("DefaultContext:" +
// context.getDefaultContext().getClass().getName());
//
Context urlContext = NamingManager.getURLContext("http", env);
assertEquals("http", urlContext.getEnvironment().get("url.schema"));
Name name = new CompositeName("http://www.apache.org");
String obj = "Name object";
context.bind(name, obj);
assertNull(InvokeRecord.getLatestUrlSchema());
}
示例9: getURLOrDefaultInitCtx
import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
/**
* Returns a non-null context for the specified name of string
* representation.
* <p>
* If an initial context factory builder has been defined, then the
* specified name parameter is ignored and the result of <code>
* getDefaultInitCtx</code>
* is returned. Otherwise, if the name is not a URL string, then it returns
* the result of invoking <code>getDefaultInitCtx
* </code>. Otherwise, it
* attempts to return a URL context
* {@link javax.naming.spi.NamingManager#getURLContext(String, Hashtable)},
* but if unsuccessful, returns the result of invoking <code>
* getDefaultInitCtx</code>.
* </p>
*
* @param name
* a name used in a naming operation which may not be null
* @return a context which may be a URL context
* @throws NamingException
* If failed to get the desired context.
*/
protected Context getURLOrDefaultInitCtx(String name)
throws NamingException {
/*
* If an initial context factory builder has been defined, then the
* specified name parameter is ignored and the result of
* getDefaultInitCtx() is returned.
*/
if (NamingManager.hasInitialContextFactoryBuilder()) {
return getDefaultInitCtx();
}
if (null == name) {
// jndi.00=name must not be null
throw new NullPointerException(Messages.getString("jndi.00")); //$NON-NLS-1$
}
// If the name has components
String scheme = UrlParser.getScheme(name);
Context ctx = null;
if (null != scheme) {
synchronized (contextCache) {
if (contextCache.containsKey(scheme)) {
return contextCache.get(scheme);
}
// So the first component is a valid URL
ctx = NamingManager.getURLContext(scheme, myProps);
if (null == ctx) {
ctx = getDefaultInitCtx();
}
contextCache.put(scheme, ctx);
}
return ctx;
}
return getDefaultInitCtx();
}
示例10: testFactoryBuilder
import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
public void testFactoryBuilder() throws IllegalStateException,
SecurityException, NamingException {
// log.setMethod("testFactoryBuilder");
if (!NamingManager.hasInitialContextFactoryBuilder()) {
InitialContextFactoryBuilder contextFactoryBuilder = MockInitialContextFactoryBuilder
.getInstance();
NamingManager
.setInitialContextFactoryBuilder(contextFactoryBuilder);
}
Hashtable<Object, Object> env = new Hashtable<Object, Object>();
env.put(Context.URL_PKG_PREFIXES, "org.apache.harmony.jndi.tests.javax.naming.spi.mock");
MyInitialContext context = new MyInitialContext(env);
// log.log(context.getEnvironment().toString());
// log.log("DefaultContext:" +
// context.getDefaultContext().getClass().getName());
//
Context urlContext = NamingManager.getURLContext("http", env);
assertEquals("http", urlContext.getEnvironment().get("url.schema"));
String name = "http://www.apache.org";
String obj = "String object";
context.bind(name, obj);
assertNull(InvokeRecord.getLatestUrlSchema());
}
示例11: getURLOrDefaultInitCtx
import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
/**
* Returns a non-null context for the specified name of string
* representation.
* <p>
* If an initial context factory builder has been defined, then the
* specified name parameter is ignored and the result of <code>
* getDefaultInitCtx</code>
* is returned. Otherwise, if the name is not a URL string, then it returns
* the result of invoking <code>getDefaultInitCtx
* </code>. Otherwise, it
* attempts to return a URL context
* {@link NamingManager#getURLContext(String, Hashtable)},
* but if unsuccessful, returns the result of invoking <code>
* getDefaultInitCtx</code>.
* </p>
*
* @param name
* a name used in a naming operation which may not be null
* @return a context which may be a URL context
* @throws NamingException
* If failed to get the desired context.
*/
protected Context getURLOrDefaultInitCtx(String name)
throws NamingException {
/*
* If an initial context factory builder has been defined, then the
* specified name parameter is ignored and the result of
* getDefaultInitCtx() is returned.
*/
if (NamingManager.hasInitialContextFactoryBuilder()) {
return getDefaultInitCtx();
}
if (null == name) {
// jndi.00=name must not be null
throw new NullPointerException(Messages.getString("jndi.00")); //$NON-NLS-1$
}
// If the name has components
String scheme = UrlParser.getScheme(name);
Context ctx = null;
if (null != scheme) {
synchronized (contextCache) {
if (contextCache.containsKey(scheme)) {
return contextCache.get(scheme);
}
// So the first component is a valid URL
ctx = NamingManager.getURLContext(scheme, myProps);
if (null == ctx) {
ctx = getDefaultInitCtx();
}
contextCache.put(scheme, ctx);
}
return ctx;
}
return getDefaultInitCtx();
}
示例12: testGetURLContext_empty_null
import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
public void testGetURLContext_empty_null() {
log.setMethod("testGetURLContext_empty_null()");
String schema = "";
Hashtable<Object, Object> h = null;
try {
Context ctx = NamingManager.getURLContext(schema, h);
assertNull(ctx);
} catch (Throwable e) {
log.log(e);
fail();
}
}
示例13: testGetURLContext_http_f1BadClassName_f2BadClassName
import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
public void testGetURLContext_http_f1BadClassName_f2BadClassName() {
log.setMethod("testGetURLContext_http_f1BadClassName_f2BadClassName()");
String schema = "http";
Hashtable<String, String> h = new Hashtable<String, String>();
h.put(Context.URL_PKG_PREFIXES, "bad.class.name:bad.class.name");
try {
Context ctx = NamingManager.getURLContext(schema, h);
assertNull(ctx);
} catch (Throwable e) {
log.log(e);
fail();
}
}
示例14: testGetURLContext_http_empty
import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
public void testGetURLContext_http_empty() {
log.setMethod("testGetURLContext_http_empty()");
String schema = "http";
Hashtable<Object, Object> h = new Hashtable<Object, Object>();
try {
Context ctx = NamingManager.getURLContext(schema, h);
assertNull(ctx);
} catch (Throwable e) {
log.log(e);
fail();
}
}
示例15: getURLOrDefaultInitCtx
import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
/**
* Retrieves a context for resolving <code>name</code>.
* If the first component of <code>name</code> name is a URL string,
* then attempt to find a URL context for it. If none is found, or if
* the first component of <code>name</code> is not a URL string,
* then return <code>getDefaultInitCtx()</code>.
*<p>
* When creating a subclass of InitialContext, use this method as
* follows.
* Define a new method that uses this method to get an initial
* context of the desired subclass.
* <blockquote><pre>
* protected XXXContext getURLOrDefaultInitXXXCtx(Name name)
* throws NamingException {
* Context answer = getURLOrDefaultInitCtx(name);
* if (!(answer instanceof XXXContext)) {
* if (answer == null) {
* throw new NoInitialContextException();
* } else {
* throw new NotContextException("Not an XXXContext");
* }
* }
* return (XXXContext)answer;
* }
* </pre></blockquote>
* When providing implementations for the new methods in the subclass,
* use this newly defined method to get the initial context.
* <blockquote><pre>
* public Object XXXMethod1(Name name, ...) {
* throws NamingException {
* return getURLOrDefaultInitXXXCtx(name).XXXMethod1(name, ...);
* }
* </pre></blockquote>
*
* @param name The non-null name for which to get the context.
* @return A URL context for <code>name</code> or the cached
* initial context. The result cannot be null.
* @exception NoInitialContextException If cannot find an initial context.
* @exception NamingException In a naming exception is encountered.
*
* @see javax.naming.spi.NamingManager#getURLContext
*/
protected Context getURLOrDefaultInitCtx(Name name)
throws NamingException {
if (NamingManager.hasInitialContextFactoryBuilder()) {
return getDefaultInitCtx();
}
if (name.size() > 0) {
String first = name.get(0);
String scheme = getURLScheme(first);
if (scheme != null) {
Context ctx = NamingManager.getURLContext(scheme, myProps);
if (ctx != null) {
return ctx;
}
}
}
return getDefaultInitCtx();
}