src/java.base/share/classes/java/util/spi/LocaleServiceProvider.java
author rpatil
Wed, 26 Dec 2018 17:09:19 +0530
changeset 53120 de9fd809bb47
parent 47216 71c04702a3d5
child 54206 003cc64366da
permissions -rw-r--r--
8214567: Use {@systemProperty} for definitions of system properties 8214569: Use {@systemProperty} for definitions of system properties Reviewed-by: lancea, mchung, alanb, naoto Contributed-by: Deepak kejriwal <deepak.kejriwal@oracle.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
30047
63b6a16968d5 8075545: Add permission check for locale service provider implementations
naoto
parents: 28093
diff changeset
     2
 * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
2
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
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
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
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
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.
21334
c60dfce46a77 8026982: javadoc errors in core libs
rriggs
parents: 18590
diff changeset
    44
 *
18590
db282abf47f9 8019529: Fix doclint issues in java.util.spi
darcy
parents: 18544
diff changeset
    45
 * <h3>Packaging of Locale Sensitive Service Provider Implementations</h3>
28093
270b6925cbc8 8062588: Support java.util.spi.*, java.text.spi.*, java.awt.im.spi loaded from classpath
naoto
parents: 25859
diff changeset
    46
 * Implementations of these locale sensitive services can be made available
270b6925cbc8 8062588: Support java.util.spi.*, java.text.spi.*, java.awt.im.spi loaded from classpath
naoto
parents: 25859
diff changeset
    47
 * by adding them to the application's class path. A provider identifies itself with a
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * provider-configuration file in the resource directory META-INF/services,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * using the fully qualified provider interface class name as the file name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * The file should contain a list of fully-qualified concrete provider class names,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * one per line. A line is terminated by any one of a line feed ('\n'), a carriage
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * return ('\r'), or a carriage return followed immediately by a line feed. Space
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * and tab characters surrounding each name, as well as blank lines, are ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * The comment character is '#' ('\u0023'); on each line all characters following
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * the first comment character are ignored. The file must be encoded in UTF-8.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * If a particular concrete provider class is named in more than one configuration
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * file, or is named in the same configuration file more than once, then the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * duplicates will be ignored. The configuration file naming a particular provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * need not be in the same jar file or other distribution unit as the provider itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * The provider must be accessible from the same class loader that was initially
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * queried to locate the configuration file; this is not necessarily the class loader
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * that loaded the file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * For example, an implementation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * {@link java.text.spi.DateFormatProvider DateFormatProvider} class should
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * take the form of a jar file which contains the file:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * META-INF/services/java.text.spi.DateFormatProvider
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * And the file <code>java.text.spi.DateFormatProvider</code> should have
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * a line such as:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * <code>com.foo.DateFormatProviderImpl</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * which is the fully qualified class name of the class implementing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * <code>DateFormatProvider</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * <h4>Invocation of Locale Sensitive Services</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * Locale sensitive factory methods and methods for name retrieval in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * <code>java.text</code> and <code>java.util</code> packages invoke
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * service provider methods when needed to support the requested locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * The methods first check whether the Java runtime environment itself
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * supports the requested locale, and use its support if available.
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
    85
 * Otherwise, they call the {@link #isSupportedLocale(Locale) isSupportedLocale}
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
    86
 * methods of installed providers for the appropriate interface to find one that
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * supports the requested locale. If such a provider is found, its other
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents: 5506
diff changeset
    88
 * methods are called to obtain the requested object or name.  When checking
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
    89
 * whether a locale is supported, the <a href="../Locale.html#def_extensions">
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
    90
 * locale's extensions</a> are ignored by default. (If locale's extensions should
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
    91
 * also be checked, the {@code isSupportedLocale} method must be overridden.)
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents: 5506
diff changeset
    92
 * If neither the Java runtime environment itself nor an installed provider
684810d882b3 6875847: Java Locale Enhancement
naoto
parents: 5506
diff changeset
    93
 * supports the requested locale, the methods go through a list of candidate
684810d882b3 6875847: Java Locale Enhancement
naoto
parents: 5506
diff changeset
    94
 * locales and repeat the availability check for each until a match is found.
684810d882b3 6875847: Java Locale Enhancement
naoto
parents: 5506
diff changeset
    95
 * The algorithm used for creating a list of candidate locales is same as
18544
54c23f2cc3a5 8017468: typo in javadoc: " ResourceBunlde "
naoto
parents: 17944
diff changeset
    96
 * the one used by <code>ResourceBundle</code> by default (see
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents: 5506
diff changeset
    97
 * {@link java.util.ResourceBundle.Control#getCandidateLocales getCandidateLocales}
684810d882b3 6875847: Java Locale Enhancement
naoto
parents: 5506
diff changeset
    98
 * for the details).  Even if a locale is resolved from the candidate list,
684810d882b3 6875847: Java Locale Enhancement
naoto
parents: 5506
diff changeset
    99
 * methods that return requested objects or names are invoked with the original
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
   100
 * requested locale including {@code Locale} extensions. The Java runtime
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
   101
 * environment must support the root locale for all locale sensitive services in
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
   102
 * order to guarantee that this process terminates.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 * Providers of names (but not providers of other objects) are allowed to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 * return null for some name requests even for locales that they claim to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 * support by including them in their return value for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 * <code>getAvailableLocales</code>. Similarly, the Java runtime
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 * environment itself may not have all names for all locales that it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 * supports. This is because the sets of objects for which names are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 * requested can be large and vary over time, so that it's not always
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 * feasible to cover them completely. If the Java runtime environment or a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 * provider returns null instead of a name, the lookup will proceed as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 * described above as if the locale was not supported.
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
   114
 * <p>
31263
a81a0af34ca0 8008577: Use CLDR Locale Data by Default
naoto
parents: 30047
diff changeset
   115
 * The search order of locale sensitive services can
53120
de9fd809bb47 8214567: Use {@systemProperty} for definitions of system properties
rpatil
parents: 47216
diff changeset
   116
 * be configured by using the {@systemProperty java.locale.providers} system property.
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
   117
 * This system property declares the user's preferred order for looking up
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
   118
 * the locale sensitive services separated by a comma. It is only read at
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
   119
 * the Java runtime startup, so the later call to System.setProperty() won't
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
   120
 * affect the order.
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
   121
 * <p>
31263
a81a0af34ca0 8008577: Use CLDR Locale Data by Default
naoto
parents: 30047
diff changeset
   122
 * Java Runtime Environment provides the following four locale providers:
a81a0af34ca0 8008577: Use CLDR Locale Data by Default
naoto
parents: 30047
diff changeset
   123
 * <ul>
a81a0af34ca0 8008577: Use CLDR Locale Data by Default
naoto
parents: 30047
diff changeset
   124
 * <li> "CLDR": A provider based on Unicode Consortium's
a81a0af34ca0 8008577: Use CLDR Locale Data by Default
naoto
parents: 30047
diff changeset
   125
 * <a href="http://cldr.unicode.org/">CLDR Project</a>.
33494
3429cce32839 8062006: Add a new locale data name "COMPAT" for java.locale.providers system property to reduce ambiguity
naoto
parents: 32854
diff changeset
   126
 * <li> "COMPAT": represents the locale sensitive services that is compatible
3429cce32839 8062006: Add a new locale data name "COMPAT" for java.locale.providers system property to reduce ambiguity
naoto
parents: 32854
diff changeset
   127
 * with the prior JDK releases up to JDK8 (same as JDK8's "JRE").
31263
a81a0af34ca0 8008577: Use CLDR Locale Data by Default
naoto
parents: 30047
diff changeset
   128
 * <li> "SPI": represents the locale sensitive services implementing the subclasses of
a81a0af34ca0 8008577: Use CLDR Locale Data by Default
naoto
parents: 30047
diff changeset
   129
 * this {@code LocaleServiceProvider} class.
a81a0af34ca0 8008577: Use CLDR Locale Data by Default
naoto
parents: 30047
diff changeset
   130
 * <li> "HOST": A provider that reflects the user's custom settings in the
a81a0af34ca0 8008577: Use CLDR Locale Data by Default
naoto
parents: 30047
diff changeset
   131
 * underlying operating system. This provider may not be available, depending
a81a0af34ca0 8008577: Use CLDR Locale Data by Default
naoto
parents: 30047
diff changeset
   132
 * on the Java Runtime Environment implementation.
33494
3429cce32839 8062006: Add a new locale data name "COMPAT" for java.locale.providers system property to reduce ambiguity
naoto
parents: 32854
diff changeset
   133
 * <li> "JRE": represents a synonym to "COMPAT". This name
3429cce32839 8062006: Add a new locale data name "COMPAT" for java.locale.providers system property to reduce ambiguity
naoto
parents: 32854
diff changeset
   134
 * is deprecated and will be removed in the future release of JDK.
31263
a81a0af34ca0 8008577: Use CLDR Locale Data by Default
naoto
parents: 30047
diff changeset
   135
 * </ul>
a81a0af34ca0 8008577: Use CLDR Locale Data by Default
naoto
parents: 30047
diff changeset
   136
 * <p>
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
   137
 * For example, if the following is specified in the property:
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
   138
 * <pre>
33494
3429cce32839 8062006: Add a new locale data name "COMPAT" for java.locale.providers system property to reduce ambiguity
naoto
parents: 32854
diff changeset
   139
 * java.locale.providers=SPI,CLDR,COMPAT
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
   140
 * </pre>
31263
a81a0af34ca0 8008577: Use CLDR Locale Data by Default
naoto
parents: 30047
diff changeset
   141
 * the locale sensitive services in the SPI providers are looked up first. If the
a81a0af34ca0 8008577: Use CLDR Locale Data by Default
naoto
parents: 30047
diff changeset
   142
 * desired locale sensitive service is not available, then the runtime looks for CLDR,
33494
3429cce32839 8062006: Add a new locale data name "COMPAT" for java.locale.providers system property to reduce ambiguity
naoto
parents: 32854
diff changeset
   143
 * COMPAT in that order.
17944
bbd67fc49daa 8013903: Japanese calendar field names are not displayed with -Djava.locale.providers=HOST on Windows
naoto
parents: 13583
diff changeset
   144
 * <p>
33494
3429cce32839 8062006: Add a new locale data name "COMPAT" for java.locale.providers system property to reduce ambiguity
naoto
parents: 32854
diff changeset
   145
 * The default order for looking up the preferred locale providers is "CLDR,COMPAT",
3429cce32839 8062006: Add a new locale data name "COMPAT" for java.locale.providers system property to reduce ambiguity
naoto
parents: 32854
diff changeset
   146
 * so specifying "CLDR,COMPAT" is identical to the default behavior. Applications which
32854
f29975c5b3c1 8138613: Remove SPI locale provider adapter from the default provider list
naoto
parents: 31263
diff changeset
   147
 * require implementations of the locale sensitive services must explicitly specify
f29975c5b3c1 8138613: Remove SPI locale provider adapter from the default provider list
naoto
parents: 31263
diff changeset
   148
 * "SPI" in order for the Java runtime to load them from the classpath.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
 * @since        1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
public abstract class LocaleServiceProvider {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
30047
63b6a16968d5 8075545: Add permission check for locale service provider implementations
naoto
parents: 28093
diff changeset
   154
    private static Void checkPermission() {
63b6a16968d5 8075545: Add permission check for locale service provider implementations
naoto
parents: 28093
diff changeset
   155
        SecurityManager sm = System.getSecurityManager();
63b6a16968d5 8075545: Add permission check for locale service provider implementations
naoto
parents: 28093
diff changeset
   156
        if (sm != null) {
63b6a16968d5 8075545: Add permission check for locale service provider implementations
naoto
parents: 28093
diff changeset
   157
            sm.checkPermission(new RuntimePermission("localeServiceProvider"));
63b6a16968d5 8075545: Add permission check for locale service provider implementations
naoto
parents: 28093
diff changeset
   158
        }
63b6a16968d5 8075545: Add permission check for locale service provider implementations
naoto
parents: 28093
diff changeset
   159
        return null;
63b6a16968d5 8075545: Add permission check for locale service provider implementations
naoto
parents: 28093
diff changeset
   160
    }
63b6a16968d5 8075545: Add permission check for locale service provider implementations
naoto
parents: 28093
diff changeset
   161
    private LocaleServiceProvider(Void ignore) { }
63b6a16968d5 8075545: Add permission check for locale service provider implementations
naoto
parents: 28093
diff changeset
   162
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    /**
30047
63b6a16968d5 8075545: Add permission check for locale service provider implementations
naoto
parents: 28093
diff changeset
   164
     * Initializes a new locale service provider.
63b6a16968d5 8075545: Add permission check for locale service provider implementations
naoto
parents: 28093
diff changeset
   165
     *
63b6a16968d5 8075545: Add permission check for locale service provider implementations
naoto
parents: 28093
diff changeset
   166
     * @throws  SecurityException
63b6a16968d5 8075545: Add permission check for locale service provider implementations
naoto
parents: 28093
diff changeset
   167
     *          If a security manager has been installed and it denies
63b6a16968d5 8075545: Add permission check for locale service provider implementations
naoto
parents: 28093
diff changeset
   168
     *          {@link RuntimePermission RuntimePermission("localeServiceProvider")}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    protected LocaleServiceProvider() {
30047
63b6a16968d5 8075545: Add permission check for locale service provider implementations
naoto
parents: 28093
diff changeset
   171
        this(checkPermission());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * Returns an array of all locales for which this locale service provider
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
   176
     * can provide localized objects or names. This information is used to
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
   177
     * compose {@code getAvailableLocales()} values of the locale-dependent
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
   178
     * services, such as {@code DateFormat.getAvailableLocales()}.
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
   179
     *
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
   180
     * <p>The array returned by this method should not include two or more
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
   181
     * {@code Locale} objects only differing in their extensions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * @return An array of all locales for which this locale service provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * can provide localized objects or names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    public abstract Locale[] getAvailableLocales();
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
   187
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
   188
    /**
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
   189
     * Returns {@code true} if the given {@code locale} is supported by
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
   190
     * this locale service provider. The given {@code locale} may contain
18590
db282abf47f9 8019529: Fix doclint issues in java.util.spi
darcy
parents: 18544
diff changeset
   191
     * <a href="../Locale.html#def_extensions">extensions</a> that should be
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
   192
     * taken into account for the support determination.
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
   193
     *
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
   194
     * <p>The default implementation returns {@code true} if the given {@code locale}
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
   195
     * is equal to any of the available {@code Locale}s returned by
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
   196
     * {@link #getAvailableLocales()} with ignoring any extensions in both the
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
   197
     * given {@code locale} and the available locales. Concrete locale service
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
   198
     * provider implementations should override this method if those
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
   199
     * implementations are {@code Locale} extensions-aware. For example,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
   200
     * {@code DecimalFormatSymbolsProvider} implementations will need to check
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
   201
     * extensions in the given {@code locale} to see if any numbering system is
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
   202
     * specified and can be supported. However, {@code CollatorProvider}
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
   203
     * implementations may not be affected by any particular numbering systems,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
   204
     * and in that case, extensions for numbering systems should be ignored.
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
   205
     *
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
   206
     * @param locale a {@code Locale} to be tested
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
   207
     * @return {@code true} if the given {@code locale} is supported by this
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
   208
     *         provider; {@code false} otherwise.
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
   209
     * @throws NullPointerException
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
   210
     *         if the given {@code locale} is {@code null}
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
   211
     * @see Locale#hasExtensions()
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
   212
     * @see Locale#stripExtensions()
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
   213
     * @since 1.8
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
   214
     */
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
   215
    public boolean isSupportedLocale(Locale locale) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
   216
        locale = locale.stripExtensions(); // throws NPE if locale == null
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
   217
        for (Locale available : getAvailableLocales()) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
   218
            if (locale.equals(available.stripExtensions())) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
   219
                return true;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
}
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
   221
        }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
   222
        return false;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
   223
    }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
   224
}