< prev index next >

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

Print this page


   1 /*
   2  * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  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


  28 import java.security.AccessController;
  29 import java.security.PrivilegedAction;
  30 import java.text.spi.BreakIteratorProvider;
  31 import java.text.spi.CollatorProvider;
  32 import java.text.spi.DateFormatProvider;
  33 import java.text.spi.DateFormatSymbolsProvider;
  34 import java.text.spi.DecimalFormatSymbolsProvider;
  35 import java.text.spi.NumberFormatProvider;
  36 import java.util.ArrayList;
  37 import java.util.Arrays;
  38 import java.util.List;
  39 import java.util.Locale;
  40 import java.util.concurrent.ConcurrentHashMap;
  41 import java.util.concurrent.ConcurrentMap;
  42 import java.util.spi.CalendarDataProvider;
  43 import java.util.spi.CalendarNameProvider;
  44 import java.util.spi.CurrencyNameProvider;
  45 import java.util.spi.LocaleNameProvider;
  46 import java.util.spi.LocaleServiceProvider;
  47 import java.util.spi.TimeZoneNameProvider;

  48 import sun.util.spi.CalendarProvider;
  49 
  50 /**
  51  * An abstract parent class for the
  52  * HostLocaleProviderAdapter/SPILocaleProviderAdapter.
  53  *
  54  * @author Naoto Sato
  55  * @author Masayoshi Okutsu
  56  */
  57 public abstract class AuxLocaleProviderAdapter extends LocaleProviderAdapter {
  58     /**
  59      * SPI implementations map
  60      */
  61     private final ConcurrentMap<Class<? extends LocaleServiceProvider>, LocaleServiceProvider> providersMap =
  62             new ConcurrentHashMap<>();
  63 
  64     /**
  65      * Getter method for Locale Service Providers
  66      */
  67     @Override


 139     }
 140 
 141     @Override
 142     public CalendarNameProvider getCalendarNameProvider() {
 143         return getLocaleServiceProvider(CalendarNameProvider.class);
 144     }
 145 
 146     /**
 147      * Getter methods for sun.util.spi.* providers
 148      */
 149     @Override
 150     public CalendarProvider getCalendarProvider() {
 151         return getLocaleServiceProvider(CalendarProvider.class);
 152     }
 153 
 154     @Override
 155     public LocaleResources getLocaleResources(Locale locale) {
 156         return null;
 157     }
 158 





 159     private static Locale[] availableLocales = null;
 160 
 161     @Override
 162     public Locale[] getAvailableLocales() {
 163         if (availableLocales == null) {
 164             List<Locale> avail = new ArrayList<>();
 165             for (Class<? extends LocaleServiceProvider> c :
 166                     LocaleServiceProviderPool.spiClasses) {
 167                 LocaleServiceProvider lsp = getLocaleServiceProvider(c);
 168                 if (lsp != null) {
 169                     avail.addAll(Arrays.asList(lsp.getAvailableLocales()));
 170                 }
 171             }
 172             availableLocales = avail.toArray(new Locale[0]);
 173         }
 174 
 175         // assuming caller won't mutate the array.
 176         return availableLocales;
 177     }
 178 
   1 /*
   2  * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  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


  28 import java.security.AccessController;
  29 import java.security.PrivilegedAction;
  30 import java.text.spi.BreakIteratorProvider;
  31 import java.text.spi.CollatorProvider;
  32 import java.text.spi.DateFormatProvider;
  33 import java.text.spi.DateFormatSymbolsProvider;
  34 import java.text.spi.DecimalFormatSymbolsProvider;
  35 import java.text.spi.NumberFormatProvider;
  36 import java.util.ArrayList;
  37 import java.util.Arrays;
  38 import java.util.List;
  39 import java.util.Locale;
  40 import java.util.concurrent.ConcurrentHashMap;
  41 import java.util.concurrent.ConcurrentMap;
  42 import java.util.spi.CalendarDataProvider;
  43 import java.util.spi.CalendarNameProvider;
  44 import java.util.spi.CurrencyNameProvider;
  45 import java.util.spi.LocaleNameProvider;
  46 import java.util.spi.LocaleServiceProvider;
  47 import java.util.spi.TimeZoneNameProvider;
  48 import sun.text.spi.JavaTimeDateTimePatternProvider;
  49 import sun.util.spi.CalendarProvider;
  50 
  51 /**
  52  * An abstract parent class for the
  53  * HostLocaleProviderAdapter/SPILocaleProviderAdapter.
  54  *
  55  * @author Naoto Sato
  56  * @author Masayoshi Okutsu
  57  */
  58 public abstract class AuxLocaleProviderAdapter extends LocaleProviderAdapter {
  59     /**
  60      * SPI implementations map
  61      */
  62     private final ConcurrentMap<Class<? extends LocaleServiceProvider>, LocaleServiceProvider> providersMap =
  63             new ConcurrentHashMap<>();
  64 
  65     /**
  66      * Getter method for Locale Service Providers
  67      */
  68     @Override


 140     }
 141 
 142     @Override
 143     public CalendarNameProvider getCalendarNameProvider() {
 144         return getLocaleServiceProvider(CalendarNameProvider.class);
 145     }
 146 
 147     /**
 148      * Getter methods for sun.util.spi.* providers
 149      */
 150     @Override
 151     public CalendarProvider getCalendarProvider() {
 152         return getLocaleServiceProvider(CalendarProvider.class);
 153     }
 154 
 155     @Override
 156     public LocaleResources getLocaleResources(Locale locale) {
 157         return null;
 158     }
 159 
 160     @Override
 161     public JavaTimeDateTimePatternProvider getJavaTimeDateTimePatternProvider() {
 162         return getLocaleServiceProvider(JavaTimeDateTimePatternProvider.class);
 163     }
 164 
 165     private static Locale[] availableLocales = null;
 166 
 167     @Override
 168     public Locale[] getAvailableLocales() {
 169         if (availableLocales == null) {
 170             List<Locale> avail = new ArrayList<>();
 171             for (Class<? extends LocaleServiceProvider> c :
 172                     LocaleServiceProviderPool.spiClasses) {
 173                 LocaleServiceProvider lsp = getLocaleServiceProvider(c);
 174                 if (lsp != null) {
 175                     avail.addAll(Arrays.asList(lsp.getAvailableLocales()));
 176                 }
 177             }
 178             availableLocales = avail.toArray(new Locale[0]);
 179         }
 180 
 181         // assuming caller won't mutate the array.
 182         return availableLocales;
 183     }
 184 
< prev index next >