summaryrefslogtreecommitdiff
path: root/java/text
diff options
context:
space:
mode:
authorAndrew John Hughes <gnu_andrew@member.fsf.org>2007-01-06 01:29:06 +0000
committerAndrew John Hughes <gnu_andrew@member.fsf.org>2007-01-06 01:29:06 +0000
commitafb79f4fb907bcbd28609f33ca10a2dfc7e4103f (patch)
tree7926422325db2da9624ba68883d96fedc26f7834 /java/text
parent9b269268d6db148542749f1d80516f85484d077b (diff)
downloadclasspath-afb79f4fb907bcbd28609f33ca10a2dfc7e4103f.tar.gz
2007-01-06 Andrew John Hughes <gnu_andrew@member.fsf.org>
* java/text/Collator.java: (getInstance(Locale)): Check providers. * java/text/spi/CollatorProvider.java: New file.
Diffstat (limited to 'java/text')
-rw-r--r--java/text/Collator.java50
-rw-r--r--java/text/spi/CollatorProvider.java79
2 files changed, 118 insertions, 11 deletions
diff --git a/java/text/Collator.java b/java/text/Collator.java
index 952361324..16ee6b124 100644
--- a/java/text/Collator.java
+++ b/java/text/Collator.java
@@ -40,10 +40,13 @@ package java.text;
import gnu.java.locale.LocaleHelper;
+import java.text.spi.CollatorProvider;
+
import java.util.Comparator;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
+import java.util.ServiceLoader;
/**
* This class is the abstract superclass of classes which perform
@@ -285,7 +288,8 @@ public abstract class Collator implements Comparator<Object>, Cloneable
/**
* This method returns an instance of <code>Collator</code> for the
* specified locale. If no <code>Collator</code> exists for the desired
- * locale, a <code>Collator</code> for the default locale will be returned.
+ * locale, the fallback procedure described in
+ * {@link java.util.spi.LocaleServiceProvider} is invoked.
*
* @param loc The desired locale to load a <code>Collator</code> for.
*
@@ -293,27 +297,51 @@ public abstract class Collator implements Comparator<Object>, Cloneable
*/
public static Collator getInstance (Locale loc)
{
- ResourceBundle res;
String pattern;
try
{
- res = ResourceBundle.getBundle("gnu.java.locale.LocaleInformation",
- loc, ClassLoader.getSystemClassLoader());
- pattern = res.getString("collation_rules");
+ ResourceBundle res =
+ ResourceBundle.getBundle("gnu.java.locale.LocaleInformation",
+ loc, ClassLoader.getSystemClassLoader());
+ return new RuleBasedCollator(res.getString("collation_rules"));
}
catch (MissingResourceException x)
{
- pattern = "<0<1<2<3<4<5<6<7<8<9<A,a<b,B<c,C<d,D<e,E<f,F<g,G<h,H<i,I<j,J<k,K" +
- "<l,L<m,M<n,N<o,O<p,P<q,Q<r,R<s,S<t,T<u,U<v,V<w,W<x,X<y,Y<z,Z";
- }
- try
- {
- return new RuleBasedCollator (pattern);
+ /* This means runtime support for the locale
+ * is not available, so we check providers. */
}
catch (ParseException x)
{
throw (InternalError)new InternalError().initCause(x);
}
+ for (CollatorProvider p : ServiceLoader.load(CollatorProvider.class))
+ {
+ for (Locale l : p.getAvailableLocales())
+ {
+ if (l.equals(loc))
+ {
+ Collator c = p.getInstance(loc);
+ if (c != null)
+ return c;
+ break;
+ }
+ }
+ }
+ if (loc.equals(Locale.ROOT))
+ {
+ try
+ {
+ return new RuleBasedCollator("<0<1<2<3<4<5<6<7<8<9<A,a<b,B<c," +
+ "C<d,D<e,E<f,F<g,G<h,H<i,I<j,J<k,K" +
+ "<l,L<m,M<n,N<o,O<p,P<q,Q<r,R<s,S<t,"+
+ "T<u,U<v,V<w,W<x,X<y,Y<z,Z");
+ }
+ catch (ParseException x)
+ {
+ throw (InternalError)new InternalError().initCause(x);
+ }
+ }
+ return getInstance(LocaleHelper.getFallbackLocale(loc));
}
/**
diff --git a/java/text/spi/CollatorProvider.java b/java/text/spi/CollatorProvider.java
new file mode 100644
index 000000000..6d6f40939
--- /dev/null
+++ b/java/text/spi/CollatorProvider.java
@@ -0,0 +1,79 @@
+/* CollatorProvider.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.Collator;
+
+import java.util.Locale;
+
+import java.util.spi.LocaleServiceProvider;
+
+/**
+ * A {@link CollatorProvider} provides localized
+ * instances of {@link java.text.Collator}.
+ *
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
+ * @since 1.6
+ */
+public abstract class CollatorProvider
+ extends LocaleServiceProvider
+{
+
+ /**
+ * Constructs a new {@link CollatorProvider}.
+ * Provided for implicit invocation by subclasses.
+ */
+ protected CollatorProvider()
+ {
+ }
+
+ /**
+ * Returns a {@link java.text.Collator} instance
+ * for the specified {@link java.util.Locale}.
+ *
+ * @param locale the desired locale.
+ * @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.Collator#getInstance(java.util.Locale)
+ */
+ public abstract Collator getInstance(Locale locale);
+
+}