This adds the missing clearCache methods to java.util.ResourceBundle:
ChangeLog:
2008-07-06 Andrew John Hughes <[EMAIL PROTECTED]>
* java/util/ResourceBundle.java,
(BundleKey.toString()): Implemented.
(clearCache()): Implemented.
(clearCache(ClassLoader)): Implemented.
--
Andrew :)
Support Free Java!
Contribute to GNU Classpath and the OpenJDK
http://www.gnu.org/software/classpath
http://openjdk.java.net
PGP Key: 94EFD9D8 (http://subkeys.pgp.net)
Fingerprint = F8EF F1EA 401E 2E60 15FA 7927 142C 2591 94EF D9D8
Index: java/util/ResourceBundle.java
===================================================================
RCS file: /sources/classpath/classpath/java/util/ResourceBundle.java,v
retrieving revision 1.41
diff -u -u -r1.41 ResourceBundle.java
--- java/util/ResourceBundle.java 6 Jul 2008 00:47:46 -0000 1.41
+++ java/util/ResourceBundle.java 6 Jul 2008 16:13:41 -0000
@@ -297,14 +297,29 @@
&& 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
@@ -498,7 +513,7 @@
}
/**
- * Tries to load a 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
@@ -571,4 +586,40 @@
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 [EMAIL PROTECTED] loader} is [EMAIL
PROTECTED] 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();
+ }
+ }
+ }
+
}