< prev index next >

src/java.base/share/classes/sun/util/locale/provider/LocaleProviderAdapter.java

Print this page




 154             typeList.add(Type.JRE);
 155         }
 156         adapterPreference = Collections.unmodifiableList(typeList);
 157     }
 158 
 159     /**
 160      * Returns the singleton instance for each adapter type
 161      */
 162     public static LocaleProviderAdapter forType(Type type) {
 163         switch (type) {
 164         case JRE:
 165         case CLDR:
 166         case SPI:
 167         case HOST:
 168         case FALLBACK:
 169             LocaleProviderAdapter adapter = null;
 170             LocaleProviderAdapter cached = adapterInstances.get(type);
 171             if (cached == null) {
 172                 try {
 173                     // lazily load adapters here
 174                     adapter = (LocaleProviderAdapter)Class.forName(type.getAdapterClassName())
 175                         .newInstance();

 176                     cached = adapterInstances.putIfAbsent(type, adapter);
 177                     if (cached != null) {
 178                         adapter = cached;
 179                     }
 180                 } catch (ClassNotFoundException |
 181                          IllegalAccessException |
 182                          InstantiationException |
 183                          UnsupportedOperationException e) {
 184                     LocaleServiceProviderPool.config(LocaleProviderAdapter.class, e.toString());
 185                     adapterInstances.putIfAbsent(type, NONEXISTENT_ADAPTER);
 186                     if (defaultLocaleProviderAdapter == type) {
 187                         defaultLocaleProviderAdapter = Type.FALLBACK;
 188                     }
 189                 }
 190             } else if (cached != NONEXISTENT_ADAPTER) {
 191                 adapter = cached;
 192             }
 193             return adapter;
 194         default:
 195             throw new InternalError("unknown locale data adapter type");




 154             typeList.add(Type.JRE);
 155         }
 156         adapterPreference = Collections.unmodifiableList(typeList);
 157     }
 158 
 159     /**
 160      * Returns the singleton instance for each adapter type
 161      */
 162     public static LocaleProviderAdapter forType(Type type) {
 163         switch (type) {
 164         case JRE:
 165         case CLDR:
 166         case SPI:
 167         case HOST:
 168         case FALLBACK:
 169             LocaleProviderAdapter adapter = null;
 170             LocaleProviderAdapter cached = adapterInstances.get(type);
 171             if (cached == null) {
 172                 try {
 173                     // lazily load adapters here
 174                     @SuppressWarnings("deprecation")
 175                     Object tmp = Class.forName(type.getAdapterClassName()).newInstance();
 176                     adapter = (LocaleProviderAdapter)tmp;
 177                     cached = adapterInstances.putIfAbsent(type, adapter);
 178                     if (cached != null) {
 179                         adapter = cached;
 180                     }
 181                 } catch (ClassNotFoundException |
 182                          IllegalAccessException |
 183                          InstantiationException |
 184                          UnsupportedOperationException e) {
 185                     LocaleServiceProviderPool.config(LocaleProviderAdapter.class, e.toString());
 186                     adapterInstances.putIfAbsent(type, NONEXISTENT_ADAPTER);
 187                     if (defaultLocaleProviderAdapter == type) {
 188                         defaultLocaleProviderAdapter = Type.FALLBACK;
 189                     }
 190                 }
 191             } else if (cached != NONEXISTENT_ADAPTER) {
 192                 adapter = cached;
 193             }
 194             return adapter;
 195         default:
 196             throw new InternalError("unknown locale data adapter type");


< prev index next >