source: trunk/src/gcc/libjava/gnu/gcj/runtime/VMClassLoader.java@ 2

Last change on this file since 2 was 2, checked in by bird, 23 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 2.2 KB
Line 
1/* Copyright (C) 1999, 2001 Free Software Foundation
2
3 This file is part of libgcj.
4
5This software is copyrighted work licensed under the terms of the
6Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
7details. */
8
9/* Author: Kresten Krab Thorup <[email protected]> */
10
11package gnu.gcj.runtime;
12
13import java.io.*;
14import java.util.StringTokenizer;
15import java.net.URL;
16
17public 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 {
38 File archive = new File (e);
39 try {
40 p.addElement(new URL("jar", "", -1, "file://"
41 + archive.getCanonicalPath ()
42 + "!/"));
43 } catch (IOException ex) {
44 // empty
45 }
46 }
47 else if (e.endsWith ("/"))
48 p.addElement (new URL("file", "", -1, e));
49 else if (new File (e).isDirectory ())
50 p.addElement (new URL("file", "", -1, e + "/"));
51 else
52 /* Ignore path element. */;
53 }
54 catch (java.net.MalformedURLException x)
55 {
56 /* Ignore this path element */
57 }
58 }
59 // Add core:/ to the end of the java.class.path so any resources
60 // compiled into this executable may be found.
61 try
62 {
63 p.addElement (new URL("core", "", -1, "/"));
64 }
65 catch (java.net.MalformedURLException x)
66 {
67 // This should never happen.
68 }
69
70 URL[] urls = new URL[p.size()];
71 p.copyInto (urls);
72 return urls;
73 }
74
75 /** This is overridden to search the internal hash table, which
76 * will only search existing linked-in classes. This will make
77 * the default implementation of loadClass (in ClassLoader) work right.
78 * The implementation of this method is in java/lang/natClassLoader.cc.
79 */
80 protected native Class findClass(String name)
81 throws java.lang.ClassNotFoundException;
82
83 // The only VMClassLoader that can exist.
84 public static VMClassLoader instance = new VMClassLoader ();
85}
Note: See TracBrowser for help on using the repository browser.