* <code>name</code> is not a URL string, then return
* <code>getDefaultInitCtx()</code>.
*<p>
* See getURLOrDefaultInitCtx(Name) for description
* of how a subclass should use this method.
* @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(String name)
throws NamingException {
if (NamingManager.hasInitialContextFactoryBuilder()) {
return getDefaultInitCtx();
}
String scheme = getURLScheme(name);
if (scheme != null) {
Context ctx = NamingManager.getURLContext(scheme, myProps);
if (ctx != null) {
return ctx;
}
}
return getDefaultInitCtx();
}
/**
* 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.
* <p><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.
* <p><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();
}
// Context methods
// Most Javadoc is deferred to the Context interface.
public Object lookup(String name) throws NamingException {
return getURLOrDefaultInitCtx(name).lookup(name);
}
public Object lookup(Name name) throws NamingException {
return getURLOrDefaultInitCtx(name).lookup(name);
}
public void bind(String name, Object obj) throws NamingException {
getURLOrDefaultInitCtx(name).bind(name, obj);
=4= |