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

Print this page
rev 6663 : imported patch 8008576


  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.util.locale.provider;
  27 
  28 import java.io.File;
  29 import java.security.AccessController;
  30 import java.security.PrivilegedAction;
  31 import java.text.spi.BreakIteratorProvider;
  32 import java.text.spi.CollatorProvider;
  33 import java.text.spi.DateFormatProvider;
  34 import java.text.spi.DateFormatSymbolsProvider;
  35 import java.text.spi.DecimalFormatSymbolsProvider;
  36 import java.text.spi.NumberFormatProvider;

  37 import java.util.HashSet;
  38 import java.util.Locale;
  39 import java.util.Set;
  40 import java.util.StringTokenizer;

  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.resources.LocaleData;

  50 
  51 /**
  52  * LocaleProviderAdapter implementation for the legacy JRE locale data.
  53  *
  54  * @author Naoto Sato
  55  * @author Masayoshi Okutsu
  56  */
  57 public class JRELocaleProviderAdapter extends LocaleProviderAdapter implements ResourceBundleBasedAdapter {
  58 
  59     private static final String LOCALE_DATA_JAR_NAME = "localedata.jar";
  60 
  61     private final ConcurrentMap<String, Set<String>> langtagSets
  62         = new ConcurrentHashMap<>();
  63 
  64     private final ConcurrentMap<Locale, LocaleResources> localeResourcesMap
  65         = new ConcurrentHashMap<>();
  66 
  67     // LocaleData specific to this LocaleProviderAdapter.
  68     private volatile LocaleData localeData;
  69 


  87         case "CollatorProvider":
  88             return (P) getCollatorProvider();
  89         case "DateFormatProvider":
  90             return (P) getDateFormatProvider();
  91         case "DateFormatSymbolsProvider":
  92             return (P) getDateFormatSymbolsProvider();
  93         case "DecimalFormatSymbolsProvider":
  94             return (P) getDecimalFormatSymbolsProvider();
  95         case "NumberFormatProvider":
  96             return (P) getNumberFormatProvider();
  97         case "CurrencyNameProvider":
  98             return (P) getCurrencyNameProvider();
  99         case "LocaleNameProvider":
 100             return (P) getLocaleNameProvider();
 101         case "TimeZoneNameProvider":
 102             return (P) getTimeZoneNameProvider();
 103         case "CalendarDataProvider":
 104             return (P) getCalendarDataProvider();
 105         case "CalendarNameProvider":
 106             return (P) getCalendarNameProvider();


 107         default:
 108             throw new InternalError("should not come down here");
 109         }
 110     }
 111 
 112     private volatile BreakIteratorProvider breakIteratorProvider = null;
 113     private volatile CollatorProvider collatorProvider = null;
 114     private volatile DateFormatProvider dateFormatProvider = null;
 115     private volatile DateFormatSymbolsProvider dateFormatSymbolsProvider = null;
 116     private volatile DecimalFormatSymbolsProvider decimalFormatSymbolsProvider = null;
 117     private volatile NumberFormatProvider numberFormatProvider = null;
 118 
 119     private volatile CurrencyNameProvider currencyNameProvider = null;
 120     private volatile LocaleNameProvider localeNameProvider = null;
 121     private volatile TimeZoneNameProvider timeZoneNameProvider = null;
 122     private volatile CalendarDataProvider calendarDataProvider = null;
 123     private volatile CalendarNameProvider calendarNameProvider = null;
 124 


 125     /*
 126      * Getter methods for java.text.spi.* providers
 127      */
 128     @Override
 129     public BreakIteratorProvider getBreakIteratorProvider() {
 130         if (breakIteratorProvider == null) {
 131             BreakIteratorProvider provider = new BreakIteratorProviderImpl(getAdapterType(),
 132                                                             getLanguageTagSet("FormatData"));
 133             synchronized (this) {
 134                 if (breakIteratorProvider == null) {
 135                     breakIteratorProvider = provider;
 136                 }
 137             }
 138         }
 139         return breakIteratorProvider;
 140     }
 141 
 142     @Override
 143     public CollatorProvider getCollatorProvider() {
 144         if (collatorProvider == null) {


 266             }
 267         }
 268         return calendarDataProvider;
 269     }
 270 
 271     @Override
 272     public CalendarNameProvider getCalendarNameProvider() {
 273         if (calendarNameProvider == null) {
 274             CalendarNameProvider provider;
 275             provider = new CalendarNameProviderImpl(getAdapterType(),
 276                                                     getLanguageTagSet("FormatData"));
 277             synchronized (this) {
 278                 if (calendarNameProvider == null) {
 279                     calendarNameProvider = provider;
 280                 }
 281             }
 282         }
 283         return calendarNameProvider;
 284     }
 285 


































 286     @Override
 287     public LocaleResources getLocaleResources(Locale locale) {
 288         LocaleResources lr = localeResourcesMap.get(locale);
 289         if (lr == null) {
 290             lr = new LocaleResources(this, locale);
 291             LocaleResources lrc = localeResourcesMap.putIfAbsent(locale, lr);
 292             if (lrc != null) {
 293                 lr = lrc;
 294             }
 295         }
 296         return lr;
 297     }
 298 
 299     // ResourceBundleBasedAdapter method implementation
 300     @Override
 301     public LocaleData getLocaleData() {
 302         if (localeData == null) {
 303             synchronized (this) {
 304                 if (localeData == null) {
 305                     localeData = new LocaleData(getAdapterType());




  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.util.locale.provider;
  27 
  28 import java.io.File;
  29 import java.security.AccessController;
  30 import java.security.PrivilegedAction;
  31 import java.text.spi.BreakIteratorProvider;
  32 import java.text.spi.CollatorProvider;
  33 import java.text.spi.DateFormatProvider;
  34 import java.text.spi.DateFormatSymbolsProvider;
  35 import java.text.spi.DecimalFormatSymbolsProvider;
  36 import java.text.spi.NumberFormatProvider;
  37 import java.util.Calendar;
  38 import java.util.HashSet;
  39 import java.util.Locale;
  40 import java.util.Set;
  41 import java.util.StringTokenizer;
  42 import java.util.TimeZone;
  43 import java.util.concurrent.ConcurrentHashMap;
  44 import java.util.concurrent.ConcurrentMap;
  45 import java.util.spi.CalendarDataProvider;
  46 import java.util.spi.CalendarNameProvider;
  47 import java.util.spi.CurrencyNameProvider;
  48 import java.util.spi.LocaleNameProvider;
  49 import java.util.spi.LocaleServiceProvider;
  50 import java.util.spi.TimeZoneNameProvider;
  51 import sun.util.resources.LocaleData;
  52 import sun.util.spi.CalendarProvider;
  53 
  54 /**
  55  * LocaleProviderAdapter implementation for the legacy JRE locale data.
  56  *
  57  * @author Naoto Sato
  58  * @author Masayoshi Okutsu
  59  */
  60 public class JRELocaleProviderAdapter extends LocaleProviderAdapter implements ResourceBundleBasedAdapter {
  61 
  62     private static final String LOCALE_DATA_JAR_NAME = "localedata.jar";
  63 
  64     private final ConcurrentMap<String, Set<String>> langtagSets
  65         = new ConcurrentHashMap<>();
  66 
  67     private final ConcurrentMap<Locale, LocaleResources> localeResourcesMap
  68         = new ConcurrentHashMap<>();
  69 
  70     // LocaleData specific to this LocaleProviderAdapter.
  71     private volatile LocaleData localeData;
  72 


  90         case "CollatorProvider":
  91             return (P) getCollatorProvider();
  92         case "DateFormatProvider":
  93             return (P) getDateFormatProvider();
  94         case "DateFormatSymbolsProvider":
  95             return (P) getDateFormatSymbolsProvider();
  96         case "DecimalFormatSymbolsProvider":
  97             return (P) getDecimalFormatSymbolsProvider();
  98         case "NumberFormatProvider":
  99             return (P) getNumberFormatProvider();
 100         case "CurrencyNameProvider":
 101             return (P) getCurrencyNameProvider();
 102         case "LocaleNameProvider":
 103             return (P) getLocaleNameProvider();
 104         case "TimeZoneNameProvider":
 105             return (P) getTimeZoneNameProvider();
 106         case "CalendarDataProvider":
 107             return (P) getCalendarDataProvider();
 108         case "CalendarNameProvider":
 109             return (P) getCalendarNameProvider();
 110         case "CalendarProvider":
 111             return (P) getCalendarProvider();
 112         default:
 113             throw new InternalError("should not come down here");
 114         }
 115     }
 116 
 117     private volatile BreakIteratorProvider breakIteratorProvider = null;
 118     private volatile CollatorProvider collatorProvider = null;
 119     private volatile DateFormatProvider dateFormatProvider = null;
 120     private volatile DateFormatSymbolsProvider dateFormatSymbolsProvider = null;
 121     private volatile DecimalFormatSymbolsProvider decimalFormatSymbolsProvider = null;
 122     private volatile NumberFormatProvider numberFormatProvider = null;
 123 
 124     private volatile CurrencyNameProvider currencyNameProvider = null;
 125     private volatile LocaleNameProvider localeNameProvider = null;
 126     private volatile TimeZoneNameProvider timeZoneNameProvider = null;
 127     private volatile CalendarDataProvider calendarDataProvider = null;
 128     private volatile CalendarNameProvider calendarNameProvider = null;
 129 
 130     private volatile CalendarProvider calendarProvider = null;
 131 
 132     /*
 133      * Getter methods for java.text.spi.* providers
 134      */
 135     @Override
 136     public BreakIteratorProvider getBreakIteratorProvider() {
 137         if (breakIteratorProvider == null) {
 138             BreakIteratorProvider provider = new BreakIteratorProviderImpl(getAdapterType(),
 139                                                             getLanguageTagSet("FormatData"));
 140             synchronized (this) {
 141                 if (breakIteratorProvider == null) {
 142                     breakIteratorProvider = provider;
 143                 }
 144             }
 145         }
 146         return breakIteratorProvider;
 147     }
 148 
 149     @Override
 150     public CollatorProvider getCollatorProvider() {
 151         if (collatorProvider == null) {


 273             }
 274         }
 275         return calendarDataProvider;
 276     }
 277 
 278     @Override
 279     public CalendarNameProvider getCalendarNameProvider() {
 280         if (calendarNameProvider == null) {
 281             CalendarNameProvider provider;
 282             provider = new CalendarNameProviderImpl(getAdapterType(),
 283                                                     getLanguageTagSet("FormatData"));
 284             synchronized (this) {
 285                 if (calendarNameProvider == null) {
 286                     calendarNameProvider = provider;
 287                 }
 288             }
 289         }
 290         return calendarNameProvider;
 291     }
 292 
 293     /**
 294      * Getter methods for sun.util.spi.* providers
 295      */
 296     @Override
 297     public CalendarProvider getCalendarProvider() {
 298         // Return a dummy here to pretend supporting this provider.
 299         // Real instantiation happens in Calendar.createCalendar().
 300         if (calendarProvider == null) {
 301             CalendarProvider provider;
 302             provider = new CalendarProvider() {
 303                 @Override
 304                 public Locale[] getAvailableLocales() {
 305                     return null;
 306                 }
 307 
 308                 @Override
 309                 public boolean isSupportedLocale(Locale l) {
 310                     return true;
 311                 }
 312 
 313                 @Override
 314                 public Calendar getInstance(TimeZone tz, Locale l) {
 315                     return null;
 316                 }
 317             };
 318             synchronized (this) {
 319                 if (calendarProvider == null) {
 320                     calendarProvider = provider;
 321                 }
 322             }
 323         }
 324         return calendarProvider;
 325     }
 326 
 327     @Override
 328     public LocaleResources getLocaleResources(Locale locale) {
 329         LocaleResources lr = localeResourcesMap.get(locale);
 330         if (lr == null) {
 331             lr = new LocaleResources(this, locale);
 332             LocaleResources lrc = localeResourcesMap.putIfAbsent(locale, lr);
 333             if (lrc != null) {
 334                 lr = lrc;
 335             }
 336         }
 337         return lr;
 338     }
 339 
 340     // ResourceBundleBasedAdapter method implementation
 341     @Override
 342     public LocaleData getLocaleData() {
 343         if (localeData == null) {
 344             synchronized (this) {
 345                 if (localeData == null) {
 346                     localeData = new LocaleData(getAdapterType());