1 5 6 package com.ibm.icu.util; 7 8 import java.util.Locale ; 9 import java.util.MissingResourceException ; 10 import java.util.Set ; 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.ICULocaleService.LocaleKey; 16 import com.ibm.icu.impl.ICULocaleService.LocaleKeyFactory; 17 import com.ibm.icu.impl.ICUService.Factory; 18 import com.ibm.icu.impl.ICUService.Key; 19 import com.ibm.icu.util.Calendar.CalendarFactory; 20 21 class CalendarServiceShim extends Calendar.CalendarShim { 22 23 Locale [] getAvailableLocales() { 24 if (service.isDefault()) { 25 return ICUResourceBundle.getAvailableLocales(ICUResourceBundle.ICU_BASE_NAME); 26 } 27 return service.getAvailableLocales(); 28 } 29 30 ULocale[] getAvailableULocales() { 31 if (service.isDefault()) { 32 return ICUResourceBundle.getAvailableULocales(ICUResourceBundle.ICU_BASE_NAME); 33 } 34 return service.getAvailableULocales(); 35 } 36 37 private static final class CalFactory extends LocaleKeyFactory { 38 private CalendarFactory delegate; 39 CalFactory(CalendarFactory delegate) { 40 super(delegate.visible() ? VISIBLE : INVISIBLE); 41 this.delegate = delegate; 42 } 43 44 public Object create(Key key, ICUService service) { 45 if (handlesKey(key)) { 46 LocaleKey lkey = (LocaleKey)key; 47 ULocale loc = lkey.canonicalLocale(); 48 Object result = delegate.createCalendar(loc); 49 if (result == null) { 50 result = service.getKey(key, null, this); 51 } 52 return result; 53 } 54 return null; 55 } 56 57 protected Set getSupportedIDs() { 58 return delegate.getSupportedLocaleNames(); 59 } 60 } 61 62 Calendar createInstance(ULocale desiredLocale) { 63 ULocale[] actualLoc = new ULocale[1]; 64 if (desiredLocale.equals(ULocale.ROOT)) { 65 desiredLocale = ULocale.ROOT; 66 } 67 Calendar cal = (Calendar)service.get(desiredLocale, actualLoc); 68 if (cal == null) { 69 throw new MissingResourceException ("Unable to construct Calendar", "", ""); 70 } 71 cal = (Calendar)cal.clone(); 72 73 78 82 return cal; 83 } 84 85 Object registerFactory(CalendarFactory factory) { 86 return service.registerFactory(new CalFactory(factory)); 87 } 88 89 boolean unregister(Object k) { 90 return service.unregisterFactory((Factory)k); 91 } 92 93 private static class CalService extends ICULocaleService { 94 CalService() { 95 super("Calendar"); 96 class RBCalendarFactory extends ICUResourceBundleFactory { 97 protected Object handleCreate(ULocale loc, int kind, ICUService sercice) { 98 return Calendar.createInstance(loc); 99 } 100 } 101 this.registerFactory(new RBCalendarFactory()); 102 markDefault(); 103 } 104 } 105 106 private static ICULocaleService service = new CalService(); 107 } 108 | Popular Tags |