OSDN Git Service

* Makefile.in: Rebuilt.
[pf3gnuchains/gcc-fork.git] / libjava / gnu / gcj / runtime / BootClassLoader.java
1 /* Copyright (C) 2005  Free Software Foundation
2
3    This file is part of libgcj.
4
5 This software is copyrighted work licensed under the terms of the
6 Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
7 details.  */
8
9 package gnu.gcj.runtime;
10
11 import java.io.File;
12 import java.io.FilenameFilter;
13 import java.io.IOException;
14 import java.net.URL;
15 import java.net.URLClassLoader;
16 import java.util.Enumeration;
17 import java.util.HashSet;
18 import java.util.StringTokenizer;
19
20 /**
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.
26  */
27 public final class BootClassLoader extends URLClassLoader
28 {
29   BootClassLoader(String libdir)
30   {
31     super(new URL[0]);
32
33     // Add the contents of the endorsed directories.
34     StringTokenizer st
35       = new StringTokenizer (System.getProperty ("java.endorsed.dirs", ""),
36                              File.pathSeparator);
37     try
38       {
39         while (st.hasMoreElements ())
40           {
41             String dirname = st.nextToken ();
42             File dir = new File (dirname);
43             if (dir.exists ())
44               {
45                 if (! dirname.endsWith (File.separator))
46                   dirname = dirname + File.separator;
47                 String files[] = dir.list (new FilenameFilter ()
48                   {
49                     public boolean accept (File dir, String name)
50                     {
51                       return name.endsWith (".jar") || name.endsWith (".zip");
52                     }
53                   });
54                 for (int i = files.length - 1; i >= 0; i--)
55                   addURL(new URL("file", "", -1, dirname + files[i]));
56               }
57           }
58
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));
65       }
66     catch (java.net.MalformedURLException x)
67       {
68         // This should never happen.
69         throw new RuntimeException(x);
70       }
71   }
72
73   public Class bootLoadClass(String name)
74     throws ClassNotFoundException
75   {
76     Class c = findLoadedClass(name);
77     if (c == null)
78       {
79         try
80           {
81             // We could hack URLClassLoader to make this more
82             // efficient, if it mattered.
83             c = findClass(name);
84           }
85         catch (ClassNotFoundException _)
86           {
87             c = null;
88           }
89       }
90     return c;
91   }
92
93   public URL bootGetResource(String name)
94   {
95     return findResource(name);
96   }
97
98   public Enumeration bootGetResources(String name) throws IOException
99   {
100     return findResources(name);
101   }
102 }