jdk/src/share/classes/java/util/spi/LocaleServiceProvider.java
author naoto
Wed, 21 Jan 2009 13:58:46 -0800
changeset 1848 6ecbe9158c6e
parent 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
6627549: ISO 3166 code addition: Saint Barthelemy and Saint Martin 6786276: Locale.getISOCountries() still contains country code "CS" Reviewed-by: okutsu
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2005-2006 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.util.spi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.Locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * This is the super class of all the locale sensitive service provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * interfaces (SPIs).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * Locale sensitive  service provider interfaces are interfaces that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * correspond to locale sensitive classes in the <code>java.text</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * and <code>java.util</code> packages. The interfaces enable the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * construction of locale sensitive objects and the retrieval of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * localized names for these packages. Locale sensitive factory methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * and methods for name retrieval in the <code>java.text</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * <code>java.util</code> packages use implementations of the provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * interfaces to offer support for locales beyond the set of locales
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * supported by the Java runtime environment itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * <h4>Packaging of Locale Sensitive Service Provider Implementations</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * Implementations of these locale sensitive services are packaged using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * <a href="../../../../technotes/guides/extensions/index.html">Java Extension Mechanism</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * as installed extensions.  A provider identifies itself with a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * provider-configuration file in the resource directory META-INF/services,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * using the fully qualified provider interface class name as the file name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * The file should contain a list of fully-qualified concrete provider class names,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * one per line. A line is terminated by any one of a line feed ('\n'), a carriage
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * return ('\r'), or a carriage return followed immediately by a line feed. Space
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * and tab characters surrounding each name, as well as blank lines, are ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * The comment character is '#' ('\u0023'); on each line all characters following
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * the first comment character are ignored. The file must be encoded in UTF-8.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * If a particular concrete provider class is named in more than one configuration
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * file, or is named in the same configuration file more than once, then the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * duplicates will be ignored. The configuration file naming a particular provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * need not be in the same jar file or other distribution unit as the provider itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * The provider must be accessible from the same class loader that was initially
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * queried to locate the configuration file; this is not necessarily the class loader
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * that loaded the file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * For example, an implementation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * {@link java.text.spi.DateFormatProvider DateFormatProvider} class should
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * take the form of a jar file which contains the file:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * META-INF/services/java.text.spi.DateFormatProvider
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * And the file <code>java.text.spi.DateFormatProvider</code> should have
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * a line such as:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * <code>com.foo.DateFormatProviderImpl</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * which is the fully qualified class name of the class implementing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * <code>DateFormatProvider</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * <h4>Invocation of Locale Sensitive Services</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * Locale sensitive factory methods and methods for name retrieval in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * <code>java.text</code> and <code>java.util</code> packages invoke
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * service provider methods when needed to support the requested locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * The methods first check whether the Java runtime environment itself
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * supports the requested locale, and use its support if available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * Otherwise, they call the <code>getAvailableLocales()</code> methods of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * installed providers for the appropriate interface to find one that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * supports the requested locale. If such a provider is found, its other
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * methods are called to obtain the requested object or name. If neither
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * the Java runtime environment itself nor an installed provider supports
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * the requested locale, a fallback locale is constructed by replacing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * first of the variant, country, or language strings of the locale that's
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * not an empty string with an empty string, and the lookup process is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * restarted. In the case that the variant contains one or more '_'s, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * fallback locale is constructed by replacing the variant with a new variant
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * which eliminates the last '_' and the part following it.  Even if a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * fallback occurs, methods that return requested objects or name are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * invoked with the original locale before the fallback.The Java runtime
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * environment must support the root locale for all locale sensitive services
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * in order to guarantee that this process terminates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * Providers of names (but not providers of other objects) are allowed to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 * return null for some name requests even for locales that they claim to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 * support by including them in their return value for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 * <code>getAvailableLocales</code>. Similarly, the Java runtime
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 * environment itself may not have all names for all locales that it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 * supports. This is because the sets of objects for which names are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 * requested can be large and vary over time, so that it's not always
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 * feasible to cover them completely. If the Java runtime environment or a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 * provider returns null instead of a name, the lookup will proceed as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 * described above as if the locale was not supported.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 * @since        1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
public abstract class LocaleServiceProvider {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * Sole constructor.  (For invocation by subclass constructors, typically
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * implicit.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    protected LocaleServiceProvider() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * Returns an array of all locales for which this locale service provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * can provide localized objects or names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * @return An array of all locales for which this locale service provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * can provide localized objects or names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    public abstract Locale[] getAvailableLocales();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
}