4 import java.net.SocketPermission;
5 import java.net.MalformedURLException;
6 import java.util.Enumeration;
7 import java.util.NoSuchElementException;
8 import java.util.PropertyPermission;
9 import java.security.*;
10 import java.security.cert.Certificate;
15 CodeSource myCodeSource;
22 System.out.println (
"new FWJavaScriptClassLoader - url is " + url);
24 baseURL =
new java.net.URL(url);
26 myCodeSource =
new CodeSource(baseURL, (Certificate[]) null);
27 }
catch (MalformedURLException ex) {
28 throw new InternalError(
"Script URL malformed: "+url);
32 protected Class findClass(String name)
33 throws ClassNotFoundException
35 System.err.println(
"LOADING CLASS '"+name+
"'");
37 byte[] b = readFile(name.replace(
'.',
'/') +
".class");
38 return defineClass(name, b, 0, b.length, myCodeSource);
39 }
catch (IOException e) {
40 throw new ClassNotFoundException(name);
44 private static final String props[] = {
50 "java.specification.name",
51 "java.specification.vendor",
52 "java.specification.version",
57 "java.vm.specification.name",
58 "java.vm.specification.vendor",
59 "java.vm.specification.version",
66 protected PermissionCollection getPermissions(CodeSource codesource) {
67 Permissions perms =
new Permissions();
68 URL url = codesource.getLocation();
69 perms.add(
new SocketPermission(url.getHost(),
"connect,accept"));
70 if (url.getProtocol().equals(
"file")) {
72 String path = url.getFile().replace(
'/', File.separatorChar);
73 path = path.substring(0, path.lastIndexOf(File.separatorChar)+1);
74 perms.add(
new FilePermission(path+
"*",
"read,write,delete"));
76 for (
int i = 0; i < props.length; i++)
77 perms.add(
new PropertyPermission(props[i],
"read"));
82 private byte[] readFile(String name)
throws IOException
84 InputStream is = getResourceAsStream(name);
85 ByteArrayOutputStream bao =
new ByteArrayOutputStream();
86 byte[] buff =
new byte[4096];
88 while ((len = is.read(buff)) > 0)
89 bao.write(buff, 0, len);
90 return bao.toByteArray();
93 protected URL findResource(String name)
96 System.err.println(
"LOADING RESOURCE '"+name+
"'");
97 return new URL(baseURL, name);
98 }
catch (MalformedURLException ex) {
103 protected Enumeration findResources(String name)
throws IOException
105 final URL url =
new URL(baseURL, name);
106 return new Enumeration() {
107 boolean hasMore =
true;
108 public boolean hasMoreElements() {
111 public Object nextElement() {
113 throw new NoSuchElementException();
FWJavaScriptClassLoader(String url)