2 *******************************************************************************
\r
3 * Copyright (C) 2001-2010, International Business Machines Corporation and *
\r
4 * others. All Rights Reserved. *
\r
5 *******************************************************************************
\r
8 package com.ibm.icu.util;
\r
10 import java.util.Locale;
\r
12 import com.ibm.icu.impl.ICULocaleService;
\r
13 import com.ibm.icu.impl.ICUResourceBundle;
\r
14 import com.ibm.icu.impl.ICUService;
\r
15 import com.ibm.icu.impl.ICUService.Factory;
\r
18 * This is a package-access implementation of registration for
\r
19 * currency. The shim is instantiated by reflection in Currency, all
\r
20 * dependencies on ICUService are located in this file. This structure
\r
21 * is to allow ICU4J to be built without service registration support.
\r
23 final class CurrencyServiceShim extends Currency.ServiceShim {
\r
25 Locale[] getAvailableLocales() {
\r
26 if (service.isDefault()) {
\r
27 return ICUResourceBundle.getAvailableLocales();
\r
29 return service.getAvailableLocales();
\r
32 ULocale[] getAvailableULocales() {
\r
33 if (service.isDefault()) {
\r
34 return ICUResourceBundle.getAvailableULocales();
\r
36 return service.getAvailableULocales();
\r
39 Currency createInstance(ULocale loc) {
\r
40 // TODO: convert to ULocale when service switches over
\r
42 if (service.isDefault()) {
\r
43 return Currency.createCurrency(loc);
\r
45 ULocale[] actualLoc = new ULocale[1];
\r
46 Currency curr = (Currency)service.get(loc, actualLoc);
\r
47 ULocale uloc = actualLoc[0];
\r
48 curr.setLocale(uloc, uloc); // services make no distinction between actual & valid
\r
52 Object registerInstance(Currency currency, ULocale locale) {
\r
53 return service.registerObject(currency, locale);
\r
56 boolean unregister(Object registryKey) {
\r
57 return service.unregisterFactory((Factory)registryKey);
\r
60 private static class CFService extends ICULocaleService {
\r
64 class CurrencyFactory extends ICUResourceBundleFactory {
\r
65 protected Object handleCreate(ULocale loc, int kind, ICUService srvc) {
\r
66 return Currency.createCurrency(loc);
\r
70 registerFactory(new CurrencyFactory());
\r
74 static final ICULocaleService service = new CFService();
\r