OSDN Git Service

libjava/ChangeLog:
[pf3gnuchains/gcc-fork.git] / libjava / classpath / java / util / ResourceBundle.java
index 9b82bc8..2124340 100644 (file)
@@ -41,6 +41,8 @@ package java.util;
 
 import gnu.classpath.VMStackWalker;
 
+import gnu.java.lang.CPStringBuilder;
+
 import java.io.IOException;
 import java.io.InputStream;
 
@@ -121,9 +123,10 @@ public abstract class ResourceBundle
    * 
    * @see BundleKey
    */
-  private static Map bundleCache = new LinkedHashMap(CACHE_SIZE + 1, 0.75F, true)
+  private static Map<BundleKey,Object> bundleCache =
+    new LinkedHashMap<BundleKey,Object>(CACHE_SIZE + 1, 0.75F, true)
   {
-    public boolean removeEldestEntry(Map.Entry entry)
+    public boolean removeEldestEntry(Map.Entry<BundleKey,Object> entry)
     {
       return size() > CACHE_SIZE;
     }
@@ -294,14 +297,29 @@ public abstract class ResourceBundle
           && locale.equals(key.locale)
           && classLoader.equals(key.classLoader);
     }    
+
+    public String toString()
+    {
+      CPStringBuilder builder = new CPStringBuilder(getClass().getName());
+      builder.append("[defaultLocale=");
+      builder.append(defaultLocale);
+      builder.append(",baseName=");
+      builder.append(baseName);
+      builder.append(",locale=");
+      builder.append(locale);
+      builder.append(",classLoader=");
+      builder.append(classLoader);
+      builder.append("]");
+      return builder.toString();
+    }
   }
   
   /** A cache lookup key. This avoids having to a new one for every
    *  getBundle() call. */
-  private static BundleKey lookupKey = new BundleKey();
+  private static final BundleKey lookupKey = new BundleKey();
   
   /** Singleton cache entry to represent previous failed lookups. */
-  private static Object nullEntry = new Object();
+  private static final Object nullEntry = new Object();
 
   /**
    * Get the appropriate ResourceBundle for the given locale. The following
@@ -452,7 +470,7 @@ public abstract class ResourceBundle
     ResourceBundle bundle = null;
     try
       {
-        Class rbClass;
+        Class<?> rbClass;
         if (classloader == null)
           rbClass = Class.forName(localizedName);
         else
@@ -495,7 +513,7 @@ public abstract class ResourceBundle
   }
 
   /**
-   * Tries to load the bundle for a given locale, also loads the backup
+   * Tries to load the bundle for a given locale, also loads the backup
    * locales with the same language.
    *
    * @param baseName the raw bundle name, without locale qualifiers
@@ -515,9 +533,9 @@ public abstract class ResourceBundle
     
     int baseLen = baseName.length();
 
-    // Build up a StringBuffer containing the complete bundle name, fully
+    // Build up a CPStringBuilder containing the complete bundle name, fully
     // qualified by locale.
-    StringBuffer sb = new StringBuffer(baseLen + variant.length() + 7);
+    CPStringBuilder sb = new CPStringBuilder(baseLen + variant.length() + 7);
 
     sb.append(baseName);
     
@@ -568,4 +586,40 @@ public abstract class ResourceBundle
     
     return first;
   }
+
+  /**
+   * Remove all resources from the cache that were loaded
+   * using the class loader of the calling class.
+   *
+   * @since 1.6
+   */
+  public static final void clearCache()
+  {
+    clearCache(VMStackWalker.getCallingClassLoader());
+  }
+
+  /**
+   * Remove all resources from the cache that were loaded
+   * using the specified class loader.
+   *
+   * @param loader the loader used for the bundles that will be removed.
+   * @throws NullPointerException if {@code loader} is {@code null}.
+   * @since 1.6
+   */
+  public static final void clearCache(ClassLoader loader)
+  {
+    if (loader == null)
+      throw new NullPointerException("The loader can not be null.");
+    synchronized (ResourceBundle.class)
+      {    
+       Iterator<BundleKey> iter = bundleCache.keySet().iterator();
+       while (iter.hasNext())
+         {
+           BundleKey key = iter.next();
+           if (key.classLoader == loader)
+             iter.remove();
+         }
+      }
+  }
+
 }