decl.c (init_decl_processing): Add new class "protectionDomain" field.
gcc/java: 2001-04-25 Bryce McKinlay <bryce@waitaki.otago.ac.nz> * decl.c (init_decl_processing): Add new class "protectionDomain" field. * class.c (make_class_data): Set initial value for "protectionDomain". libjava: 2001-04-25 Bryce McKinlay <bryce@albatross.co.nz> java.security merge and ClassLoader compliance fixes. * java/lang/Class.h (Class): Include ProtectionDomain.h. New protectionDomain field. (forName): Add initialize parameter. Fixes declaration to comply with JDK spec. * java/lang/natClass.cc (forName): Correct declaration of the three-arg variant. Honour "initialize" flag. (getProtectionDomain0): New method. * java/lang/Class.java: Fix forName() declaration. (getPackage): New method based on Classpath implementation. (getProtectionDomain0): New native method decl. (getProtectionDomain): New method. * java/lang/ClassLoader.java (getParent): Now final. (definedPackages): New field. (getPackage): New. (defineClass): New variant with protectionDomain argument. (definePackage): New. (getPackages): New. (findSystemClass): Now final. (getSystemResourceAsStream): Remove redundant "final" modifier. (getSystemResource): Remove redundant "final" modifier. (getResources): Now final. (protectionDomainPermission): New static field. (unknownProtectionDomain): Ditto. (defaultProtectionDomain): Ditto. (getSystemClassLoader): Now non-native. * java/util/ResourceBundle.java (tryGetSomeBundle): Use the correct arguments for Class.forName(). * java/lang/Package.java: New file. * gnu/gcj/runtime/VMClassLoader.java (getVMClassLoader): Removed. (instance): Static initialize singleton. (findClass): Override this, not findSystemClass. * java/lang/natClassLoader.cc (defineClass0): Set class's protectionDomain field as specified. (getSystemClassLoader): Removed. (findClass): Renamed from findSystemClass. Call the interpreter via URLClassLoader.findClass if loading class via dlopen fails. * java/security/*.java: java.security import/merge with Classpath. * java/security/acl/*.java: Likewise. * java/security/interfaces/*.java: Likewise. * java/security/spec/*.java: Likewise. * java/net/NetPermission.java: Likewise. * java/net/SocketPermission.java: Likewise. * gnu/java/security/provider/DefaultPolicy.java: Likewise. * Makefile.am: Add new classes. * Makefile.in: Rebuilt. * gcj/javaprims.h: CNI namespace rebuild. From-SVN: r41543
This commit is contained in:
parent
744cfa53c3
commit
28f7d9d05a
115 changed files with 11887 additions and 1549 deletions
|
@ -12,6 +12,7 @@ package java.lang;
|
|||
import java.io.Serializable;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.*;
|
||||
import java.security.*;
|
||||
|
||||
/**
|
||||
* @author Tom Tromey <tromey@cygnus.com>
|
||||
|
@ -30,7 +31,9 @@ public final class Class implements Serializable
|
|||
{
|
||||
public static native Class forName (String className)
|
||||
throws ClassNotFoundException;
|
||||
public static native Class forName (String className, ClassLoader loader)
|
||||
/** @since 1.2 */
|
||||
public static native Class forName (String className, boolean initialize,
|
||||
ClassLoader loader)
|
||||
throws ClassNotFoundException;
|
||||
public native Class[] getClasses ();
|
||||
public native ClassLoader getClassLoader ();
|
||||
|
@ -88,6 +91,30 @@ public final class Class implements Serializable
|
|||
private native Field[] _getFields (Field[] result, int offset);
|
||||
public native Field[] getFields () throws SecurityException;
|
||||
|
||||
/**
|
||||
* Returns the <code>Package</code> in which this class is defined
|
||||
* Returns null when this information is not available from the
|
||||
* classloader of this class or when the classloader of this class
|
||||
* is null.
|
||||
*
|
||||
* @since 1.2
|
||||
*/
|
||||
public Package getPackage()
|
||||
{
|
||||
ClassLoader cl = getClassLoader();
|
||||
if (cl != null)
|
||||
{
|
||||
String name = getName();
|
||||
String pkg = "";
|
||||
int idx = name.lastIndexOf('.');
|
||||
if (idx >= 0)
|
||||
pkg = name.substring(0, idx);
|
||||
return cl.getPackage(pkg);
|
||||
}
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
public native Class[] getInterfaces ();
|
||||
|
||||
private final native void getSignature (StringBuffer buffer);
|
||||
|
@ -154,6 +181,35 @@ public final class Class implements Serializable
|
|||
public native Object newInstance ()
|
||||
throws InstantiationException, IllegalAccessException;
|
||||
|
||||
// We need a native method to retrieve the protection domain, because we
|
||||
// can't add fields to java.lang.Class that are accessible from Java.
|
||||
private native ProtectionDomain getProtectionDomain0();
|
||||
|
||||
/**
|
||||
* Returns the protection domain of this class. If the classloader
|
||||
* did not record the protection domain when creating this class
|
||||
* the unknown protection domain is returned which has a <code>null</code>
|
||||
* code source and all permissions.
|
||||
*
|
||||
* @exception SecurityException if a security manager exists and the caller
|
||||
* does not have <code>RuntimePermission("getProtectionDomain")</code>.
|
||||
*
|
||||
* @since 1.2
|
||||
*/
|
||||
public ProtectionDomain getProtectionDomain()
|
||||
{
|
||||
SecurityManager sm = System.getSecurityManager();
|
||||
if (sm != null)
|
||||
sm.checkPermission(ClassLoader.protectionDomainPermission);
|
||||
|
||||
ProtectionDomain protectionDomain = getProtectionDomain0();
|
||||
|
||||
if (protectionDomain == null)
|
||||
return ClassLoader.unknownProtectionDomain;
|
||||
else
|
||||
return protectionDomain;
|
||||
}
|
||||
|
||||
public String toString ()
|
||||
{
|
||||
if (isPrimitive ())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue