< prev index next >
src/java.base/share/classes/sun/util/locale/provider/SPILocaleProviderAdapter.java
Print this page
rev 59397 : imported patch 8245241
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
@@ -41,13 +41,13 @@
import java.text.spi.DecimalFormatSymbolsProvider;
import java.text.spi.NumberFormatProvider;
import java.util.Arrays;
import java.util.Locale;
import java.util.Map;
+import java.util.ServiceConfigurationError;
import java.util.ServiceLoader;
import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
import java.util.spi.CalendarDataProvider;
import java.util.spi.CalendarNameProvider;
import java.util.spi.CurrencyNameProvider;
import java.util.spi.LocaleNameProvider;
import java.util.spi.LocaleServiceProvider;
@@ -70,11 +70,11 @@
}
@Override
protected <P extends LocaleServiceProvider> P findInstalledProvider(final Class<P> c) {
try {
- return AccessController.doPrivileged(new PrivilegedExceptionAction<P>() {
+ return AccessController.doPrivileged(new PrivilegedExceptionAction<>() {
@Override
@SuppressWarnings(value={"unchecked", "deprecation"})
public P run() {
P delegate = null;
@@ -89,57 +89,57 @@
"Delegate")
.newInstance();
} catch (ClassNotFoundException |
InstantiationException |
IllegalAccessException e) {
- LocaleServiceProviderPool.config(SPILocaleProviderAdapter.class, e.toString());
- return null;
+ throw new ServiceConfigurationError(
+ "SPI locale provider cannot be instantiated.", e);
}
}
((Delegate)delegate).addImpl(provider);
}
return delegate;
}
});
} catch (PrivilegedActionException e) {
- LocaleServiceProviderPool.config(SPILocaleProviderAdapter.class, e.toString());
+ throw new ServiceConfigurationError(
+ "SPI locale provider cannot be instantiated.", e);
}
- return null;
}
/*
* Delegate interface. All the implementations have to have the class name
* following "<provider class name>Delegate" convention.
*/
private interface Delegate<P extends LocaleServiceProvider> {
- default public void addImpl(P impl) {
+ default void addImpl(P impl) {
for (Locale l : impl.getAvailableLocales()) {
getDelegateMap().putIfAbsent(l, impl);
}
}
/*
* Obtain the real SPI implementation, using locale fallback
*/
- default public P getImpl(Locale locale) {
+ default P getImpl(Locale locale) {
for (Locale l : LocaleServiceProviderPool.getLookupLocales(locale.stripExtensions())) {
P ret = getDelegateMap().get(l);
if (ret != null) {
return ret;
}
}
return null;
}
- public Map<Locale, P> getDelegateMap();
+ Map<Locale, P> getDelegateMap();
- default public Locale[] getAvailableLocalesDelegate() {
- return getDelegateMap().keySet().stream().toArray(Locale[]::new);
+ default Locale[] getAvailableLocalesDelegate() {
+ return getDelegateMap().keySet().toArray(new Locale[0]);
}
- default public boolean isSupportedLocaleDelegate(Locale locale) {
+ default boolean isSupportedLocaleDelegate(Locale locale) {
Map<Locale, P> map = getDelegateMap();
Locale override = CalendarDataUtility.findRegionOverride(locale);
// First, call the method with extensions (if any)
P impl = map.get(override);
< prev index next >