diff options
author | Andrew John Hughes <gnu_andrew@member.fsf.org> | 2007-01-08 00:41:23 +0000 |
---|---|---|
committer | Andrew John Hughes <gnu_andrew@member.fsf.org> | 2007-01-08 00:41:23 +0000 |
commit | 2c95f90d9e99e45009f5c28d95689a510c2b025b (patch) | |
tree | 7869fa640aba5cd22bfe940a8fe42288ec0636e3 /java | |
parent | 17e6bcdd1455677776ea82b19354a42062238357 (diff) | |
download | classpath-2c95f90d9e99e45009f5c28d95689a510c2b025b.tar.gz |
2007-01-08 Andrew John Hughes <gnu_andrew@member.fsf.org>
* java/text/DateFormat.java:
(computeInstance(int,int,Locale,boolean,boolean)):
Throw an exception when locale info. is unavailable.
(computeDefault(int,int,boolean,boolean)): New method.
(getDateInstance(int,Locale)): Check providers.
(getDateTimeInstance(int,int,Locale)): Likewise.
(getTimeInstance(int,Locale)): Likewise.
* java/text/DateFormatSymbols.java:
Update documentation to match DecimalFormatSymbols.
* java/text/DecimalFormatSymbols.java:
(DecimalFormatSymbols(Locale)): Reordered.
(getInstance()): Implemented.
(getInstance(Locale)): Implemented.
* java/text/NumberFormat.java:
(computeInstance(Locale,String,String)):
Throw an exception when locale info is unavailable.
(getCurrencyInstance(Locale)): Check providers.
(getIntegerInstance(Locale)): Likewise.
(getNumberInstance(Locale)): Likewise.
(getPercentInstance(Locale)): Likewise.
* java/text/spi/DateFormatProvider.java: New file.
* java/text/spi/DecimalFormatSymbolsProvider.java: Likewise.
* java/text/spi/NumberFormatProvider.java: Likewise.
Diffstat (limited to 'java')
-rw-r--r-- | java/text/DateFormat.java | 148 | ||||
-rw-r--r-- | java/text/DateFormatSymbols.java | 8 | ||||
-rw-r--r-- | java/text/DecimalFormatSymbols.java | 89 | ||||
-rw-r--r-- | java/text/NumberFormat.java | 135 | ||||
-rw-r--r-- | java/text/spi/DateFormatProvider.java | 129 | ||||
-rw-r--r-- | java/text/spi/DecimalFormatSymbolsProvider.java | 79 | ||||
-rw-r--r-- | java/text/spi/NumberFormatProvider.java | 129 |
7 files changed, 674 insertions, 43 deletions
diff --git a/java/text/DateFormat.java b/java/text/DateFormat.java index 73aa62d98..53b757e88 100644 --- a/java/text/DateFormat.java +++ b/java/text/DateFormat.java @@ -39,12 +39,17 @@ exception statement from your version. */ package java.text; +import gnu.java.locale.LocaleHelper; + +import java.text.spi.DateFormatProvider; + import java.io.InvalidObjectException; import java.util.Calendar; import java.util.Date; import java.util.Locale; import java.util.MissingResourceException; import java.util.ResourceBundle; +import java.util.ServiceLoader; import java.util.TimeZone; /** @@ -550,17 +555,14 @@ public abstract class DateFormat extends Format implements Cloneable private static DateFormat computeInstance (int dateStyle, int timeStyle, Locale loc, boolean use_date, boolean use_time) + throws MissingResourceException { - ResourceBundle res; - try - { - res = ResourceBundle.getBundle("gnu.java.locale.LocaleInformation", - loc, ClassLoader.getSystemClassLoader()); - } - catch (MissingResourceException x) - { - res = null; - } + if (loc.equals(Locale.ROOT)) + return computeDefault(dateStyle,timeStyle,use_date,use_time); + + ResourceBundle res = + ResourceBundle.getBundle("gnu.java.locale.LocaleInformation", + loc, ClassLoader.getSystemClassLoader()); String pattern = null; if (use_date) @@ -642,6 +644,59 @@ public abstract class DateFormat extends Format implements Cloneable return new SimpleDateFormat (pattern, loc); } + private static DateFormat computeDefault (int dateStyle, int timeStyle, + boolean use_date, boolean use_time) + { + String pattern = null; + if (use_date) + { + switch (dateStyle) + { + case FULL: + pattern = "EEEE MMMM d, yyyy G"; + break; + case LONG: + pattern = "MMMM d, yyyy"; + break; + case MEDIUM: + pattern = "d-MMM-yy"; + break; + case SHORT: + pattern = "M/d/yy"; + default: + throw new IllegalArgumentException (); + } + } + + if (use_time) + { + if (pattern == null) + pattern = ""; + else + pattern += " "; + + switch (timeStyle) + { + case FULL: + pattern += "h:mm:ss;S 'o''clock' a z"; + break; + case LONG: + pattern += "h:mm:ss a z"; + break; + case MEDIUM: + pattern += "h:mm:ss a"; + break; + case SHORT: + pattern += "h:mm a"; + break; + default: + throw new IllegalArgumentException (); + } + } + + return new SimpleDateFormat (pattern, Locale.ROOT); + } + /** * This method returns an instance of <code>DateFormat</code> that will * format using the default formatting style for dates. @@ -678,7 +733,29 @@ public abstract class DateFormat extends Format implements Cloneable */ public static final DateFormat getDateInstance (int style, Locale loc) { - return computeInstance (style, loc, true, false); + try + { + return computeInstance (style, loc, true, false); + } + catch (MissingResourceException e) + { + for (DateFormatProvider p : + ServiceLoader.load(DateFormatProvider.class)) + { + for (Locale l : p.getAvailableLocales()) + { + if (l.equals(loc)) + { + DateFormat df = p.getDateInstance(style, loc); + if (df != null) + return df; + break; + } + } + } + return getDateInstance(style, + LocaleHelper.getFallbackLocale(loc)); + } } /** @@ -717,7 +794,30 @@ public abstract class DateFormat extends Format implements Cloneable int timeStyle, Locale loc) { - return computeInstance (dateStyle, timeStyle, loc, true, true); + try + { + return computeInstance (dateStyle, timeStyle, loc, true, true); + } + catch (MissingResourceException e) + { + for (DateFormatProvider p : + ServiceLoader.load(DateFormatProvider.class)) + { + for (Locale l : p.getAvailableLocales()) + { + if (l.equals(loc)) + { + DateFormat df = p.getDateTimeInstance(dateStyle, + timeStyle, loc); + if (df != null) + return df; + break; + } + } + } + return getDateTimeInstance(dateStyle, timeStyle, + LocaleHelper.getFallbackLocale(loc)); + } } /** @@ -779,7 +879,29 @@ public abstract class DateFormat extends Format implements Cloneable */ public static final DateFormat getTimeInstance (int style, Locale loc) { - return computeInstance (style, loc, false, true); + try + { + return computeInstance (style, loc, false, true); + } + catch (MissingResourceException e) + { + for (DateFormatProvider p : + ServiceLoader.load(DateFormatProvider.class)) + { + for (Locale l : p.getAvailableLocales()) + { + if (l.equals(loc)) + { + DateFormat df = p.getTimeInstance(style, loc); + if (df != null) + return df; + break; + } + } + } + return getTimeInstance(style, + LocaleHelper.getFallbackLocale(loc)); + } } /** diff --git a/java/text/DateFormatSymbols.java b/java/text/DateFormatSymbols.java index 0d10eb3c6..406376a0f 100644 --- a/java/text/DateFormatSymbols.java +++ b/java/text/DateFormatSymbols.java @@ -167,12 +167,13 @@ public class DateFormatSymbols implements java.io.Serializable, Cloneable * by loading the date format information for the specified locale. * This constructor only obtains instances using the runtime's resources; * to also include {@link java.text.spi.DateFormatSymbolsProvider} instances, - * call {@link #getInstance(Locale)} instead. + * call {@link #getInstance(java.util.Locale)} instead. * * @param locale The locale for which date formatting symbols should * be loaded. * @throws MissingResourceException if the resources for the specified * locale could not be found or loaded. + * @see #getInstance(java.util.Locale) */ public DateFormatSymbols (Locale locale) throws MissingResourceException @@ -195,10 +196,13 @@ public class DateFormatSymbols implements java.io.Serializable, Cloneable /** * This method loads the format symbol information for the default - * locale. + * locale. This constructor only obtains instances using the runtime's resources; + * to also include {@link java.text.spi.DateFormatSymbolsProvider} instances, + * call {@link #getInstance()} instead. * * @throws MissingResourceException if the resources for the default * locale could not be found or loaded. + * @see #getInstance() */ public DateFormatSymbols() throws MissingResourceException diff --git a/java/text/DecimalFormatSymbols.java b/java/text/DecimalFormatSymbols.java index 29d2d7ed3..f87ebbf13 100644 --- a/java/text/DecimalFormatSymbols.java +++ b/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)); + } + } diff --git a/java/text/NumberFormat.java b/java/text/NumberFormat.java index 1bef97ffe..4a72f443a 100644 --- a/java/text/NumberFormat.java +++ b/java/text/NumberFormat.java @@ -1,5 +1,6 @@ /* NumberFormat.java -- Formats and parses numbers - Copyright (C) 1998, 1999, 2000, 2001, 2003, 2004 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2000, 2001, 2003, 2004, 2007 + Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -38,14 +39,20 @@ exception statement from your version. */ package java.text; +import gnu.java.locale.LocaleHelper; + import java.io.IOException; import java.io.InvalidObjectException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; + +import java.text.spi.NumberFormatProvider; + import java.util.Currency; import java.util.Locale; import java.util.MissingResourceException; import java.util.ResourceBundle; +import java.util.ServiceLoader; /** * This is the abstract superclass of all classes which format and @@ -309,17 +316,13 @@ public abstract class NumberFormat extends Format implements Cloneable private static NumberFormat computeInstance(Locale loc, String resource, String def) + throws MissingResourceException { - ResourceBundle res; - try - { - res = ResourceBundle.getBundle("gnu.java.locale.LocaleInformation", - loc, ClassLoader.getSystemClassLoader()); - } - catch (MissingResourceException x) - { - res = null; - } + if (loc.equals(Locale.ROOT)) + return new DecimalFormat(def, DecimalFormatSymbols.getInstance(loc)); + ResourceBundle res = + ResourceBundle.getBundle("gnu.java.locale.LocaleInformation", + loc, ClassLoader.getSystemClassLoader()); String fmt; try { @@ -329,7 +332,7 @@ public abstract class NumberFormat extends Format implements Cloneable { fmt = def; } - DecimalFormatSymbols dfs = new DecimalFormatSymbols (loc); + DecimalFormatSymbols dfs = DecimalFormatSymbols.getInstance(loc); return new DecimalFormat (fmt, dfs); } @@ -352,11 +355,33 @@ public abstract class NumberFormat extends Format implements Cloneable */ public static NumberFormat getCurrencyInstance (Locale loc) { - NumberFormat format; - - format = computeInstance (loc, "currencyFormat", "\u00A4#,##0.00;(\u00A4#,##0.00)"); - format.setMaximumFractionDigits(format.getCurrency().getDefaultFractionDigits()); - return format; + try + { + NumberFormat format; + + format = computeInstance (loc, "currencyFormat", + "\u00A4#,##0.00;(\u00A4#,##0.00)"); + format.setMaximumFractionDigits(format.getCurrency().getDefaultFractionDigits()); + return format; + } + catch (MissingResourceException e) + { + for (NumberFormatProvider p : + ServiceLoader.load(NumberFormatProvider.class)) + { + for (Locale l : p.getAvailableLocales()) + { + if (l.equals(loc)) + { + NumberFormat nf = p.getCurrencyInstance(loc); + if (nf != null) + return nf; + break; + } + } + } + return getCurrencyInstance(LocaleHelper.getFallbackLocale(loc)); + } } /** @@ -456,7 +481,28 @@ public abstract class NumberFormat extends Format implements Cloneable */ public static NumberFormat getNumberInstance (Locale loc) { - return computeInstance (loc, "numberFormat", "#,##0.###"); + try + { + return computeInstance (loc, "numberFormat", "#,##0.###"); + } + catch (MissingResourceException e) + { + for (NumberFormatProvider p : + ServiceLoader.load(NumberFormatProvider.class)) + { + for (Locale l : p.getAvailableLocales()) + { + if (l.equals(loc)) + { + NumberFormat nf = p.getNumberInstance(loc); + if (nf != null) + return nf; + break; + } + } + } + return getNumberInstance(LocaleHelper.getFallbackLocale(loc)); + } } /** @@ -484,10 +530,32 @@ public abstract class NumberFormat extends Format implements Cloneable */ public static NumberFormat getIntegerInstance(Locale locale) { - NumberFormat format = computeInstance (locale, "integerFormat", "#,##0"); - format.setMaximumFractionDigits(0); - format.setParseIntegerOnly (true); - return format; + try + { + NumberFormat format = computeInstance (locale, + "integerFormat", "#,##0"); + format.setMaximumFractionDigits(0); + format.setParseIntegerOnly (true); + return format; + } + catch (MissingResourceException e) + { + for (NumberFormatProvider p : + ServiceLoader.load(NumberFormatProvider.class)) + { + for (Locale l : p.getAvailableLocales()) + { + if (l.equals(locale)) + { + NumberFormat nf = p.getIntegerInstance(locale); + if (nf != null) + return nf; + break; + } + } + } + return getIntegerInstance(LocaleHelper.getFallbackLocale(locale)); + } } /** @@ -511,7 +579,28 @@ public abstract class NumberFormat extends Format implements Cloneable */ public static NumberFormat getPercentInstance (Locale loc) { - return computeInstance (loc, "percentFormat", "#,##0%"); + try + { + return computeInstance (loc, "percentFormat", "#,##0%"); + } + catch (MissingResourceException e) + { + for (NumberFormatProvider p : + ServiceLoader.load(NumberFormatProvider.class)) + { + for (Locale l : p.getAvailableLocales()) + { + if (l.equals(loc)) + { + NumberFormat nf = p.getPercentInstance(loc); + if (nf != null) + return nf; + break; + } + } + } + return getPercentInstance(LocaleHelper.getFallbackLocale(loc)); + } } /** diff --git a/java/text/spi/DateFormatProvider.java b/java/text/spi/DateFormatProvider.java new file mode 100644 index 000000000..43d54a0c6 --- /dev/null +++ b/java/text/spi/DateFormatProvider.java @@ -0,0 +1,129 @@ +/* DateFormatProvider.java -- Providers of localized instances + Copyright (C) 2007 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package java.text.spi; + +import java.text.DateFormat; + +import java.util.Locale; + +import java.util.spi.LocaleServiceProvider; + +/** + * A {@link DateFormatProvider} provides localized + * instances of {@link java.text.DateFormat}. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.6 + */ +public abstract class DateFormatProvider + extends LocaleServiceProvider +{ + + /** + * Constructs a new {@link DateFormatProvider}. + * Provided for implicit invocation by subclasses. + */ + protected DateFormatProvider() + { + } + + /** + * Returns a {@link java.text.DateFormat} instance + * for formatting dates with the given style in the specified + * {@link java.util.Locale}. + * + * @param style the formatting style; one of {@link DateFormat#SHORT}, + * {@link DateFormat#MEDIUM}, {@link DateFormat#LONG} + * or {@link DateFormat#FULL}. + * @param locale the desired locale. + * @return the localized instance for formatting dates. + * @throws NullPointerException if the locale is null. + * @throws IllegalArgumentException if the style is invalid or + * the locale is not one + * returned by + * {@link getAvailableLocales()} + * @see java.text.DateFormat#getDateInstance(int,java.util.Locale) + */ + public abstract DateFormat getDateInstance(int style, + Locale locale); + + /** + * Returns a {@link java.text.DateFormat} instance + * for formatting dates and times with the given style in the + * specified {@link java.util.Locale}. + * + * @param dateStyle the date formatting style; one of + * {@link DateFormat#SHORT}, {@link DateFormat#MEDIUM}, + * {@link DateFormat#LONG} or {@link DateFormat#FULL}. + * @param timeStyle the time formatting style; one of + * {@link DateFormat#SHORT}, {@link DateFormat#MEDIUM}, + * {@link DateFormat#LONG} or {@link DateFormat#FULL}. + * @param locale the desired locale. + * @return the localized instance for formatting dates. + * @throws NullPointerException if the locale is null. + * @throws IllegalArgumentException if either style is invalid or + * the locale is not one + * returned by + * {@link getAvailableLocales()} + * @see java.text.DateFormat#getDateInstance(java.util.Locale) + */ + public abstract DateFormat getDateTimeInstance(int dateStyle, + int timeStyle, + Locale locale); + + /** + * Returns a {@link java.text.DateFormat} instance + * for formatting times with the given style in the specified + * {@link java.util.Locale}. + * + * @param style the formatting style; one of {@link DateFormat#SHORT}, + * {@link DateFormat#MEDIUM}, {@link DateFormat#LONG} + * or {@link DateFormat#FULL}. + * @param locale the desired locale. + * @return the localized instance for formatting times. + * @throws NullPointerException if the locale is null. + * @throws IllegalArgumentException if the style is invalid or + * the locale is not one + * returned by + * {@link getAvailableLocales()} + * @see java.text.DateFormat#getTimeInstance(int,java.util.Locale) + */ + public abstract DateFormat getTimeInstance(int style, + Locale locale); + +} diff --git a/java/text/spi/DecimalFormatSymbolsProvider.java b/java/text/spi/DecimalFormatSymbolsProvider.java new file mode 100644 index 000000000..d772b1eee --- /dev/null +++ b/java/text/spi/DecimalFormatSymbolsProvider.java @@ -0,0 +1,79 @@ +/* DecimalFormatSymbolsProvider.java -- Providers of localized instances + Copyright (C) 2007 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package java.text.spi; + +import java.text.DecimalFormatSymbols; + +import java.util.Locale; + +import java.util.spi.LocaleServiceProvider; + +/** + * A {@link DecimalFormatSymbolsProvider} provides localized + * instances of {@link java.text.DecimalFormatSymbols}. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.6 + */ +public abstract class DecimalFormatSymbolsProvider + extends LocaleServiceProvider +{ + + /** + * Constructs a new {@link DecimalFormatSymbolsProvider}. + * Provided for implicit invocation by subclasses. + */ + protected DecimalFormatSymbolsProvider() + { + } + + /** + * Returns a {@link java.text.DecimalFormatSymbols} instance + * for the specified {@link java.util.Locale}. + * + * @param locale the locale to express the symbols in. + * @return the localized instance. + * @throws NullPointerException if the locale is null. + * @throws IllegalArgumentException if the locale is not one + * returned by + * {@link getAvailableLocales()} + * @see java.text.DecimalFormatSymbols#getInstance(java.util.Locale) + */ + public abstract DecimalFormatSymbols getInstance(Locale locale); + +} diff --git a/java/text/spi/NumberFormatProvider.java b/java/text/spi/NumberFormatProvider.java new file mode 100644 index 000000000..2a252701f --- /dev/null +++ b/java/text/spi/NumberFormatProvider.java @@ -0,0 +1,129 @@ +/* NumberFormatProvider.java -- Providers of localized instances + Copyright (C) 2007 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package java.text.spi; + +import java.text.NumberFormat; + +import java.util.Locale; + +import java.util.spi.LocaleServiceProvider; + +/** + * A {@link NumberFormatProvider} provides localized + * instances of {@link java.text.NumberFormat}. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.6 + */ +public abstract class NumberFormatProvider + extends LocaleServiceProvider +{ + + /** + * Constructs a new {@link NumberFormatProvider}. + * Provided for implicit invocation by subclasses. + */ + protected NumberFormatProvider() + { + } + + /** + * Returns a {@link java.text.NumberFormat} instance + * for monetary values in the specified + * {@link java.util.Locale}. + * + * @param locale the desired locale. + * @return the localized instance for monetary values. + * @throws NullPointerException if the locale is null. + * @throws IllegalArgumentException if the locale is not one + * returned by + * {@link getAvailableLocales()} + * @see java.text.NumberFormat#getCurrencyInstance(java.util.Locale) + */ + public abstract NumberFormat getCurrencyInstance(Locale locale); + + /** + * Returns a {@link java.text.NumberFormat} instance + * for integers in the specified {@link java.util.Locale}. + * The returned instance should be configured to round + * floating point numbers to the nearest integer using + * {@link java.math.RoundingMode#HALF_EVEN} rounding, + * and to parse only the integer part of a number. + * + * @param locale the desired locale. + * @return the localized instance for integers. + * @throws NullPointerException if the locale is null. + * @throws IllegalArgumentException if the locale is not one + * returned by + * {@link getAvailableLocales()} + * @see java.text.NumberFormat#getIntegerInstance(java.util.Locale) + * @see java.math.RoundingMode#HALF_EVEN + * @see java.text.NumberFormat#isParseIntegerOnly() + */ + public abstract NumberFormat getIntegerInstance(Locale locale); + + /** + * Returns a general-purpose {@link java.text.NumberFormat} + * instance in the specified {@link java.util.Locale}. + * + * @param locale the desired locale. + * @return a general-purpose localized instance. + * @throws NullPointerException if the locale is null. + * @throws IllegalArgumentException if the locale is not one + * returned by + * {@link getAvailableLocales()} + * @see java.text.NumberFormat#getNumberInstance(java.util.Locale) + */ + public abstract NumberFormat getNumberInstance(Locale locale); + + /** + * Returns a {@link java.text.NumberFormat} instance + * for percentage values in the specified + * {@link java.util.Locale}. + * + * @param locale the desired locale. + * @return the localized instance for percentage values. + * @throws NullPointerException if the locale is null. + * @throws IllegalArgumentException if the locale is not one + * returned by + * {@link getAvailableLocales()} + * @see java.text.NumberFormat#getPercentInstance(java.util.Locale) + */ + public abstract NumberFormat getPercentInstance(Locale locale); + +} |