KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ibm > icu > util > CurrencyServiceShim


1 /**
2  *******************************************************************************
3  * Copyright (C) 2001-2004, 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 JavaDoc;
11
12 import com.ibm.icu.impl.ICUResourceBundle;
13 import com.ibm.icu.impl.ICUService;
14 import com.ibm.icu.impl.ICUService.Factory;
15 import com.ibm.icu.impl.ICULocaleService;
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 JavaDoc[] getAvailableLocales() {
26         if (service.isDefault()) {
27             return ICUResourceBundle.getAvailableLocales(ICUResourceBundle.ICU_BASE_NAME);
28         }
29         return service.getAvailableLocales();
30     }
31
32     ULocale[] getAvailableULocales() {
33         if (service.isDefault()) {
34             return ICUResourceBundle.getAvailableULocales(ICUResourceBundle.ICU_BASE_NAME);
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         ULocale[] actualLoc = new ULocale[1];
46     Currency curr = (Currency)service.get(loc, actualLoc);
47         ULocale uloc = actualLoc[0];
48         curr.setLocale(uloc, uloc); // services make no distinction between actual & valid
49
return curr;
50     }
51
52     Object JavaDoc registerInstance(Currency currency, ULocale locale) {
53         return service.registerObject(currency, locale);
54     }
55     
56     boolean unregister(Object JavaDoc registryKey) {
57         return service.unregisterFactory((Factory)registryKey);
58     }
59
60     private static class CFService extends ICULocaleService {
61         CFService() {
62             super("Currency");
63
64             class CurrencyFactory extends ICUResourceBundleFactory {
65                 protected Object JavaDoc handleCreate(ULocale loc, int kind, ICUService service) {
66                     return Currency.createCurrency(loc);
67                 }
68             }
69             
70             registerFactory(new CurrencyFactory());
71             markDefault();
72         }
73     }
74     static final ICULocaleService service = new CFService();
75 }
76
Popular Tags