aboutsummaryrefslogtreecommitdiff
path: root/libjava/java/util/ResourceBundle.java
diff options
context:
space:
mode:
authorTom Tromey <tromey@cygnus.com>1999-04-30 09:31:00 +0000
committerTom Tromey <tromey@gcc.gnu.org>1999-04-30 09:31:00 +0000
commita0e894a8cc0344dbbefc57523ff53e990854fcfb (patch)
tree4928c712cce75c2d0d4c9cf9f6f78ef4a4052149 /libjava/java/util/ResourceBundle.java
parent1c609c4cbee4dd46a739fae213da8d48fe1147e4 (diff)
downloadgcc-a0e894a8cc0344dbbefc57523ff53e990854fcfb.zip
gcc-a0e894a8cc0344dbbefc57523ff53e990854fcfb.tar.gz
gcc-a0e894a8cc0344dbbefc57523ff53e990854fcfb.tar.bz2
StringBuffer.java (ensureCapacity): Don't resize vector when shared.
* java/lang/StringBuffer.java (ensureCapacity): Don't resize vector when shared. * java/util/Locale.java (Locale(String,String)): Implement in terms of 3-argument version; variant now defaults to empty string. (toString): Assume variant is not null. (equals): Assume all strings are not null. (Locale): Throw NullPointerException if any argument is null. * java/util/ResourceBundle.java (getBundle): Don't try the base name; now implicit in partialGetBundle call. (trySomeGetBundle): Search for parent bundles and call setParent as required. (partialGetBundle): Added `langStop' argument. Use `Locale.toString' to compute bundleName. (resource_cache): New static field. (partialGetBundle): Cache the returned resource bundle. Now synchronized. * gnu/gcj/text/LocaleData_en.java (contents): [collatorRule] Added missing `<'. * mauve-libgcj: Enable Collator and RuleBasedCollator. * java/text/natCollator.cc (decomposeCharacter): `base' now `const'. * Makefile.in: Rebuilt. * Makefile.am (ordinary_java_source_files): Added CollationElementIterator, CollationKey, Collator, RuleBasedCollator. (nat_source_files): Added natCollator.cc. * java/text/RuleBasedCollator.java (ceiNext): No longer static. (compare): Pass `this' to CollationElementIterator constructor. (getCollationElementIterator): Likewise. (ceiNext): Fix off-by-one error when finding initial substring. (next): Correctly mask off bits when computing return value. Fixed return values when one string is shorter than the other. * java/text/CollationElementIterator.java (collator): New field. (CollationElementIterator): Added collator argument. (next): Call ceiNext on collator object. From-SVN: r26707
Diffstat (limited to 'libjava/java/util/ResourceBundle.java')
-rw-r--r--libjava/java/util/ResourceBundle.java98
1 files changed, 49 insertions, 49 deletions
diff --git a/libjava/java/util/ResourceBundle.java b/libjava/java/util/ResourceBundle.java
index ba1d3f9..05503c6 100644
--- a/libjava/java/util/ResourceBundle.java
+++ b/libjava/java/util/ResourceBundle.java
@@ -20,6 +20,9 @@ public abstract class ResourceBundle
{
protected ResourceBundle parent;
+ // This is used to cache resource bundles.
+ private static Hashtable resource_cache = new Hashtable ();
+
public ResourceBundle ()
{
}
@@ -65,15 +68,17 @@ public abstract class ResourceBundle
String stopHere)
{
Class rbc;
+ ResourceBundle needs_parent = null, r, result = null;
while (true)
{
try
{
rbc = Class.forName(bundleName);
+ r = null;
try
{
- return (ResourceBundle) rbc.newInstance();
+ r = (ResourceBundle) rbc.newInstance();
}
catch (IllegalAccessException ex)
{
@@ -83,45 +88,61 @@ public abstract class ResourceBundle
{
// Fall through
}
- return null;
+ if (r != null)
+ {
+ if (result == null)
+ result = r;
+ if (needs_parent != null)
+ {
+ // We've been through the loop one or more times
+ // already. Set the parent and keep going.
+ needs_parent.setParent(r);
+ }
+ needs_parent = r;
+ }
}
catch (ClassNotFoundException ex)
{
- if (bundleName.compareTo(stopHere) == 0)
- return null;
- else
- {
- int last = bundleName.lastIndexOf('_');
-
- // No more underscores?
- if (last == -1)
- return null;
+ // Fall through.
+ }
+
+ if (bundleName.equals(stopHere))
+ return result;
+ else
+ {
+ int last = bundleName.lastIndexOf('_');
- // Loop around, testing this new shorter name.
- bundleName = bundleName.substring(0, last);
- }
+ // No more underscores?
+ if (last == -1)
+ return result;
+
+ // Loop around, testing this new shorter name.
+ bundleName = bundleName.substring(0, last);
}
}
}
-
- // Search for bundles, but stop at baseName_language.
- private static final ResourceBundle partialGetBundle (String baseName,
- Locale locale)
+
+ // Search for bundles, but stop at baseName_language (if required).
+ // This is synchronized so that the cache works correctly.
+ private static final synchronized ResourceBundle
+ partialGetBundle (String baseName, Locale locale, boolean langStop)
{
ResourceBundle rb;
- String bundleName = (baseName
- + "_"
- + locale.getLanguage() + "_"
- + locale.getCountry() + "_"
- + locale.getVariant());
+ String bundleName = baseName + "_" + locale;
+
+ // Check the cache.
+ Object obj = resource_cache.get(bundleName);
+ if (obj != null)
+ return (ResourceBundle) obj;
String stopHere = (baseName
- + "_"
- + locale.getLanguage());
+ + (langStop ? ("_" + locale.getLanguage()) : ""));
rb = trySomeGetBundle(bundleName, stopHere);
+ if (rb != null)
+ resource_cache.put(bundleName, rb);
return rb;
}
@@ -138,39 +159,18 @@ public abstract class ResourceBundle
if (locale == null)
throw new NullPointerException ();
- rb = partialGetBundle(baseName, locale);
+ rb = partialGetBundle(baseName, locale, false);
if (rb != null)
return rb;
+ // Finally, try the default locale.
if (! locale.equals(Locale.getDefault()))
{
- rb = partialGetBundle(baseName, Locale.getDefault());
+ rb = partialGetBundle(baseName, Locale.getDefault(), true);
if (rb != null)
return rb;
}
- // Try just the baseName.
- try
- {
- rbc = Class.forName (baseName);
- try
- {
- return (ResourceBundle) rbc.newInstance();
- }
- catch (IllegalAccessException ex)
- {
- // Fall through.
- }
- catch (InstantiationException ex)
- {
- // Fall through.
- }
- }
- catch (ClassNotFoundException ex)
- {
- // Fall through.
- }
-
throw new MissingResourceException("can't load bundle",
baseName,
"bundle");