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