// Reset the toString() value.
thisString = null;
// Create a loader for this URL.
URLLoader loader = null;
String file = newUrl.getFile();
try
{
file = gnu.java.net.protocol.file.Connection.unquote(file);
}
catch (MalformedURLException e)
{
// ignore
}
String protocol = newUrl.getProtocol();
// If we have a file: URL, we want to make it absolute
// here, before we decide whether it is really a jar.
URL absoluteURL;
if ("file".equals (protocol))
{
File dir = new File(file);
try
{
absoluteURL = dir.getCanonicalFile().toURL();
}
catch (IOException ignore)
{
try
{
absoluteURL = dir.getAbsoluteFile().toURL();
}
catch (MalformedURLException _)
{
// This really should not happen.
absoluteURL = newUrl;
}
}
}
else
{
// This doesn't hurt, and it simplifies the logic a
// little.
absoluteURL = newUrl;
}
// First see if we can find a handler with the correct name.
try
{
Class handler = Class.forName(URL_LOADER_PREFIX + protocol);
Class[] argTypes = new Class[] { URLClassLoader.class,
URLStreamHandlerCache.class,
URLStreamHandlerFactory.class,
URL.class,
URL.class };
Constructor k = handler.getDeclaredConstructor(argTypes);
loader
= (URLLoader) k.newInstance(new Object[] { this,
factoryCache,
factory,
newUrl,
absoluteURL });
}
catch (ClassNotFoundException ignore)
{
// Fall through.
}
catch (NoSuchMethodException nsme)
{
// Programming error in the class library.
InternalError vme
= new InternalError("couldn't find URLLoader constructor");
vme.initCause(nsme);
throw vme;
}
catch (InstantiationException inste)
{
// Programming error in the class library.
InternalError vme
= new InternalError("couldn't instantiate URLLoader");
vme.initCause(inste);
throw vme;
}
catch (InvocationTargetException ite)
{
// Programming error in the class library.
InternalError vme
= new InternalError("error instantiating URLLoader");
vme.initCause(ite);
throw vme;
}
catch (IllegalAccessException illae)
{
// Programming error in the class library.
InternalError vme
= new InternalError("invalid access to URLLoader");
vme.initCause(illae);
throw vme;
}
if (loader == null)
{
// If it is not a directory, use the jar loader.
if (! (file.endsWith("/") || file.endsWith(File.separator)))
loader = new JarURLLoader(this, factoryCache, factory,
newUrl, absoluteURL);
else if ("file".equals(protocol))
loader = new FileURLLoader(this, factoryCache, factory,
newUrl, absoluteURL);
else
loader = new RemoteURLLoader(this, factoryCache, factory,
newUrl);
}
urlinfos.add(loader);
ArrayList extra = loader.getClassPath();
if (extra != null)
urlinfos.addAll(extra);
}
}