11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package sun.util.locale.provider; 27 28 import java.security.AccessController; 29 import java.security.PrivilegedActionException; 30 import java.security.PrivilegedExceptionAction; 31 import java.text.*; 32 import java.text.spi.*; 33 import java.util.*; 34 import java.util.concurrent.*; 35 import java.util.spi.*; 36 37 /** 38 * LocaleProviderAdapter implementation for the installed SPI implementations. 39 * 40 * @author Naoto Sato 41 * @author Masayoshi Okutsu 42 */ 43 public class SPILocaleProviderAdapter extends AuxLocaleProviderAdapter { 44 45 /** 46 * Returns the type of this LocaleProviderAdapter 47 */ 48 @Override 49 public LocaleProviderAdapter.Type getAdapterType() { 50 return LocaleProviderAdapter.Type.SPI; 51 } 52 53 @Override 54 protected <P extends LocaleServiceProvider> P findInstalledProvider(final Class<P> c) { 55 try { 394 } 395 396 @Override 397 public boolean isSupportedLocale(Locale locale) { 398 return map.containsKey(locale); 399 } 400 401 @Override 402 public int getFirstDayOfWeek(Locale locale) { 403 CalendarDataProvider cdp = getImpl(locale); 404 assert cdp != null; 405 return cdp.getFirstDayOfWeek(locale); 406 } 407 408 @Override 409 public int getMinimalDaysInFirstWeek(Locale locale) { 410 CalendarDataProvider cdp = getImpl(locale); 411 assert cdp != null; 412 return cdp.getMinimalDaysInFirstWeek(locale); 413 } 414 415 @Override 416 public String getDisplayName(String calendarType, 417 int field, int value, 418 int style, Locale locale) { 419 CalendarDataProvider cdp = getImpl(locale); 420 assert cdp != null; 421 return cdp.getDisplayName(calendarType, field, value, style, locale); 422 } 423 424 @Override 425 public Map<String, Integer> getDisplayNames(String calendarType, 426 int field, int style, 427 Locale locale) { 428 CalendarDataProvider cdp = getImpl(locale); 429 assert cdp != null; 430 return cdp.getDisplayNames(calendarType, field, style, locale); 431 } 432 } 433 434 static class CurrencyNameProviderDelegate extends CurrencyNameProvider 435 implements Delegate<CurrencyNameProvider> { 436 private ConcurrentMap<Locale, CurrencyNameProvider> map = new ConcurrentHashMap<>(); 437 438 @Override 439 public void addImpl(CurrencyNameProvider impl) { 440 for (Locale l : impl.getAvailableLocales()) { 441 map.put(l, impl); 442 } 443 } 444 445 @Override 446 public CurrencyNameProvider getImpl(Locale locale) { 447 return SPILocaleProviderAdapter.getImpl(map, locale); 448 } | 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package sun.util.locale.provider; 27 28 import java.security.AccessController; 29 import java.security.PrivilegedActionException; 30 import java.security.PrivilegedExceptionAction; 31 import java.text.BreakIterator; 32 import java.text.Collator; 33 import java.text.DateFormat; 34 import java.text.DateFormatSymbols; 35 import java.text.DecimalFormatSymbols; 36 import java.text.NumberFormat; 37 import java.text.spi.BreakIteratorProvider; 38 import java.text.spi.CollatorProvider; 39 import java.text.spi.DateFormatProvider; 40 import java.text.spi.DateFormatSymbolsProvider; 41 import java.text.spi.DecimalFormatSymbolsProvider; 42 import java.text.spi.NumberFormatProvider; 43 import java.util.Locale; 44 import java.util.Map; 45 import java.util.ServiceLoader; 46 import java.util.concurrent.ConcurrentHashMap; 47 import java.util.concurrent.ConcurrentMap; 48 import java.util.spi.CalendarDataProvider; 49 import java.util.spi.CalendarNameProvider; 50 import java.util.spi.CurrencyNameProvider; 51 import java.util.spi.LocaleNameProvider; 52 import java.util.spi.LocaleServiceProvider; 53 import java.util.spi.TimeZoneNameProvider; 54 55 /** 56 * LocaleProviderAdapter implementation for the installed SPI implementations. 57 * 58 * @author Naoto Sato 59 * @author Masayoshi Okutsu 60 */ 61 public class SPILocaleProviderAdapter extends AuxLocaleProviderAdapter { 62 63 /** 64 * Returns the type of this LocaleProviderAdapter 65 */ 66 @Override 67 public LocaleProviderAdapter.Type getAdapterType() { 68 return LocaleProviderAdapter.Type.SPI; 69 } 70 71 @Override 72 protected <P extends LocaleServiceProvider> P findInstalledProvider(final Class<P> c) { 73 try { 412 } 413 414 @Override 415 public boolean isSupportedLocale(Locale locale) { 416 return map.containsKey(locale); 417 } 418 419 @Override 420 public int getFirstDayOfWeek(Locale locale) { 421 CalendarDataProvider cdp = getImpl(locale); 422 assert cdp != null; 423 return cdp.getFirstDayOfWeek(locale); 424 } 425 426 @Override 427 public int getMinimalDaysInFirstWeek(Locale locale) { 428 CalendarDataProvider cdp = getImpl(locale); 429 assert cdp != null; 430 return cdp.getMinimalDaysInFirstWeek(locale); 431 } 432 } 433 434 static class CalendarNameProviderDelegate extends CalendarNameProvider 435 implements Delegate<CalendarNameProvider> { 436 private ConcurrentMap<Locale, CalendarNameProvider> map = new ConcurrentHashMap<>(); 437 438 @Override 439 public void addImpl(CalendarNameProvider impl) { 440 for (Locale l : impl.getAvailableLocales()) { 441 map.put(l, impl); 442 } 443 } 444 445 @Override 446 public CalendarNameProvider getImpl(Locale locale) { 447 return SPILocaleProviderAdapter.getImpl(map, locale); 448 } 449 450 @Override 451 public Locale[] getAvailableLocales() { 452 return map.keySet().toArray(new Locale[0]); 453 } 454 455 @Override 456 public boolean isSupportedLocale(Locale locale) { 457 return map.containsKey(locale); 458 } 459 460 @Override 461 public String getDisplayName(String calendarType, 462 int field, int value, 463 int style, Locale locale) { 464 CalendarNameProvider cdp = getImpl(locale); 465 assert cdp != null; 466 return cdp.getDisplayName(calendarType, field, value, style, locale); 467 } 468 469 @Override 470 public Map<String, Integer> getDisplayNames(String calendarType, 471 int field, int style, 472 Locale locale) { 473 CalendarNameProvider cdp = getImpl(locale); 474 assert cdp != null; 475 return cdp.getDisplayNames(calendarType, field, style, locale); 476 } 477 } 478 479 static class CurrencyNameProviderDelegate extends CurrencyNameProvider 480 implements Delegate<CurrencyNameProvider> { 481 private ConcurrentMap<Locale, CurrencyNameProvider> map = new ConcurrentHashMap<>(); 482 483 @Override 484 public void addImpl(CurrencyNameProvider impl) { 485 for (Locale l : impl.getAvailableLocales()) { 486 map.put(l, impl); 487 } 488 } 489 490 @Override 491 public CurrencyNameProvider getImpl(Locale locale) { 492 return SPILocaleProviderAdapter.getImpl(map, locale); 493 } |