< prev index next >

src/java.base/share/classes/sun/util/locale/provider/SPILocaleProviderAdapter.java

Print this page
rev 59397 : imported patch 8245241

*** 1,7 **** /* ! * Copyright (c) 2012, 2018, 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 --- 1,7 ---- /* ! * 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,53 **** 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.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; --- 41,53 ---- 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.spi.CalendarDataProvider; import java.util.spi.CalendarNameProvider; import java.util.spi.CurrencyNameProvider; import java.util.spi.LocaleNameProvider; import java.util.spi.LocaleServiceProvider;
*** 70,80 **** } @Override protected <P extends LocaleServiceProvider> P findInstalledProvider(final Class<P> c) { try { ! return AccessController.doPrivileged(new PrivilegedExceptionAction<P>() { @Override @SuppressWarnings(value={"unchecked", "deprecation"}) public P run() { P delegate = null; --- 70,80 ---- } @Override protected <P extends LocaleServiceProvider> P findInstalledProvider(final Class<P> c) { try { ! return AccessController.doPrivileged(new PrivilegedExceptionAction<>() { @Override @SuppressWarnings(value={"unchecked", "deprecation"}) public P run() { P delegate = null;
*** 89,145 **** "Delegate") .newInstance(); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { ! LocaleServiceProviderPool.config(SPILocaleProviderAdapter.class, e.toString()); ! return null; } } ((Delegate)delegate).addImpl(provider); } return delegate; } }); } catch (PrivilegedActionException e) { ! LocaleServiceProviderPool.config(SPILocaleProviderAdapter.class, e.toString()); } - 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) { for (Locale l : impl.getAvailableLocales()) { getDelegateMap().putIfAbsent(l, impl); } } /* * Obtain the real SPI implementation, using locale fallback */ ! default public 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(); ! default public Locale[] getAvailableLocalesDelegate() { ! return getDelegateMap().keySet().stream().toArray(Locale[]::new); } ! default public 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); --- 89,145 ---- "Delegate") .newInstance(); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { ! throw new ServiceConfigurationError( ! "SPI locale provider cannot be instantiated.", e); } } ((Delegate)delegate).addImpl(provider); } return delegate; } }); } catch (PrivilegedActionException e) { ! throw new ServiceConfigurationError( ! "SPI locale provider cannot be instantiated.", e); } } /* * Delegate interface. All the implementations have to have the class name * following "<provider class name>Delegate" convention. */ private interface Delegate<P extends LocaleServiceProvider> { ! default void addImpl(P impl) { for (Locale l : impl.getAvailableLocales()) { getDelegateMap().putIfAbsent(l, impl); } } /* * Obtain the real SPI implementation, using locale fallback */ ! default P getImpl(Locale locale) { for (Locale l : LocaleServiceProviderPool.getLookupLocales(locale.stripExtensions())) { P ret = getDelegateMap().get(l); if (ret != null) { return ret; } } return null; } ! Map<Locale, P> getDelegateMap(); ! default Locale[] getAvailableLocalesDelegate() { ! return getDelegateMap().keySet().toArray(new Locale[0]); } ! 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 >