--- /home/tromey/gnu/Nightly/classpath/classpath/java/lang/ClassLoader.java 2004-11-08 02:18:59.000000000 -0700 +++ java/lang/ClassLoader.java 2004-11-25 02:16:35.000000000 -0700 @@ -41,21 +41,16 @@ import gnu.java.util.DoubleEnumeration; import gnu.java.util.EmptyEnumeration; -import java.io.File; import java.io.IOException; import java.io.InputStream; -import java.lang.reflect.Constructor; import java.net.URL; -import java.net.URLClassLoader; import java.security.CodeSource; import java.security.PermissionCollection; import java.security.Policy; import java.security.ProtectionDomain; -import java.util.ArrayList; import java.util.Enumeration; import java.util.HashMap; import java.util.Map; -import java.util.StringTokenizer; /** * The ClassLoader is a way of customizing the way Java gets its classes @@ -84,8 +79,8 @@ *
The bootstrap classloader in GNU Classpath is implemented as a couple of
* static (native) methods on the package private class
* java.lang.VMClassLoader, the system classloader is an
- * anonymous inner class of ClassLoader and a subclass of
- * java.net.URLClassLoader.
+ * instance of gnu.java.lang.SystemClassLoader
+ * (which is a subclass of java.net.URLClassLoader).
*
*
Users of a ClassLoader will normally just use the methods
*
java.class.path. This is set as the context
* class loader for a thread. The system property
* java.system.class.loader, if defined, is taken to be the
* name of the class to use as the system class loader, which must have
- * a public constructor which takes a ClassLoader as a parent. The parent
- * class loader passed in the constructor is the default system class
- * loader.
+ * a public constructor which takes a ClassLoader as a parent; otherwise this
+ * uses gnu.java.lang.SystemClassLoader.
*
* Note that this is different from the bootstrap classloader that - * actually loads all the real "system" classes. + * actually loads all the real "system" classes (the bootstrap classloader + * is the parent of the returned system classloader). * *
A security check will be performed for
* RuntimePermission("getClassLoader") if the calling class
@@ -724,11 +744,11 @@
{
Class c = VMSecurityManager.getClassContext()[1];
ClassLoader cl = c.getClassLoader();
- if (cl != null && cl != System.systemClassLoader)
+ if (cl != null && cl != systemClassLoader)
sm.checkPermission(new RuntimePermission("getClassLoader"));
}
- return System.systemClassLoader;
+ return systemClassLoader;
}
/**
@@ -944,121 +964,4 @@
}
return false;
}
-
- private static URL[] getExtClassLoaderUrls()
- {
- String classpath = getSystemProperty("java.ext.dirs", "");
- StringTokenizer tok = new StringTokenizer(classpath, File.pathSeparator);
- ArrayList list = new ArrayList();
- while (tok.hasMoreTokens())
- {
- try
- {
- File f = new File(tok.nextToken());
- File[] files = f.listFiles();
- for (int i = 0; i < files.length; i++)
- {
- list.add(files[i].toURL());
- }
- }
- catch(Exception x)
- {
- }
- }
- URL[] urls = new URL[list.size()];
- list.toArray(urls);
- return urls;
- }
-
- private static void addFileURL(ArrayList list, String file)
- {
- try
- {
- list.add(new File(file).toURL());
- }
- catch(java.net.MalformedURLException x)
- {
- }
- }
-
- private static URL[] getSystemClassLoaderUrls()
- {
- String classpath = getSystemProperty("java.class.path", ".");
- StringTokenizer tok = new StringTokenizer(classpath, File.pathSeparator, true);
- ArrayList list = new ArrayList();
- while (tok.hasMoreTokens())
- {
- String s = tok.nextToken();
- if (s.equals(File.pathSeparator))
- addFileURL(list, ".");
- else
- {
- addFileURL(list, s);
- if (tok.hasMoreTokens())
- {
- // Skip the separator.
- tok.nextToken();
- // If the classpath ended with a separator,
- // append the current directory.
- if (!tok.hasMoreTokens())
- addFileURL(list, ".");
- }
- }
- }
- URL[] urls = new URL[list.size()];
- list.toArray(urls);
- return urls;
- }
-
- static ClassLoader defaultGetSystemClassLoader()
- {
- ClassLoader extClassLoader =
- new URLClassLoader(getExtClassLoaderUrls(), null);
- ClassLoader systemClassLoader =
- new URLClassLoader(getSystemClassLoaderUrls(), extClassLoader)
- {
- protected synchronized Class loadClass(String name,
- boolean resolve)
- throws ClassNotFoundException
- {
- SecurityManager sm = Runtime.securityManager;
- if (sm != null)
- {
- int lastDot = name.lastIndexOf('.');
- if (lastDot != -1)
- sm.checkPackageAccess(name.substring(0, lastDot));
- }
- return super.loadClass(name, resolve);
- }
- };
- String loader = getSystemProperty("java.system.class.loader", null);
- if (loader == null)
- {
- return systemClassLoader;
- }
- try
- {
- Constructor c = Class.forName(loader, false, systemClassLoader)
- .getConstructor(new Class[] { ClassLoader.class });
- return (ClassLoader)c.newInstance(new Object[] { systemClassLoader });
- }
- catch (Exception e)
- {
- System.err.println("Requested system classloader " + loader + " failed.");
- throw (Error)
- new Error("Requested system classloader " + loader + " failed.")
- .initCause(e);
- }
- }
-
- static String getSystemProperty(String name, String defaultValue)
- {
- // access properties directly to bypass security
- String val = System.properties.getProperty(name);
- if (val == null)
- {
- val = defaultValue;
- }
- return val;
- }
}