Source for java.util.spi.LocaleServiceProvider

   1: /* LocaleServiceProvider.java -- Superclass of locale SPIs
   2:    Copyright (C) 2007 Free Software Foundation, Inc.
   3: 
   4: This file is part of GNU Classpath.
   5: 
   6: GNU Classpath is free software; you can redistribute it and/or modify
   7: it under the terms of the GNU General Public License as published by
   8: the Free Software Foundation; either version 2, or (at your option)
   9: any later version.
  10: 
  11: GNU Classpath is distributed in the hope that it will be useful, but
  12: WITHOUT ANY WARRANTY; without even the implied warranty of
  13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14: General Public License for more details.
  15: 
  16: You should have received a copy of the GNU General Public License
  17: along with GNU Classpath; see the file COPYING.  If not, write to the
  18: Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  19: 02110-1301 USA.
  20: 
  21: Linking this library statically or dynamically with other modules is
  22: making a combined work based on this library.  Thus, the terms and
  23: conditions of the GNU General Public License cover the whole
  24: combination.
  25: 
  26: As a special exception, the copyright holders of this library give you
  27: permission to link this library with independent modules to produce an
  28: executable, regardless of the license terms of these independent
  29: modules, and to copy and distribute the resulting executable under
  30: terms of your choice, provided that you also meet, for each linked
  31: independent module, the terms and conditions of the license of that
  32: module.  An independent module is a module which is not derived from
  33: or based on this library.  If you modify this library, you may extend
  34: this exception to your version of the library, but you are not
  35: obligated to do so.  If you do not wish to do so, delete this
  36: exception statement from your version. */
  37: 
  38: package java.util.spi;
  39: 
  40: import java.util.Locale;
  41: 
  42: /**
  43:  * <p>
  44:  * This is the superclass of all the {@link Locale} service
  45:  * provider interfaces or SPIs.  The locale SPIs are used
  46:  * to allow for the provision of additional support for
  47:  * locale-specific data.  The runtime environment has its
  48:  * own collection of locale data, but these interfaces allow
  49:  * this to be extended by external classes.
  50:  * </p>
  51:  * <p>
  52:  * Service providers are created as concrete implementations
  53:  * of these interfaces, and accessed using the extension
  54:  * mechanism, realised by {@link ServiceLoader}.  When a factory
  55:  * method of one of the locale-specific classes (such as
  56:  * {@link java.text.DateFormatSymbols} or {@link java.util.Currency})
  57:  * is called, the runtime environment is first asked to
  58:  * provide data for the specified locale.  If the runtime
  59:  * environment fails to provide this, then the offer is
  60:  * made to service providers which implement the appropriate
  61:  * interface.
  62:  * </p>
  63:  * <p>
  64:  * Each provider implements the method specified by this
  65:  * class, {@link #getAvailableLocales()}.  This method is
  66:  * called first to determine whether the provider will be of
  67:  * any use in providing data for the specified locale.  If
  68:  * a provider is found to be capable, then a more specific
  69:  * method appropriate to the class requiring the data will
  70:  * be called.  In the case of {@link java.text.DateFormatSymbols},
  71:  * this would be
  72:  * {@link java.text.spi.DateFormatSymbols#getInstance(Locale)}.
  73:  * </p>
  74:  * <p>
  75:  * If neither a service provider nor the runtime environment
  76:  * itself can fulfill the request, a fallback procedure is
  77:  * engaged.  The locale is modified by applying the first
  78:  * applicable rule:
  79:  * </p>
  80:  * <ol>
  81:  * <li>If the variant contains a <code>'_'</code>, then
  82:  * this and everything following it is trimmed.</li>
  83:  * <li>If the variant is non-empty, it is converted to
  84:  * an empty string.</li>
  85:  * <li>If the country is non-empty, it is converted to
  86:  * an empty string.</li>
  87:  * <li>If the language is non-empty, it is converted to
  88:  * an empty string.</li>
  89:  * </ol>
  90:  * <p>
  91:  * The modified locale is then used to start the same
  92:  * process again.  The root locale (@link java.util.Locale#ROOT}
  93:  * must be supported by the runtime environment in order
  94:  * to terminate this cycle.
  95:  * </p>
  96:  * <p>
  97:  * Note that any names returned by the providers may
  98:  * be <code>null</code>.  Returning a <code>null</code>
  99:  * name is considered equivalent to not supporting a
 100:  * particular locale.
 101:  * </p>
 102:  *
 103:  * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
 104:  * @since 1.6
 105:  */
 106: public abstract class LocaleServiceProvider
 107: {
 108: 
 109:   /**
 110:    * Constructs a new {@link LocaleServiceProvider}.
 111:    * Provided for implicit invocation by subclasses.
 112:    */
 113:   protected LocaleServiceProvider()
 114:   {
 115:   }
 116: 
 117:   /**
 118:    * Returns an array of {@link Locale} instances,
 119:    * for which the provider can supply localized data.
 120:    *
 121:    * @return an array of supported locales.
 122:    */
 123:   public abstract Locale[] getAvailableLocales();
 124: 
 125: }