Print this page
rev 6057 : imported patch 8001205.8001562

Split Close
Expand all
Collapse all
          --- old/src/share/classes/sun/util/locale/provider/LocaleServiceProviderPool.java
          +++ new/src/share/classes/sun/util/locale/provider/LocaleServiceProviderPool.java
↓ open down ↓ 18 lines elided ↑ open up ↑
  19   19   * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20   20   *
  21   21   * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22   22   * or visit www.oracle.com if you need additional information or have any
  23   23   * questions.
  24   24   */
  25   25  
  26   26  package sun.util.locale.provider;
  27   27  
  28   28  import java.util.ArrayList;
       29 +import java.util.Arrays;
  29   30  import java.util.Collections;
  30   31  import java.util.HashSet;
  31   32  import java.util.IllformedLocaleException;
  32   33  import java.util.List;
  33   34  import java.util.Locale;
  34   35  import java.util.Locale.Builder;
  35   36  import java.util.ResourceBundle.Control;
  36   37  import java.util.Set;
  37   38  import java.util.concurrent.ConcurrentHashMap;
  38   39  import java.util.concurrent.ConcurrentMap;
↓ open down ↓ 131 lines elided ↑ open up ↑
 170  171           * Available locales for all locale sensitive services.
 171  172           * This also contains JRE's available locales
 172  173           */
 173  174          static final Locale[] allAvailableLocales;
 174  175  
 175  176          static {
 176  177              Set<Locale> all = new HashSet<>();
 177  178              for (Class<? extends LocaleServiceProvider> c : spiClasses) {
 178  179                  LocaleServiceProviderPool pool =
 179  180                      LocaleServiceProviderPool.getPool(c);
 180      -                all.addAll(pool.getAvailableLocaleList());
      181 +                all.addAll(pool.getAvailableLocaleSet());
 181  182              }
 182  183  
 183  184              allAvailableLocales = all.toArray(new Locale[0]);
 184  185          }
 185  186  
 186  187          // No instantiation
 187  188          private AllAvailableLocales() {
 188  189          }
 189  190      }
 190  191  
↓ open down ↓ 4 lines elided ↑ open up ↑
 195  196       *
 196  197       * @return an array of the available locales for all provider classes
 197  198       */
 198  199      public static Locale[] getAllAvailableLocales() {
 199  200          return AllAvailableLocales.allAvailableLocales.clone();
 200  201      }
 201  202  
 202  203      /**
 203  204       * Returns an array of available locales.  This array is a
 204  205       * merged array of all the locales that are provided by each
 205      -     * provider, including the JRE.
      206 +     * provider, including the JRE's FormatData locales.
 206  207       *
 207  208       * @return an array of the available locales
 208  209       */
 209  210      public Locale[] getAvailableLocales() {
 210      -        Set<Locale> locList = getAvailableLocaleList();
      211 +        Set<Locale> locList = new HashSet<>();
      212 +        locList.addAll(getAvailableLocaleSet());
      213 +        // Make sure it all contains JRE's FormatData locales for compatibility.
      214 +        locList.addAll(Arrays.asList(LocaleProviderAdapter.forJRE().getAvailableLocales()));
 211  215          Locale[] tmp = new Locale[locList.size()];
 212  216          locList.toArray(tmp);
 213  217          return tmp;
 214  218      }
 215  219  
 216      -    private synchronized Set<Locale> getAvailableLocaleList() {
      220 +    /**
      221 +     * Returns the union of locale sets that are available from
      222 +     * each service provider. This method does NOT return the
      223 +     * defensive copy.
      224 +     *
      225 +     * @return a set of available locales
      226 +     */
      227 +    private synchronized Set<Locale> getAvailableLocaleSet() {
 217  228          if (availableLocales == null) {
 218  229              availableLocales = new HashSet<>();
 219  230              for (LocaleServiceProvider lsp : providers.values()) {
 220  231                  Locale[] locales = lsp.getAvailableLocales();
 221  232                  for (Locale locale: locales) {
 222  233                      availableLocales.add(getLookupLocale(locale));
 223  234                  }
 224  235              }
 225      -
 226      -            // Remove Locale.ROOT for the compatibility.
 227      -            availableLocales.remove(Locale.ROOT);
 228  236          }
 229  237  
 230  238          return availableLocales;
 231  239      }
 232  240  
 233  241      /**
 234  242       * Returns whether any provider for this locale sensitive
 235  243       * service is available or not, excluding JRE's one.
 236  244       *
 237  245       * @return true if any provider (other than JRE) is available
↓ open down ↓ 50 lines elided ↑ open up ↑
 288  296          // Check whether JRE is the sole locale data provider or not,
 289  297          // and directly call it if it is.
 290  298          if (!hasProviders()) {
 291  299              return getter.getObject(
 292  300                  (P)providers.get(LocaleProviderAdapter.Type.JRE),
 293  301                  locale, key, params);
 294  302          }
 295  303  
 296  304          List<Locale> lookupLocales = getLookupLocales(locale);
 297  305  
 298      -        Set<Locale> available = getAvailableLocaleList();
      306 +        Set<Locale> available = getAvailableLocaleSet();
 299  307          for (Locale current : lookupLocales) {
 300  308              if (available.contains(current)) {
 301  309                  S providersObj;
 302  310  
 303  311                  for (LocaleProviderAdapter.Type type: findProviders(current)) {
 304  312                      LocaleServiceProvider lsp = providers.get(type);
 305  313                      providersObj = getter.getObject((P)lsp, locale, key, params);
 306  314                      if (providersObj != null) {
 307  315                          return providersObj;
 308  316                      } else if (isObjectProvider) {
↓ open down ↓ 122 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX