1 /* Copyright (C) 2005 Free Software Foundation
3 This file is part of libgcj.
5 This software is copyrighted work licensed under the terms of the
6 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
9 package gnu.gcj.runtime;
12 import java.io.FilenameFilter;
13 import java.io.IOException;
15 import java.net.URLClassLoader;
16 import java.util.Enumeration;
17 import java.util.HashSet;
18 import java.util.StringTokenizer;
21 * This is a helper for the bootstrap class loader. It is a
22 * URLClassLoader so that we can read a class path and re-use all the
23 * existing code for finding classes, extracting them from jars, etc.
24 * However, it is never called the way that an ordinary ClassLoader is
25 * called. For instance, loadClass() is never used.
27 public final class BootClassLoader extends URLClassLoader
29 BootClassLoader(String libdir)
33 // Add the contents of the endorsed directories.
35 = new StringTokenizer (System.getProperty ("java.endorsed.dirs", ""),
39 while (st.hasMoreElements ())
41 String dirname = st.nextToken ();
42 File dir = new File (dirname);
45 if (! dirname.endsWith (File.separator))
46 dirname = dirname + File.separator;
47 String files[] = dir.list (new FilenameFilter ()
49 public boolean accept (File dir, String name)
51 return name.endsWith (".jar") || name.endsWith (".zip");
54 for (int i = files.length - 1; i >= 0; i--)
55 addURL(new URL("file", "", -1, dirname + files[i]));
59 String w3clib = (libdir + File.separator
60 + System.mapLibraryName ("w3c-gcj"));
61 addURL(new URL("gcjlib", "", -1, w3clib));
62 String saxlib = (libdir + File.separator
63 + System.mapLibraryName ("sax-gcj"));
64 addURL(new URL("gcjlib", "", -1, saxlib));
66 catch (java.net.MalformedURLException x)
68 // This should never happen.
69 throw new RuntimeException(x);
73 public Class bootLoadClass(String name)
74 throws ClassNotFoundException
76 Class c = findLoadedClass(name);
81 // We could hack URLClassLoader to make this more
82 // efficient, if it mattered.
85 catch (ClassNotFoundException _)
93 public URL bootGetResource(String name)
95 return findResource(name);
98 public Enumeration bootGetResources(String name) throws IOException
100 return findResources(name);