author | naoto |
Mon, 05 Oct 2015 08:16:11 -0700 | |
changeset 32854 | f29975c5b3c1 |
parent 31263 | a81a0af34ca0 |
child 33309 | 3aecb54196d9 |
permissions | -rw-r--r-- |
13583 | 1 |
/* |
25996
4aa9eb909760
8055088: Optimization for locale resources loading isn't working
okutsu
parents:
25859
diff
changeset
|
2 |
* Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. |
13583 | 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 |
|
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; |
|
16052
60d3d3dd4880
8004240: Return value from getAdapterPrefence() can be modified
naoto
parents:
15260
diff
changeset
|
36 |
import java.util.Collections; |
13583 | 37 |
import java.util.List; |
38 |
import java.util.Locale; |
|
39 |
import java.util.ResourceBundle; |
|
40 |
import java.util.Set; |
|
15260 | 41 |
import java.util.concurrent.ConcurrentHashMap; |
42 |
import java.util.concurrent.ConcurrentMap; |
|
13583 | 43 |
import java.util.spi.CalendarDataProvider; |
14502
d63fed06fed4
8000986: Split java.util.spi.CalendarDataProvider into week parameters and field names portions
okutsu
parents:
14024
diff
changeset
|
44 |
import java.util.spi.CalendarNameProvider; |
13583 | 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.util.cldr.CLDRLocaleProviderAdapter; |
|
16481
8e30386cc014
8008576: Calendar mismatch using Host LocaleProviderAdapter
naoto
parents:
16052
diff
changeset
|
50 |
import sun.util.spi.CalendarProvider; |
13583 | 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.resources", "sun.text.resources"), |
|
64 |
CLDR("sun.util.resources.cldr", "sun.text.resources.cldr"), |
|
65 |
SPI, |
|
14024
694c379c2958
7196799: CLDR adapter can not be invoked when region code is specified in Locale
naoto
parents:
13583
diff
changeset
|
66 |
HOST, |
694c379c2958
7196799: CLDR adapter can not be invoked when region code is specified in Locale
naoto
parents:
13583
diff
changeset
|
67 |
FALLBACK("sun.util.resources", "sun.text.resources"); |
13583 | 68 |
|
69 |
private final String UTIL_RESOURCES_PACKAGE; |
|
70 |
private final String TEXT_RESOURCES_PACKAGE; |
|
71 |
||
72 |
private Type() { |
|
73 |
this(null, null); |
|
74 |
} |
|
75 |
||
76 |
private Type(String util, String text) { |
|
77 |
UTIL_RESOURCES_PACKAGE = util; |
|
78 |
TEXT_RESOURCES_PACKAGE = text; |
|
79 |
} |
|
80 |
||
81 |
public String getUtilResourcesPackage() { |
|
82 |
return UTIL_RESOURCES_PACKAGE; |
|
83 |
} |
|
84 |
||
85 |
public String getTextResourcesPackage() { |
|
86 |
return TEXT_RESOURCES_PACKAGE; |
|
87 |
} |
|
88 |
} |
|
89 |
||
90 |
/** |
|
31263 | 91 |
* LocaleProviderAdapter preference list. |
13583 | 92 |
*/ |
16052
60d3d3dd4880
8004240: Return value from getAdapterPrefence() can be modified
naoto
parents:
15260
diff
changeset
|
93 |
private static final List<Type> adapterPreference; |
13583 | 94 |
|
95 |
/** |
|
96 |
* JRE Locale Data Adapter instance |
|
97 |
*/ |
|
98 |
private static LocaleProviderAdapter jreLocaleProviderAdapter = new JRELocaleProviderAdapter(); |
|
99 |
||
100 |
/** |
|
101 |
* SPI Locale Data Adapter instance |
|
102 |
*/ |
|
103 |
private static LocaleProviderAdapter spiLocaleProviderAdapter = new SPILocaleProviderAdapter(); |
|
104 |
||
105 |
/** |
|
106 |
* CLDR Locale Data Adapter instance, if any. |
|
107 |
*/ |
|
108 |
private static LocaleProviderAdapter cldrLocaleProviderAdapter = null; |
|
109 |
||
110 |
/** |
|
111 |
* HOST Locale Data Adapter instance, if any. |
|
112 |
*/ |
|
113 |
private static LocaleProviderAdapter hostLocaleProviderAdapter = null; |
|
114 |
||
14024
694c379c2958
7196799: CLDR adapter can not be invoked when region code is specified in Locale
naoto
parents:
13583
diff
changeset
|
115 |
/** |
694c379c2958
7196799: CLDR adapter can not be invoked when region code is specified in Locale
naoto
parents:
13583
diff
changeset
|
116 |
* FALLBACK Locale Data Adapter instance. It's basically the same with JRE, but only kicks |
694c379c2958
7196799: CLDR adapter can not be invoked when region code is specified in Locale
naoto
parents:
13583
diff
changeset
|
117 |
* in for the root locale. |
694c379c2958
7196799: CLDR adapter can not be invoked when region code is specified in Locale
naoto
parents:
13583
diff
changeset
|
118 |
*/ |
694c379c2958
7196799: CLDR adapter can not be invoked when region code is specified in Locale
naoto
parents:
13583
diff
changeset
|
119 |
private static LocaleProviderAdapter fallbackLocaleProviderAdapter = null; |
694c379c2958
7196799: CLDR adapter can not be invoked when region code is specified in Locale
naoto
parents:
13583
diff
changeset
|
120 |
|
15260 | 121 |
/** |
17944
bbd67fc49daa
8013903: Japanese calendar field names are not displayed with -Djava.locale.providers=HOST on Windows
naoto
parents:
16481
diff
changeset
|
122 |
* Default fallback adapter type, which should return something meaningful in any case. |
bbd67fc49daa
8013903: Japanese calendar field names are not displayed with -Djava.locale.providers=HOST on Windows
naoto
parents:
16481
diff
changeset
|
123 |
* This is either JRE or FALLBACK. |
bbd67fc49daa
8013903: Japanese calendar field names are not displayed with -Djava.locale.providers=HOST on Windows
naoto
parents:
16481
diff
changeset
|
124 |
*/ |
bbd67fc49daa
8013903: Japanese calendar field names are not displayed with -Djava.locale.providers=HOST on Windows
naoto
parents:
16481
diff
changeset
|
125 |
static LocaleProviderAdapter.Type defaultLocaleProviderAdapter = null; |
bbd67fc49daa
8013903: Japanese calendar field names are not displayed with -Djava.locale.providers=HOST on Windows
naoto
parents:
16481
diff
changeset
|
126 |
|
bbd67fc49daa
8013903: Japanese calendar field names are not displayed with -Djava.locale.providers=HOST on Windows
naoto
parents:
16481
diff
changeset
|
127 |
/** |
15260 | 128 |
* Adapter lookup cache. |
129 |
*/ |
|
130 |
private static ConcurrentMap<Class<? extends LocaleServiceProvider>, ConcurrentMap<Locale, LocaleProviderAdapter>> |
|
131 |
adapterCache = new ConcurrentHashMap<>(); |
|
132 |
||
13583 | 133 |
static { |
134 |
String order = AccessController.doPrivileged( |
|
135 |
new sun.security.action.GetPropertyAction("java.locale.providers")); |
|
16052
60d3d3dd4880
8004240: Return value from getAdapterPrefence() can be modified
naoto
parents:
15260
diff
changeset
|
136 |
List<Type> typeList = new ArrayList<>(); |
60d3d3dd4880
8004240: Return value from getAdapterPrefence() can be modified
naoto
parents:
15260
diff
changeset
|
137 |
|
60d3d3dd4880
8004240: Return value from getAdapterPrefence() can be modified
naoto
parents:
15260
diff
changeset
|
138 |
// Check user specified adapter preference |
14024
694c379c2958
7196799: CLDR adapter can not be invoked when region code is specified in Locale
naoto
parents:
13583
diff
changeset
|
139 |
if (order != null && order.length() != 0) { |
694c379c2958
7196799: CLDR adapter can not be invoked when region code is specified in Locale
naoto
parents:
13583
diff
changeset
|
140 |
String[] types = order.split(","); |
694c379c2958
7196799: CLDR adapter can not be invoked when region code is specified in Locale
naoto
parents:
13583
diff
changeset
|
141 |
for (String type : types) { |
694c379c2958
7196799: CLDR adapter can not be invoked when region code is specified in Locale
naoto
parents:
13583
diff
changeset
|
142 |
try { |
694c379c2958
7196799: CLDR adapter can not be invoked when region code is specified in Locale
naoto
parents:
13583
diff
changeset
|
143 |
Type aType = Type.valueOf(type.trim().toUpperCase(Locale.ROOT)); |
13583 | 144 |
|
14024
694c379c2958
7196799: CLDR adapter can not be invoked when region code is specified in Locale
naoto
parents:
13583
diff
changeset
|
145 |
// load adapter if necessary |
694c379c2958
7196799: CLDR adapter can not be invoked when region code is specified in Locale
naoto
parents:
13583
diff
changeset
|
146 |
switch (aType) { |
694c379c2958
7196799: CLDR adapter can not be invoked when region code is specified in Locale
naoto
parents:
13583
diff
changeset
|
147 |
case CLDR: |
17944
bbd67fc49daa
8013903: Japanese calendar field names are not displayed with -Djava.locale.providers=HOST on Windows
naoto
parents:
16481
diff
changeset
|
148 |
if (cldrLocaleProviderAdapter == null) { |
bbd67fc49daa
8013903: Japanese calendar field names are not displayed with -Djava.locale.providers=HOST on Windows
naoto
parents:
16481
diff
changeset
|
149 |
cldrLocaleProviderAdapter = new CLDRLocaleProviderAdapter(); |
bbd67fc49daa
8013903: Japanese calendar field names are not displayed with -Djava.locale.providers=HOST on Windows
naoto
parents:
16481
diff
changeset
|
150 |
} |
14024
694c379c2958
7196799: CLDR adapter can not be invoked when region code is specified in Locale
naoto
parents:
13583
diff
changeset
|
151 |
break; |
694c379c2958
7196799: CLDR adapter can not be invoked when region code is specified in Locale
naoto
parents:
13583
diff
changeset
|
152 |
case HOST: |
17944
bbd67fc49daa
8013903: Japanese calendar field names are not displayed with -Djava.locale.providers=HOST on Windows
naoto
parents:
16481
diff
changeset
|
153 |
if (hostLocaleProviderAdapter == null) { |
bbd67fc49daa
8013903: Japanese calendar field names are not displayed with -Djava.locale.providers=HOST on Windows
naoto
parents:
16481
diff
changeset
|
154 |
hostLocaleProviderAdapter = new HostLocaleProviderAdapter(); |
bbd67fc49daa
8013903: Japanese calendar field names are not displayed with -Djava.locale.providers=HOST on Windows
naoto
parents:
16481
diff
changeset
|
155 |
} |
14024
694c379c2958
7196799: CLDR adapter can not be invoked when region code is specified in Locale
naoto
parents:
13583
diff
changeset
|
156 |
break; |
694c379c2958
7196799: CLDR adapter can not be invoked when region code is specified in Locale
naoto
parents:
13583
diff
changeset
|
157 |
} |
17944
bbd67fc49daa
8013903: Japanese calendar field names are not displayed with -Djava.locale.providers=HOST on Windows
naoto
parents:
16481
diff
changeset
|
158 |
if (!typeList.contains(aType)) { |
bbd67fc49daa
8013903: Japanese calendar field names are not displayed with -Djava.locale.providers=HOST on Windows
naoto
parents:
16481
diff
changeset
|
159 |
typeList.add(aType); |
bbd67fc49daa
8013903: Japanese calendar field names are not displayed with -Djava.locale.providers=HOST on Windows
naoto
parents:
16481
diff
changeset
|
160 |
} |
14024
694c379c2958
7196799: CLDR adapter can not be invoked when region code is specified in Locale
naoto
parents:
13583
diff
changeset
|
161 |
} catch (IllegalArgumentException | UnsupportedOperationException e) { |
694c379c2958
7196799: CLDR adapter can not be invoked when region code is specified in Locale
naoto
parents:
13583
diff
changeset
|
162 |
// could be caused by the user specifying wrong |
694c379c2958
7196799: CLDR adapter can not be invoked when region code is specified in Locale
naoto
parents:
13583
diff
changeset
|
163 |
// provider name or format in the system property |
694c379c2958
7196799: CLDR adapter can not be invoked when region code is specified in Locale
naoto
parents:
13583
diff
changeset
|
164 |
LocaleServiceProviderPool.config(LocaleProviderAdapter.class, e.toString()); |
694c379c2958
7196799: CLDR adapter can not be invoked when region code is specified in Locale
naoto
parents:
13583
diff
changeset
|
165 |
} |
694c379c2958
7196799: CLDR adapter can not be invoked when region code is specified in Locale
naoto
parents:
13583
diff
changeset
|
166 |
} |
16052
60d3d3dd4880
8004240: Return value from getAdapterPrefence() can be modified
naoto
parents:
15260
diff
changeset
|
167 |
} |
13583 | 168 |
|
16052
60d3d3dd4880
8004240: Return value from getAdapterPrefence() can be modified
naoto
parents:
15260
diff
changeset
|
169 |
if (!typeList.isEmpty()) { |
60d3d3dd4880
8004240: Return value from getAdapterPrefence() can be modified
naoto
parents:
15260
diff
changeset
|
170 |
if (!typeList.contains(Type.JRE)) { |
60d3d3dd4880
8004240: Return value from getAdapterPrefence() can be modified
naoto
parents:
15260
diff
changeset
|
171 |
// Append FALLBACK as the last resort. |
60d3d3dd4880
8004240: Return value from getAdapterPrefence() can be modified
naoto
parents:
15260
diff
changeset
|
172 |
fallbackLocaleProviderAdapter = new FallbackLocaleProviderAdapter(); |
60d3d3dd4880
8004240: Return value from getAdapterPrefence() can be modified
naoto
parents:
15260
diff
changeset
|
173 |
typeList.add(Type.FALLBACK); |
17944
bbd67fc49daa
8013903: Japanese calendar field names are not displayed with -Djava.locale.providers=HOST on Windows
naoto
parents:
16481
diff
changeset
|
174 |
defaultLocaleProviderAdapter = Type.FALLBACK; |
bbd67fc49daa
8013903: Japanese calendar field names are not displayed with -Djava.locale.providers=HOST on Windows
naoto
parents:
16481
diff
changeset
|
175 |
} else { |
bbd67fc49daa
8013903: Japanese calendar field names are not displayed with -Djava.locale.providers=HOST on Windows
naoto
parents:
16481
diff
changeset
|
176 |
defaultLocaleProviderAdapter = Type.JRE; |
14024
694c379c2958
7196799: CLDR adapter can not be invoked when region code is specified in Locale
naoto
parents:
13583
diff
changeset
|
177 |
} |
16052
60d3d3dd4880
8004240: Return value from getAdapterPrefence() can be modified
naoto
parents:
15260
diff
changeset
|
178 |
} else { |
31263 | 179 |
// Default preference list. |
180 |
try { |
|
181 |
cldrLocaleProviderAdapter = new CLDRLocaleProviderAdapter(); |
|
182 |
typeList.add(Type.CLDR); |
|
183 |
defaultLocaleProviderAdapter = Type.CLDR; |
|
184 |
} catch (UnsupportedOperationException e) { |
|
185 |
LocaleServiceProviderPool.config(LocaleProviderAdapter.class, e.toString()); |
|
186 |
} |
|
16052
60d3d3dd4880
8004240: Return value from getAdapterPrefence() can be modified
naoto
parents:
15260
diff
changeset
|
187 |
typeList.add(Type.JRE); |
17944
bbd67fc49daa
8013903: Japanese calendar field names are not displayed with -Djava.locale.providers=HOST on Windows
naoto
parents:
16481
diff
changeset
|
188 |
defaultLocaleProviderAdapter = Type.JRE; |
14024
694c379c2958
7196799: CLDR adapter can not be invoked when region code is specified in Locale
naoto
parents:
13583
diff
changeset
|
189 |
} |
16052
60d3d3dd4880
8004240: Return value from getAdapterPrefence() can be modified
naoto
parents:
15260
diff
changeset
|
190 |
|
60d3d3dd4880
8004240: Return value from getAdapterPrefence() can be modified
naoto
parents:
15260
diff
changeset
|
191 |
adapterPreference = Collections.unmodifiableList(typeList); |
13583 | 192 |
} |
193 |
||
194 |
/** |
|
195 |
* Returns the singleton instance for each adapter type |
|
196 |
*/ |
|
197 |
public static LocaleProviderAdapter forType(Type type) { |
|
198 |
switch (type) { |
|
199 |
case JRE: |
|
200 |
return jreLocaleProviderAdapter; |
|
201 |
case CLDR: |
|
202 |
return cldrLocaleProviderAdapter; |
|
203 |
case SPI: |
|
204 |
return spiLocaleProviderAdapter; |
|
205 |
case HOST: |
|
206 |
return hostLocaleProviderAdapter; |
|
14024
694c379c2958
7196799: CLDR adapter can not be invoked when region code is specified in Locale
naoto
parents:
13583
diff
changeset
|
207 |
case FALLBACK: |
694c379c2958
7196799: CLDR adapter can not be invoked when region code is specified in Locale
naoto
parents:
13583
diff
changeset
|
208 |
return fallbackLocaleProviderAdapter; |
13583 | 209 |
default: |
210 |
throw new InternalError("unknown locale data adapter type"); |
|
211 |
} |
|
212 |
} |
|
213 |
||
214 |
public static LocaleProviderAdapter forJRE() { |
|
215 |
return jreLocaleProviderAdapter; |
|
216 |
} |
|
217 |
||
218 |
public static LocaleProviderAdapter getResourceBundleBased() { |
|
219 |
for (Type type : getAdapterPreference()) { |
|
14024
694c379c2958
7196799: CLDR adapter can not be invoked when region code is specified in Locale
naoto
parents:
13583
diff
changeset
|
220 |
if (type == Type.JRE || type == Type.CLDR || type == Type.FALLBACK) { |
31263 | 221 |
LocaleProviderAdapter adapter = forType(type); |
222 |
if (adapter != null) { |
|
223 |
return adapter; |
|
224 |
} |
|
13583 | 225 |
} |
226 |
} |
|
227 |
// Shouldn't happen. |
|
228 |
throw new InternalError(); |
|
229 |
} |
|
230 |
/** |
|
231 |
* Returns the preference order of LocaleProviderAdapter.Type |
|
232 |
*/ |
|
16052
60d3d3dd4880
8004240: Return value from getAdapterPrefence() can be modified
naoto
parents:
15260
diff
changeset
|
233 |
public static List<Type> getAdapterPreference() { |
13583 | 234 |
return adapterPreference; |
235 |
} |
|
236 |
||
237 |
/** |
|
238 |
* Returns a LocaleProviderAdapter for the given locale service provider that |
|
239 |
* best matches the given locale. This method returns the LocaleProviderAdapter |
|
240 |
* for JRE if none is found for the given locale. |
|
241 |
* |
|
242 |
* @param providerClass the class for the locale service provider |
|
243 |
* @param locale the desired locale. |
|
244 |
* @return a LocaleProviderAdapter |
|
245 |
*/ |
|
246 |
public static LocaleProviderAdapter getAdapter(Class<? extends LocaleServiceProvider> providerClass, |
|
247 |
Locale locale) { |
|
15260 | 248 |
LocaleProviderAdapter adapter; |
249 |
||
250 |
// cache lookup |
|
251 |
ConcurrentMap<Locale, LocaleProviderAdapter> adapterMap = adapterCache.get(providerClass); |
|
252 |
if (adapterMap != null) { |
|
253 |
if ((adapter = adapterMap.get(locale)) != null) { |
|
254 |
return adapter; |
|
255 |
} |
|
256 |
} else { |
|
257 |
adapterMap = new ConcurrentHashMap<>(); |
|
258 |
adapterCache.putIfAbsent(providerClass, adapterMap); |
|
259 |
} |
|
260 |
||
13583 | 261 |
// Fast look-up for the given locale |
15260 | 262 |
adapter = findAdapter(providerClass, locale); |
13583 | 263 |
if (adapter != null) { |
15260 | 264 |
adapterMap.putIfAbsent(locale, adapter); |
13583 | 265 |
return adapter; |
266 |
} |
|
267 |
||
268 |
// Try finding an adapter in the normal candidate locales path of the given locale. |
|
269 |
List<Locale> lookupLocales = ResourceBundle.Control.getControl(ResourceBundle.Control.FORMAT_DEFAULT) |
|
270 |
.getCandidateLocales("", locale); |
|
271 |
for (Locale loc : lookupLocales) { |
|
272 |
if (loc.equals(locale)) { |
|
273 |
// We've already done with this loc. |
|
274 |
continue; |
|
275 |
} |
|
276 |
adapter = findAdapter(providerClass, loc); |
|
277 |
if (adapter != null) { |
|
15260 | 278 |
adapterMap.putIfAbsent(locale, adapter); |
13583 | 279 |
return adapter; |
280 |
} |
|
281 |
} |
|
282 |
||
14024
694c379c2958
7196799: CLDR adapter can not be invoked when region code is specified in Locale
naoto
parents:
13583
diff
changeset
|
283 |
// returns the adapter for FALLBACK as the last resort |
15260 | 284 |
adapterMap.putIfAbsent(locale, fallbackLocaleProviderAdapter); |
14024
694c379c2958
7196799: CLDR adapter can not be invoked when region code is specified in Locale
naoto
parents:
13583
diff
changeset
|
285 |
return fallbackLocaleProviderAdapter; |
13583 | 286 |
} |
287 |
||
288 |
private static LocaleProviderAdapter findAdapter(Class<? extends LocaleServiceProvider> providerClass, |
|
289 |
Locale locale) { |
|
290 |
for (Type type : getAdapterPreference()) { |
|
291 |
LocaleProviderAdapter adapter = forType(type); |
|
292 |
LocaleServiceProvider provider = adapter.getLocaleServiceProvider(providerClass); |
|
293 |
if (provider != null) { |
|
294 |
if (provider.isSupportedLocale(locale)) { |
|
295 |
return adapter; |
|
296 |
} |
|
297 |
} |
|
298 |
} |
|
299 |
return null; |
|
300 |
} |
|
301 |
||
302 |
/** |
|
303 |
* A utility method for implementing the default LocaleServiceProvider.isSupportedLocale |
|
14024
694c379c2958
7196799: CLDR adapter can not be invoked when region code is specified in Locale
naoto
parents:
13583
diff
changeset
|
304 |
* for the JRE, CLDR, and FALLBACK adapters. |
13583 | 305 |
*/ |
31263 | 306 |
public boolean isSupportedProviderLocale(Locale locale, Set<String> langtags) { |
307 |
LocaleProviderAdapter.Type type = getAdapterType(); |
|
14024
694c379c2958
7196799: CLDR adapter can not be invoked when region code is specified in Locale
naoto
parents:
13583
diff
changeset
|
308 |
assert type == Type.JRE || type == Type.CLDR || type == Type.FALLBACK; |
13583 | 309 |
return false; |
310 |
} |
|
311 |
||
312 |
public static Locale[] toLocaleArray(Set<String> tags) { |
|
313 |
Locale[] locs = new Locale[tags.size() + 1]; |
|
314 |
int index = 0; |
|
315 |
locs[index++] = Locale.ROOT; |
|
316 |
for (String tag : tags) { |
|
317 |
switch (tag) { |
|
318 |
case "ja-JP-JP": |
|
319 |
locs[index++] = JRELocaleConstants.JA_JP_JP; |
|
320 |
break; |
|
321 |
case "th-TH-TH": |
|
322 |
locs[index++] = JRELocaleConstants.TH_TH_TH; |
|
323 |
break; |
|
324 |
default: |
|
325 |
locs[index++] = Locale.forLanguageTag(tag); |
|
326 |
break; |
|
327 |
} |
|
328 |
} |
|
329 |
return locs; |
|
330 |
} |
|
331 |
||
332 |
/** |
|
333 |
* Returns the type of this LocaleProviderAdapter |
|
334 |
*/ |
|
335 |
public abstract LocaleProviderAdapter.Type getAdapterType(); |
|
336 |
||
337 |
/** |
|
338 |
* Getter method for Locale Service Providers. |
|
339 |
*/ |
|
340 |
public abstract <P extends LocaleServiceProvider> P getLocaleServiceProvider(Class<P> c); |
|
341 |
||
342 |
/** |
|
343 |
* Returns a BreakIteratorProvider for this LocaleProviderAdapter, or null if no |
|
344 |
* BreakIteratorProvider is available. |
|
345 |
* |
|
346 |
* @return a BreakIteratorProvider |
|
347 |
*/ |
|
348 |
public abstract BreakIteratorProvider getBreakIteratorProvider(); |
|
349 |
||
350 |
/** |
|
351 |
* Returns a ollatorProvider for this LocaleProviderAdapter, or null if no |
|
352 |
* ollatorProvider is available. |
|
353 |
* |
|
354 |
* @return a ollatorProvider |
|
355 |
*/ |
|
356 |
public abstract CollatorProvider getCollatorProvider(); |
|
357 |
||
358 |
/** |
|
359 |
* Returns a DateFormatProvider for this LocaleProviderAdapter, or null if no |
|
360 |
* DateFormatProvider is available. |
|
361 |
* |
|
362 |
* @return a DateFormatProvider |
|
363 |
*/ |
|
364 |
public abstract DateFormatProvider getDateFormatProvider(); |
|
365 |
||
366 |
/** |
|
367 |
* Returns a DateFormatSymbolsProvider for this LocaleProviderAdapter, or null if no |
|
368 |
* DateFormatSymbolsProvider is available. |
|
369 |
* |
|
370 |
* @return a DateFormatSymbolsProvider |
|
371 |
*/ |
|
372 |
public abstract DateFormatSymbolsProvider getDateFormatSymbolsProvider(); |
|
373 |
||
374 |
/** |
|
375 |
* Returns a DecimalFormatSymbolsProvider for this LocaleProviderAdapter, or null if no |
|
376 |
* DecimalFormatSymbolsProvider is available. |
|
377 |
* |
|
378 |
* @return a DecimalFormatSymbolsProvider |
|
379 |
*/ |
|
380 |
public abstract DecimalFormatSymbolsProvider getDecimalFormatSymbolsProvider(); |
|
381 |
||
382 |
/** |
|
383 |
* Returns a NumberFormatProvider for this LocaleProviderAdapter, or null if no |
|
384 |
* NumberFormatProvider is available. |
|
385 |
* |
|
386 |
* @return a NumberFormatProvider |
|
387 |
*/ |
|
388 |
public abstract NumberFormatProvider getNumberFormatProvider(); |
|
389 |
||
390 |
/* |
|
391 |
* Getter methods for java.util.spi.* providers |
|
392 |
*/ |
|
393 |
||
394 |
/** |
|
395 |
* Returns a CurrencyNameProvider for this LocaleProviderAdapter, or null if no |
|
396 |
* CurrencyNameProvider is available. |
|
397 |
* |
|
398 |
* @return a CurrencyNameProvider |
|
399 |
*/ |
|
400 |
public abstract CurrencyNameProvider getCurrencyNameProvider(); |
|
401 |
||
402 |
/** |
|
403 |
* Returns a LocaleNameProvider for this LocaleProviderAdapter, or null if no |
|
404 |
* LocaleNameProvider is available. |
|
405 |
* |
|
406 |
* @return a LocaleNameProvider |
|
407 |
*/ |
|
408 |
public abstract LocaleNameProvider getLocaleNameProvider(); |
|
409 |
||
410 |
/** |
|
411 |
* Returns a TimeZoneNameProvider for this LocaleProviderAdapter, or null if no |
|
412 |
* TimeZoneNameProvider is available. |
|
413 |
* |
|
414 |
* @return a TimeZoneNameProvider |
|
415 |
*/ |
|
416 |
public abstract TimeZoneNameProvider getTimeZoneNameProvider(); |
|
417 |
||
418 |
/** |
|
419 |
* Returns a CalendarDataProvider for this LocaleProviderAdapter, or null if no |
|
420 |
* CalendarDataProvider is available. |
|
421 |
* |
|
422 |
* @return a CalendarDataProvider |
|
423 |
*/ |
|
424 |
public abstract CalendarDataProvider getCalendarDataProvider(); |
|
425 |
||
14502
d63fed06fed4
8000986: Split java.util.spi.CalendarDataProvider into week parameters and field names portions
okutsu
parents:
14024
diff
changeset
|
426 |
/** |
d63fed06fed4
8000986: Split java.util.spi.CalendarDataProvider into week parameters and field names portions
okutsu
parents:
14024
diff
changeset
|
427 |
* Returns a CalendarNameProvider for this LocaleProviderAdapter, or null if no |
d63fed06fed4
8000986: Split java.util.spi.CalendarDataProvider into week parameters and field names portions
okutsu
parents:
14024
diff
changeset
|
428 |
* CalendarNameProvider is available. |
d63fed06fed4
8000986: Split java.util.spi.CalendarDataProvider into week parameters and field names portions
okutsu
parents:
14024
diff
changeset
|
429 |
* |
d63fed06fed4
8000986: Split java.util.spi.CalendarDataProvider into week parameters and field names portions
okutsu
parents:
14024
diff
changeset
|
430 |
* @return a CalendarNameProvider |
d63fed06fed4
8000986: Split java.util.spi.CalendarDataProvider into week parameters and field names portions
okutsu
parents:
14024
diff
changeset
|
431 |
*/ |
d63fed06fed4
8000986: Split java.util.spi.CalendarDataProvider into week parameters and field names portions
okutsu
parents:
14024
diff
changeset
|
432 |
public abstract CalendarNameProvider getCalendarNameProvider(); |
d63fed06fed4
8000986: Split java.util.spi.CalendarDataProvider into week parameters and field names portions
okutsu
parents:
14024
diff
changeset
|
433 |
|
16481
8e30386cc014
8008576: Calendar mismatch using Host LocaleProviderAdapter
naoto
parents:
16052
diff
changeset
|
434 |
/** |
8e30386cc014
8008576: Calendar mismatch using Host LocaleProviderAdapter
naoto
parents:
16052
diff
changeset
|
435 |
* Returns a CalendarProvider for this LocaleProviderAdapter, or null if no |
8e30386cc014
8008576: Calendar mismatch using Host LocaleProviderAdapter
naoto
parents:
16052
diff
changeset
|
436 |
* CalendarProvider is available. |
8e30386cc014
8008576: Calendar mismatch using Host LocaleProviderAdapter
naoto
parents:
16052
diff
changeset
|
437 |
* |
8e30386cc014
8008576: Calendar mismatch using Host LocaleProviderAdapter
naoto
parents:
16052
diff
changeset
|
438 |
* @return a CalendarProvider |
8e30386cc014
8008576: Calendar mismatch using Host LocaleProviderAdapter
naoto
parents:
16052
diff
changeset
|
439 |
*/ |
8e30386cc014
8008576: Calendar mismatch using Host LocaleProviderAdapter
naoto
parents:
16052
diff
changeset
|
440 |
public abstract CalendarProvider getCalendarProvider(); |
8e30386cc014
8008576: Calendar mismatch using Host LocaleProviderAdapter
naoto
parents:
16052
diff
changeset
|
441 |
|
13583 | 442 |
public abstract LocaleResources getLocaleResources(Locale locale); |
443 |
||
444 |
public abstract Locale[] getAvailableLocales(); |
|
445 |
} |