本文整理汇总了Java中java.util.spi.LocaleServiceProvider类的典型用法代码示例。如果您正苦于以下问题:Java LocaleServiceProvider类的具体用法?Java LocaleServiceProvider怎么用?Java LocaleServiceProvider使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LocaleServiceProvider类属于java.util.spi包,在下文中一共展示了LocaleServiceProvider类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAvailableLocales
import java.util.spi.LocaleServiceProvider; //导入依赖的package包/类
@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;
}
示例2: findProviders
import java.util.spi.LocaleServiceProvider; //导入依赖的package包/类
/**
* 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;
}
示例3: getAvailableLocales
import java.util.spi.LocaleServiceProvider; //导入依赖的package包/类
@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;
}
示例4: getAvailableLocaleSet
import java.util.spi.LocaleServiceProvider; //导入依赖的package包/类
/**
* 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;
}
示例5: getProviderByLocale
import java.util.spi.LocaleServiceProvider; //导入依赖的package包/类
/**
* 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;
}
示例6: getProviderSupportLocales
import java.util.spi.LocaleServiceProvider; //导入依赖的package包/类
/**
* 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]);
}
示例7: getLocaleServiceProvider
import java.util.spi.LocaleServiceProvider; //导入依赖的package包/类
/**
* 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");
}
}
示例8: findAdapter
import java.util.spi.LocaleServiceProvider; //导入依赖的package包/类
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;
}
示例9: getLocaleServiceProvider
import java.util.spi.LocaleServiceProvider; //导入依赖的package包/类
/**
* 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;
}
示例10: findInstalledProvider
import java.util.spi.LocaleServiceProvider; //导入依赖的package包/类
@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;
}
示例11: getPool
import java.util.spi.LocaleServiceProvider; //导入依赖的package包/类
/**
* 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;
}
示例12: LocaleServiceProviderPool
import java.util.spi.LocaleServiceProvider; //导入依赖的package包/类
/**
* 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);
}
}
}
}
示例13: getAvailableLocaleSet
import java.util.spi.LocaleServiceProvider; //导入依赖的package包/类
/**
* 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;
}
示例14: getImpl
import java.util.spi.LocaleServiceProvider; //导入依赖的package包/类
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;
}
示例15: getLocaleServiceProvider
import java.util.spi.LocaleServiceProvider; //导入依赖的package包/类
/**
* 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");
}
}