* Initializes the initial context using the supplied environment.
* Environment properties are discussed in the class description.
*
* <p> This method will modify <tt>environment</tt> and save
* a reference to it. The caller may no longer modify it.
*
* @param environment
* environment used to create the initial context.
* Null indicates an empty environment.
*
* @throws NamingException if a naming exception is encountered
*
* @see #InitialContext(boolean)
* @since 1.3
*/
protected void init(Hashtable<?,?> environment)
throws NamingException
{
myProps = ResourceManager.getInitialEnvironment(environment);
if (myProps.get(Context.INITIAL_CONTEXT_FACTORY) != null) {
// user has specified initial context factory; try to get it
getDefaultInitCtx();
}
}
/**
* A static method to retrieve the named object.
* This is a shortcut method equivalent to invoking:
* <p>
* <code>
* InitialContext ic = new InitialContext();
* Object obj = ic.lookup();
* </code>
* <p> If <tt>name</tt> is empty, returns a new instance of this context
* (which represents the same naming context as this context, but its
* environment may be modified independently and it may be accessed
* concurrently).
*
* @param name
* the name of the object to look up
* @return the object bound to <tt>name</tt>
* @throws NamingException if a naming exception is encountered
*
* @see #doLookup(String)
* @see #lookup(Name)
* @since 1.6
*/
public static <T> T doLookup(Name name)
throws NamingException {
return (T) (new InitialContext()).lookup(name);
}
/**
* A static method to retrieve the named object.
* See {@link #doLookup(Name)} for details.
* @param name
* the name of the object to look up
* @return the object bound to <tt>name</tt>
* @throws NamingException if a naming exception is encountered
* @since 1.6
*/
public static <T> T doLookup(String name)
throws NamingException {
return (T) (new InitialContext()).lookup(name);
}
private static String getURLScheme(String str) {
int colon_posn = str.indexOf(':');
int slash_posn = str.indexOf('/');
if (colon_posn > 0 && (slash_posn == -1 || colon_posn < slash_posn))
return str.substring(0, colon_posn);
return null;
}
/**
* 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;
}
/**
* Retrieves a context for resolving the string name <code>name</code>.
* If <code>name</code> name is a URL string, then attempt
* to find a URL context for it. If none is found, or if
=3= |