]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-4_8_1_1/main/classes/core/src/com/ibm/icu/util/CurrencyServiceShim.java
Added flags.
[Dictionary.git] / jars / icu4j-4_8_1_1 / main / classes / core / src / com / ibm / icu / util / CurrencyServiceShim.java
1 /**
2  *******************************************************************************
3  * Copyright (C) 2001-2011, International Business Machines Corporation and    *
4  * others. All Rights Reserved.                                                *
5  *******************************************************************************
6  */
7
8 package com.ibm.icu.util;
9
10 import java.util.Locale;
11
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;
16
17 /**
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.  
22  */
23 final class CurrencyServiceShim extends Currency.ServiceShim {
24     
25     Locale[] getAvailableLocales() {
26         if (service.isDefault()) {
27             return ICUResourceBundle.getAvailableLocales();
28         }
29         return service.getAvailableLocales();
30     }
31
32     ULocale[] getAvailableULocales() {
33         if (service.isDefault()) {
34             return ICUResourceBundle.getAvailableULocales();
35         }
36         return service.getAvailableULocales();
37     }
38
39     Currency createInstance(ULocale loc) {
40         // TODO: convert to ULocale when service switches over
41
42         if (service.isDefault()) {
43             return Currency.createCurrency(loc);
44         }
45         Currency curr = (Currency)service.get(loc);
46         return curr;
47     }
48
49     Object registerInstance(Currency currency, ULocale locale) {
50         return service.registerObject(currency, locale);
51     }
52     
53     boolean unregister(Object registryKey) {
54         return service.unregisterFactory((Factory)registryKey);
55     }
56
57     private static class CFService extends ICULocaleService {
58         CFService() {
59             super("Currency");
60
61             class CurrencyFactory extends ICUResourceBundleFactory {
62                 protected Object handleCreate(ULocale loc, int kind, ICUService srvc) {
63                     return Currency.createCurrency(loc);
64                 }
65             }
66             
67             registerFactory(new CurrencyFactory());
68             markDefault();
69         }
70     }
71     static final ICULocaleService service = new CFService();
72 }