diff options
author | Andrew John Hughes <gnu_andrew@member.fsf.org> | 2008-07-06 17:38:25 +0000 |
---|---|---|
committer | Andrew John Hughes <gnu_andrew@member.fsf.org> | 2008-07-06 17:38:25 +0000 |
commit | 40449444a8b32089522a6c8372c2ee49b654e324 (patch) | |
tree | 6101cb58a4fb319663028b430c448b88c4982df8 | |
parent | b06c998865b0572825eacd17b00072874a9f5892 (diff) | |
download | classpath-40449444a8b32089522a6c8372c2ee49b654e324.tar.gz |
Implement cache clearing for java.util.ResourceBundle
2008-07-06 Andrew John Hughes <gnu_andrew@member.fsf.org>
* java/util/ResourceBundle.java,
(BundleKey.toString()): Implemented.
(clearCache()): Implemented.
(clearCache(ClassLoader)): Implemented.
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | java/util/ResourceBundle.java | 57 |
2 files changed, 61 insertions, 3 deletions
@@ -1,5 +1,12 @@ 2008-07-06 Andrew John Hughes <gnu_andrew@member.fsf.org> + * java/util/ResourceBundle.java, + (BundleKey.toString()): Implemented. + (clearCache()): Implemented. + (clearCache(ClassLoader)): Implemented. + +2008-07-06 Andrew John Hughes <gnu_andrew@member.fsf.org> + * java/util/ResourceBundle.java: Fix generic warnings. diff --git a/java/util/ResourceBundle.java b/java/util/ResourceBundle.java index cb5579eeb..21243403c 100644 --- a/java/util/ResourceBundle.java +++ b/java/util/ResourceBundle.java @@ -297,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 @@ -498,7 +513,7 @@ public abstract class ResourceBundle } /** - * 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 @@ 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(); + } + } + } + } |