/Users/lyon/j4p/src/serialPorts/NativeClassLoader.java
|
1 package serialPorts;
2
3 import sun.misc.ClassFileTransformer;
4 import sun.misc.CompoundEnumeration;
5 import sun.misc.Resource;
6 import sun.misc.URLClassPath;
7 import sun.reflect.Reflection;
8
9 import java.io.File;
10 import java.io.IOException;
11 import java.io.InputStream;
12 import java.lang.reflect.Constructor;
13 import java.lang.reflect.InvocationTargetException;
14 import java.net.URL;
15 import java.security.*;
16 import java.util.*;
17
18
19 class SystemClassLoaderAction implements PrivilegedExceptionAction {
20 private ClassLoader parent;
21
22 SystemClassLoaderAction(ClassLoader parent) {
23 this.parent = parent;
24 }
25
26 public Object run() throws Exception {
27 ClassLoader sys;
28 Constructor ctor;
29 Class c;
30 Class cp[] = {ClassLoader.class};
31 Object params[] = {parent};
32
33 String cls = System.getProperty("java.system.class.loader");
34 if (cls == null) {
35 return parent;
36 }
37
38 c = Class.forName(cls, true, parent);
39 ctor = c.getDeclaredConstructor(cp);
40 sys = (ClassLoader) ctor.newInstance(params);
41 Thread.currentThread().setContextClassLoader(sys);
42 return sys;
43 }
44
45 }
46
47