001 /* LocaleServiceProvider.java -- Superclass of locale SPIs 002 Copyright (C) 2007 Free Software Foundation, Inc. 003 004 This file is part of GNU Classpath. 005 006 GNU Classpath is free software; you can redistribute it and/or modify 007 it under the terms of the GNU General Public License as published by 008 the Free Software Foundation; either version 2, or (at your option) 009 any later version. 010 011 GNU Classpath is distributed in the hope that it will be useful, but 012 WITHOUT ANY WARRANTY; without even the implied warranty of 013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 General Public License for more details. 015 016 You should have received a copy of the GNU General Public License 017 along with GNU Classpath; see the file COPYING. If not, write to the 018 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 019 02110-1301 USA. 020 021 Linking this library statically or dynamically with other modules is 022 making a combined work based on this library. Thus, the terms and 023 conditions of the GNU General Public License cover the whole 024 combination. 025 026 As a special exception, the copyright holders of this library give you 027 permission to link this library with independent modules to produce an 028 executable, regardless of the license terms of these independent 029 modules, and to copy and distribute the resulting executable under 030 terms of your choice, provided that you also meet, for each linked 031 independent module, the terms and conditions of the license of that 032 module. An independent module is a module which is not derived from 033 or based on this library. If you modify this library, you may extend 034 this exception to your version of the library, but you are not 035 obligated to do so. If you do not wish to do so, delete this 036 exception statement from your version. */ 037 038 package java.util.spi; 039 040 import java.util.Locale; 041 042 /** 043 * <p> 044 * This is the superclass of all the {@link Locale} service 045 * provider interfaces or SPIs. The locale SPIs are used 046 * to allow for the provision of additional support for 047 * locale-specific data. The runtime environment has its 048 * own collection of locale data, but these interfaces allow 049 * this to be extended by external classes. 050 * </p> 051 * <p> 052 * Service providers are created as concrete implementations 053 * of these interfaces, and accessed using the extension 054 * mechanism, realised by {@link ServiceLoader}. When a factory 055 * method of one of the locale-specific classes (such as 056 * {@link java.text.DateFormatSymbols} or {@link java.util.Currency}) 057 * is called, the runtime environment is first asked to 058 * provide data for the specified locale. If the runtime 059 * environment fails to provide this, then the offer is 060 * made to service providers which implement the appropriate 061 * interface. 062 * </p> 063 * <p> 064 * Each provider implements the method specified by this 065 * class, {@link #getAvailableLocales()}. This method is 066 * called first to determine whether the provider will be of 067 * any use in providing data for the specified locale. If 068 * a provider is found to be capable, then a more specific 069 * method appropriate to the class requiring the data will 070 * be called. In the case of {@link java.text.DateFormatSymbols}, 071 * this would be 072 * {@link java.text.spi.DateFormatSymbols#getInstance(Locale)}. 073 * </p> 074 * <p> 075 * If neither a service provider nor the runtime environment 076 * itself can fulfill the request, a fallback procedure is 077 * engaged. The locale is modified by applying the first 078 * applicable rule: 079 * </p> 080 * <ol> 081 * <li>If the variant contains a <code>'_'</code>, then 082 * this and everything following it is trimmed.</li> 083 * <li>If the variant is non-empty, it is converted to 084 * an empty string.</li> 085 * <li>If the country is non-empty, it is converted to 086 * an empty string.</li> 087 * <li>If the language is non-empty, it is converted to 088 * an empty string.</li> 089 * </ol> 090 * <p> 091 * The modified locale is then used to start the same 092 * process again. The root locale (@link java.util.Locale#ROOT} 093 * must be supported by the runtime environment in order 094 * to terminate this cycle. 095 * </p> 096 * <p> 097 * Note that any names returned by the providers may 098 * be <code>null</code>. Returning a <code>null</code> 099 * 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 }