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]

Remove natResourceBundle.cc


I'm checking in this patch to remove natResourceBundle.cc, and replace 
it with code similar to what Mark Wielaard suggested.

Bryce.


2001-11-04  Bryce McKinlay  <bryce@waitaki.otago.ac.nz>

	* java/util/ResourceBundle.java (getClassContext): Removed.
	(Security): New class, extends SecurityManger.
	(getBundle): Use Security.getCallingClassLoader instead of
	getClassContext.
	* java/util/natResourceBundle.cc: Removed.

Index: ResourceBundle.java
===================================================================
RCS file: /cvs/gcc/egcs/libjava/java/util/ResourceBundle.java,v
retrieving revision 1.15
diff -u -r1.15 ResourceBundle.java
--- ResourceBundle.java	2001/09/27 00:24:52	1.15
+++ ResourceBundle.java	2001/11/04 03:41:46
@@ -28,6 +28,8 @@
 package java.util;
 import java.lang.ref.Reference;
 import java.lang.ref.SoftReference;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 import gnu.classpath.Configuration;
 
 /**
@@ -74,14 +76,6 @@
  * @author Jochen Hoenicke */
 public abstract class ResourceBundle
 {
-  static 
-  {
-    if (Configuration.INIT_LOAD_LIBRARY)
-      {
-	System.loadLibrary ("javautil");
-      }
-  }
-
   /**
    * The parent bundle.  This is consulted when you call getObject
    * and there is no such resource in the current bundle.  This
@@ -97,6 +91,36 @@
   private Locale locale;
 
   /**
+   * We override SecurityManager in order to access getClassContext(). 
+   */
+  class Security extends SecurityManager
+  {
+    /** Return the ClassLoader of the class which called into this
+        ResourceBundle, or null if it cannot be determined. */
+    ClassLoader getCallingClassLoader()
+    {
+      Class[] stack = super.getClassContext();
+      for (int i = 0; i < stack.length; i++)
+        if (stack[i] != Security.class && stack[i] != ResourceBundle.class)
+	  return stack[i].getClassLoader();
+      return null;
+    }
+  }
+  
+  // This will always work since java.util classes have (all) system
+  // permissions.
+  static Security security = (Security) AccessController.doPrivileged
+    (
+      new PrivilegedAction()
+      {
+        public Object run()
+        {
+          return new Security();
+        }
+      }
+    );
+
+  /**
    * The constructor.  It does nothing special.
    */
   public ResourceBundle()
@@ -157,32 +181,19 @@
   }
 
   /**
-   * This method returns an array with the classes of the calling
-   * methods.  The zeroth entry is the class that called this method
-   * (should always be ResourceBundle), the first contains the class
-   * that called the caller (i.e. the class that called getBundle).
-   *
-   * Implementation note: This depends on the fact, that getBundle
-   * doesn't get inlined, but since it calls a private method, it
-   * isn't inlineable.
-   *
-   * @return an array containing the classes for the callers.  
-   */
-  private static native Class[] getClassContext();
-
-  /**
    * Get the appropriate ResourceBundle for the default locale.  
    * @param baseName the name of the ResourceBundle.  This should be
    * a name of a Class or a properties-File.  See the class
    * description for details.  
    * @return the desired resource bundle
    * @exception MissingResourceException 
-   *    if the resource bundle couldn't be found.  */
+   *    if the resource bundle couldn't be found.  
+   */
   public static final ResourceBundle getBundle(String baseName)
     throws MissingResourceException
   {
     return getBundle(baseName, Locale.getDefault(),
-		     getClassContext()[1].getClassLoader());
+		     security.getCallingClassLoader());
   }
 
   /**
@@ -199,7 +210,7 @@
 					       Locale locale)
     throws MissingResourceException
   {
-    return getBundle(baseName, locale, getClassContext()[1].getClassLoader());
+    return getBundle(baseName, locale, security.getCallingClassLoader());
   }
 
   /**

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