src/share/classes/sun/util/locale/provider/CurrencyNameProviderImpl.java

Print this page
rev 5957 : imported patch 8000245.8000273.8000615


  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.util.locale.provider;
  27 
  28 import java.util.Locale;
  29 import java.util.MissingResourceException;

  30 import java.util.Set;
  31 import java.util.spi.CurrencyNameProvider;
  32 import sun.util.resources.OpenListResourceBundle;
  33 
  34 /**
  35  * Concrete implementation of the
  36  * {@link java.util.spi.CurrencyNameProvider CurrencyNameProvider} class
  37  * for the JRE LocaleProviderAdapter.
  38  *
  39  * @author Naoto Sato
  40  * @author Masayoshi Okutsu
  41  */
  42 public class CurrencyNameProviderImpl extends CurrencyNameProvider
  43                                       implements AvailableLanguageTags {
  44     private final LocaleProviderAdapter.Type type;
  45     private final Set<String> langtags;
  46 
  47     public CurrencyNameProviderImpl(LocaleProviderAdapter.Type type, Set<String> langtags) {
  48         this.type = type;
  49         this.langtags = langtags;
  50     }
  51 
  52     @Override


 104      *     user, or null if the name is not available for the locale
 105      * @exception IllegalArgumentException if <code>currencyCode</code> is not in
 106      *     the form of three upper-case letters, or <code>locale</code> isn't
 107      *     one of the locales returned from
 108      *     {@link java.util.spi.LocaleServiceProvider#getAvailableLocales()
 109      *     getAvailableLocales()}.
 110      * @exception NullPointerException if <code>currencyCode</code> or
 111      *     <code>locale</code> is <code>null</code>
 112      * @since 1.7
 113      */
 114     @Override
 115     public String getDisplayName(String currencyCode, Locale locale) {
 116         return getString(currencyCode.toLowerCase(Locale.ROOT), locale);
 117     }
 118 
 119     private String getString(String key, Locale locale) {
 120         if (locale == null) {
 121             throw new NullPointerException();
 122         }
 123 
 124         OpenListResourceBundle bundle = LocaleProviderAdapter.forType(type).getLocaleData().getCurrencyNames(locale);
 125         LocaleServiceProviderPool pool =
 126                 LocaleServiceProviderPool.getPool(CurrencyNameProvider.class);
 127         try {
 128             if (!pool.hasProviders() ||
 129                 (bundle.getLocale().equals(locale) &&
 130                  bundle.handleGetKeys().contains(key))) {
 131                 return bundle.getString(key);
 132             }
 133         } catch (MissingResourceException mre) {}
 134 
 135         return null;
 136     }
 137 }


  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.util.locale.provider;
  27 
  28 import java.util.Locale;
  29 import java.util.MissingResourceException;
  30 import java.util.ResourceBundle;
  31 import java.util.Set;
  32 import java.util.spi.CurrencyNameProvider;

  33 
  34 /**
  35  * Concrete implementation of the
  36  * {@link java.util.spi.CurrencyNameProvider CurrencyNameProvider} class
  37  * for the JRE LocaleProviderAdapter.
  38  *
  39  * @author Naoto Sato
  40  * @author Masayoshi Okutsu
  41  */
  42 public class CurrencyNameProviderImpl extends CurrencyNameProvider
  43                                       implements AvailableLanguageTags {
  44     private final LocaleProviderAdapter.Type type;
  45     private final Set<String> langtags;
  46 
  47     public CurrencyNameProviderImpl(LocaleProviderAdapter.Type type, Set<String> langtags) {
  48         this.type = type;
  49         this.langtags = langtags;
  50     }
  51 
  52     @Override


 104      *     user, or null if the name is not available for the locale
 105      * @exception IllegalArgumentException if <code>currencyCode</code> is not in
 106      *     the form of three upper-case letters, or <code>locale</code> isn't
 107      *     one of the locales returned from
 108      *     {@link java.util.spi.LocaleServiceProvider#getAvailableLocales()
 109      *     getAvailableLocales()}.
 110      * @exception NullPointerException if <code>currencyCode</code> or
 111      *     <code>locale</code> is <code>null</code>
 112      * @since 1.7
 113      */
 114     @Override
 115     public String getDisplayName(String currencyCode, Locale locale) {
 116         return getString(currencyCode.toLowerCase(Locale.ROOT), locale);
 117     }
 118 
 119     private String getString(String key, Locale locale) {
 120         if (locale == null) {
 121             throw new NullPointerException();
 122         }
 123 
 124         ResourceBundle bundle = LocaleProviderAdapter.forType(type).getLocaleData().getCurrencyNames(locale);


 125         try {
 126             if (bundle.containsKey(key)) {


 127                 return bundle.getString(key);
 128             }
 129         } catch (MissingResourceException mre) {}
 130 
 131         return null;
 132     }
 133 }