2 *******************************************************************************
3 * Copyright (C) 2001-2011, International Business Machines Corporation and *
4 * others. All Rights Reserved. *
5 *******************************************************************************
8 package com.ibm.icu.util;
10 import java.util.Locale;
12 import com.ibm.icu.impl.ICULocaleService;
13 import com.ibm.icu.impl.ICUResourceBundle;
14 import com.ibm.icu.impl.ICUService;
15 import com.ibm.icu.impl.ICUService.Factory;
18 * This is a package-access implementation of registration for
19 * currency. The shim is instantiated by reflection in Currency, all
20 * dependencies on ICUService are located in this file. This structure
21 * is to allow ICU4J to be built without service registration support.
23 final class CurrencyServiceShim extends Currency.ServiceShim {
25 Locale[] getAvailableLocales() {
26 if (service.isDefault()) {
27 return ICUResourceBundle.getAvailableLocales();
29 return service.getAvailableLocales();
32 ULocale[] getAvailableULocales() {
33 if (service.isDefault()) {
34 return ICUResourceBundle.getAvailableULocales();
36 return service.getAvailableULocales();
39 Currency createInstance(ULocale loc) {
40 // TODO: convert to ULocale when service switches over
42 if (service.isDefault()) {
43 return Currency.createCurrency(loc);
45 Currency curr = (Currency)service.get(loc);
49 Object registerInstance(Currency currency, ULocale locale) {
50 return service.registerObject(currency, locale);
53 boolean unregister(Object registryKey) {
54 return service.unregisterFactory((Factory)registryKey);
57 private static class CFService extends ICULocaleService {
61 class CurrencyFactory extends ICUResourceBundleFactory {
62 protected Object handleCreate(ULocale loc, int kind, ICUService srvc) {
63 return Currency.createCurrency(loc);
67 registerFactory(new CurrencyFactory());
71 static final ICULocaleService service = new CFService();