This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

java.security & classloader patches checked in


Here's the patch I checked in to the trunk along with the import/merge
of all the java.security classes from classpath. There was also a small
compiler patch that was approved a few weeks back. I intend to backport
some of the ClassLoader bits to the branch, but not the java.security
and protectionDomain parts, since that seems to be what we've agreed on.

There seem to be some serious problems currently with the trunk at -O2
that make meaningful testing impossible - however all seems to be well
with a `make GCJFLAGS="-g"' build of libgcj.

regards

   [ bryce ]


2001-04-25  Bryce McKinlay  <bryce@waitaki.otago.ac.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.

Index: java/lang/Class.h
===================================================================
RCS file: /cvs/gcc/egcs/libjava/java/lang/Class.h,v
retrieving revision 1.31
diff -u -r1.31 Class.h
--- Class.h	2001/01/17 10:22:32	1.31
+++ Class.h	2001/04/25 15:35:58
@@ -19,6 +19,7 @@
 #include <java/lang/String.h>
 #include <java/net/URL.h>
 #include <java/lang/reflect/Modifier.h>
+#include <java/security/ProtectionDomain.h>
 
 // We declare these here to avoid including gcj/cni.h.
 extern "C" void _Jv_InitClass (jclass klass);
@@ -105,7 +106,8 @@
 class java::lang::Class : public java::lang::Object
 {
 public:
-  static jclass forName (jstring className, java::lang::ClassLoader *loader);
+  static jclass forName (jstring className, jboolean initialize, 
+			 java::lang::ClassLoader *loader);
   static jclass forName (jstring className);
   JArray<jclass> *getClasses (void);
 
@@ -135,6 +137,7 @@
 		    jint offset);
   java::lang::reflect::Field *getPrivateField (jstring);
   java::lang::reflect::Method *getPrivateMethod (jstring, JArray<jclass> *);
+  java::security::ProtectionDomain *getProtectionDomain0 ();
 
 public:
   JArray<java::lang::reflect::Field *> *getFields (void);
@@ -380,6 +383,8 @@
   _Jv_IDispatchTable *idt;
   // Pointer to the class that represents an array of this class.
   jclass arrayclass;
+  // Security Domain to which this class belongs (or null).
+  java::security::ProtectionDomain *protectionDomain;
 };
 
 #endif /* __JAVA_LANG_CLASS_H__ */
Index: java/lang/natClass.cc
===================================================================
RCS file: /cvs/gcc/egcs/libjava/java/lang/natClass.cc,v
retrieving revision 1.41
diff -u -r1.41 natClass.cc
--- natClass.cc	2001/03/26 07:05:32	1.41
+++ natClass.cc	2001/04/25 15:36:00
@@ -72,7 +72,8 @@
 
 
 jclass
-java::lang::Class::forName (jstring className, java::lang::ClassLoader *loader)
+java::lang::Class::forName (jstring className, jboolean initialize,
+                            java::lang::ClassLoader *loader)
 {
   if (! className)
     throw new java::lang::NullPointerException;
@@ -90,11 +91,12 @@
 		  ? _Jv_FindClassFromSignature (name->data, loader)
 		  : _Jv_FindClass (name, loader));
 
-  if (klass)
-    _Jv_InitClass (klass);
-  else
+  if (klass == NULL)
     throw new java::lang::ClassNotFoundException (className);
 
+  if (initialize)
+    _Jv_InitClass (klass);
+
   return klass;
 }
 
@@ -102,7 +104,7 @@
 java::lang::Class::forName (jstring className)
 {
   // FIXME: should use class loader from calling method.
-  return forName (className, NULL);
+  return forName (className, true, NULL);
 }
 
 java::lang::reflect::Constructor *
@@ -1414,4 +1416,11 @@
 	}
     }
   throw new java::lang::NoSuchMethodException;
+}
+
+// Private accessor method for Java code to retrieve the protection domain.
+java::security::ProtectionDomain *
+java::lang::Class::getProtectionDomain0 ()
+{
+  return protectionDomain;
 }
Index: java/lang/Class.java
===================================================================
RCS file: /cvs/gcc/egcs/libjava/java/lang/Class.java,v
retrieving revision 1.10
diff -u -r1.10 Class.java
--- Class.java	2000/11/26 03:58:55	1.10
+++ Class.java	2001/04/25 15:36:00
@@ -12,6 +12,7 @@
 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 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 @@
   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);
@@ -153,6 +180,35 @@
   public native boolean isPrimitive ();
   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 ()
   {
Index: java/lang/ClassLoader.java
===================================================================
RCS file: /cvs/gcc/egcs/libjava/java/lang/ClassLoader.java,v
retrieving revision 1.11
diff -u -r1.11 ClassLoader.java
--- ClassLoader.java	2000/11/27 04:07:48	1.11
+++ ClassLoader.java	2001/04/25 15:36:00
@@ -1,6 +1,6 @@
 // ClassLoader.java - Define policies for loading Java classes.
 
-/* Copyright (C) 1998, 1999, 2000  Free Software Foundation
+/* Copyright (C) 1998, 1999, 2000, 2001  Free Software Foundation
 
    This file is part of libgcj.
 
@@ -14,7 +14,14 @@
 import java.io.IOException;
 import java.net.URL;
 import java.net.URLConnection;
+import java.security.AllPermission;
+import java.security.CodeSource;
+import java.security.Permission;
+import java.security.Permissions;
+import java.security.Policy;
+import java.security.ProtectionDomain;
 import java.util.Enumeration;
+import java.util.HashMap;
 import java.util.Stack;
 
 /**
@@ -25,18 +32,24 @@
  * @author  Kresten Krab Thorup
  */
 
-public abstract class ClassLoader {
-
+public abstract class ClassLoader
+{
   static private ClassLoader system;
   private ClassLoader parent;
+  private HashMap definedPackages = new HashMap();
 
-  public ClassLoader getParent ()
+  public final ClassLoader getParent ()
   {
     /* FIXME: security */
     return parent;
   }
-    
-  public static native ClassLoader getSystemClassLoader ();
+
+  public static ClassLoader getSystemClassLoader ()
+  {
+    if (system == null)
+      system = gnu.gcj.runtime.VMClassLoader.instance;
+    return system;
+  }
 
   /**
    * Creates a <code>ClassLoader</code> with no parent.
@@ -55,6 +68,7 @@
    * <code>checkCreateClassLoader</code> on the current 
    * security manager. 
    * @exception java.lang.SecurityException if not allowed
+   * @since 1.2
    */
   protected ClassLoader(ClassLoader parent) 
   {
@@ -71,11 +85,15 @@
    * @see       ClassLoader#loadClass(String,boolean)
    * @exception java.lang.ClassNotFoundException 
    */ 
-  public Class loadClass(String name) 
-    throws java.lang.ClassNotFoundException, java.lang.LinkageError
+  public Class loadClass(String name)
+    throws java.lang.ClassNotFoundException
   { 
     return loadClass (name, false);
   }
+  
+  /* findClass implementation for the system classloader. 
+  native Class systemFindClass(String name)
+    throws java.lang.ClassNotFoundException;
 
   /** 
    * Loads the class by the given name.  The default implementation
@@ -96,7 +114,7 @@
    * @deprecated 
    */ 
   protected Class loadClass(String name, boolean link)
-    throws java.lang.ClassNotFoundException, java.lang.LinkageError
+    throws java.lang.ClassNotFoundException
   {
     Class c = findLoadedClass (name);
 
@@ -106,7 +124,7 @@
 	  if (parent != null)
 	    return parent.loadClass (name, link);
 	  else
-	    c = findSystemClass (name);
+	    c = system.findClass (name);
 	} catch (ClassNotFoundException ex) {
 	  /* ignore, we'll try findClass */;
 	}
@@ -130,6 +148,7 @@
    * @param name Name of the class to find.
    * @return     The class found.
    * @exception  java.lang.ClassNotFoundException
+   * @since 1.2
    */
   protected Class findClass (String name)
     throws ClassNotFoundException
@@ -137,6 +156,28 @@
     throw new ClassNotFoundException (name);
   }
 
+  // Protection Domain definitions 
+  // FIXME: should there be a special protection domain used for native code?
+  
+  // The permission required to check what a classes protection domain is.
+  static final Permission protectionDomainPermission
+    = new RuntimePermission("getProtectionDomain");
+  // The protection domain returned if we cannot determine it. 
+  static ProtectionDomain unknownProtectionDomain;
+  // Protection domain to use when a class is defined without one specified.
+  static ProtectionDomain defaultProtectionDomain;
+
+  static
+  {
+    Permissions permissions = new Permissions();
+    permissions.add(new AllPermission());
+    unknownProtectionDomain = new ProtectionDomain(null, permissions);  
+
+    CodeSource cs = new CodeSource(null, null);
+    defaultProtectionDomain =
+      new ProtectionDomain(cs, Policy.getPolicy().getPermissions(cs));
+  }
+
   /** 
    * Defines a class, given the class-data.  According to the JVM, this
    * method should not be used; instead use the variant of this method
@@ -158,9 +199,14 @@
   protected final Class defineClass(byte[] data, int off, int len) 
     throws ClassFormatError
   {
-    return defineClass (null, data, off, len);
+    return defineClass (null, data, off, len, defaultProtectionDomain);
   }
 
+  protected final Class defineClass(String name, byte[] data, int off, int len)
+  {
+    return defineClass (name, data, off, len, defaultProtectionDomain);
+  }
+  
   /** 
    * Defines a class, given the class-data.  This is preferable
    * over <code>defineClass(byte[],off,len)</code> since it is more
@@ -182,6 +228,7 @@
    * @param     data    bytes in class file format.
    * @param     off     offset to start interpreting data.
    * @param     len     length of data in class file.
+   * @param     protectionDomain security protection domain for the class.
    * @return    the class defined.
    * @exception java.lang.ClassNotFoundException 
    * @exception java.lang.LinkageError
@@ -189,7 +236,8 @@
   protected final synchronized Class defineClass(String name,
 						 byte[] data,
 						 int off,
-						 int len)
+						 int len,
+						 ProtectionDomain protectionDomain)
     throws ClassFormatError
   {
     if (data==null || data.length < off+len || off<0 || len<0)
@@ -201,13 +249,16 @@
       throw new java.lang.LinkageError ("class " 
 					+ name 
 					+ " already loaded");
+    
+    if (protectionDomain == null)
+      protectionDomain = defaultProtectionDomain;
 
     try {
       // Since we're calling into native code here, 
       // we better make sure that any generated
       // exception is to spec!
 
-      return defineClass0 (name, data, off, len);
+      return defineClass0 (name, data, off, len, protectionDomain);
 
     } catch (ClassFormatError x) {
       throw x;		// rethrow
@@ -229,10 +280,10 @@
   private native Class defineClass0 (String name,
 				     byte[] data,
 				     int off,
-				     int len)
+				     int len,
+				     ProtectionDomain protectionDomain)
     throws ClassFormatError;
 
-
   /** 
    * Link the given class.  This will bring the class to a state where
    * the class initializer can be run.  Linking involves the following
@@ -262,13 +313,11 @@
    * @exception java.lang.LinkageError
    */
   protected final void resolveClass(Class clazz)
-    throws java.lang.LinkageError
   {
     resolveClass0(clazz);
   }
 
   static void resolveClass0(Class clazz)
-    throws java.lang.LinkageError
   {
     synchronized (clazz)
       {
@@ -288,14 +337,123 @@
 
   /** Internal method.  Calls _Jv_PrepareClass and
    * _Jv_PrepareCompiledClass.  This is only called from resolveClass.  */ 
-  private static native void linkClass0(Class clazz)
-    throws java.lang.LinkageError;
+  private static native void linkClass0(Class clazz);
 
   /** Internal method.  Marks the given clazz to be in an erroneous
    * state, and calls notifyAll() on the class object.  This should only
    * be called when the caller has the lock on the class object.  */
   private static native void markClassErrorState0(Class clazz);
 
+  /**
+   * Defines a new package and creates a Package object.
+   * The package should be defined before any class in the package is
+   * defined with <code>defineClass()</code>. The package should not yet
+   * be defined before in this classloader or in one of its parents (which
+   * means that <code>getPackage()</code> should return <code>null</code>).
+   * All parameters except the <code>name</code> of the package may be
+   * <code>null</code>.
+   * <p>
+   * Subclasses should call this method from their <code>findClass()</code>
+   * implementation before calling <code>defineClass()</code> on a Class
+   * in a not yet defined Package (which can be checked by calling
+   * <code>getPackage()</code>).
+   *
+   * @param name The name of the Package
+   * @param specTitle The name of the specification
+   * @param specVendor The name of the specification designer
+   * @param specVersion The version of this specification
+   * @param implTitle The name of the implementation
+   * @param implVendor The vendor that wrote this implementation
+   * @param implVersion The version of this implementation
+   * @param sealed If sealed the origin of the package classes
+   * @return the Package object for the specified package
+   *
+   * @exception IllegalArgumentException if the package name is null or if
+   * it was already defined by this classloader or one of its parents.
+   *
+   * @see Package
+   * @since 1.2
+   */
+  protected Package definePackage(String name,
+				  String specTitle, String specVendor,
+				  String specVersion, String implTitle,
+				  String implVendor, String implVersion,
+				  URL sealed)
+  {
+    if (getPackage(name) != null)
+      throw new IllegalArgumentException("Package " + name
+					 + " already defined");
+    Package p = new Package(name,
+			    specTitle, specVendor, specVersion,
+			    implTitle, implVendor, implVersion,
+			    sealed);
+    synchronized (definedPackages)
+    {
+      definedPackages.put(name, p);
+    }
+    return p;
+  }
+
+  /**
+   * Returns the Package object for the requested package name. It returns
+   * null when the package is not defined by this classloader or one of its
+   * parents.
+   *
+   * @since 1.2
+   */
+  protected Package getPackage(String name)
+  {
+    Package p;
+    if (parent == null)
+      // XXX - Should we use the bootstrap classloader?
+      p = null;
+    else
+      p = parent.getPackage(name);
+
+    if (p == null)
+      {
+        synchronized (definedPackages)
+	{
+	  p = (Package) definedPackages.get(name);
+	}
+      }
+
+    return p;
+  }
+
+  /**
+   * Returns all Package objects defined by this classloader and its parents.
+   *
+   * @since 1.2
+   */
+  protected Package[] getPackages()
+  {
+    Package[] allPackages;
+
+    // Get all our packages.
+    Package[] packages;
+    synchronized(definedPackages)
+    {
+      packages = new Package[definedPackages.size()];
+      definedPackages.values().toArray(packages);
+    }
+
+    // If we have a parent get all packages defined by our parents.
+    if (parent != null)
+      {
+	Package[] parentPackages = parent.getPackages();
+	allPackages = new Package[parentPackages.length + packages.length];
+	System.arraycopy(parentPackages, 0, allPackages, 0,
+			 parentPackages.length);
+	System.arraycopy(packages, 0, allPackages, parentPackages.length,
+			 packages.length);
+      }
+    else
+      // XXX - Should we use the bootstrap classloader?
+      allPackages = packages;
+
+    return allPackages;
+  }
 
   /** 
    * Returns a class found in a system-specific way, typically
@@ -307,14 +465,14 @@
    * @exception java.lang.LinkageError 
    * @exception java.lang.ClassNotFoundException 
    */
-  protected Class findSystemClass(String name) 
-    throws java.lang.ClassNotFoundException, java.lang.LinkageError
+  protected final Class findSystemClass(String name) 
+    throws java.lang.ClassNotFoundException
   {
     return getSystemClassLoader ().loadClass (name);
   }
 
   /*
-   * Does currently nothing.
+   * Does currently nothing. FIXME.
    */ 
   protected final void setSigners(Class claz, Object[] signers) {
     /* claz.setSigners (signers); */
@@ -328,13 +486,13 @@
    * @param     name  class to find.
    * @return    the class loaded, or null.
    */ 
-  protected native Class findLoadedClass(String name);
+  protected final native Class findLoadedClass(String name);
 
-  public static final InputStream getSystemResourceAsStream(String name) {
+  public static InputStream getSystemResourceAsStream(String name) {
     return getSystemClassLoader().getResourceAsStream (name);
   }
 
-  public static final URL getSystemResource(String name) {
+  public static URL getSystemResource(String name) {
     return getSystemClassLoader().getResource (name);
   }
 
@@ -397,7 +555,7 @@
     return null;
   }
 
-  public Enumeration getResources (String name) throws IOException
+  public final Enumeration getResources (String name) throws IOException
   {
     // The rules say search the parent class if non-null,
     // otherwise search the built-in class loader (assumed to be
Index: java/lang/natClassLoader.cc
===================================================================
RCS file: /cvs/gcc/egcs/libjava/java/lang/natClassLoader.cc,v
retrieving revision 1.30
diff -u -r1.30 natClassLoader.cc
--- natClassLoader.cc	2001/03/26 07:05:32	1.30
+++ natClassLoader.cc	2001/04/25 15:36:00
@@ -48,20 +48,12 @@
 
 /////////// java.lang.ClassLoader native methods ////////////
 
-java::lang::ClassLoader *
-java::lang::ClassLoader::getSystemClassLoader (void)
-{
-  JvSynchronize sync (&ClassLoaderClass);
-  if (! system)
-    system = gnu::gcj::runtime::VMClassLoader::getVMClassLoader ();
-  return system;
-}
-
 java::lang::Class *
 java::lang::ClassLoader::defineClass0 (jstring name,
 				       jbyteArray data, 
 				       jint offset,
-				       jint length)
+				       jint length,
+				       java::security::ProtectionDomain *pd)
 {
 #ifdef INTERPRETER
   jclass klass;
@@ -109,6 +101,8 @@
 
       throw ex;
     }
+    
+  klass->protectionDomain = pd;
 
   // if everything proceeded sucessfully, we're loaded.
   JvAssert (klass->state == JV_STATE_LOADED);
@@ -180,10 +174,10 @@
 }
 
 
-/** this is the only native method in VMClassLoader, so 
-    we define it here. */
+// This is the findClass() implementation for the System classloader. It is 
+// the only native method in VMClassLoader, so we define it here.
 jclass
-gnu::gcj::runtime::VMClassLoader::findSystemClass (jstring name)
+gnu::gcj::runtime::VMClassLoader::findClass (jstring name)
 {
   _Jv_Utf8Const *name_u = _Jv_makeUtf8Const (name);
   jclass klass = _Jv_FindClassInCache (name_u, 0);
@@ -211,6 +205,12 @@
 	  if (loaded)
 	    klass = _Jv_FindClassInCache (name_u, 0);
 	}
+    }
+
+  // Now try loading using the interpreter.
+  if (! klass)
+    {
+      klass = java::net::URLClassLoader::findClass (name);
     }
 
   return klass;
Index: java/lang/Package.java
===================================================================
RCS file: Package.java
diff -N Package.java
--- /dev/null	Tue May  5 13:32:27 1998
+++ Package.java	Wed Apr 25 08:36:01 2001
@@ -0,0 +1,287 @@
+/* java.lang.Package - Everything you ever wanted to know about a package.
+   Copyright (C) 2000, 2001 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING.  If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+As a special exception, if you link this library with other files to
+produce an executable, this library does not by itself cause the
+resulting executable to be covered by the GNU General Public License.
+This exception does not however invalidate any other reasons why the
+executable file might be covered by the GNU General Public License. */
+
+package java.lang;
+
+import java.net.URL;
+import java.util.NoSuchElementException;
+import java.util.StringTokenizer;
+
+/**
+ * Everything you ever wanted to know about a package. This class makes it
+ * possible to attach specification and implementation information to a
+ * package as explained in the
+ * <a href="http://java.sun.com/products/jdk/1.3/docs/guide/versioning/spec/VersioningSpecification.html#PackageVersionSpecification";>Package Versioning Specification</a>
+ * section of the
+ * <a href="http://java.sun.com/products/jdk/1.3/docs/guide/versioning/spec/VersioningSpecification.html";>Product Versioning Specification</a>.
+ * It also allows packages to be sealed with respect to the originating URL.
+ * <p>
+ * The most usefull method is the <code>isCompatibleWith()</code> method that
+ * compares a desired version of a specification with the version of the
+ * specification as implemented by a package. A package is considered
+ * compatible with another version if the version of the specification is
+ * equal or higher then the requested version. Version numbers are represented
+ * as strings of positive numbers seperated by dots (e.g. "1.2.0").
+ * The first number is called the major number, the second the minor,
+ * the third the micro, etc. A version is considered higher then another
+ * version if it has a bigger major number then the another version or when
+ * the major numbers of the versions are equal if it has a bigger minor number
+ * then the other version, etc. (If a version has no minor, micro, etc numbers
+ * then they are considered the be 0.)
+ *
+ * @since 1.2
+ * @author Mark Wielaard (mark@klomp.org)
+ */
+public class Package
+{
+  /** The name of the Package */
+  final private String name;
+
+  /** The name if the implementation */
+  final private String implTitle;
+  /** The vendor that wrote this implementation */
+  final private String implVendor;
+  /** The version of this implementation */
+  final private String implVersion;
+
+  /** The name of the specification */
+  final private String specTitle;
+  /** The name of the specification designer */
+  final private String specVendor;
+  /** The version of this specification */
+  final private String specVersion;
+
+  /** If sealed the origin of the package classes, otherwise null */
+  final private URL sealed;
+
+  /** 
+   * A package local constructor for the Package class.
+   * All parameters except the <code>name</code> of the package may be
+   * <code>null</code>.
+   * There are no public constructors defined for Package this is a package
+   * local constructor that is used by java.lang.Classloader.definePackage().
+   * 
+   * @param name The name of the Package
+   * @param specTitle The name of the specification
+   * @param specVendor The name of the specification designer
+   * @param specVersion The version of this specification
+   * @param implTitle The name of the implementation
+   * @param implVendor The vendor that wrote this implementation
+   * @param implVersion The version of this implementation
+   * @param sealed If sealed the origin of the package classes
+   */
+  Package(String name,
+	  String specTitle, String specVendor, String specVersion,
+	  String implTitle, String implVendor, String implVersion, URL sealed)
+  {
+    if (name == null)
+      throw new IllegalArgumentException("null Package name");
+
+    this.name = name;
+
+    this.implTitle = implTitle;
+    this.implVendor = implVendor;
+    this.implVersion = implVersion;
+
+    this.specTitle = specTitle;
+    this.specVendor = specVendor;
+    this.specVersion = specVersion;
+
+    this.sealed = sealed;
+  }
+
+  /** 
+   * Returns the Package name.
+   */
+  public String getName()
+  {
+    return name;
+  }
+
+  /** 
+   * Returns the name of the implementation or null if unknown.
+   */
+  public String getImplementationTitle()
+  {
+    return implTitle;
+  }
+
+  /** 
+   * Returns the vendor that wrote this implementation or null if unknown.
+   */
+  public String getImplementationVendor()
+  {
+    return implVendor;
+  }
+
+  /** 
+   * Returns the version of this implementation or null if unknown.
+   */
+  public String getImplementationVersion()
+  {
+    return implVersion;
+  }
+
+  /** 
+   * Returns the name of the specification or null if unknown.
+   */
+  public String getSpecificationTitle()
+  {
+    return specTitle;
+  }
+
+  /** 
+   * Returns the name of the specification designer or null if unknown.
+   */
+  public String getSpecificationVendor()
+  {
+    return specVendor;
+  }
+
+  /** 
+   * Returns the version of the specification or null if unknown.
+   */
+  public String getSpecificationVersion()
+  {
+    return specVersion;
+  }
+
+  /** 
+   * Returns true if this Package is sealed.
+   */
+  public boolean isSealed()
+  {
+    return (sealed != null);
+  }
+
+  /** 
+   * Returns true if this Package is sealed and the origin of the classes is
+   * the given URL.
+   * 
+   * @param url 
+   */
+  public boolean isSealed(URL url)
+  {
+    return url.equals(sealed);
+  }
+
+  /**
+   * Checks if the version of the specification is higher or at least as high
+   * as the desired version.
+   * @param version the (minimal) desired version of the specification
+   * @exception NumberFormatException when either version or the
+   * specification version is not a correctly formatted version number
+   * @exception NullPointerException if the supplied version or the
+   * Package specification version is null.
+   */
+  public boolean isCompatibleWith(String version) throws NumberFormatException
+  {
+    StringTokenizer versionTokens = new StringTokenizer(version, ".");
+    StringTokenizer specTokens = new StringTokenizer(specVersion, ".");
+    try
+      {
+	while (versionTokens.hasMoreElements())
+	  {
+	    int vers = Integer.parseInt(versionTokens.nextToken());
+	    int spec = Integer.parseInt(specTokens.nextToken());
+	    if (spec < vers)
+	      return false;
+	    else if (spec > vers)
+	      return true;
+	    // They must be equal, next Token please!
+	  }
+      }
+    catch (NoSuchElementException e)
+      {
+	// this must have been thrown by spec.netToken() so return false
+	return false;
+      }
+
+    // They must have been exactly the same version.
+    // Or the specVersion has more subversions. That is also good.
+    return true;
+  }
+
+  /**
+   * Returns the named package if it is known by the callers class loader.
+   * It may return null if the package is unknown, when there is no
+   * information on that particular package available or when the callers
+   * classloader is null.
+   * @param name the name of the desired package
+   */
+  public static Package getPackage(String name)
+  {
+    // Get the caller's classloader
+    SecurityManager sm = System.getSecurityManager();
+    Class c = sm.getClassContext()[1];
+    ClassLoader cl = c.getClassLoader();
+
+    if (cl != null)
+      return cl.getPackage(name);
+    else
+      return null;
+  }
+
+  /**
+   * Returns all the packages that are known to the callers class loader.
+   * It may return an empty array if the classloader of the caller is null.
+   */
+  public static Package[] getPackages()
+  {
+    // Get the caller's classloader
+    SecurityManager sm = System.getSecurityManager();
+    Class c = sm.getClassContext()[1];
+    ClassLoader cl = c.getClassLoader();
+
+    if (cl != null)
+      return cl.getPackages();
+    else
+      return new Package[0];
+  }
+
+  /** 
+   * Returns the hashCode of the name of this package.
+   */
+  public int hashCode()
+  {
+    return name.hashCode();
+  }
+
+  /** 
+   * Returns a string representation of this package name, specification,
+   * implementation and class origin if sealed.
+   */
+  public String toString()
+  {
+    return "package: " + name +
+	   " spec: " + specTitle +
+	   " version: " + specVersion +
+	   " vendor: " + specVendor +
+	   " implementation: " + implTitle +
+	   " version: " + implVersion +
+	   " vendor: " + implVendor + " sealed: " + sealed;
+  }
+}
Index: java/util/ResourceBundle.java
===================================================================
RCS file: /cvs/gcc/egcs/libjava/java/util/ResourceBundle.java,v
retrieving revision 1.11
diff -u -r1.11 ResourceBundle.java
--- ResourceBundle.java	2000/12/15 15:49:50	1.11
+++ ResourceBundle.java	2001/04/25 15:36:01
@@ -83,9 +83,7 @@
 	{
 	  try 
 	    {
-	      // This call is wrong by the spec, but it will have to
-	      // do until our Class.forName is fixed.
-	      rbc = Class.forName(bundleName, loader);
+	      rbc = Class.forName(bundleName, true, loader);
 	      r = null;
 	      try 
 		{
Index: gnu/gcj/runtime/VMClassLoader.java
===================================================================
RCS file: /cvs/gcc/egcs/libjava/gnu/gcj/runtime/VMClassLoader.java,v
retrieving revision 1.5
diff -u -r1.5 VMClassLoader.java
--- VMClassLoader.java	2000/08/26 19:25:13	1.5
+++ VMClassLoader.java	2001/04/25 15:36:01
@@ -65,18 +65,11 @@
   /** This is overridden to search the internal hash table, which 
    * will only search existing linked-in classes.   This will make
    * the default implementation of loadClass (in ClassLoader) work right.
+   * The implementation of this method is in java/lang/natClassLoader.cc.
    */
-  protected final native Class findSystemClass(String name) 
-    throws java.lang.ClassNotFoundException, java.lang.LinkageError;
+  protected native Class findClass(String name) 
+    throws java.lang.ClassNotFoundException;
 
-  // Return the sole VMClassLoader.
-  private static synchronized VMClassLoader getVMClassLoader ()
-  {
-    if (redirect == null)
-      redirect = new VMClassLoader ();
-    return redirect;
-  }
-
   // The only VMClassLoader that can exist.
-  private static VMClassLoader redirect;
+  public static VMClassLoader instance = new VMClassLoader ();
 }
Index: Makefile.am
===================================================================
RCS file: /cvs/gcc/egcs/libjava/Makefile.am,v
retrieving revision 1.139
diff -u -r1.139 Makefile.am
--- Makefile.am	2001/04/22 03:05:37	1.139
+++ Makefile.am	2001/04/25 15:36:02
@@ -843,6 +843,7 @@
 java/lang/Number.java \
 java/lang/NumberFormatException.java \
 java/lang/OutOfMemoryError.java	\
+java/lang/Package.java \
 java/lang/Process.java \
 java/lang/Runnable.java	\
 java/lang/Runtime.java \
@@ -1036,6 +1037,7 @@
 gnu/java/locale/Calendar_de.java \
 gnu/java/locale/Calendar_en.java \
 gnu/java/locale/Calendar_nl.java \
+gnu/java/security/provider/DefaultPolicy.java \
 gnu/java/security/provider/Gnu.java \
 gnu/java/security/provider/SHA.java \
 gnu/java/security/provider/SHA1PRNG.java \
@@ -1068,6 +1070,7 @@
 java/net/JarURLConnection.java \
 java/net/MalformedURLException.java \
 java/net/MulticastSocket.java \
+java/net/NetPermission.java \
 java/net/NoRouteToHostException.java \
 java/net/PlainDatagramSocketImpl.java \
 java/net/PlainSocketImpl.java \
@@ -1078,6 +1081,7 @@
 java/net/SocketImpl.java \
 java/net/SocketImplFactory.java	\
 java/net/SocketOptions.java \
+java/net/SocketPermission.java \
 java/net/URL.java \
 java/net/URLClassLoader.java \
 java/net/URLConnection.java \
@@ -1087,34 +1091,80 @@
 java/net/URLStreamHandlerFactory.java \
 java/net/UnknownHostException.java \
 java/net/UnknownServiceException.java \
+java/security/AccessControlContext.java \
+java/security/AccessControlException.java \
+java/security/AccessController.java \
+java/security/AlgorithmParameterGenerator.java \
+java/security/AlgorithmParameters.java \
 java/security/AlgorithmParameterGeneratorSpi.java \
+java/security/AlgorithmParametersSpi.java \
+java/security/AllPermission.java \
 java/security/BasicPermission.java \
+java/security/Certificate.java \
+java/security/CodeSource.java \
 java/security/DigestException.java \
 java/security/DigestOutputStream.java \
+java/security/DummyKeyPairGenerator.java \
+java/security/DummySignature.java \
+java/security/DigestInputStream.java \
+java/security/DomainCombiner.java \
+java/security/DummyMessageDigest.java \
 java/security/GeneralSecurityException.java \
 java/security/Guard.java \
+java/security/GuardedObject.java \
+java/security/Identity.java \
+java/security/IdentityScope.java \
 java/security/InvalidAlgorithmParameterException.java \
 java/security/InvalidKeyException.java \
 java/security/InvalidParameterException.java \
 java/security/Key.java \
-java/security/KeyException.java	\
-java/security/KeyPair.java \
+java/security/KeyFactorySpi.java \
 java/security/KeyPairGenerator.java \
+java/security/KeyStoreException.java \
+java/security/KeyException.java \
+java/security/KeyManagementException.java \
 java/security/KeyPairGeneratorSpi.java \
+java/security/KeyStoreSpi.java \
+java/security/KeyFactory.java \
+java/security/KeyPair.java \
+java/security/KeyStore.java \
 java/security/MessageDigest.java \
+java/security/MessageDigestSpi.java \
 java/security/NoSuchAlgorithmException.java \
 java/security/NoSuchProviderException.java \
 java/security/Permission.java \
-java/security/PermissionCollection.java	\
 java/security/Principal.java \
+java/security/PrivilegedExceptionAction.java \
+java/security/PublicKey.java \
+java/security/PermissionCollection.java \
 java/security/PrivateKey.java \
+java/security/ProtectionDomain.java \
+java/security/Permissions.java \
+java/security/PrivilegedAction.java \
 java/security/Provider.java \
-java/security/PublicKey.java \
+java/security/Policy.java \
+java/security/PrivilegedActionException.java \
+java/security/ProviderException.java \
 java/security/SecureClassLoader.java \
-java/security/SecureRandom.java	\
+java/security/SecureRandomSpi.java \
+java/security/SecurityPermission.java \
+java/security/SignatureException.java \
+java/security/SignedObject.java \
+java/security/SecureRandom.java \
 java/security/Security.java \
 java/security/Signature.java \
-java/security/SignatureException.java \
+java/security/SignatureSpi.java \
+java/security/Signer.java \
+java/security/UnrecoverableKeyException.java \
+java/security/UnresolvedPermission.java \
+java/security/acl/Acl.java \
+java/security/acl/AclNotFoundException.java \
+java/security/acl/LastOwnerException.java \
+java/security/acl/Owner.java \
+java/security/acl/AclEntry.java \
+java/security/acl/Group.java \
+java/security/acl/NotOwnerException.java \
+java/security/acl/Permission.java \
 java/security/cert/CRL.java \
 java/security/cert/CRLException.java \
 java/security/cert/Certificate.java \
@@ -1130,19 +1180,28 @@
 java/security/cert/X509Certificate.java \
 java/security/cert/X509Extension.java \
 java/security/interfaces/DSAKey.java \
-java/security/interfaces/DSAParams.java	\
+java/security/interfaces/DSAKeyPairGenerator.java \
+java/security/interfaces/DSAParams.java \
 java/security/interfaces/DSAPrivateKey.java \
 java/security/interfaces/DSAPublicKey.java \
+java/security/interfaces/RSAKey.java \
 java/security/interfaces/RSAPrivateCrtKey.java \
 java/security/interfaces/RSAPrivateKey.java \
 java/security/interfaces/RSAPublicKey.java \
 java/security/spec/AlgorithmParameterSpec.java \
-java/security/spec/InvalidKeySpecException.java	\
+java/security/spec/DSAParameterSpec.java \
+java/security/spec/DSAPrivateKeySpec.java \
+java/security/spec/DSAPublicKeySpec.java \
+java/security/spec/EncodedKeySpec.java \
+java/security/spec/InvalidKeySpecException.java \
 java/security/spec/InvalidParameterSpecException.java \
-java/security/spec/KeySpec.java	\
+java/security/spec/KeySpec.java \
+java/security/spec/PKCS8EncodedKeySpec.java \
+java/security/spec/RSAKeyGenParameterSpec.java \
 java/security/spec/RSAPrivateCrtKeySpec.java \
 java/security/spec/RSAPrivateKeySpec.java \
 java/security/spec/RSAPublicKeySpec.java \
+java/security/spec/X509EncodedKeySpec.java \
 java/sql/Array.java \
 java/sql/BatchUpdateException.java \
 java/sql/Blob.java \
Index: gcj/javaprims.h
===================================================================
RCS file: /cvs/gcc/egcs/libjava/gcj/javaprims.h,v
retrieving revision 1.17
diff -u -r1.17 javaprims.h
--- javaprims.h	2001/03/28 11:04:29	1.17
+++ javaprims.h	2001/04/25 15:36:02
@@ -39,7 +39,6 @@
   {
     namespace io
     {
-      class BlockDataException;
       class BufferedInputStream;
       class BufferedOutputStream;
       class BufferedReader;
@@ -176,6 +175,7 @@
       class NumberFormatException;
       class Object;
       class OutOfMemoryError;
+      class Package;
       class Process;
       class Runnable;
       class Runtime;
@@ -233,10 +233,12 @@
       class ArrayList;
       class Arrays;
       class Arrays$ListImpl;
+      class BasicMapEntry;
       class BitSet;
       class Calendar;
       class Collection;
       class Collections;
+      class Collections$ReverseComparator;
       class Collections$SynchronizedCollection;
       class Collections$SynchronizedIterator;
       class Collections$SynchronizedList;
@@ -302,6 +304,12 @@
       class Timer$TaskQueue;
       class TimerTask;
       class TooManyListenersException;
+      class TreeMap;
+      class TreeMap$Node;
+      class TreeMap$SubMap;
+      class TreeMap$TreeIterator;
+      class TreeMap$VerifyResult;
+      class TreeSet;
       class Vector;
       class WeakHashMap;
       class WeakHashMap$Entry;
Index: gnu/java/security/provider/DefaultPolicy.java
===================================================================
RCS file: DefaultPolicy.java
diff -N DefaultPolicy.java
--- /dev/null	Tue May  5 13:32:27 1998
+++ DefaultPolicy.java	Wed Apr 25 08:36:02 2001
@@ -0,0 +1,55 @@
+/* DefaultPolicy.java 
+   Copyright (C) 2001 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+ 
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING.  If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+As a special exception, if you link this library with other files to
+produce an executable, this library does not by itself cause the
+resulting executable to be covered by the GNU General Public License.
+This exception does not however invalidate any other reasons why the
+executable file might be covered by the GNU General Public License. */
+
+package gnu.java.security.provider;
+
+import java.security.*;
+
+/** 
+  * This is just a stub policy implementation which grants all permissions
+  * to any code source. FIXME: This should be replaced with a real
+  * implementation that reads the policy configuration from a file, like
+  * $JAVA_HOME/jre/lib/security/java.security.
+  */
+public class DefaultPolicy extends Policy
+{
+  static Permissions allPermissions = new Permissions();
+  
+  static
+  {
+    allPermissions.add(new AllPermission());
+  }
+
+  public PermissionCollection getPermissions(CodeSource codesource)
+  {
+    return allPermissions;
+  }
+  
+  public void refresh()
+  {
+    // Nothing.
+  }
+}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]