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
23 * questions.
24 */
25
26 package sun.util.locale.provider;
27
28 import java.security.AccessController;
29 import java.text.spi.BreakIteratorProvider;
30 import java.text.spi.CollatorProvider;
31 import java.text.spi.DateFormatProvider;
32 import java.text.spi.DateFormatSymbolsProvider;
33 import java.text.spi.DecimalFormatSymbolsProvider;
34 import java.text.spi.NumberFormatProvider;
35 import java.util.ArrayList;
36 import java.util.Collections;
37 import java.util.List;
38 import java.util.Locale;
39 import java.util.Map;
40 import java.util.ResourceBundle;
41 import java.util.Set;
42 import java.util.concurrent.ConcurrentHashMap;
43 import java.util.concurrent.ConcurrentMap;
44 import java.util.spi.CalendarDataProvider;
45 import java.util.spi.CalendarNameProvider;
46 import java.util.spi.CurrencyNameProvider;
47 import java.util.spi.LocaleNameProvider;
48 import java.util.spi.LocaleServiceProvider;
49 import java.util.spi.TimeZoneNameProvider;
50 import sun.util.spi.CalendarProvider;
51
52 /**
53 * The LocaleProviderAdapter abstract class.
54 *
55 * @author Naoto Sato
56 * @author Masayoshi Okutsu
57 */
58 public abstract class LocaleProviderAdapter {
59 /**
60 * Adapter type.
61 */
62 public static enum Type {
63 JRE("sun.util.locale.provider.JRELocaleProviderAdapter", "sun.util.resources", "sun.text.resources"),
64 CLDR("sun.util.cldr.CLDRLocaleProviderAdapter", "sun.util.resources.cldr", "sun.text.resources.cldr"),
65 SPI("sun.util.locale.provider.SPILocaleProviderAdapter"),
66 HOST("sun.util.locale.provider.HostLocaleProviderAdapter"),
67 FALLBACK("sun.util.locale.provider.FallbackLocaleProviderAdapter", "sun.util.resources", "sun.text.resources");
68
69 private final String CLASSNAME;
99 private static final List<Type> adapterPreference;
100
101 /**
102 * LocaleProviderAdapter instances
103 */
104 private static final Map<Type, LocaleProviderAdapter> adapterInstances = new ConcurrentHashMap<>();
105
106 /**
107 * Default fallback adapter type, which should return something meaningful in any case.
108 * This is either CLDR or FALLBACK.
109 */
110 static volatile LocaleProviderAdapter.Type defaultLocaleProviderAdapter;
111
112 /**
113 * Adapter lookup cache.
114 */
115 private static ConcurrentMap<Class<? extends LocaleServiceProvider>, ConcurrentMap<Locale, LocaleProviderAdapter>>
116 adapterCache = new ConcurrentHashMap<>();
117
118 static {
119 String order = AccessController.doPrivileged(
120 new sun.security.action.GetPropertyAction("java.locale.providers"));
121 List<Type> typeList = new ArrayList<>();
122
123 // Check user specified adapter preference
124 if (order != null && order.length() != 0) {
125 String[] types = order.split(",");
126 for (String type : types) {
127 type = type.trim().toUpperCase(Locale.ROOT);
128 if (type.equals("COMPAT")) {
129 type = "JRE";
130 }
131 try {
132 Type aType = Type.valueOf(type.trim().toUpperCase(Locale.ROOT));
133 if (!typeList.contains(aType)) {
134 typeList.add(aType);
135 }
136 } catch (IllegalArgumentException | UnsupportedOperationException e) {
137 // could be caused by the user specifying wrong
138 // provider name or format in the system property
139 LocaleServiceProviderPool.config(LocaleProviderAdapter.class, e.toString());
140 }
|
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
23 * questions.
24 */
25
26 package sun.util.locale.provider;
27
28 import java.text.spi.BreakIteratorProvider;
29 import java.text.spi.CollatorProvider;
30 import java.text.spi.DateFormatProvider;
31 import java.text.spi.DateFormatSymbolsProvider;
32 import java.text.spi.DecimalFormatSymbolsProvider;
33 import java.text.spi.NumberFormatProvider;
34 import java.util.ArrayList;
35 import java.util.Collections;
36 import java.util.List;
37 import java.util.Locale;
38 import java.util.Map;
39 import java.util.ResourceBundle;
40 import java.util.Set;
41 import java.util.concurrent.ConcurrentHashMap;
42 import java.util.concurrent.ConcurrentMap;
43 import java.util.spi.CalendarDataProvider;
44 import java.util.spi.CalendarNameProvider;
45 import java.util.spi.CurrencyNameProvider;
46 import java.util.spi.LocaleNameProvider;
47 import java.util.spi.LocaleServiceProvider;
48 import java.util.spi.TimeZoneNameProvider;
49 import sun.security.action.GetPropertyAction;
50 import sun.util.spi.CalendarProvider;
51
52 /**
53 * The LocaleProviderAdapter abstract class.
54 *
55 * @author Naoto Sato
56 * @author Masayoshi Okutsu
57 */
58 public abstract class LocaleProviderAdapter {
59 /**
60 * Adapter type.
61 */
62 public static enum Type {
63 JRE("sun.util.locale.provider.JRELocaleProviderAdapter", "sun.util.resources", "sun.text.resources"),
64 CLDR("sun.util.cldr.CLDRLocaleProviderAdapter", "sun.util.resources.cldr", "sun.text.resources.cldr"),
65 SPI("sun.util.locale.provider.SPILocaleProviderAdapter"),
66 HOST("sun.util.locale.provider.HostLocaleProviderAdapter"),
67 FALLBACK("sun.util.locale.provider.FallbackLocaleProviderAdapter", "sun.util.resources", "sun.text.resources");
68
69 private final String CLASSNAME;
99 private static final List<Type> adapterPreference;
100
101 /**
102 * LocaleProviderAdapter instances
103 */
104 private static final Map<Type, LocaleProviderAdapter> adapterInstances = new ConcurrentHashMap<>();
105
106 /**
107 * Default fallback adapter type, which should return something meaningful in any case.
108 * This is either CLDR or FALLBACK.
109 */
110 static volatile LocaleProviderAdapter.Type defaultLocaleProviderAdapter;
111
112 /**
113 * Adapter lookup cache.
114 */
115 private static ConcurrentMap<Class<? extends LocaleServiceProvider>, ConcurrentMap<Locale, LocaleProviderAdapter>>
116 adapterCache = new ConcurrentHashMap<>();
117
118 static {
119 String order = GetPropertyAction.getProperty("java.locale.providers");
120 List<Type> typeList = new ArrayList<>();
121
122 // Check user specified adapter preference
123 if (order != null && order.length() != 0) {
124 String[] types = order.split(",");
125 for (String type : types) {
126 type = type.trim().toUpperCase(Locale.ROOT);
127 if (type.equals("COMPAT")) {
128 type = "JRE";
129 }
130 try {
131 Type aType = Type.valueOf(type.trim().toUpperCase(Locale.ROOT));
132 if (!typeList.contains(aType)) {
133 typeList.add(aType);
134 }
135 } catch (IllegalArgumentException | UnsupportedOperationException e) {
136 // could be caused by the user specifying wrong
137 // provider name or format in the system property
138 LocaleServiceProviderPool.config(LocaleProviderAdapter.class, e.toString());
139 }
|