1:
8:
9: package ;
10:
11: import ;
12: import ;
13: import ;
14: import ;
15: import ;
16:
17: public final class SystemClassLoader extends URLClassLoader
18: {
19: SystemClassLoader(ClassLoader parent)
20: {
21: super(new URL[0], parent);
22: }
23:
24:
25:
26:
27: void addClass(Class klass)
28: {
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)
35: {
36:
37:
38: definePackage(packageName, null, null, null, null, null, null, null);
39: }
40: loadedClasses.put(className, klass);
41: }
42:
43:
44:
45:
46:
47: void init()
48: {
49: String sep = File.pathSeparator;
50: StringTokenizer st
51: = new StringTokenizer (System.getProperty ("java.class.path", "."),
52: sep, true);
53:
54:
55: boolean last_was_sep = true;
56: while (st.hasMoreElements ())
57: {
58: String e = st.nextToken ();
59: try
60: {
61: if (sep.equals(e))
62: {
63: if (last_was_sep)
64: {
65:
66: addURL(new URL("file", "", -1, "./"));
67: last_was_sep = false;
68: }
69: else
70: last_was_sep = true;
71: continue;
72: }
73:
74: last_was_sep = false;
75: File path = new File(e);
76:
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));
83: }
84: catch (java.net.MalformedURLException x)
85: {
86:
87: throw new RuntimeException(x);
88: }
89: }
90:
91: if (last_was_sep)
92: {
93: try
94: {
95: addURL(new URL("file", "", -1, "./"));
96: }
97: catch (java.net.MalformedURLException x)
98: {
99:
100: throw new RuntimeException(x);
101: }
102: }
103: }
104: }