home *** CD-ROM | disk | FTP | other *** search
Wrap
package sun.util; import java.security.AccessController; import java.security.PrivilegedActionException; import java.util.Arrays; import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.logging.Logger; import java.util.spi.LocaleServiceProvider; import sun.util.resources.LocaleData; import sun.util.resources.OpenListResourceBundle; public final class LocaleServiceProviderPool { private static Map<Class, LocaleServiceProviderPool> poolOfPools = new ConcurrentHashMap(); private Set<LocaleServiceProvider> providers = new LinkedHashSet(); private Map<Locale, LocaleServiceProvider> providersCache = new ConcurrentHashMap(); private Set<Locale> availableLocales = null; private static List<Locale> availableJRELocales = null; private Set<Locale> providerLocales = null; public static LocaleServiceProviderPool getPool(Class<? extends LocaleServiceProvider> var0) { LocaleServiceProviderPool var1 = (LocaleServiceProviderPool)poolOfPools.get(var0); if (var1 == null) { LocaleServiceProviderPool var2 = new LocaleServiceProviderPool(var0); var1 = (LocaleServiceProviderPool)poolOfPools.put(var0, var2); if (var1 == null) { var1 = var2; } } return var1; } private LocaleServiceProviderPool(Class<? extends LocaleServiceProvider> var1) { try { AccessController.doPrivileged(new 1(this, var1)); } catch (PrivilegedActionException var3) { Logger.getLogger("sun.util.LocaleServiceProviderPool").config(var3.toString()); } } public static Locale[] getAllAvailableLocales() { return (Locale[])sun.util.LocaleServiceProviderPool.AllAvailableLocales.allAvailableLocales.clone(); } public synchronized Locale[] getAvailableLocales() { if (this.availableLocales == null) { this.availableLocales = new HashSet(this.getJRELocales()); if (this.hasProviders()) { this.availableLocales.addAll(this.getProviderLocales()); } } Locale[] var1 = new Locale[this.availableLocales.size()]; this.availableLocales.toArray(var1); return var1; } private synchronized Set<Locale> getProviderLocales() { if (this.providerLocales == null) { this.providerLocales = new HashSet(); if (this.hasProviders()) { for(LocaleServiceProvider var2 : this.providers) { Locale[] var3 = var2.getAvailableLocales(); for(Locale var7 : var3) { this.providerLocales.add(var7); } } } } return this.providerLocales; } public boolean hasProviders() { return !this.providers.isEmpty(); } private synchronized List<Locale> getJRELocales() { if (availableJRELocales == null) { availableJRELocales = Arrays.asList(LocaleData.getAvailableLocales()); } return availableJRELocales; } private boolean isJRESupported(Locale var1) { List var2 = this.getJRELocales(); return var2.contains(var1); } public <P, S> S getLocalizedObject(LocalizedObjectGetter<P, S> var1, Locale var2, Object... var3) { return (S)this.getLocalizedObjectImpl(var1, var2, true, (OpenListResourceBundle)null, (String)null, var3); } public <P, S> S getLocalizedObject(LocalizedObjectGetter<P, S> var1, Locale var2, OpenListResourceBundle var3, String var4, Object... var5) { return (S)this.getLocalizedObjectImpl(var1, var2, false, var3, var4, var5); } private <P, S> S getLocalizedObjectImpl(LocalizedObjectGetter<P, S> var1, Locale var2, boolean var3, OpenListResourceBundle var4, String var5, Object... var6) { if (this.hasProviders()) { Locale var7 = var4 != null ? var4.getLocale() : null; Locale var8 = var2; for(Object var10 = null; (var2 = this.findProviderLocale(var2, var7)) != null; var2 = getParentLocale(var2)) { LocaleServiceProvider var9 = this.findProvider(var2); if (var9 != null) { var10 = var1.getObject(var9, var8, var5, var6); if (var10 != null) { return (S)var10; } if (var3) { Logger.getLogger("sun.util.LocaleServiceProviderPool").config("A locale sensitive service provider returned null for a localized objects, which should not happen. provider: " + var9 + " locale: " + var8); } } } for(; var4 != null; var4 = var4.getParent()) { var7 = var4.getLocale(); if (var4.handleGetKeys().contains(var5)) { return null; } LocaleServiceProvider var13 = this.findProvider(var7); if (var13 != null) { Object var15 = var1.getObject(var13, var8, var5, var6); if (var15 != null) { return (S)var15; } } } } return null; } private LocaleServiceProvider findProvider(Locale var1) { if (!this.hasProviders()) { return null; } else { if (this.providersCache.containsKey(var1)) { LocaleServiceProvider var2 = (LocaleServiceProvider)this.providersCache.get(var1); if (var2 != sun.util.LocaleServiceProviderPool.NullProvider.access$200()) { return var2; } } else { for(LocaleServiceProvider var3 : this.providers) { Locale[] var4 = var3.getAvailableLocales(); for(Locale var8 : var4) { if (var1.equals(var8)) { LocaleServiceProvider var9 = (LocaleServiceProvider)this.providersCache.put(var1, var3); return var9 != null ? var9 : var3; } } } this.providersCache.put(var1, sun.util.LocaleServiceProviderPool.NullProvider.access$200()); } return null; } } private Locale findProviderLocale(Locale var1, Locale var2) { Set var3 = this.getProviderLocales(); Locale var4; for(var4 = var1; var4 != null; var4 = getParentLocale(var4)) { if (var2 != null) { if (var4.equals(var2)) { var4 = null; break; } } else if (this.isJRESupported(var4)) { var4 = null; break; } if (var3.contains(var4)) { break; } } return var4; } private static Locale getParentLocale(Locale var0) { String var1 = var0.getVariant(); if (var1 != "") { int var2 = var1.lastIndexOf(95); return var2 != -1 ? new Locale(var0.getLanguage(), var0.getCountry(), var1.substring(0, var2)) : new Locale(var0.getLanguage(), var0.getCountry()); } else if (var0.getCountry() != "") { return new Locale(var0.getLanguage()); } else { return var0.getLanguage() != "" ? Locale.ROOT : null; } } // $FF: synthetic method static Set access$000(LocaleServiceProviderPool var0) { return var0.providers; } // $FF: synthetic method static Set access$100(LocaleServiceProviderPool var0) { return var0.getProviderLocales(); } }