| 1 | /* Copyright (C) 1999, 2001, 2002 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 <[email protected]> */
|
|---|
| 10 |
|
|---|
| 11 | package gnu.gcj.runtime;
|
|---|
| 12 |
|
|---|
| 13 | import java.io.*;
|
|---|
| 14 | import java.util.StringTokenizer;
|
|---|
| 15 | import java.net.URL;
|
|---|
| 16 |
|
|---|
| 17 | public 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 (File.separator) && new File (e).isDirectory ())
|
|---|
| 37 | p.addElement (new URL("file", "", -1, e + File.separator));
|
|---|
| 38 | else
|
|---|
| 39 | p.addElement (new URL("file", "", -1, e));
|
|---|
| 40 | }
|
|---|
| 41 | catch (java.net.MalformedURLException x)
|
|---|
| 42 | {
|
|---|
| 43 | /* Ignore this path element */
|
|---|
| 44 | }
|
|---|
| 45 | }
|
|---|
| 46 | // Add core:/ to the end of the java.class.path so any resources
|
|---|
| 47 | // compiled into this executable may be found.
|
|---|
| 48 | try
|
|---|
| 49 | {
|
|---|
| 50 | p.addElement (new URL("core", "", -1, "/"));
|
|---|
| 51 | }
|
|---|
| 52 | catch (java.net.MalformedURLException x)
|
|---|
| 53 | {
|
|---|
| 54 | // This should never happen.
|
|---|
| 55 | }
|
|---|
| 56 |
|
|---|
| 57 | URL[] urls = new URL[p.size()];
|
|---|
| 58 | p.copyInto (urls);
|
|---|
| 59 | return urls;
|
|---|
| 60 | }
|
|---|
| 61 |
|
|---|
| 62 | /** This is overridden to search the internal hash table, which
|
|---|
| 63 | * will only search existing linked-in classes. This will make
|
|---|
| 64 | * the default implementation of loadClass (in ClassLoader) work right.
|
|---|
| 65 | * The implementation of this method is in java/lang/natClassLoader.cc.
|
|---|
| 66 | */
|
|---|
| 67 | protected native Class findClass(String name)
|
|---|
| 68 | throws java.lang.ClassNotFoundException;
|
|---|
| 69 |
|
|---|
| 70 | // The only VMClassLoader that can exist.
|
|---|
| 71 | public static VMClassLoader instance = new VMClassLoader ();
|
|---|
| 72 | }
|
|---|