OSDN Git Service

* All files: Updated copyright information.
[pf3gnuchains/gcc-fork.git] / libjava / gnu / gcj / runtime / VMClassLoader.java
1 /* Copyright (C) 1999  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 /* Author: Kresten Krab Thorup <krab@gnu.org>  */
10
11 package gnu.gcj.runtime;
12
13 import java.io.*;
14 import java.util.StringTokenizer;
15 import java.net.URL;
16
17 final class VMClassLoader extends java.net.URLClassLoader
18 {
19   private VMClassLoader ()
20   {     
21     super (init());
22   }
23
24   private static URL[] init() 
25   {
26     StringTokenizer st
27         = new StringTokenizer (System.getProperty ("java.class.path", "."),
28                                System.getProperty ("path.separator", ":"));
29
30     java.util.Vector p = new java.util.Vector();
31     while (st.hasMoreElements ()) 
32       {  
33         String e = st.nextToken ();
34         try
35           {
36             if (e.endsWith(".jar") || e.endsWith (".zip"))
37               p.addElement(new URL("jar", "", -1, "file:///"+e+"!/"));
38             else if (e.endsWith ("/"))
39               p.addElement (new URL("file", "", -1, e));
40             else if (new File (e).isDirectory ())
41               p.addElement (new URL("file", "", -1, e + "/"));
42             else
43               /* Ignore path element. */;
44           } 
45         catch (java.net.MalformedURLException x)
46           {
47             /* Ignore this path element */
48           }
49       }
50
51     URL[] urls = new URL[p.size()];
52     p.copyInto (urls);
53     return urls;
54   }
55
56   /** This is overridden to search the internal hash table, which 
57    * will only search existing linked-in classes.   This will make
58    * the default implementation of loadClass (in ClassLoader) work right.
59    */
60   protected final native Class findSystemClass(String name) 
61     throws java.lang.ClassNotFoundException, java.lang.LinkageError;
62
63   // Return the sole VMClassLoader.
64   private static synchronized VMClassLoader getVMClassLoader ()
65   {
66     if (redirect == null)
67       redirect = new VMClassLoader ();
68     return redirect;
69   }
70
71   // The only VMClassLoader that can exist.
72   private static VMClassLoader redirect;
73 }