Retrieves a context for resolving
name
.
If the first component of
name
name is a URL string,
then attempt to find a URL context for it. If none is found, or if
the first component of
name
is not a URL string,
then return
getDefaultInitCtx()
.
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.
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;
}
When providing implementations for the new methods in the subclass,
use this newly defined method to get the initial context.
public Object XXXMethod1(Name name, ...) {
throws NamingException {
return getURLOrDefaultInitXXXCtx(name).XXXMethod1(name, ...);
}
Returns:
A URL context for
name
or the cached
initial context. The result cannot be null.
Parameters:
-
name - The non-null name for which to get the context.
Throws:
-
NoInitialContextException - If cannot find an initial context.
-
NamingException - In a naming exception is encountered.
See Also:
NamingManager.getURLContext(java.lang.String, java.util.Hashtable, ?>)
,