41 |
import gnu.java.util.DoubleEnumeration; |
import gnu.java.util.DoubleEnumeration; |
42 |
import gnu.java.util.EmptyEnumeration; |
import gnu.java.util.EmptyEnumeration; |
43 |
|
|
44 |
|
import java.io.File; |
45 |
import java.io.IOException; |
import java.io.IOException; |
46 |
import java.io.InputStream; |
import java.io.InputStream; |
47 |
|
import java.lang.reflect.Constructor; |
48 |
import java.net.URL; |
import java.net.URL; |
49 |
|
import java.net.URLClassLoader; |
50 |
import java.nio.ByteBuffer; |
import java.nio.ByteBuffer; |
51 |
import java.security.CodeSource; |
import java.security.CodeSource; |
52 |
import java.security.PermissionCollection; |
import java.security.PermissionCollection; |
53 |
import java.security.Policy; |
import java.security.Policy; |
54 |
import java.security.ProtectionDomain; |
import java.security.ProtectionDomain; |
55 |
|
import java.util.ArrayList; |
56 |
import java.util.Enumeration; |
import java.util.Enumeration; |
57 |
import java.util.HashMap; |
import java.util.HashMap; |
58 |
import java.util.Map; |
import java.util.Map; |
59 |
|
import java.util.StringTokenizer; |
60 |
|
|
61 |
/** |
/** |
62 |
* The ClassLoader is a way of customizing the way Java gets its classes |
* The ClassLoader is a way of customizing the way Java gets its classes |
966 |
} |
} |
967 |
return false; |
return false; |
968 |
} |
} |
969 |
|
|
970 |
|
private static URL[] getExtClassLoaderUrls() |
971 |
|
{ |
972 |
|
String classpath = getSystemProperty("java.ext.dirs", ""); |
973 |
|
StringTokenizer tok = new StringTokenizer(classpath, File.pathSeparator); |
974 |
|
ArrayList list = new ArrayList(); |
975 |
|
while (tok.hasMoreTokens()) |
976 |
|
{ |
977 |
|
try |
978 |
|
{ |
979 |
|
File f = new File(tok.nextToken()); |
980 |
|
File[] files = f.listFiles(); |
981 |
|
for (int i = 0; i < files.length; i++) |
982 |
|
{ |
983 |
|
list.add(files[i].toURL()); |
984 |
|
} |
985 |
|
} |
986 |
|
catch(Exception x) |
987 |
|
{ |
988 |
|
} |
989 |
|
} |
990 |
|
URL[] urls = new URL[list.size()]; |
991 |
|
list.toArray(urls); |
992 |
|
return urls; |
993 |
|
} |
994 |
|
|
995 |
|
private static URL[] getSystemClassLoaderUrls() |
996 |
|
{ |
997 |
|
String classpath = getSystemProperty("java.class.path", "."); |
998 |
|
StringTokenizer tok = new StringTokenizer(classpath, File.pathSeparator); |
999 |
|
ArrayList list = new ArrayList(); |
1000 |
|
while (tok.hasMoreTokens()) |
1001 |
|
{ |
1002 |
|
try |
1003 |
|
{ |
1004 |
|
list.add(new File(tok.nextToken()).toURL()); |
1005 |
|
} |
1006 |
|
catch(java.net.MalformedURLException x) |
1007 |
|
{ |
1008 |
|
} |
1009 |
|
} |
1010 |
|
URL[] urls = new URL[list.size()]; |
1011 |
|
list.toArray(urls); |
1012 |
|
return urls; |
1013 |
|
} |
1014 |
|
|
1015 |
|
static ClassLoader defaultGetSystemClassLoader() |
1016 |
|
{ |
1017 |
|
ClassLoader extClassLoader = |
1018 |
|
new URLClassLoader(getExtClassLoaderUrls(), null); |
1019 |
|
ClassLoader systemClassLoader = |
1020 |
|
new URLClassLoader(getSystemClassLoaderUrls(), extClassLoader) |
1021 |
|
{ |
1022 |
|
protected synchronized Class loadClass(String name, |
1023 |
|
boolean resolve) |
1024 |
|
throws ClassNotFoundException |
1025 |
|
{ |
1026 |
|
SecurityManager sm = Runtime.securityManager; |
1027 |
|
if (sm != null) |
1028 |
|
{ |
1029 |
|
int lastDot = name.lastIndexOf('.'); |
1030 |
|
if (lastDot != -1) |
1031 |
|
sm.checkPackageAccess(name.substring(0, lastDot)); |
1032 |
|
} |
1033 |
|
return super.loadClass(name, resolve); |
1034 |
|
} |
1035 |
|
}; |
1036 |
|
String loader = getSystemProperty("java.system.class.loader", null); |
1037 |
|
if (loader == null) |
1038 |
|
{ |
1039 |
|
return systemClassLoader; |
1040 |
|
} |
1041 |
|
try |
1042 |
|
{ |
1043 |
|
Constructor c = Class.forName(loader, false, systemClassLoader) |
1044 |
|
.getConstructor(new Class[] { ClassLoader.class }); |
1045 |
|
return (ClassLoader)c.newInstance(new Object[] { systemClassLoader }); |
1046 |
|
} |
1047 |
|
catch (Exception e) |
1048 |
|
{ |
1049 |
|
System.err.println("Requested system classloader " + loader + " failed."); |
1050 |
|
throw (Error) |
1051 |
|
new Error("Requested system classloader " + loader + " failed.") |
1052 |
|
.initCause(e); |
1053 |
|
} |
1054 |
|
} |
1055 |
|
|
1056 |
|
static String getSystemProperty(String name, String defaultValue) |
1057 |
|
{ |
1058 |
|
// access properties directly to bypass security |
1059 |
|
String val = System.properties.getProperty(name); |
1060 |
|
if (val == null) |
1061 |
|
{ |
1062 |
|
val = defaultValue; |
1063 |
|
} |
1064 |
|
return val; |
1065 |
|
} |
1066 |
} |
} |