001 /*
002 * Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation. Sun designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Sun in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022 * CA 95054 USA or visit www.sun.com if you need additional information or
023 * have any questions.
024 */
025
026 package java.util.spi;
027
028 import java.util.Locale;
029
030 /**
031 * <p>
032 * This is the super class of all the locale sensitive service provider
033 * interfaces (SPIs).
034 * <p>
035 * Locale sensitive service provider interfaces are interfaces that
036 * correspond to locale sensitive classes in the <code>java.text</code>
037 * and <code>java.util</code> packages. The interfaces enable the
038 * construction of locale sensitive objects and the retrieval of
039 * localized names for these packages. Locale sensitive factory methods
040 * and methods for name retrieval in the <code>java.text</code> and
041 * <code>java.util</code> packages use implementations of the provider
042 * interfaces to offer support for locales beyond the set of locales
043 * supported by the Java runtime environment itself.
044 * <p>
045 * <h4>Packaging of Locale Sensitive Service Provider Implementations</h4>
046 * Implementations of these locale sensitive services are packaged using the
047 * <a href="../../../../technotes/guides/extensions/index.html">Java Extension Mechanism</a>
048 * as installed extensions. A provider identifies itself with a
049 * provider-configuration file in the resource directory META-INF/services,
050 * using the fully qualified provider interface class name as the file name.
051 * The file should contain a list of fully-qualified concrete provider class names,
052 * one per line. A line is terminated by any one of a line feed ('\n'), a carriage
053 * return ('\r'), or a carriage return followed immediately by a line feed. Space
054 * and tab characters surrounding each name, as well as blank lines, are ignored.
055 * The comment character is '#' ('\u0023'); on each line all characters following
056 * the first comment character are ignored. The file must be encoded in UTF-8.
057 * <p>
058 * If a particular concrete provider class is named in more than one configuration
059 * file, or is named in the same configuration file more than once, then the
060 * duplicates will be ignored. The configuration file naming a particular provider
061 * need not be in the same jar file or other distribution unit as the provider itself.
062 * The provider must be accessible from the same class loader that was initially
063 * queried to locate the configuration file; this is not necessarily the class loader
064 * that loaded the file.
065 * <p>
066 * For example, an implementation of the
067 * {@link java.text.spi.DateFormatProvider DateFormatProvider} class should
068 * take the form of a jar file which contains the file:
069 * <pre>
070 * META-INF/services/java.text.spi.DateFormatProvider
071 * </pre>
072 * And the file <code>java.text.spi.DateFormatProvider</code> should have
073 * a line such as:
074 * <pre>
075 * <code>com.foo.DateFormatProviderImpl</code>
076 * </pre>
077 * which is the fully qualified class name of the class implementing
078 * <code>DateFormatProvider</code>.
079 * <h4>Invocation of Locale Sensitive Services</h4>
080 * <p>
081 * Locale sensitive factory methods and methods for name retrieval in the
082 * <code>java.text</code> and <code>java.util</code> packages invoke
083 * service provider methods when needed to support the requested locale.
084 * The methods first check whether the Java runtime environment itself
085 * supports the requested locale, and use its support if available.
086 * Otherwise, they call the <code>getAvailableLocales()</code> methods of
087 * installed providers for the appropriate interface to find one that
088 * supports the requested locale. If such a provider is found, its other
089 * methods are called to obtain the requested object or name. If neither
090 * the Java runtime environment itself nor an installed provider supports
091 * the requested locale, a fallback locale is constructed by replacing the
092 * first of the variant, country, or language strings of the locale that's
093 * not an empty string with an empty string, and the lookup process is
094 * restarted. In the case that the variant contains one or more '_'s, the
095 * fallback locale is constructed by replacing the variant with a new variant
096 * which eliminates the last '_' and the part following it. Even if a
097 * fallback occurs, methods that return requested objects or name are
098 * invoked with the original locale before the fallback.The Java runtime
099 * environment must support the root locale for all locale sensitive services
100 * in order to guarantee that this process terminates.
101 * <p>
102 * Providers of names (but not providers of other objects) are allowed to
103 * return null for some name requests even for locales that they claim to
104 * support by including them in their return value for
105 * <code>getAvailableLocales</code>. Similarly, the Java runtime
106 * environment itself may not have all names for all locales that it
107 * supports. This is because the sets of objects for which names are
108 * requested can be large and vary over time, so that it's not always
109 * feasible to cover them completely. If the Java runtime environment or a
110 * provider returns null instead of a name, the lookup will proceed as
111 * described above as if the locale was not supported.
112 *
113 * @since 1.6
114 * @version @(#)LocaleServiceProvider.java 1.10 07/05/05
115 */
116 public abstract class LocaleServiceProvider {
117
118 /**
119 * Sole constructor. (For invocation by subclass constructors, typically
120 * implicit.)
121 */
122 protected LocaleServiceProvider() {
123 }
124
125 /**
126 * Returns an array of all locales for which this locale service provider
127 * can provide localized objects or names.
128 *
129 * @return An array of all locales for which this locale service provider
130 * can provide localized objects or names.
131 */
132 public abstract Locale[] getAvailableLocales();
133 }
|