*/
public static final int ARRAY16 = 9;
- /**
+ /*
+ * Bundle cache stuff
+ */
+
+ /**
+ * Place holder in the bundle cache indicating that the requested bundle is not available
+ */
+ private static final ICUResourceBundle NULL_BUNDLE =
+ new ICUResourceBundle(null, null, null, 0, null) {
+ public int hashCode() {
+ return 0;
+ }
+ public boolean equals(Object rhs) {
+ return this == rhs;
+ }
+ };
+
+ /**
+ * An object storing information required for creating a bundle, used by
+ * the bundle cache.
+ */
+ private static class BundleCacheData {
+ ClassLoader root;
+ String baseName;
+ String localeID;
+
+ BundleCacheData(ClassLoader root, String baseName, String localeID) {
+ this.root = root;
+ this.baseName = baseName;
+ this.localeID = localeID;
+ }
+
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (!(obj instanceof BundleCacheData)) {
+ return false;
+ }
+ BundleCacheData data = (BundleCacheData)obj;
+ return this.root.equals(data.root) &&
+ this.baseName.equals(data.baseName) &&
+ this.localeID.equals(data.localeID);
+ }
+
+ public int hashCode() {
+ return root.hashCode() ^ baseName.hashCode() ^ localeID.hashCode();
+ }
+ }
+
+ private static class BundleCache extends SoftCache<BundleCacheData, ICUResourceBundle, BundleCacheData> {
+
+ /* (non-Javadoc)
+ * @see com.ibm.icu.impl.CacheBase#createInstance(java.lang.Object, java.lang.Object)
+ */
+ @Override
+ protected ICUResourceBundle createInstance(BundleCacheData key, BundleCacheData data) {
+ String resolvedName = getFullName(data.baseName, data.localeID);
+ ICUResourceBundleReader reader = ICUResourceBundleReader.getReader(resolvedName, data.root);
+ if (reader == null) {
+ return NULL_BUNDLE;
+ }
+ return ICUResourceBundle.getBundle(reader, data.baseName, data.localeID, data.root);
+ }
+ }
+
+ private static final BundleCache BUNDLE_CACHE = new BundleCache();
+
+ /**
* Create a bundle using a reader.
* @param baseName The name for the bundle.
* @param localeID The locale identification.
* @return the new bundle
*/
public static ICUResourceBundle createBundle(String baseName, String localeID, ClassLoader root) {
- String resolvedName = getFullName(baseName, localeID);
- ICUResourceBundleReader reader = ICUResourceBundleReader.getReader(resolvedName, root);
- if (reader == null) {
- // could not open the .res file
- return null;
- }
- return getBundle(reader, baseName, localeID, root);
+ BundleCacheData bundleKey = new BundleCacheData(root, baseName, localeID);
+ ICUResourceBundle b = BUNDLE_CACHE.getInstance(bundleKey, bundleKey);
+ return b == NULL_BUNDLE ? null : b;
}
protected String getLocaleID() {