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