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
9 package gnu
.gcj
.runtime
;
12 import java
.util
.StringTokenizer
;
13 import java
.util
.HashSet
;
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('.');
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
49 String sep
= File
.pathSeparator
;
51 = new StringTokenizer (System
.getProperty ("java.class.path", "."),
53 // Pretend we start with a ':', so if we see a ':' first we add
55 boolean last_was_sep
= true;
56 while (st
.hasMoreElements ())
58 String e
= st
.nextToken ();
65 // We saw two separators in a row, so add ".".
66 addURL(new URL("file", "", -1, "./"));
75 File path
= new File(e
);
76 // Ignore invalid paths.
79 if (!e
.endsWith (File
.separator
) && path
.isDirectory ())
80 addURL(new URL("file", "", -1, e
+ File
.separator
));
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.
95 addURL(new URL("file", "", -1, "./"));
97 catch (java
.net
.MalformedURLException x
)
99 // This should never happen.
100 throw new RuntimeException(x
);