Lines 1-5
Link Here
|
1 |
/* |
1 |
/* |
2 |
* DynamicJava - Copyright (C) 1999-2001 |
2 |
* DynamicJava - Copyright (C) 1999-2001 |
|
|
3 |
* The Rationalizer AG - Copyright (C) 2002 |
3 |
* |
4 |
* |
4 |
* Permission is hereby granted, free of charge, to any person obtaining a |
5 |
* Permission is hereby granted, free of charge, to any person obtaining a |
5 |
* copy of this software and associated documentation files |
6 |
* copy of this software and associated documentation files |
Lines 22-28
Link Here
|
22 |
* Except as contained in this notice, the name of Dyade shall not be |
23 |
* Except as contained in this notice, the name of Dyade shall not be |
23 |
* used in advertising or otherwise to promote the sale, use or other |
24 |
* used in advertising or otherwise to promote the sale, use or other |
24 |
* dealings in this Software without prior written authorization from |
25 |
* dealings in this Software without prior written authorization from |
25 |
* Dyade. |
26 |
* Dyade. The same applies to the name of The Rationalizer. |
26 |
* |
27 |
* |
27 |
*/ |
28 |
*/ |
28 |
|
29 |
|
Lines 36-50
Link Here
|
36 |
import koala.dynamicjava.tree.*; |
37 |
import koala.dynamicjava.tree.*; |
37 |
import koala.dynamicjava.util.*; |
38 |
import koala.dynamicjava.util.*; |
38 |
|
39 |
|
|
|
40 |
import java.security.CodeSource; |
41 |
import java.security.SecureClassLoader; |
42 |
|
43 |
import java.net.URL; |
44 |
import java.net.MalformedURLException; |
45 |
|
39 |
/** |
46 |
/** |
40 |
* This class is responsible for loading bytecode classes |
47 |
* This class is responsible for loading bytecode classes. |
|
|
48 |
* |
49 |
* <p>All classes <em>created</em> by <code>TreeClassLoader</code>s |
50 |
* have an identical |
51 |
* {@link java.security CodeSource}. This code source has no certificates |
52 |
* but may have a location. The latter is set to the value of the system |
53 |
* property with the value of {@link #CODE_SOURCE_URL_PROPERTY} as key, if |
54 |
* it is a valid URL. If the property is defined but its value is not a valid |
55 |
* URL, the location of the code source is set to <code>null</code>. If the |
56 |
* property is not defined, the value of {@link #DEFAULT_CODE_SOURCE_URL} is |
57 |
* used as location.</p> |
41 |
* |
58 |
* |
42 |
* @author Stephane Hillion |
59 |
* @author Stephane Hillion |
|
|
60 |
* @author <a href="mailto:hkrug@rationalizer.com">Holger Krug</a> |
43 |
* @version 1.1 - 1999/05/18 |
61 |
* @version 1.1 - 1999/05/18 |
44 |
*/ |
62 |
*/ |
45 |
|
63 |
|
46 |
public class TreeClassLoader extends ClassLoader |
64 |
public class TreeClassLoader extends SecureClassLoader |
47 |
implements ClassLoaderContainer { |
65 |
implements ClassLoaderContainer { |
|
|
66 |
|
67 |
/** |
68 |
* The default value for the {@link java.security.CodeSource} URL. |
69 |
* May be overriden by setting the system property with name given by |
70 |
* the value of {@link #CODE_SOURCE_URL_PROPERTY}. |
71 |
*/ |
72 |
public static String DEFAULT_CODE_SOURCE_URL = |
73 |
"http://koala.ilog.fr/djava/javadoc/koala/dynamicjava/interpreter/TreeClassLoader.html"; |
74 |
|
75 |
/** |
76 |
* Name of the system property to define the value for the URL |
77 |
* of the {@link java.security.CodeSource} assigned to classes |
78 |
* created by this classloader. The default value is the value of |
79 |
* {@link #DEFAULT_CODE_SOURCE_URL}. |
80 |
* |
81 |
* <p>If the property value is not a wellformed URL, the URL is set |
82 |
* to <code>null</code>. |
83 |
*/ |
84 |
public static String CODE_SOURCE_URL_PROPERTY = |
85 |
"koala.dynamicjava.interpreter.TreeClassLoader.codesource.url"; |
86 |
|
87 |
/** |
88 |
* The code source for classes defined by instances of |
89 |
* <code>TreeClassLoader</code>. Initializes when <code>TreeClassLoader</code> |
90 |
* is loaded the first time. |
91 |
* |
92 |
* @see #DEFAULT_CODE_SOURCE_URL |
93 |
* @see #CODE_SOURCE_URL_PROPERTY |
94 |
*/ |
95 |
protected static final CodeSource codeSource; |
96 |
|
97 |
/** |
98 |
* Initializes the code source. |
99 |
*/ |
100 |
static { |
101 |
try { |
102 |
String url = System.getProperty(CODE_SOURCE_URL_PROPERTY); |
103 |
if ( url != null ) codeSource = new CodeSource(new URL(url), null); |
104 |
} catch (java.net.MalformedURLException mfue) { |
105 |
// property value malformed, return null |
106 |
// [XXX]: print error message |
107 |
codeSource = new CodeSource(null, null); |
108 |
} |
109 |
try { |
110 |
codeSource = new CodeSource(new URL(DEFAULT_CODE_SOURCE_URL), null); |
111 |
} catch (java.net.MalformedURLException mfue) { |
112 |
// should never appear |
113 |
throw new RuntimeException(mfue.getMessage()); |
114 |
} |
115 |
|
116 |
} |
117 |
|
48 |
/** |
118 |
/** |
49 |
* The place where the interpreted classes are stored |
119 |
* The place where the interpreted classes are stored |
50 |
*/ |
120 |
*/ |
Lines 64-85
Link Here
|
64 |
* The auxiliary class loader |
134 |
* The auxiliary class loader |
65 |
*/ |
135 |
*/ |
66 |
protected ClassLoader classLoader; |
136 |
protected ClassLoader classLoader; |
67 |
|
137 |
|
68 |
/** |
138 |
/** |
69 |
* Creates a new class loader |
139 |
* Creates a new class loader |
70 |
* @param i the object used to interpret the classes |
140 |
* @param i the object used to interpret the classes |
71 |
*/ |
141 |
*/ |
72 |
public TreeClassLoader(Interpreter i) { |
142 |
public TreeClassLoader(Interpreter i) { |
73 |
interpreter = i; |
143 |
super(i.getClass().getClassLoader()); |
74 |
} |
144 |
interpreter = i; |
|
|
145 |
} |
75 |
|
146 |
|
76 |
/** |
147 |
/** |
77 |
* Converts an array of bytes into an instance of class Class and |
148 |
* Converts an array of bytes into an instance of class Class and |
78 |
* links this class. |
149 |
* links this class. |
|
|
150 |
* |
79 |
* @exception ClassFormatError if the class could not be defined |
151 |
* @exception ClassFormatError if the class could not be defined |
80 |
*/ |
152 |
*/ |
81 |
public Class defineClass(String name, byte[] code) { |
153 |
public Class defineClass(String name, byte[] code) { |
82 |
Class c = defineClass(name, code, 0, code.length); |
154 |
Class c = defineClass(name, code, 0, code.length, codeSource); |
83 |
classes.put(name, c); |
155 |
classes.put(name, c); |
84 |
trees.remove(name); |
156 |
trees.remove(name); |
85 |
return c; |
157 |
return c; |
Lines 154-159
Link Here
|
154 |
} catch (ClassNotFoundException e) { |
226 |
} catch (ClassNotFoundException e) { |
155 |
} |
227 |
} |
156 |
|
228 |
|
157 |
return interpreter.loadClass(name); |
229 |
return interpreter.loadClass(name); |
158 |
} |
230 |
} |
159 |
} |
231 |
} |