This patch adds the CollationProvider. Changelog:
2007-01-06 Andrew John Hughes <[EMAIL PROTECTED]>
* java/text/Collator.java:
(getInstance(Locale)): Check providers.
* java/text/spi/CollatorProvider.java:
New file.
--
Andrew :-)
Escape the Java Trap with GNU Classpath!
http://www.gnu.org/philosophy/java-trap.html
public class gcj extends Freedom implements Java { ... }
Index: java/text/Collator.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/text/Collator.java,v
retrieving revision 1.18
diff -u -3 -p -u -r1.18 Collator.java
--- java/text/Collator.java 10 Dec 2006 20:25:46 -0000 1.18
+++ java/text/Collator.java 6 Jan 2007 01:10:20 -0000
@@ -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 implement
/**
* 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
+ * [EMAIL PROTECTED] 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 implement
*/
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));
}
/**
Index: java/text/spi/CollatorProvider.java
===================================================================
RCS file: java/text/spi/CollatorProvider.java
diff -N java/text/spi/CollatorProvider.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ java/text/spi/CollatorProvider.java 6 Jan 2007 01:10:20 -0000
@@ -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 [EMAIL PROTECTED] CollatorProvider} provides localized
+ * instances of [EMAIL PROTECTED] java.text.Collator}.
+ *
+ * @author Andrew John Hughes ([EMAIL PROTECTED])
+ * @since 1.6
+ */
+public abstract class CollatorProvider
+ extends LocaleServiceProvider
+{
+
+ /**
+ * Constructs a new [EMAIL PROTECTED] CollatorProvider}.
+ * Provided for implicit invocation by subclasses.
+ */
+ protected CollatorProvider()
+ {
+ }
+
+ /**
+ * Returns a [EMAIL PROTECTED] java.text.Collator} instance
+ * for the specified [EMAIL PROTECTED] 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
+ * [EMAIL PROTECTED] getAvailableLocales()}
+ * @see java.text.Collator#getInstance(java.util.Locale)
+ */
+ public abstract Collator getInstance(Locale locale);
+
+}
signature.asc
Description: Digital signature
