Merge from mainline
[official-gcc.git] / libjava / gnu / gcj / runtime / SystemClassLoader.java
blobefd33230fbe8b0acfa806c7cc3bba73ce91a8825
1 /* Copyright (C) 2005, 2006 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
7 details. */
9 package gnu.gcj.runtime;
11 import java.io.*;
12 import java.util.StringTokenizer;
13 import java.util.HashSet;
14 import java.net.URL;
15 import java.net.URLClassLoader;
17 public final class SystemClassLoader extends URLClassLoader
19 SystemClassLoader(ClassLoader parent)
21 super(new URL[0], parent);
24 // This is called to register a native class which was linked into
25 // the application but which is registered with the system class
26 // loader after the VM is initialized.
27 void addClass(Class klass)
29 String packageName = null;
30 String className = klass.getName();
31 int lastDot = className.lastIndexOf('.');
32 if (lastDot != -1)
33 packageName = className.substring(0, lastDot);
34 if (packageName != null && getPackage(packageName) == null)
36 // Should have some way to store this information in a
37 // precompiled manifest.
38 definePackage(packageName, null, null, null, null, null, null, null);
40 loadedClasses.put(className, klass);
43 // We add the URLs to the system class loader late. The reason for
44 // this is that during bootstrap we don't want to parse URLs or
45 // create URL connections, since that will result in circularities
46 // causing a crash.
47 void init()
49 String sep = File.pathSeparator;
50 StringTokenizer st
51 = new StringTokenizer (System.getProperty ("java.class.path", "."),
52 sep, true);
53 // Pretend we start with a ':', so if we see a ':' first we add
54 // '.'.
55 boolean last_was_sep = true;
56 while (st.hasMoreElements ())
58 String e = st.nextToken ();
59 try
61 if (sep.equals(e))
63 if (last_was_sep)
65 // We saw two separators in a row, so add ".".
66 addURL(new URL("file", "", -1, "./"));
67 last_was_sep = false;
69 else
70 last_was_sep = true;
71 continue;
74 last_was_sep = false;
75 File path = new File(e);
76 // Ignore invalid paths.
77 if (!path.exists())
78 continue;
79 if (!e.endsWith (File.separator) && path.isDirectory ())
80 addURL(new URL("file", "", -1, e + File.separator));
81 else
82 addURL(new URL("file", "", -1, e));
84 catch (java.net.MalformedURLException x)
86 // This should never happen.
87 throw new RuntimeException(x);
90 // If we saw a trailing ":", add "." to the path.
91 if (last_was_sep)
93 try
95 addURL(new URL("file", "", -1, "./"));
97 catch (java.net.MalformedURLException x)
99 // This should never happen.
100 throw new RuntimeException(x);