01: /**
02: *******************************************************************************
03: * Copyright (C) 2001-2004, International Business Machines Corporation and *
04: * others. All Rights Reserved. *
05: *******************************************************************************
06: */package com.ibm.icu.util;
07:
08: import java.util.Locale;
09:
10: import com.ibm.icu.impl.ICUResourceBundle;
11: import com.ibm.icu.impl.ICUService;
12: import com.ibm.icu.impl.ICUService.Factory;
13: import com.ibm.icu.impl.ICULocaleService;
14:
15: /**
16: * This is a package-access implementation of registration for
17: * currency. The shim is instantiated by reflection in Currency, all
18: * dependencies on ICUService are located in this file. This structure
19: * is to allow ICU4J to be built without service registration support.
20: */
21: final class CurrencyServiceShim extends Currency.ServiceShim {
22:
23: Locale[] getAvailableLocales() {
24: if (service.isDefault()) {
25: return ICUResourceBundle
26: .getAvailableLocales(ICUResourceBundle.ICU_BASE_NAME);
27: }
28: return service.getAvailableLocales();
29: }
30:
31: ULocale[] getAvailableULocales() {
32: if (service.isDefault()) {
33: return ICUResourceBundle
34: .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 registerInstance(Currency currency, ULocale locale) {
53: return service.registerObject(currency, locale);
54: }
55:
56: boolean unregister(Object 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 handleCreate(ULocale loc, int kind,
66: ICUService service) {
67: return Currency.createCurrency(loc);
68: }
69: }
70:
71: registerFactory(new CurrencyFactory());
72: markDefault();
73: }
74: }
75:
76: static final ICULocaleService service = new CFService();
77: }
|