src/share/classes/sun/util/locale/provider/LocaleProviderAdapter.java

Print this page
rev 6663 : imported patch 8008576


  30 import java.text.spi.CollatorProvider;
  31 import java.text.spi.DateFormatProvider;
  32 import java.text.spi.DateFormatSymbolsProvider;
  33 import java.text.spi.DecimalFormatSymbolsProvider;
  34 import java.text.spi.NumberFormatProvider;
  35 import java.util.ArrayList;
  36 import java.util.Collections;
  37 import java.util.List;
  38 import java.util.Locale;
  39 import java.util.ResourceBundle;
  40 import java.util.Set;
  41 import java.util.concurrent.ConcurrentHashMap;
  42 import java.util.concurrent.ConcurrentMap;
  43 import java.util.spi.CalendarDataProvider;
  44 import java.util.spi.CalendarNameProvider;
  45 import java.util.spi.CurrencyNameProvider;
  46 import java.util.spi.LocaleNameProvider;
  47 import java.util.spi.LocaleServiceProvider;
  48 import java.util.spi.TimeZoneNameProvider;
  49 import sun.util.cldr.CLDRLocaleProviderAdapter;

  50 
  51 /**
  52  * The LocaleProviderAdapter abstract class.
  53  *
  54  * @author Naoto Sato
  55  * @author Masayoshi Okutsu
  56  */
  57 public abstract class LocaleProviderAdapter {
  58     /**
  59      * Adapter type.
  60      */
  61     public static enum Type {
  62         JRE("sun.util.resources", "sun.text.resources"),
  63         CLDR("sun.util.resources.cldr", "sun.text.resources.cldr"),
  64         SPI,
  65         HOST,
  66         FALLBACK("sun.util.resources", "sun.text.resources");
  67 
  68         private final String UTIL_RESOURCES_PACKAGE;
  69         private final String TEXT_RESOURCES_PACKAGE;


 278      * A utility method for implementing the default LocaleServiceProvider.isSupportedLocale
 279      * for the JRE, CLDR, and FALLBACK adapters.
 280      */
 281     static boolean isSupportedLocale(Locale locale, LocaleProviderAdapter.Type type, Set<String> langtags) {
 282         assert type == Type.JRE || type == Type.CLDR || type == Type.FALLBACK;
 283         if (Locale.ROOT.equals(locale)) {
 284             return true;
 285         }
 286 
 287         if (type == Type.FALLBACK) {
 288             // no other locales except ROOT are supported for FALLBACK
 289             return false;
 290         }
 291 
 292         locale = locale.stripExtensions();
 293         if (langtags.contains(locale.toLanguageTag())) {
 294             return true;
 295         }
 296         if (type == Type.JRE) {
 297             String oldname = locale.toString().replace('_', '-');
 298             return langtags.contains(oldname);



 299         }
 300         return false;
 301     }
 302 
 303     public static Locale[] toLocaleArray(Set<String> tags) {
 304         Locale[] locs = new Locale[tags.size() + 1];
 305         int index = 0;
 306         locs[index++] = Locale.ROOT;
 307         for (String tag : tags) {
 308             switch (tag) {
 309             case "ja-JP-JP":
 310                 locs[index++] = JRELocaleConstants.JA_JP_JP;
 311                 break;
 312             case "th-TH-TH":
 313                 locs[index++] = JRELocaleConstants.TH_TH_TH;
 314                 break;
 315             default:
 316                 locs[index++] = Locale.forLanguageTag(tag);
 317                 break;
 318             }


 405      * @return a TimeZoneNameProvider
 406      */
 407     public abstract TimeZoneNameProvider getTimeZoneNameProvider();
 408 
 409     /**
 410      * Returns a CalendarDataProvider for this LocaleProviderAdapter, or null if no
 411      * CalendarDataProvider is available.
 412      *
 413      * @return a CalendarDataProvider
 414      */
 415     public abstract CalendarDataProvider getCalendarDataProvider();
 416 
 417     /**
 418      * Returns a CalendarNameProvider for this LocaleProviderAdapter, or null if no
 419      * CalendarNameProvider is available.
 420      *
 421      * @return a CalendarNameProvider
 422      */
 423     public abstract CalendarNameProvider getCalendarNameProvider();
 424 








 425     public abstract LocaleResources getLocaleResources(Locale locale);
 426 
 427     public abstract Locale[] getAvailableLocales();
 428 }


  30 import java.text.spi.CollatorProvider;
  31 import java.text.spi.DateFormatProvider;
  32 import java.text.spi.DateFormatSymbolsProvider;
  33 import java.text.spi.DecimalFormatSymbolsProvider;
  34 import java.text.spi.NumberFormatProvider;
  35 import java.util.ArrayList;
  36 import java.util.Collections;
  37 import java.util.List;
  38 import java.util.Locale;
  39 import java.util.ResourceBundle;
  40 import java.util.Set;
  41 import java.util.concurrent.ConcurrentHashMap;
  42 import java.util.concurrent.ConcurrentMap;
  43 import java.util.spi.CalendarDataProvider;
  44 import java.util.spi.CalendarNameProvider;
  45 import java.util.spi.CurrencyNameProvider;
  46 import java.util.spi.LocaleNameProvider;
  47 import java.util.spi.LocaleServiceProvider;
  48 import java.util.spi.TimeZoneNameProvider;
  49 import sun.util.cldr.CLDRLocaleProviderAdapter;
  50 import sun.util.spi.CalendarProvider;
  51 
  52 /**
  53  * The LocaleProviderAdapter abstract class.
  54  *
  55  * @author Naoto Sato
  56  * @author Masayoshi Okutsu
  57  */
  58 public abstract class LocaleProviderAdapter {
  59     /**
  60      * Adapter type.
  61      */
  62     public static enum Type {
  63         JRE("sun.util.resources", "sun.text.resources"),
  64         CLDR("sun.util.resources.cldr", "sun.text.resources.cldr"),
  65         SPI,
  66         HOST,
  67         FALLBACK("sun.util.resources", "sun.text.resources");
  68 
  69         private final String UTIL_RESOURCES_PACKAGE;
  70         private final String TEXT_RESOURCES_PACKAGE;


 279      * A utility method for implementing the default LocaleServiceProvider.isSupportedLocale
 280      * for the JRE, CLDR, and FALLBACK adapters.
 281      */
 282     static boolean isSupportedLocale(Locale locale, LocaleProviderAdapter.Type type, Set<String> langtags) {
 283         assert type == Type.JRE || type == Type.CLDR || type == Type.FALLBACK;
 284         if (Locale.ROOT.equals(locale)) {
 285             return true;
 286         }
 287 
 288         if (type == Type.FALLBACK) {
 289             // no other locales except ROOT are supported for FALLBACK
 290             return false;
 291         }
 292 
 293         locale = locale.stripExtensions();
 294         if (langtags.contains(locale.toLanguageTag())) {
 295             return true;
 296         }
 297         if (type == Type.JRE) {
 298             String oldname = locale.toString().replace('_', '-');
 299             return langtags.contains(oldname) ||
 300                    "ja-JP-JP".equals(oldname) ||
 301                    "th-TH-TH".equals(oldname) ||
 302                    "no-NO-NY".equals(oldname);
 303         }
 304         return false;
 305     }
 306 
 307     public static Locale[] toLocaleArray(Set<String> tags) {
 308         Locale[] locs = new Locale[tags.size() + 1];
 309         int index = 0;
 310         locs[index++] = Locale.ROOT;
 311         for (String tag : tags) {
 312             switch (tag) {
 313             case "ja-JP-JP":
 314                 locs[index++] = JRELocaleConstants.JA_JP_JP;
 315                 break;
 316             case "th-TH-TH":
 317                 locs[index++] = JRELocaleConstants.TH_TH_TH;
 318                 break;
 319             default:
 320                 locs[index++] = Locale.forLanguageTag(tag);
 321                 break;
 322             }


 409      * @return a TimeZoneNameProvider
 410      */
 411     public abstract TimeZoneNameProvider getTimeZoneNameProvider();
 412 
 413     /**
 414      * Returns a CalendarDataProvider for this LocaleProviderAdapter, or null if no
 415      * CalendarDataProvider is available.
 416      *
 417      * @return a CalendarDataProvider
 418      */
 419     public abstract CalendarDataProvider getCalendarDataProvider();
 420 
 421     /**
 422      * Returns a CalendarNameProvider for this LocaleProviderAdapter, or null if no
 423      * CalendarNameProvider is available.
 424      *
 425      * @return a CalendarNameProvider
 426      */
 427     public abstract CalendarNameProvider getCalendarNameProvider();
 428 
 429     /**
 430      * Returns a CalendarProvider for this LocaleProviderAdapter, or null if no
 431      * CalendarProvider is available.
 432      *
 433      * @return a CalendarProvider
 434      */
 435     public abstract CalendarProvider getCalendarProvider();
 436 
 437     public abstract LocaleResources getLocaleResources(Locale locale);
 438 
 439     public abstract Locale[] getAvailableLocales();
 440 }