39 |
|
|
40 |
import java.io.Serializable; |
import java.io.Serializable; |
41 |
import java.io.InputStream; |
import java.io.InputStream; |
42 |
import java.lang.reflect.*; |
import java.lang.reflect.Constructor; |
43 |
import java.security.*; |
import java.lang.reflect.Field; |
44 |
|
import java.lang.reflect.InvocationTargetException; |
45 |
|
import java.lang.reflect.Method; |
46 |
import java.net.URL; |
import java.net.URL; |
47 |
import gnu.java.lang.*; |
import java.security.AllPermission; |
48 |
|
import java.security.Permissions; |
49 |
|
import java.security.ProtectionDomain; |
50 |
|
import gnu.java.lang.ClassHelper; |
51 |
|
|
52 |
/* |
/* |
53 |
* This class is a reference version, mainly for compiling a class library |
* This class is a reference version, mainly for compiling a class library |
102 |
unknownProtectionDomain = new ProtectionDomain(null, permissions); |
unknownProtectionDomain = new ProtectionDomain(null, permissions); |
103 |
} |
} |
104 |
|
|
|
/** Permission needed to get the protection domain. */ |
|
|
private final static Permission protectionDomainPermission |
|
|
= new RuntimePermission("getProtectionDomain"); |
|
|
|
|
105 |
/** |
/** |
106 |
* Class is non-instantiable from Java code; only the VM can create |
* Class is non-instantiable from Java code; only the VM can create |
107 |
* instances of this class. |
* instances of this class. |
216 |
{ |
{ |
217 |
return getConstructor(null).newInstance(null); |
return getConstructor(null).newInstance(null); |
218 |
} |
} |
219 |
catch(IllegalArgumentException e) |
catch (IllegalArgumentException e) |
220 |
{ |
{ |
221 |
throw (Error) new InternalError("Should not happen").initCause(e); |
throw (Error) new InternalError("Should not happen").initCause(e); |
222 |
} |
} |
223 |
catch(InvocationTargetException e) |
catch (InvocationTargetException e) |
224 |
{ |
{ |
225 |
throw (InstantiationException) |
throw (InstantiationException) |
226 |
new InstantiationException(e.toString()).initCause(e); |
new InstantiationException(e.toString()).initCause(e); |
227 |
} |
} |
228 |
catch(NoSuchMethodException e) |
catch (NoSuchMethodException e) |
229 |
{ |
{ |
230 |
throw (InstantiationException) |
throw (InstantiationException) |
231 |
new InstantiationException(e.toString()).initCause(e); |
new InstantiationException(e.toString()).initCause(e); |
331 |
* @see ClassLoader |
* @see ClassLoader |
332 |
* @see RuntimePermission |
* @see RuntimePermission |
333 |
*/ |
*/ |
334 |
public native ClassLoader getClassLoader(); |
public ClassLoader getClassLoader() |
335 |
|
{ |
336 |
|
if (isPrimitive()) |
337 |
|
return null; |
338 |
|
ClassLoader loader = getClassLoader0(); |
339 |
|
// Check if we may get the classloader |
340 |
|
SecurityManager sm = System.getSecurityManager(); |
341 |
|
if (sm != null) |
342 |
|
{ |
343 |
|
// Get the calling class and classloader |
344 |
|
Class c = VMSecurityManager.getClassContext()[1]; |
345 |
|
ClassLoader cl = c.getClassLoader(); |
346 |
|
if (cl != null && cl != ClassLoader.systemClassLoader) |
347 |
|
sm.checkPermission(new RuntimePermission("getClassLoader")); |
348 |
|
} |
349 |
|
return loader; |
350 |
|
} |
351 |
|
|
352 |
/** |
/** |
353 |
* Get the direct superclass of this class. If this is an interface, |
* Get the direct superclass of this class. If this is an interface, |
397 |
*/ |
*/ |
398 |
public Class getComponentType() |
public Class getComponentType() |
399 |
{ |
{ |
400 |
if(isArray()) |
if (isArray()) |
401 |
try |
try |
402 |
{ |
{ |
403 |
return Class.forName(getName().substring(1), false, |
String name = getName(); |
404 |
getClassLoader()); |
switch (name.charAt(1)) |
405 |
|
{ |
406 |
|
case 'B': |
407 |
|
return byte.class; |
408 |
|
case 'C': |
409 |
|
return char.class; |
410 |
|
case 'D': |
411 |
|
return double.class; |
412 |
|
case 'F': |
413 |
|
return float.class; |
414 |
|
case 'I': |
415 |
|
return int.class; |
416 |
|
case 'J': |
417 |
|
return long.class; |
418 |
|
case 'S': |
419 |
|
return short.class; |
420 |
|
case 'Z': |
421 |
|
return boolean.class; |
422 |
|
default: |
423 |
|
return null; |
424 |
|
case '[': |
425 |
|
name = name.substring(1); |
426 |
|
break; |
427 |
|
case 'L': |
428 |
|
name = name.substring(2, name.length() - 1); |
429 |
|
} |
430 |
|
return Class.forName(name, false, getClassLoader()); |
431 |
} |
} |
432 |
catch(ClassNotFoundException e) |
catch(ClassNotFoundException e) |
433 |
{ |
{ |
434 |
|
// Shouldn't happen, but ignore it anyway. |
435 |
} |
} |
436 |
return null; |
return null; |
437 |
} |
} |
792 |
{ |
{ |
793 |
SecurityManager sm = System.getSecurityManager(); |
SecurityManager sm = System.getSecurityManager(); |
794 |
if (sm != null) |
if (sm != null) |
795 |
sm.checkPermission(protectionDomainPermission); |
sm.checkPermission(new RuntimePermission("getProtectionDomain")); |
796 |
|
|
797 |
return pd == null ? unknownProtectionDomain : pd; |
return pd == null ? unknownProtectionDomain : pd; |
798 |
} |
} |
865 |
} |
} |
866 |
return c.defaultAssertionStatus; |
return c.defaultAssertionStatus; |
867 |
} |
} |
|
} |
|
868 |
|
|
869 |
|
/** |
870 |
|
* Return the class loader of this class. |
871 |
|
* |
872 |
|
* @return the class loader |
873 |
|
*/ |
874 |
|
native ClassLoader getClassLoader0(); |
875 |
|
} // class Class |