This patch adds the BreakIterator service provider.

Changelog:

2007-01-03  Andrew John Hughes  <[EMAIL PROTECTED]>

        * java/text/BreakIterator.java:
        (getCharacterInstance(Locale)): Check providers.
        (getLineInstance(Locale)): Likewise.
        (getSentenceInstance(Locale)): Likewise.
        (getWordInstance(Locale)): Likewise.
        * java/text/spi/BreakIteratorProvider.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/BreakIterator.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/text/BreakIterator.java,v
retrieving revision 1.14
diff -u -3 -p -u -r1.14 BreakIterator.java
--- java/text/BreakIterator.java        21 Dec 2006 13:02:50 -0000      1.14
+++ java/text/BreakIterator.java        3 Jan 2007 22:27:55 -0000
@@ -1,5 +1,6 @@
 /* BreakIterator.java -- Breaks text into elements
-   Copyright (C) 1998, 1999, 2001, 2004, 2005  Free Software Foundation, Inc.
+   Copyright (C) 1998, 1999, 2001, 2004, 2005, 2007
+   Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -38,9 +39,19 @@ exception statement from your version. *
 
 package java.text;
 
+import gnu.java.locale.LocaleHelper;
+
+import gnu.java.text.CharacterBreakIterator;
+import gnu.java.text.LineBreakIterator;
+import gnu.java.text.SentenceBreakIterator;
+import gnu.java.text.WordBreakIterator;
+
+import java.text.spi.BreakIteratorProvider;
+
 import java.util.Locale;
 import java.util.MissingResourceException;
 import java.util.ResourceBundle;
+import java.util.ServiceLoader;
 
 /**
  * This class iterates over text elements such as words, lines, sentences,
@@ -179,19 +190,34 @@ public abstract class BreakIterator impl
 
   /**
    * This method returns an instance of <code>BreakIterator</code> that will
-   * iterate over characters as defined in the specified locale.  If the
-   * desired locale is not available, the default locale is used.
+   * iterate over characters as defined in the specified locale.
    *
    * @param locale The desired locale.
    *
-   * @return A <code>BreakIterator</code> instance for the default locale.
+   * @return A <code>BreakIterator</code> instance for the specified locale.
    */
   public static BreakIterator getCharacterInstance (Locale locale)
   {
-    BreakIterator r = getInstance ("CharacterIterator", locale);
-    if (r == null)
-      r = new gnu.java.text.CharacterBreakIterator ();
-    return r;
+    BreakIterator r = getInstance("CharacterIterator", locale);
+    if (r != null)
+      return r;
+    for (BreakIteratorProvider p :
+          ServiceLoader.load(BreakIteratorProvider.class))
+      {
+       for (Locale loc : p.getAvailableLocales())
+         {
+           if (loc.equals(locale))
+             {
+               BreakIterator bi = p.getCharacterInstance(locale);
+               if (bi != null)
+                 return bi;
+               break;
+             }
+         }
+      }
+    if (locale.equals(Locale.ROOT))
+      return new CharacterBreakIterator();
+    return getCharacterInstance(LocaleHelper.getFallbackLocale(locale));
   }
 
   /**
@@ -207,8 +233,7 @@ public abstract class BreakIterator impl
 
   /**
    * This method returns an instance of <code>BreakIterator</code> that will
-   * iterate over line breaks as defined in the specified locale.  If the
-   * desired locale is not available, the default locale is used.
+   * iterate over line breaks as defined in the specified locale.
    *
    * @param locale The desired locale.
    *
@@ -217,9 +242,25 @@ public abstract class BreakIterator impl
   public static BreakIterator getLineInstance (Locale locale)
   {
     BreakIterator r = getInstance ("LineIterator", locale);
-    if (r == null)
-      r = new gnu.java.text.LineBreakIterator ();
-    return r;
+    if (r != null)
+      return r;
+    for (BreakIteratorProvider p :
+          ServiceLoader.load(BreakIteratorProvider.class))
+      {
+       for (Locale loc : p.getAvailableLocales())
+         {
+           if (loc.equals(locale))
+             {
+               BreakIterator bi = p.getLineInstance(locale);
+               if (bi != null)
+                 return bi;
+               break;
+             }
+         }
+      }
+    if (locale.equals(Locale.ROOT))
+      return new LineBreakIterator();
+    return getLineInstance(LocaleHelper.getFallbackLocale(locale));
   }
 
   /**
@@ -235,8 +276,7 @@ public abstract class BreakIterator impl
 
   /**
    * This method returns an instance of <code>BreakIterator</code> that will
-   * iterate over sentences as defined in the specified locale.  If the
-   * desired locale is not available, the default locale is used.
+   * iterate over sentences as defined in the specified locale.
    *
    * @param locale The desired locale.
    *
@@ -245,9 +285,25 @@ public abstract class BreakIterator impl
   public static BreakIterator getSentenceInstance (Locale locale)
   {
     BreakIterator r = getInstance ("SentenceIterator", locale);
-    if (r == null)
-      r = new gnu.java.text.SentenceBreakIterator ();
-    return r;
+    if (r != null)
+      return r;
+    for (BreakIteratorProvider p :
+          ServiceLoader.load(BreakIteratorProvider.class))
+      {
+       for (Locale loc : p.getAvailableLocales())
+         {
+           if (loc.equals(locale))
+             {
+               BreakIterator bi = p.getSentenceInstance(locale);
+               if (bi != null)
+                 return bi;
+               break;
+             }
+         }
+      }
+    if (locale.equals(Locale.ROOT))
+      return new SentenceBreakIterator();
+    return getSentenceInstance(LocaleHelper.getFallbackLocale(locale));
   }
 
   /**
@@ -271,8 +327,7 @@ public abstract class BreakIterator impl
 
   /**
    * This method returns an instance of <code>BreakIterator</code> that will
-   * iterate over words as defined in the specified locale.  If the
-   * desired locale is not available, the default locale is used.
+   * iterate over words as defined in the specified locale.  
    *
    * @param locale The desired locale.
    *
@@ -281,9 +336,25 @@ public abstract class BreakIterator impl
   public static BreakIterator getWordInstance (Locale locale)
   {
     BreakIterator r = getInstance ("WordIterator", locale);
-    if (r == null)
-      r = new gnu.java.text.WordBreakIterator ();
-    return r;
+    if (r != null)
+      return r;
+    for (BreakIteratorProvider p :
+          ServiceLoader.load(BreakIteratorProvider.class))
+      {
+       for (Locale loc : p.getAvailableLocales())
+         {
+           if (loc.equals(locale))
+             {
+               BreakIterator bi = p.getWordInstance(locale);
+               if (bi != null)
+                 return bi;
+               break;
+             }
+         }
+      }
+    if (locale.equals(Locale.ROOT))
+      return new WordBreakIterator();
+    return getWordInstance(LocaleHelper.getFallbackLocale(locale));
   }
 
   /**
Index: java/text/spi/BreakIteratorProvider.java
===================================================================
RCS file: java/text/spi/BreakIteratorProvider.java
diff -N java/text/spi/BreakIteratorProvider.java
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ java/text/spi/BreakIteratorProvider.java    3 Jan 2007 22:27:55 -0000
@@ -0,0 +1,124 @@
+/* BreakIteratorProvider.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.BreakIterator;
+
+import java.util.Locale;
+
+import java.util.spi.LocaleServiceProvider;
+
+/**
+ * A [EMAIL PROTECTED] BreakIteratorProvider} provides localized
+ * instances of [EMAIL PROTECTED] java.text.BreakIterator}.
+ *
+ * @author Andrew John Hughes ([EMAIL PROTECTED])
+ * @since 1.6
+ */
+public abstract class BreakIteratorProvider
+  extends LocaleServiceProvider
+{
+
+  /**
+   * Constructs a new [EMAIL PROTECTED] BreakIteratorProvider}.
+   * Provided for implicit invocation by subclasses.
+   */
+  protected BreakIteratorProvider()
+  {
+  }
+
+  /**
+   * Returns a [EMAIL PROTECTED] java.text.BreakIterator} instance
+   * for character breaks in the specified
+   * [EMAIL PROTECTED] java.util.Locale}.
+   *
+   * @param locale the desired locale.
+   * @return the localized instance for character breaks.
+   * @throws NullPointerException if the locale is null.
+   * @throws IllegalArgumentException if the locale is not one
+   *                                  returned by
+   *                                  [EMAIL PROTECTED] getAvailableLocales()}
+   * @see java.text.BreakIterator#getCharacterInstance(java.util.Locale)
+   */
+  public abstract BreakIterator getCharacterInstance(Locale locale);
+
+  /**
+   * Returns a [EMAIL PROTECTED] java.text.BreakIterator} instance
+   * for line breaks in the specified [EMAIL PROTECTED] java.util.Locale}.
+   *
+   * @param locale the desired locale.
+   * @return the localized instance for line breaks.
+   * @throws NullPointerException if the locale is null.
+   * @throws IllegalArgumentException if the locale is not one
+   *                                  returned by
+   *                                  [EMAIL PROTECTED] getAvailableLocales()}
+   * @see java.text.BreakIterator#getLineInstance(java.util.Locale)
+   */
+  public abstract BreakIterator getLineInstance(Locale locale);
+
+  /**
+   * Returns a [EMAIL PROTECTED] java.text.BreakIterator} instance
+   * for sentence breaks in the specified
+   * [EMAIL PROTECTED] java.util.Locale}.
+   *
+   * @param locale the desired locale.
+   * @return the localized instance for sentence breaks.
+   * @throws NullPointerException if the locale is null.
+   * @throws IllegalArgumentException if the locale is not one
+   *                                  returned by
+   *                                  [EMAIL PROTECTED] getAvailableLocales()}
+   * @see java.text.BreakIterator#getSentenceInstance(java.util.Locale)
+   */
+  public abstract BreakIterator getSentenceInstance(Locale locale);
+
+  /**
+   * Returns a [EMAIL PROTECTED] java.text.BreakIterator} instance
+   * for word breaks in the specified
+   * [EMAIL PROTECTED] java.util.Locale}.
+   *
+   * @param locale the desired locale.
+   * @return the localized instance for word breaks.
+   * @throws NullPointerException if the locale is null.
+   * @throws IllegalArgumentException if the locale is not one
+   *                                  returned by
+   *                                  [EMAIL PROTECTED] getAvailableLocales()}
+   * @see java.text.BreakIterator#getWordInstance(java.util.Locale)
+   */
+  public abstract BreakIterator getWordInstance(Locale locale);
+
+}
Index: java/text/spi/DateFormatSymbolsProvider.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/java/text/spi/DateFormatSymbolsProvider.java,v
retrieving revision 1.1
diff -u -3 -p -u -r1.1 DateFormatSymbolsProvider.java
--- java/text/spi/DateFormatSymbolsProvider.java        3 Jan 2007 00:57:14 
-0000       1.1
+++ java/text/spi/DateFormatSymbolsProvider.java        3 Jan 2007 22:27:55 
-0000
@@ -1,4 +1,4 @@
-/* DateFormatSymbolsProvider.java -- Providers of localized currency symbols
+/* DateFormatSymbolsProvider.java -- Providers of localized instances
    Copyright (C) 2007 Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
Index: java/util/ServiceConfigurationError.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/java/util/ServiceConfigurationError.java,v
retrieving revision 1.1
diff -u -3 -p -u -r1.1 ServiceConfigurationError.java
--- java/util/ServiceConfigurationError.java    1 Jan 2007 20:27:37 -0000       
1.1
+++ java/util/ServiceConfigurationError.java    3 Jan 2007 22:27:55 -0000
@@ -59,6 +59,11 @@ public class ServiceConfigurationError
 {
   
   /**
+   * Compatible with JDK 1.6
+   */
+  private static final long serialVersionUID = 74132770414881L;
+
+  /**
    * Constructs a new [EMAIL PROTECTED] ServiceConfigurationError}
    * with the specified message.
    *

Attachment: signature.asc
Description: Digital signature

Reply via email to