Java 类java.util.spi.LocaleServiceProvider 实例源码

项目:OpenJSharp    文件:AuxLocaleProviderAdapter.java   
@Override
public Locale[] getAvailableLocales() {
    if (availableLocales == null) {
        Set<Locale> avail = new HashSet<>();
        for (Class<? extends LocaleServiceProvider> c :
                LocaleServiceProviderPool.spiClasses) {
            LocaleServiceProvider lsp = getLocaleServiceProvider(c);
            if (lsp != null) {
                avail.addAll(Arrays.asList(lsp.getAvailableLocales()));
            }
        }
        availableLocales = avail.toArray(new Locale[0]);
    }

    // assuming caller won't mutate the array.
    return availableLocales;
}
项目:OpenJSharp    文件:LocaleServiceProviderPool.java   
/**
 * Returns the list of locale service provider instances that support
 * the specified locale.
 *
 * @param locale the given locale
 * @return the list of locale data adapter types
 */
private List<LocaleProviderAdapter.Type> findProviders(Locale locale) {
    List<LocaleProviderAdapter.Type> providersList = providersCache.get(locale);
    if (providersList == null) {
        for (LocaleProviderAdapter.Type type : LocaleProviderAdapter.getAdapterPreference()) {
            LocaleServiceProvider lsp = providers.get(type);
            if (lsp != null) {
                if (lsp.isSupportedLocale(locale)) {
                    if (providersList == null) {
                        providersList = new ArrayList<>(2);
                    }
                    providersList.add(type);

                }
            }
        }
        if (providersList == null) {
            providersList = NULL_LIST;
        }
        List<LocaleProviderAdapter.Type> val = providersCache.putIfAbsent(locale, providersList);
        if (val != null) {
            providersList = val;
        }
    }
        return providersList;
    }
项目:jdk8u-jdk    文件:AuxLocaleProviderAdapter.java   
@Override
public Locale[] getAvailableLocales() {
    if (availableLocales == null) {
        Set<Locale> avail = new HashSet<>();
        for (Class<? extends LocaleServiceProvider> c :
                LocaleServiceProviderPool.spiClasses) {
            LocaleServiceProvider lsp = getLocaleServiceProvider(c);
            if (lsp != null) {
                avail.addAll(Arrays.asList(lsp.getAvailableLocales()));
            }
        }
        availableLocales = avail.toArray(new Locale[0]);
    }

    // assuming caller won't mutate the array.
    return availableLocales;
}
项目:jdk8u-jdk    文件:LocaleServiceProviderPool.java   
/**
 * Returns the list of locale service provider instances that support
 * the specified locale.
 *
 * @param locale the given locale
 * @return the list of locale data adapter types
 */
private List<LocaleProviderAdapter.Type> findProviders(Locale locale) {
    List<LocaleProviderAdapter.Type> providersList = providersCache.get(locale);
    if (providersList == null) {
        for (LocaleProviderAdapter.Type type : LocaleProviderAdapter.getAdapterPreference()) {
            LocaleServiceProvider lsp = providers.get(type);
            if (lsp != null) {
                if (lsp.isSupportedLocale(locale)) {
                    if (providersList == null) {
                        providersList = new ArrayList<>(2);
                    }
                    providersList.add(type);

                }
            }
        }
        if (providersList == null) {
            providersList = NULL_LIST;
        }
        List<LocaleProviderAdapter.Type> val = providersCache.putIfAbsent(locale, providersList);
        if (val != null) {
            providersList = val;
        }
    }
        return providersList;
    }
项目:openjdk-jdk10    文件:AuxLocaleProviderAdapter.java   
@Override
public Locale[] getAvailableLocales() {
    if (availableLocales == null) {
        List<Locale> avail = new ArrayList<>();
        for (Class<? extends LocaleServiceProvider> c :
                LocaleServiceProviderPool.spiClasses) {
            LocaleServiceProvider lsp = getLocaleServiceProvider(c);
            if (lsp != null) {
                avail.addAll(Arrays.asList(lsp.getAvailableLocales()));
            }
        }
        availableLocales = avail.toArray(new Locale[0]);
    }

    // assuming caller won't mutate the array.
    return availableLocales;
}
项目:openjdk-jdk10    文件:LocaleServiceProviderPool.java   
/**
 * Returns the union of locale sets that are available from
 * each service provider. This method does NOT return the
 * defensive copy.
 *
 * @return a set of available locales
 */
private synchronized Set<Locale> getAvailableLocaleSet() {
    if (availableLocales == null) {
        availableLocales = new HashSet<>();
        for (LocaleProviderAdapter.Type type : LocaleProviderAdapter.getAdapterPreference()) {
            LocaleProviderAdapter lda = LocaleProviderAdapter.forType(type);
            if (lda != null) {
                LocaleServiceProvider lsp = lda.getLocaleServiceProvider(providerClass);
                if (lsp != null) {
                    Locale[] locales = lsp.getAvailableLocales();
                    for (Locale locale: locales) {
                        availableLocales.add(getLookupLocale(locale));
                    }
                }
            }
        }
    }

    return availableLocales;
}
项目:openjdk9    文件:AuxLocaleProviderAdapter.java   
@Override
public Locale[] getAvailableLocales() {
    if (availableLocales == null) {
        List<Locale> avail = new ArrayList<>();
        for (Class<? extends LocaleServiceProvider> c :
                LocaleServiceProviderPool.spiClasses) {
            LocaleServiceProvider lsp = getLocaleServiceProvider(c);
            if (lsp != null) {
                avail.addAll(Arrays.asList(lsp.getAvailableLocales()));
            }
        }
        availableLocales = avail.toArray(new Locale[0]);
    }

    // assuming caller won't mutate the array.
    return availableLocales;
}
项目:openjdk9    文件:LocaleServiceProviderPool.java   
/**
 * Returns the union of locale sets that are available from
 * each service provider. This method does NOT return the
 * defensive copy.
 *
 * @return a set of available locales
 */
private synchronized Set<Locale> getAvailableLocaleSet() {
    if (availableLocales == null) {
        availableLocales = new HashSet<>();
        for (LocaleProviderAdapter.Type type : LocaleProviderAdapter.getAdapterPreference()) {
            LocaleProviderAdapter lda = LocaleProviderAdapter.forType(type);
            if (lda != null) {
                LocaleServiceProvider lsp = lda.getLocaleServiceProvider(providerClass);
                if (lsp != null) {
                    Locale[] locales = lsp.getAvailableLocales();
                    for (Locale locale: locales) {
                        availableLocales.add(getLookupLocale(locale));
                    }
                }
            }
        }
    }

    return availableLocales;
}
项目:jdk8u_jdk    文件:AuxLocaleProviderAdapter.java   
@Override
public Locale[] getAvailableLocales() {
    if (availableLocales == null) {
        Set<Locale> avail = new HashSet<>();
        for (Class<? extends LocaleServiceProvider> c :
                LocaleServiceProviderPool.spiClasses) {
            LocaleServiceProvider lsp = getLocaleServiceProvider(c);
            if (lsp != null) {
                avail.addAll(Arrays.asList(lsp.getAvailableLocales()));
            }
        }
        availableLocales = avail.toArray(new Locale[0]);
    }

    // assuming caller won't mutate the array.
    return availableLocales;
}
项目:jdk8u_jdk    文件:LocaleServiceProviderPool.java   
/**
 * Returns the list of locale service provider instances that support
 * the specified locale.
 *
 * @param locale the given locale
 * @return the list of locale data adapter types
 */
private List<LocaleProviderAdapter.Type> findProviders(Locale locale) {
    List<LocaleProviderAdapter.Type> providersList = providersCache.get(locale);
    if (providersList == null) {
        for (LocaleProviderAdapter.Type type : LocaleProviderAdapter.getAdapterPreference()) {
            LocaleServiceProvider lsp = providers.get(type);
            if (lsp != null) {
                if (lsp.isSupportedLocale(locale)) {
                    if (providersList == null) {
                        providersList = new ArrayList<>(2);
                    }
                    providersList.add(type);

                }
            }
        }
        if (providersList == null) {
            providersList = NULL_LIST;
        }
        List<LocaleProviderAdapter.Type> val = providersCache.putIfAbsent(locale, providersList);
        if (val != null) {
            providersList = val;
        }
    }
        return providersList;
    }
项目:lookaside_java-1.8.0-openjdk    文件:AuxLocaleProviderAdapter.java   
@Override
public Locale[] getAvailableLocales() {
    if (availableLocales == null) {
        Set<Locale> avail = new HashSet<>();
        for (Class<? extends LocaleServiceProvider> c :
                LocaleServiceProviderPool.spiClasses) {
            LocaleServiceProvider lsp = getLocaleServiceProvider(c);
            if (lsp != null) {
                avail.addAll(Arrays.asList(lsp.getAvailableLocales()));
            }
        }
        availableLocales = avail.toArray(new Locale[0]);
    }

    // assuming caller won't mutate the array.
    return availableLocales;
}
项目:lookaside_java-1.8.0-openjdk    文件:LocaleServiceProviderPool.java   
/**
 * Returns the list of locale service provider instances that support
 * the specified locale.
 *
 * @param locale the given locale
 * @return the list of locale data adapter types
 */
private List<LocaleProviderAdapter.Type> findProviders(Locale locale) {
    List<LocaleProviderAdapter.Type> providersList = providersCache.get(locale);
    if (providersList == null) {
        for (LocaleProviderAdapter.Type type : LocaleProviderAdapter.getAdapterPreference()) {
            LocaleServiceProvider lsp = providers.get(type);
            if (lsp != null) {
                if (lsp.isSupportedLocale(locale)) {
                    if (providersList == null) {
                        providersList = new ArrayList<>(2);
                    }
                    providersList.add(type);

                }
            }
        }
        if (providersList == null) {
            providersList = NULL_LIST;
        }
        List<LocaleProviderAdapter.Type> val = providersCache.putIfAbsent(locale, providersList);
        if (val != null) {
            providersList = val;
        }
    }
        return providersList;
    }
项目:infobip-open-jdk-8    文件:AuxLocaleProviderAdapter.java   
@Override
public Locale[] getAvailableLocales() {
    if (availableLocales == null) {
        Set<Locale> avail = new HashSet<>();
        for (Class<? extends LocaleServiceProvider> c :
                LocaleServiceProviderPool.spiClasses) {
            LocaleServiceProvider lsp = getLocaleServiceProvider(c);
            if (lsp != null) {
                avail.addAll(Arrays.asList(lsp.getAvailableLocales()));
            }
        }
        availableLocales = avail.toArray(new Locale[0]);
    }

    // assuming caller won't mutate the array.
    return availableLocales;
}
项目:infobip-open-jdk-8    文件:LocaleServiceProviderPool.java   
/**
 * Returns the list of locale service provider instances that support
 * the specified locale.
 *
 * @param locale the given locale
 * @return the list of locale data adapter types
 */
private List<LocaleProviderAdapter.Type> findProviders(Locale locale) {
    List<LocaleProviderAdapter.Type> providersList = providersCache.get(locale);
    if (providersList == null) {
        for (LocaleProviderAdapter.Type type : LocaleProviderAdapter.getAdapterPreference()) {
            LocaleServiceProvider lsp = providers.get(type);
            if (lsp != null) {
                if (lsp.isSupportedLocale(locale)) {
                    if (providersList == null) {
                        providersList = new ArrayList<>(2);
                    }
                    providersList.add(type);

                }
            }
        }
        if (providersList == null) {
            providersList = NULL_LIST;
        }
        List<LocaleProviderAdapter.Type> val = providersCache.putIfAbsent(locale, providersList);
        if (val != null) {
            providersList = val;
        }
    }
        return providersList;
    }
项目:jdk8u-dev-jdk    文件:AuxLocaleProviderAdapter.java   
@Override
public Locale[] getAvailableLocales() {
    if (availableLocales == null) {
        Set<Locale> avail = new HashSet<>();
        for (Class<? extends LocaleServiceProvider> c :
                LocaleServiceProviderPool.spiClasses) {
            LocaleServiceProvider lsp = getLocaleServiceProvider(c);
            if (lsp != null) {
                avail.addAll(Arrays.asList(lsp.getAvailableLocales()));
            }
        }
        availableLocales = avail.toArray(new Locale[0]);
    }

    // assuming caller won't mutate the array.
    return availableLocales;
}
项目:jdk8u-dev-jdk    文件:LocaleServiceProviderPool.java   
/**
 * Returns the list of locale service provider instances that support
 * the specified locale.
 *
 * @param locale the given locale
 * @return the list of locale data adapter types
 */
private List<LocaleProviderAdapter.Type> findProviders(Locale locale) {
    List<LocaleProviderAdapter.Type> providersList = providersCache.get(locale);
    if (providersList == null) {
        for (LocaleProviderAdapter.Type type : LocaleProviderAdapter.getAdapterPreference()) {
            LocaleServiceProvider lsp = providers.get(type);
            if (lsp != null) {
                if (lsp.isSupportedLocale(locale)) {
                    if (providersList == null) {
                        providersList = new ArrayList<>(2);
                    }
                    providersList.add(type);

                }
            }
        }
        if (providersList == null) {
            providersList = NULL_LIST;
        }
        List<LocaleProviderAdapter.Type> val = providersCache.putIfAbsent(locale, providersList);
        if (val != null) {
            providersList = val;
        }
    }
        return providersList;
    }
项目:OLD-OpenJDK8    文件:AuxLocaleProviderAdapter.java   
@Override
public Locale[] getAvailableLocales() {
    if (availableLocales == null) {
        Set<Locale> avail = new HashSet<>();
        for (Class<? extends LocaleServiceProvider> c :
                LocaleServiceProviderPool.spiClasses) {
            LocaleServiceProvider lsp = getLocaleServiceProvider(c);
            if (lsp != null) {
                avail.addAll(Arrays.asList(lsp.getAvailableLocales()));
            }
        }
        availableLocales = avail.toArray(new Locale[0]);
    }

    // assuming caller won't mutate the array.
    return availableLocales;
}
项目:OLD-OpenJDK8    文件:LocaleServiceProviderPool.java   
/**
 * Returns the list of locale service provider instances that support
 * the specified locale.
 *
 * @param locale the given locale
 * @return the list of locale data adapter types
 */
private List<LocaleProviderAdapter.Type> findProviders(Locale locale) {
    List<LocaleProviderAdapter.Type> providersList = providersCache.get(locale);
    if (providersList == null) {
        for (LocaleProviderAdapter.Type type : LocaleProviderAdapter.getAdapterPreference()) {
            LocaleServiceProvider lsp = providers.get(type);
            if (lsp != null) {
                if (lsp.isSupportedLocale(locale)) {
                    if (providersList == null) {
                        providersList = new ArrayList<>(2);
                    }
                    providersList.add(type);

                }
            }
        }
        if (providersList == null) {
            providersList = NULL_LIST;
        }
        List<LocaleProviderAdapter.Type> val = providersCache.putIfAbsent(locale, providersList);
        if (val != null) {
            providersList = val;
        }
    }
        return providersList;
    }
项目:cn1    文件:LocaleServiceProviderLoader.java   
/**
 * Get provider that support specified locale. If there is no provider
 * found, return <code>null</code>.
 * 
 * @param cache
 *            cached providers
 * @param locale
 *            the specified locale
 * @param providerFileName
 *            provider configuration file name
 * @return <code>LocaleServiceProvider</code> that support the locale
 */
public static LocaleServiceProvider getProviderByLocale(
        HashMap<ClassLoader, Object> cache, Locale locale,
        String providerFileName) {
    HashMap<LocaleServiceProvider, Set<Locale>> providers = getProviders(
            cache, providerFileName);
    // no provider installed
    if (providers == null || providers.size() == 0) {
        return null;
    }

    // find provider
    for (LocaleServiceProvider provider : providers.keySet()) {
        if (providers.get(provider).contains(locale)) {
            return provider;
        }
    }

    // no provider found
    return null;
}
项目:cn1    文件:LocaleServiceProviderLoader.java   
/**
 * Return all locales supported by the installed providers. If no provider
 * installed return <code>null</code>.
 * 
 * @param cache
 *            cached providers
 * @param providerFileName
 *            provider configuration file name
 * @return all locales supported by the installed providers
 */
public static Locale[] getProviderSupportLocales(
        HashMap<ClassLoader, Object> cache, String providerFileName) {

    HashMap<LocaleServiceProvider, Set<Locale>> providers = getProviders(
            cache, providerFileName);

    if (providers == null || providers.size() == 0) {
        return null;
    }

    List<Locale> locales = new ArrayList<Locale>();
    for (Set<Locale> element : providers.values()) {
        locales.addAll(element);
    }

    return locales.toArray(new Locale[0]);
}
项目:OpenJSharp    文件:JRELocaleProviderAdapter.java   
/**
 * Getter method for Locale Service Providers
 */
@Override
@SuppressWarnings("unchecked")
public <P extends LocaleServiceProvider> P getLocaleServiceProvider(Class<P> c) {
    switch (c.getSimpleName()) {
    case "BreakIteratorProvider":
        return (P) getBreakIteratorProvider();
    case "CollatorProvider":
        return (P) getCollatorProvider();
    case "DateFormatProvider":
        return (P) getDateFormatProvider();
    case "DateFormatSymbolsProvider":
        return (P) getDateFormatSymbolsProvider();
    case "DecimalFormatSymbolsProvider":
        return (P) getDecimalFormatSymbolsProvider();
    case "NumberFormatProvider":
        return (P) getNumberFormatProvider();
    case "CurrencyNameProvider":
        return (P) getCurrencyNameProvider();
    case "LocaleNameProvider":
        return (P) getLocaleNameProvider();
    case "TimeZoneNameProvider":
        return (P) getTimeZoneNameProvider();
    case "CalendarDataProvider":
        return (P) getCalendarDataProvider();
    case "CalendarNameProvider":
        return (P) getCalendarNameProvider();
    case "CalendarProvider":
        return (P) getCalendarProvider();
    default:
        throw new InternalError("should not come down here");
    }
}
项目:OpenJSharp    文件:LocaleProviderAdapter.java   
private static LocaleProviderAdapter findAdapter(Class<? extends LocaleServiceProvider> providerClass,
                                             Locale locale) {
    for (Type type : getAdapterPreference()) {
        LocaleProviderAdapter adapter = forType(type);
        LocaleServiceProvider provider = adapter.getLocaleServiceProvider(providerClass);
        if (provider != null) {
            if (provider.isSupportedLocale(locale)) {
                return adapter;
            }
        }
    }
    return null;
}
项目:OpenJSharp    文件:AuxLocaleProviderAdapter.java   
/**
 * Getter method for Locale Service Providers
 */
@Override
public <P extends LocaleServiceProvider> P getLocaleServiceProvider(Class<P> c) {
    @SuppressWarnings("unchecked")
    P lsp = (P) providersMap.get(c);
    if (lsp == null) {
        lsp = findInstalledProvider(c);
        providersMap.putIfAbsent(c, lsp == null ? NULL_PROVIDER : lsp);
    }

    return lsp;
}
项目:OpenJSharp    文件:HostLocaleProviderAdapter.java   
@Override
@SuppressWarnings("unchecked")
protected <P extends LocaleServiceProvider> P findInstalledProvider(final Class<P> c) {
    try {
        Method getter = HostLocaleProviderAdapterImpl.class.getMethod(
                "get" + c.getSimpleName(), (Class<?>[]) null);
        return (P)getter.invoke(null, (Object[]) null);
    }  catch (NoSuchMethodException |
              IllegalAccessException |
              IllegalArgumentException |
              InvocationTargetException ex) {
        LocaleServiceProviderPool.config(HostLocaleProviderAdapter.class, ex.toString());
    }
    return null;
}
项目:OpenJSharp    文件:LocaleServiceProviderPool.java   
/**
 * A factory method that returns a singleton instance
 */
public static LocaleServiceProviderPool getPool(Class<? extends LocaleServiceProvider> providerClass) {
    LocaleServiceProviderPool pool = poolOfPools.get(providerClass);
    if (pool == null) {
        LocaleServiceProviderPool newPool =
            new LocaleServiceProviderPool(providerClass);
        pool = poolOfPools.putIfAbsent(providerClass, newPool);
        if (pool == null) {
            pool = newPool;
        }
    }

    return pool;
}
项目:OpenJSharp    文件:LocaleServiceProviderPool.java   
/**
 * The sole constructor.
 *
 * @param c class of the locale sensitive service
 */
private LocaleServiceProviderPool (final Class<? extends LocaleServiceProvider> c) {
    providerClass = c;

    for (LocaleProviderAdapter.Type type : LocaleProviderAdapter.getAdapterPreference()) {
        LocaleProviderAdapter lda = LocaleProviderAdapter.forType(type);
        if (lda != null) {
            LocaleServiceProvider provider = lda.getLocaleServiceProvider(c);
            if (provider != null) {
                providers.putIfAbsent(type, provider);
            }
        }
    }
}
项目:OpenJSharp    文件:LocaleServiceProviderPool.java   
/**
 * Returns the union of locale sets that are available from
 * each service provider. This method does NOT return the
 * defensive copy.
 *
 * @return a set of available locales
 */
private synchronized Set<Locale> getAvailableLocaleSet() {
    if (availableLocales == null) {
        availableLocales = new HashSet<>();
        for (LocaleServiceProvider lsp : providers.values()) {
            Locale[] locales = lsp.getAvailableLocales();
            for (Locale locale: locales) {
                availableLocales.add(getLookupLocale(locale));
            }
        }
    }

    return availableLocales;
}
项目:OpenJSharp    文件:SPILocaleProviderAdapter.java   
private static <P extends LocaleServiceProvider> P getImpl(Map<Locale, P> map, Locale locale) {
    for (Locale l : LocaleServiceProviderPool.getLookupLocales(locale)) {
        P ret = map.get(l);
        if (ret != null) {
            return ret;
        }
    }
    return null;
}
项目:jdk8u-jdk    文件:JRELocaleProviderAdapter.java   
/**
 * Getter method for Locale Service Providers
 */
@Override
@SuppressWarnings("unchecked")
public <P extends LocaleServiceProvider> P getLocaleServiceProvider(Class<P> c) {
    switch (c.getSimpleName()) {
    case "BreakIteratorProvider":
        return (P) getBreakIteratorProvider();
    case "CollatorProvider":
        return (P) getCollatorProvider();
    case "DateFormatProvider":
        return (P) getDateFormatProvider();
    case "DateFormatSymbolsProvider":
        return (P) getDateFormatSymbolsProvider();
    case "DecimalFormatSymbolsProvider":
        return (P) getDecimalFormatSymbolsProvider();
    case "NumberFormatProvider":
        return (P) getNumberFormatProvider();
    case "CurrencyNameProvider":
        return (P) getCurrencyNameProvider();
    case "LocaleNameProvider":
        return (P) getLocaleNameProvider();
    case "TimeZoneNameProvider":
        return (P) getTimeZoneNameProvider();
    case "CalendarDataProvider":
        return (P) getCalendarDataProvider();
    case "CalendarNameProvider":
        return (P) getCalendarNameProvider();
    case "CalendarProvider":
        return (P) getCalendarProvider();
    default:
        throw new InternalError("should not come down here");
    }
}
项目:jdk8u-jdk    文件:LocaleProviderAdapter.java   
private static LocaleProviderAdapter findAdapter(Class<? extends LocaleServiceProvider> providerClass,
                                             Locale locale) {
    for (Type type : getAdapterPreference()) {
        LocaleProviderAdapter adapter = forType(type);
        LocaleServiceProvider provider = adapter.getLocaleServiceProvider(providerClass);
        if (provider != null) {
            if (provider.isSupportedLocale(locale)) {
                return adapter;
            }
        }
    }
    return null;
}
项目:jdk8u-jdk    文件:AuxLocaleProviderAdapter.java   
/**
 * Getter method for Locale Service Providers
 */
@Override
public <P extends LocaleServiceProvider> P getLocaleServiceProvider(Class<P> c) {
    @SuppressWarnings("unchecked")
    P lsp = (P) providersMap.get(c);
    if (lsp == null) {
        lsp = findInstalledProvider(c);
        providersMap.putIfAbsent(c, lsp == null ? NULL_PROVIDER : lsp);
    }

    return lsp;
}
项目:jdk8u-jdk    文件:HostLocaleProviderAdapter.java   
@Override
@SuppressWarnings("unchecked")
protected <P extends LocaleServiceProvider> P findInstalledProvider(final Class<P> c) {
    try {
        Method getter = HostLocaleProviderAdapterImpl.class.getMethod(
                "get" + c.getSimpleName(), (Class<?>[]) null);
        return (P)getter.invoke(null, (Object[]) null);
    }  catch (NoSuchMethodException |
              IllegalAccessException |
              IllegalArgumentException |
              InvocationTargetException ex) {
        LocaleServiceProviderPool.config(HostLocaleProviderAdapter.class, ex.toString());
    }
    return null;
}
项目:jdk8u-jdk    文件:LocaleServiceProviderPool.java   
/**
 * A factory method that returns a singleton instance
 */
public static LocaleServiceProviderPool getPool(Class<? extends LocaleServiceProvider> providerClass) {
    LocaleServiceProviderPool pool = poolOfPools.get(providerClass);
    if (pool == null) {
        LocaleServiceProviderPool newPool =
            new LocaleServiceProviderPool(providerClass);
        pool = poolOfPools.putIfAbsent(providerClass, newPool);
        if (pool == null) {
            pool = newPool;
        }
    }

    return pool;
}
项目:jdk8u-jdk    文件:LocaleServiceProviderPool.java   
/**
 * The sole constructor.
 *
 * @param c class of the locale sensitive service
 */
private LocaleServiceProviderPool (final Class<? extends LocaleServiceProvider> c) {
    providerClass = c;

    for (LocaleProviderAdapter.Type type : LocaleProviderAdapter.getAdapterPreference()) {
        LocaleProviderAdapter lda = LocaleProviderAdapter.forType(type);
        if (lda != null) {
            LocaleServiceProvider provider = lda.getLocaleServiceProvider(c);
            if (provider != null) {
                providers.putIfAbsent(type, provider);
            }
        }
    }
}
项目:jdk8u-jdk    文件:LocaleServiceProviderPool.java   
/**
 * Returns the union of locale sets that are available from
 * each service provider. This method does NOT return the
 * defensive copy.
 *
 * @return a set of available locales
 */
private synchronized Set<Locale> getAvailableLocaleSet() {
    if (availableLocales == null) {
        availableLocales = new HashSet<>();
        for (LocaleServiceProvider lsp : providers.values()) {
            Locale[] locales = lsp.getAvailableLocales();
            for (Locale locale: locales) {
                availableLocales.add(getLookupLocale(locale));
            }
        }
    }

    return availableLocales;
}
项目:jdk8u-jdk    文件:SPILocaleProviderAdapter.java   
private static <P extends LocaleServiceProvider> P getImpl(Map<Locale, P> map, Locale locale) {
    for (Locale l : LocaleServiceProviderPool.getLookupLocales(locale)) {
        P ret = map.get(l);
        if (ret != null) {
            return ret;
        }
    }
    return null;
}
项目:openjdk-jdk10    文件:JRELocaleProviderAdapter.java   
/**
 * Getter method for Locale Service Providers
 */
@Override
@SuppressWarnings("unchecked")
public <P extends LocaleServiceProvider> P getLocaleServiceProvider(Class<P> c) {
    switch (c.getSimpleName()) {
    case "BreakIteratorProvider":
        return (P) getBreakIteratorProvider();
    case "CollatorProvider":
        return (P) getCollatorProvider();
    case "DateFormatProvider":
        return (P) getDateFormatProvider();
    case "DateFormatSymbolsProvider":
        return (P) getDateFormatSymbolsProvider();
    case "DecimalFormatSymbolsProvider":
        return (P) getDecimalFormatSymbolsProvider();
    case "NumberFormatProvider":
        return (P) getNumberFormatProvider();
    case "CurrencyNameProvider":
        return (P) getCurrencyNameProvider();
    case "LocaleNameProvider":
        return (P) getLocaleNameProvider();
    case "TimeZoneNameProvider":
        return (P) getTimeZoneNameProvider();
    case "CalendarDataProvider":
        return (P) getCalendarDataProvider();
    case "CalendarNameProvider":
        return (P) getCalendarNameProvider();
    case "CalendarProvider":
        return (P) getCalendarProvider();
    case "JavaTimeDateTimePatternProvider":
        return (P) getJavaTimeDateTimePatternProvider();
    default:
        throw new InternalError("should not come down here");
    }
}
项目:openjdk-jdk10    文件:LocaleProviderAdapter.java   
private static LocaleProviderAdapter findAdapter(Class<? extends LocaleServiceProvider> providerClass,
                                             Locale locale) {
    for (Type type : getAdapterPreference()) {
        LocaleProviderAdapter adapter = forType(type);
        if (adapter != null) {
            LocaleServiceProvider provider = adapter.getLocaleServiceProvider(providerClass);
            if (provider != null) {
                if (provider.isSupportedLocale(locale)) {
                    return adapter;
                }
            }
        }
    }
    return null;
}
项目:openjdk-jdk10    文件:AuxLocaleProviderAdapter.java   
/**
 * Getter method for Locale Service Providers
 */
@Override
public <P extends LocaleServiceProvider> P getLocaleServiceProvider(Class<P> c) {
    @SuppressWarnings("unchecked")
    P lsp = (P) providersMap.get(c);
    if (lsp == null) {
        lsp = findInstalledProvider(c);
        providersMap.putIfAbsent(c, lsp == null ? NULL_PROVIDER : lsp);
    }

    return lsp;
}
项目:openjdk-jdk10    文件:HostLocaleProviderAdapter.java   
@Override
@SuppressWarnings("unchecked")
protected <P extends LocaleServiceProvider> P findInstalledProvider(final Class<P> c) {
    try {
        Method getter = HostLocaleProviderAdapterImpl.class.getMethod(
                "get" + c.getSimpleName(), (Class<?>[]) null);
        return (P)getter.invoke(null, (Object[]) null);
    }  catch (NoSuchMethodException |
              IllegalAccessException |
              IllegalArgumentException |
              InvocationTargetException ex) {
        LocaleServiceProviderPool.config(HostLocaleProviderAdapter.class, ex.toString());
    }
    return null;
}