diff options
Diffstat (limited to 'libjava/classpath/java/text/DecimalFormatSymbols.java')
-rw-r--r-- | libjava/classpath/java/text/DecimalFormatSymbols.java | 89 |
1 files changed, 84 insertions, 5 deletions
diff --git a/libjava/classpath/java/text/DecimalFormatSymbols.java b/libjava/classpath/java/text/DecimalFormatSymbols.java index 29d2d7ed337..f87ebbf138f 100644 --- a/libjava/classpath/java/text/DecimalFormatSymbols.java +++ b/libjava/classpath/java/text/DecimalFormatSymbols.java @@ -1,5 +1,5 @@ /* DecimalFormatSymbols.java -- Format symbols used by DecimalFormat - Copyright (C) 1999, 2000, 2001, 2004 Free Software Foundation, Inc. + Copyright (C) 1999, 2000, 2001, 2004, 2007 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -38,13 +38,19 @@ exception statement from your version. */ package java.text; +import gnu.java.locale.LocaleHelper; + import java.io.IOException; import java.io.ObjectInputStream; import java.io.Serializable; + +import java.text.spi.DecimalFormatSymbolsProvider; + import java.util.Currency; import java.util.Locale; import java.util.MissingResourceException; import java.util.ResourceBundle; +import java.util.ServiceLoader; /** * This class is a container for the symbols used by @@ -80,6 +86,11 @@ public class DecimalFormatSymbols implements Cloneable, Serializable /** * This method initializes a new instance of * <code>DecimalFormatSymbols</code> for the default locale. + * This constructor only obtains instances using the runtime's resources; + * to also include {@link java.text.spi.DateFormatSymbolsProvider} instances, + * call {@link #getInstance()} instead. + * + * @see #getInstance() */ public DecimalFormatSymbols () { @@ -137,18 +148,19 @@ public class DecimalFormatSymbols implements Cloneable, Serializable * international currency symbol will be set to the strings "?" * and "XXX" respectively. This generally happens with language * locales (those with no specified country), such as - * <code>Locale.ENGLISH</code>. + * <code>Locale.ENGLISH</code>. This constructor only obtains + * instances using the runtime's resources; to also include + * {@link java.text.spi.DecimalFormatSymbolsProvider} instances, + * call {@link #getInstance(java.util.Locale)} instead. * * @param loc The local to load symbols for. * @throws NullPointerException if the locale is null. + * @see #getInstance(java.util.Locale) */ public DecimalFormatSymbols (Locale loc) { ResourceBundle res; - currency = Currency.getInstance("XXX"); - currencySymbol = "?"; - intlCurrencySymbol = "XXX"; try { res = ResourceBundle.getBundle("gnu.java.locale.LocaleInformation", @@ -158,6 +170,9 @@ public class DecimalFormatSymbols implements Cloneable, Serializable { res = null; } + currency = Currency.getInstance("XXX"); + currencySymbol = "?"; + intlCurrencySymbol = "XXX"; try { Currency localeCurrency = Currency.getInstance(loc); @@ -684,4 +699,68 @@ public class DecimalFormatSymbols implements Cloneable, Serializable serialVersionOnStream = 2; } + + /** + * Returns a {@link DecimalFormatSymbols} instance for the + * default locale obtained from either the runtime itself + * or one of the installed + * {@link java.text.spi.DecimalFormatSymbolsProvider} instances. + * This is equivalent to calling + * <code>getInstance(Locale.getDefault())</code>. + * + * @return a {@link DecimalFormatSymbols} instance for the default + * locale. + * @since 1.6 + */ + public static final DecimalFormatSymbols getInstance() + { + return getInstance(Locale.getDefault()); + } + + /** + * Returns a {@link DecimalFormatSymbols} instance for the + * specified locale obtained from either the runtime itself + * or one of the installed + * {@link java.text.spi.DecimalFormatSymbolsProvider} instances. + * + * @param locale the locale for which an instance should be + * returned. + * @return a {@link DecimalFormatSymbols} instance for the specified + * locale. + * @throws NullPointerException if <code>locale</code> is + * <code>null</code>. + * @since 1.6 + */ + public static final DecimalFormatSymbols getInstance(Locale locale) + { + try + { + if (!locale.equals(Locale.ROOT)) + ResourceBundle.getBundle("gnu.java.locale.LocaleInformation", + locale, + ClassLoader.getSystemClassLoader()); + return new DecimalFormatSymbols(locale); + } + catch (MissingResourceException x) + { + /* This means runtime support for the locale + * is not available, so we check providers. */ + } + for (DecimalFormatSymbolsProvider p : + ServiceLoader.load(DecimalFormatSymbolsProvider.class)) + { + for (Locale loc : p.getAvailableLocales()) + { + if (loc.equals(locale)) + { + DecimalFormatSymbols syms = p.getInstance(locale); + if (syms != null) + return syms; + break; + } + } + } + return getInstance(LocaleHelper.getFallbackLocale(locale)); + } + } |