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

Print this page
rev 5994 : imported patch 8001205


 137             providers.putIfAbsent(LocaleProviderAdapter.Type.SPI, provider);
 138         }
 139 
 140         // Add the CLDR Locale Data Adapter implementation, if needed.
 141         lda =  LocaleProviderAdapter.forType(LocaleProviderAdapter.Type.CLDR);
 142         if (lda != null) {
 143             provider = lda.getLocaleServiceProvider(c);
 144             if (provider != null) {
 145                 providers.putIfAbsent(LocaleProviderAdapter.Type.CLDR, provider);
 146             }
 147         }
 148 
 149         // Add the Host Locale Data Adapter implementation, if needed.
 150         lda =  LocaleProviderAdapter.forType(LocaleProviderAdapter.Type.HOST);
 151         if (lda != null) {
 152             provider = lda.getLocaleServiceProvider(c);
 153             if (provider != null) {
 154                 providers.putIfAbsent(LocaleProviderAdapter.Type.HOST, provider);
 155             }
 156         }







 157     }


 158 
 159     static void config(Class<? extends Object> caller, String message) {
 160         PlatformLogger logger = PlatformLogger.getLogger(caller.getCanonicalName());
 161         logger.config(message);
 162     }
 163 
 164     /**
 165      * Lazy loaded set of available locales.
 166      * Loading all locales is a very long operation.
 167      */
 168     private static class AllAvailableLocales {
 169         /**
 170          * Available locales for all locale sensitive services.
 171          * This also contains JRE's available locales
 172          */
 173         static final Locale[] allAvailableLocales;
 174 
 175         static {
 176             Set<Locale> all = new HashSet<>();
 177             for (Class<? extends LocaleServiceProvider> c : spiClasses) {
 178                 LocaleServiceProviderPool pool =
 179                     LocaleServiceProviderPool.getPool(c);
 180                 all.addAll(pool.getAvailableLocaleList());
 181             }
 182 



 183             allAvailableLocales = all.toArray(new Locale[0]);
 184         }
 185 
 186         // No instantiation
 187         private AllAvailableLocales() {
 188         }
 189     }
 190 
 191     /**
 192      * Returns an array of available locales for all the provider classes.
 193      * This array is a merged array of all the locales that are provided by each
 194      * provider, including the JRE.
 195      *
 196      * @return an array of the available locales for all provider classes
 197      */
 198     public static Locale[] getAllAvailableLocales() {
 199         return AllAvailableLocales.allAvailableLocales.clone();
 200     }
 201 
 202     /**
 203      * Returns an array of available locales.  This array is a
 204      * merged array of all the locales that are provided by each
 205      * provider, including the JRE.
 206      *
 207      * @return an array of the available locales
 208      */
 209     public Locale[] getAvailableLocales() {
 210         Set<Locale> locList = getAvailableLocaleList();


 211         Locale[] tmp = new Locale[locList.size()];
 212         locList.toArray(tmp);
 213         return tmp;
 214     }
 215 
 216     private synchronized Set<Locale> getAvailableLocaleList() {
 217         if (availableLocales == null) {
 218             availableLocales = new HashSet<>();
 219             for (LocaleServiceProvider lsp : providers.values()) {
 220                 Locale[] locales = lsp.getAvailableLocales();
 221                 for (Locale locale: locales) {
 222                     availableLocales.add(getLookupLocale(locale));
 223                 }
 224             }
 225 
 226             // Remove Locale.ROOT for the compatibility.
 227             availableLocales.remove(Locale.ROOT);
 228         }
 229 
 230         return availableLocales;
 231     }
 232 
 233     /**
 234      * Returns whether any provider for this locale sensitive
 235      * service is available or not, excluding JRE's one.
 236      *
 237      * @return true if any provider (other than JRE) is available
 238      */
 239     boolean hasProviders() {
 240         return providers.size() != 1 ||
 241                providers.get(LocaleProviderAdapter.Type.JRE) == null;
 242     }
 243 
 244     /**
 245      * Returns the provider's localized object for the specified
 246      * locale.
 247      *




 137             providers.putIfAbsent(LocaleProviderAdapter.Type.SPI, provider);
 138         }
 139 
 140         // Add the CLDR Locale Data Adapter implementation, if needed.
 141         lda =  LocaleProviderAdapter.forType(LocaleProviderAdapter.Type.CLDR);
 142         if (lda != null) {
 143             provider = lda.getLocaleServiceProvider(c);
 144             if (provider != null) {
 145                 providers.putIfAbsent(LocaleProviderAdapter.Type.CLDR, provider);
 146             }
 147         }
 148 
 149         // Add the Host Locale Data Adapter implementation, if needed.
 150         lda =  LocaleProviderAdapter.forType(LocaleProviderAdapter.Type.HOST);
 151         if (lda != null) {
 152             provider = lda.getLocaleServiceProvider(c);
 153             if (provider != null) {
 154                 providers.putIfAbsent(LocaleProviderAdapter.Type.HOST, provider);
 155             }
 156         }
 157 
 158         // Add the Fallback Locale Data Adapter implementation, if needed.
 159         lda =  LocaleProviderAdapter.forType(LocaleProviderAdapter.Type.FALLBACK);
 160         if (lda != null) {
 161             provider = lda.getLocaleServiceProvider(c);
 162             if (provider != null) {
 163                 providers.putIfAbsent(LocaleProviderAdapter.Type.FALLBACK, provider);
 164             }
 165         }
 166     }
 167 
 168     static void config(Class<? extends Object> caller, String message) {
 169         PlatformLogger logger = PlatformLogger.getLogger(caller.getCanonicalName());
 170         logger.config(message);
 171     }
 172 
 173     /**
 174      * Lazy loaded set of available locales.
 175      * Loading all locales is a very long operation.
 176      */
 177     private static class AllAvailableLocales {
 178         /**
 179          * Available locales for all locale sensitive services.
 180          * This also contains JRE's available locales
 181          */
 182         static final Locale[] allAvailableLocales;
 183 
 184         static {
 185             Set<Locale> all = new HashSet<>();
 186             for (Class<? extends LocaleServiceProvider> c : spiClasses) {
 187                 LocaleServiceProviderPool pool =
 188                     LocaleServiceProviderPool.getPool(c);
 189                 all.addAll(pool.getAvailableLocaleList());
 190             }
 191 
 192             // Remove Locale.ROOT for the compatibility.
 193             all.remove(Locale.ROOT);
 194 
 195             allAvailableLocales = all.toArray(new Locale[0]);
 196         }
 197 
 198         // No instantiation
 199         private AllAvailableLocales() {
 200         }
 201     }
 202 
 203     /**
 204      * Returns an array of available locales for all the provider classes.
 205      * This array is a merged array of all the locales that are provided by each
 206      * provider, including the JRE.
 207      *
 208      * @return an array of the available locales for all provider classes
 209      */
 210     public static Locale[] getAllAvailableLocales() {
 211         return AllAvailableLocales.allAvailableLocales.clone();
 212     }
 213 
 214     /**
 215      * Returns an array of available locales.  This array is a
 216      * merged array of all the locales that are provided by each
 217      * provider, including the JRE.
 218      *
 219      * @return an array of the available locales
 220      */
 221     public Locale[] getAvailableLocales() {
 222         Set<Locale> locList = getAvailableLocaleList();
 223         // Remove Locale.ROOT for the compatibility.
 224         locList.remove(Locale.ROOT);
 225         Locale[] tmp = new Locale[locList.size()];
 226         locList.toArray(tmp);
 227         return tmp;
 228     }
 229 
 230     private synchronized Set<Locale> getAvailableLocaleList() {
 231         if (availableLocales == null) {
 232             availableLocales = new HashSet<>();
 233             for (LocaleServiceProvider lsp : providers.values()) {
 234                 Locale[] locales = lsp.getAvailableLocales();
 235                 for (Locale locale: locales) {
 236                     availableLocales.add(getLookupLocale(locale));
 237                 }
 238             }



 239         }
 240 
 241         return availableLocales;
 242     }
 243 
 244     /**
 245      * Returns whether any provider for this locale sensitive
 246      * service is available or not, excluding JRE's one.
 247      *
 248      * @return true if any provider (other than JRE) is available
 249      */
 250     boolean hasProviders() {
 251         return providers.size() != 1 ||
 252                providers.get(LocaleProviderAdapter.Type.JRE) == null;
 253     }
 254 
 255     /**
 256      * Returns the provider's localized object for the specified
 257      * locale.
 258      *