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

Print this page




  29  *
  30  * The original version of this source code and documentation
  31  * is copyrighted and owned by Taligent, Inc., a wholly-owned
  32  * subsidiary of IBM. These materials are provided under terms
  33  * of a License Agreement between Taligent and Sun. This technology
  34  * is protected by multiple US and International patents.
  35  *
  36  * This notice and attribution to Taligent may not be removed.
  37  * Taligent is a registered trademark of Taligent, Inc.
  38  *
  39  */
  40 
  41 package sun.util.locale.provider;
  42 
  43 import java.text.MessageFormat;
  44 import java.util.Calendar;
  45 import java.util.Locale;
  46 import java.util.ResourceBundle;
  47 import java.util.concurrent.ConcurrentHashMap;
  48 import java.util.concurrent.ConcurrentMap;
  49 import sun.util.resources.OpenListResourceBundle;
  50 
  51 /**
  52  * Central accessor to locale-dependent resources.
  53  *
  54  * @author Masayoshi Okutsu
  55  */
  56 public class LocaleResources {
  57 
  58     private final LocaleProviderAdapter adapter;
  59     private final Locale locale;
  60 
  61     // Resource cache
  62     private ConcurrentMap<String, Object> cache = new ConcurrentHashMap<>();
  63 
  64 
  65     LocaleResources(LocaleProviderAdapter adapter, Locale locale) {
  66         this.adapter = adapter;
  67         this.locale = locale;
  68     }
  69 
  70     public OpenListResourceBundle getTimeZoneNames() {
  71         OpenListResourceBundle tznames = (OpenListResourceBundle) cache.get("TimeZoneNames");
  72         if (tznames == null) {
  73             tznames = adapter.getLocaleData().getTimeZoneNames(locale);
  74             OpenListResourceBundle olrb = (OpenListResourceBundle) cache.putIfAbsent("TimeZoneNames", tznames);
  75             if (olrb != null) {
  76                 tznames = olrb;
  77             }
  78         }
  79         return tznames;
  80     }
  81 
  82     public String getDateTimePattern(int timeStyle, int dateStyle, Calendar cal) {
  83         String pattern;
  84 
  85         if (cal == null) {
  86             cal = Calendar.getInstance(locale);
  87         }
  88         String calType = cal.getCalendarType();
  89         String timePattern = null;
  90         String datePattern = null;
  91         if (timeStyle >= 0) {
  92             timePattern = getDateTimePattern("TimePatterns", timeStyle, calType);
  93         }
  94         if (dateStyle >= 0) {




  29  *
  30  * The original version of this source code and documentation
  31  * is copyrighted and owned by Taligent, Inc., a wholly-owned
  32  * subsidiary of IBM. These materials are provided under terms
  33  * of a License Agreement between Taligent and Sun. This technology
  34  * is protected by multiple US and International patents.
  35  *
  36  * This notice and attribution to Taligent may not be removed.
  37  * Taligent is a registered trademark of Taligent, Inc.
  38  *
  39  */
  40 
  41 package sun.util.locale.provider;
  42 
  43 import java.text.MessageFormat;
  44 import java.util.Calendar;
  45 import java.util.Locale;
  46 import java.util.ResourceBundle;
  47 import java.util.concurrent.ConcurrentHashMap;
  48 import java.util.concurrent.ConcurrentMap;
  49 import sun.util.resources.TimeZoneNamesBundle;
  50 
  51 /**
  52  * Central accessor to locale-dependent resources.
  53  *
  54  * @author Masayoshi Okutsu
  55  */
  56 public class LocaleResources {
  57 
  58     private final LocaleProviderAdapter adapter;
  59     private final Locale locale;
  60 
  61     // Resource cache
  62     private ConcurrentMap<String, Object> cache = new ConcurrentHashMap<>();
  63 
  64 
  65     LocaleResources(LocaleProviderAdapter adapter, Locale locale) {
  66         this.adapter = adapter;
  67         this.locale = locale;
  68     }
  69 
  70     public TimeZoneNamesBundle getTimeZoneNames() {
  71         TimeZoneNamesBundle tznames = (TimeZoneNamesBundle) cache.get("TimeZoneNames");
  72         if (tznames == null) {
  73             tznames = adapter.getLocaleData().getTimeZoneNames(locale);
  74             TimeZoneNamesBundle olrb = (TimeZoneNamesBundle) cache.putIfAbsent("TimeZoneNames", tznames);
  75             if (olrb != null) {
  76                 tznames = olrb;
  77             }
  78         }
  79         return tznames;
  80     }
  81 
  82     public String getDateTimePattern(int timeStyle, int dateStyle, Calendar cal) {
  83         String pattern;
  84 
  85         if (cal == null) {
  86             cal = Calendar.getInstance(locale);
  87         }
  88         String calType = cal.getCalendarType();
  89         String timePattern = null;
  90         String datePattern = null;
  91         if (timeStyle >= 0) {
  92             timePattern = getDateTimePattern("TimePatterns", timeStyle, calType);
  93         }
  94         if (dateStyle >= 0) {