Home | History | Annotate | Download | only in util
      1 //  2016 and later: Unicode, Inc. and others.
      2 // License & terms of use: http://www.unicode.org/copyright.html#License
      3 /**
      4  *******************************************************************************
      5  * Copyright (C) 2001-2011, International Business Machines Corporation and    *
      6  * others. All Rights Reserved.                                                *
      7  *******************************************************************************
      8  */
      9 
     10 package com.ibm.icu.util;
     11 
     12 import java.util.Locale;
     13 
     14 import com.ibm.icu.impl.ICULocaleService;
     15 import com.ibm.icu.impl.ICUResourceBundle;
     16 import com.ibm.icu.impl.ICUService;
     17 import com.ibm.icu.impl.ICUService.Factory;
     18 
     19 /**
     20  * This is a package-access implementation of registration for
     21  * currency.  The shim is instantiated by reflection in Currency, all
     22  * dependencies on ICUService are located in this file. This structure
     23  * is to allow ICU4J to be built without service registration support.
     24  */
     25 final class CurrencyServiceShim extends Currency.ServiceShim {
     26 
     27     Locale[] getAvailableLocales() {
     28         if (service.isDefault()) {
     29             return ICUResourceBundle.getAvailableLocales();
     30         }
     31         return service.getAvailableLocales();
     32     }
     33 
     34     ULocale[] getAvailableULocales() {
     35         if (service.isDefault()) {
     36             return ICUResourceBundle.getAvailableULocales();
     37         }
     38         return service.getAvailableULocales();
     39     }
     40 
     41     Currency createInstance(ULocale loc) {
     42         // TODO: convert to ULocale when service switches over
     43 
     44         if (service.isDefault()) {
     45             return Currency.createCurrency(loc);
     46         }
     47         Currency curr = (Currency)service.get(loc);
     48         return curr;
     49     }
     50 
     51     Object registerInstance(Currency currency, ULocale locale) {
     52         return service.registerObject(currency, locale);
     53     }
     54 
     55     boolean unregister(Object registryKey) {
     56         return service.unregisterFactory((Factory)registryKey);
     57     }
     58 
     59     private static class CFService extends ICULocaleService {
     60         CFService() {
     61             super("Currency");
     62 
     63             class CurrencyFactory extends ICUResourceBundleFactory {
     64                 protected Object handleCreate(ULocale loc, int kind, ICUService srvc) {
     65                     return Currency.createCurrency(loc);
     66                 }
     67             }
     68 
     69             registerFactory(new CurrencyFactory());
     70             markDefault();
     71         }
     72     }
     73     static final ICULocaleService service = new CFService();
     74 }
     75