38 |
|
|
39 |
package java.lang; |
package java.lang; |
40 |
|
|
41 |
|
import java.security.ProtectionDomain; |
42 |
|
import java.net.URL; |
43 |
|
import java.io.IOException; |
44 |
|
import java.util.Enumeration; |
45 |
|
import java.util.Map; |
46 |
|
import java.util.HashMap; |
47 |
|
|
48 |
/** |
/** |
49 |
* java.lang.VMClassLoader is a package-private helper for VMs to implement |
* java.lang.VMClassLoader is a package-private helper for VMs to implement |
50 |
* on behalf of java.lang.ClassLoader. |
* on behalf of java.lang.ClassLoader. |
56 |
final class VMClassLoader |
final class VMClassLoader |
57 |
{ |
{ |
58 |
/** |
/** |
59 |
* Helper to define a class using a string of bytes. |
* Helper to define a class using a string of bytes. This assumes that |
60 |
|
* the security checks have already been performed, if necessary. |
61 |
|
* <strong>This method will be removed in a future version of GNU |
62 |
|
* Classpath</strong>. |
63 |
* |
* |
64 |
* @param name the name to give the class, or null if unknown |
* @param name the name to give the class, or null if unknown |
65 |
* @param data the data representing the classfile, in classfile format |
* @param data the data representing the classfile, in classfile format |
67 |
* @param len the length of the classfile data in the array |
* @param len the length of the classfile data in the array |
68 |
* @return the class that was defined |
* @return the class that was defined |
69 |
* @throws ClassFormatError if data is not in proper classfile format |
* @throws ClassFormatError if data is not in proper classfile format |
70 |
* @XXX This should also have a ProtectionDomain argument. |
* @deprecated Implement |
71 |
|
* {@link #defineClass(ClassLoader, String, byte[], int, int, ProtectionDomain)} |
72 |
|
* instead. |
73 |
*/ |
*/ |
74 |
static final native Class defineClass(ClassLoader cl, String name, |
static final native Class defineClass(ClassLoader cl, String name, |
75 |
byte[] data, int offset, int len) |
byte[] data, int offset, int len) |
76 |
throws ClassFormatError; |
throws ClassFormatError; |
77 |
|
|
78 |
/** |
/** |
79 |
|
* Helper to define a class using a string of bytes. This assumes that |
80 |
|
* the security checks have already been performed, if necessary. |
81 |
|
* |
82 |
|
* <strong>For backward compatibility, this just ignores the protection |
83 |
|
* domain; that is the wrong behavior, and you should directly implement |
84 |
|
* this method natively if you can.</strong> |
85 |
|
* |
86 |
|
* @param name the name to give the class, or null if unknown |
87 |
|
* @param data the data representing the classfile, in classfile format |
88 |
|
* @param offset the offset into the data where the classfile starts |
89 |
|
* @param len the length of the classfile data in the array |
90 |
|
* @param pd the protection domain |
91 |
|
* @return the class that was defined |
92 |
|
* @throws ClassFormatError if data is not in proper classfile format |
93 |
|
*/ |
94 |
|
static final Class defineClass(ClassLoader cl, String name, |
95 |
|
byte[] data, int offset, int len, |
96 |
|
ProtectionDomain pd) |
97 |
|
throws ClassFormatError |
98 |
|
{ |
99 |
|
return defineClass(cl, name, data, offset, len); |
100 |
|
} |
101 |
|
|
102 |
|
/** |
103 |
* Helper to resolve all references to other classes from this class. |
* Helper to resolve all references to other classes from this class. |
104 |
* |
* |
105 |
* @param c the class to resolve |
* @param c the class to resolve |
107 |
static final native void resolveClass(Class c); |
static final native void resolveClass(Class c); |
108 |
|
|
109 |
/** |
/** |
110 |
|
* Helper to load a class from the bootstrap class loader. |
111 |
|
* |
112 |
|
* XXX - Not implemented yet; this requires native help. |
113 |
|
* |
114 |
|
* @param name the class name to load |
115 |
|
* @param resolve whether to resolve it |
116 |
|
* @return the class, loaded by the bootstrap classloader |
117 |
|
*/ |
118 |
|
static final Class loadClass(String name, boolean resolve) |
119 |
|
throws ClassNotFoundException |
120 |
|
{ |
121 |
|
return Class.forName(name, resolve, ClassLoader.getSystemClassLoader()); |
122 |
|
} |
123 |
|
|
124 |
|
/** |
125 |
|
* Helper to load a resource from the bootstrap class loader. |
126 |
|
* |
127 |
|
* XXX - Not implemented yet; this requires native help. |
128 |
|
* |
129 |
|
* @param name the resource to find |
130 |
|
* @return the URL to the resource |
131 |
|
*/ |
132 |
|
static URL getResource(String name) |
133 |
|
{ |
134 |
|
return ClassLoader.getSystemResource(name); |
135 |
|
} |
136 |
|
|
137 |
|
/** |
138 |
|
* Helper to get a list of resources from the bootstrap class loader. |
139 |
|
* |
140 |
|
* XXX - Not implemented yet; this requires native help. |
141 |
|
* |
142 |
|
* @param name the resource to find |
143 |
|
* @return an enumeration of resources |
144 |
|
* @throws IOException if one occurs |
145 |
|
*/ |
146 |
|
static Enumeration getResources(String name) throws IOException |
147 |
|
{ |
148 |
|
return ClassLoader.getSystemResources(name); |
149 |
|
} |
150 |
|
|
151 |
|
/** |
152 |
|
* Helper to get a package from the bootstrap class loader. The default |
153 |
|
* implementation of returning null may be adequate, or you may decide |
154 |
|
* that this needs some native help. |
155 |
|
* |
156 |
|
* @param name the name to find |
157 |
|
* @return the named package, if it exists |
158 |
|
*/ |
159 |
|
static Package getPackage(String name) |
160 |
|
{ |
161 |
|
return null; |
162 |
|
} |
163 |
|
|
164 |
|
/** |
165 |
|
* Helper to get all packages from the bootstrap class loader. The default |
166 |
|
* implementation of returning an empty array may be adequate, or you may |
167 |
|
* decide that this needs some native help. |
168 |
|
* |
169 |
|
* @return all named packages, if any exist |
170 |
|
*/ |
171 |
|
static Package[] getPackages() |
172 |
|
{ |
173 |
|
return new Package[0]; |
174 |
|
} |
175 |
|
|
176 |
|
/** |
177 |
* Helper for java.lang.Integer, Byte, etc to get the TYPE class |
* Helper for java.lang.Integer, Byte, etc to get the TYPE class |
178 |
* at initialization time. The type code is one of the chars that |
* at initialization time. The type code is one of the chars that |
179 |
* represents the primitive type as in JNI. |
* represents the primitive type as in JNI. |
256 |
* classes (those with a null ClassLoader), as well as the initial value for |
* classes (those with a null ClassLoader), as well as the initial value for |
257 |
* every ClassLoader's default assertion status. |
* every ClassLoader's default assertion status. |
258 |
* |
* |
259 |
|
* XXX - Not implemented yet; this requires native help. |
260 |
|
* |
261 |
* @return the system-wide default assertion status |
* @return the system-wide default assertion status |
|
* @XXX Implement this for 1.4 compatibility. |
|
|
static final native boolean defaultAssertionStatus(); |
|
262 |
*/ |
*/ |
263 |
|
static final boolean defaultAssertionStatus() |
264 |
|
{ |
265 |
|
return true; |
266 |
|
} |
267 |
|
|
268 |
/** |
/** |
269 |
* The system default for package assertion status. This is used for all |
* The system default for package assertion status. This is used for all |
271 |
* package names to Boolean.TRUE or Boolean.FALSE, with the unnamed package |
* package names to Boolean.TRUE or Boolean.FALSE, with the unnamed package |
272 |
* represented as a null key. |
* represented as a null key. |
273 |
* |
* |
274 |
|
* XXX - Not implemented yet; this requires native help. |
275 |
|
* |
276 |
* @return a (read-only) map for the default packageAssertionStatus |
* @return a (read-only) map for the default packageAssertionStatus |
|
* @XXX Implement this for 1.4 compatibility. |
|
|
static final native Map packageAssertionStatus(); |
|
277 |
*/ |
*/ |
278 |
|
static final Map packageAssertionStatus() |
279 |
|
{ |
280 |
|
return new HashMap(); |
281 |
|
} |
282 |
|
|
283 |
/** |
/** |
284 |
* The system default for class assertion status. This is used for all |
* The system default for class assertion status. This is used for all |
285 |
* ClassLoader's classAssertionStatus defaults. It must be a map of |
* ClassLoader's classAssertionStatus defaults. It must be a map of |
286 |
* class names to Boolean.TRUE or Boolean.FALSE |
* class names to Boolean.TRUE or Boolean.FALSE |
287 |
* |
* |
288 |
|
* XXX - Not implemented yet; this requires native help. |
289 |
|
* |
290 |
* @return a (read-only) map for the default classAssertionStatus |
* @return a (read-only) map for the default classAssertionStatus |
|
* @XXX Implement this for 1.4 compatibility. |
|
|
static final native Map classAssertionStatus(); |
|
291 |
*/ |
*/ |
292 |
|
static final Map classAssertionStatus() |
293 |
|
{ |
294 |
|
return new HashMap(); |
295 |
|
} |
296 |
} |
} |