author | naoto |
Thu, 22 Oct 2015 21:41:57 -0700 | |
changeset 33309 | 3aecb54196d9 |
parent 25859 | 3317bb8137f4 |
child 33310 | 2701a9854bb5 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
23010
6dadb192ad81
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents:
17944
diff
changeset
|
2 |
* Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 24 |
*/ |
25 |
||
13583 | 26 |
package sun.util.locale.provider; |
2 | 27 |
|
6501 | 28 |
import java.util.ArrayList; |
14418
967376921f20
8001205: Calendar.getDisplayName(...): Returns null when provider is SPI but there is no SPI implementation
naoto
parents:
14331
diff
changeset
|
29 |
import java.util.Arrays; |
13583 | 30 |
import java.util.Collections; |
2 | 31 |
import java.util.HashSet; |
6501 | 32 |
import java.util.IllformedLocaleException; |
2 | 33 |
import java.util.List; |
34 |
import java.util.Locale; |
|
6501 | 35 |
import java.util.Locale.Builder; |
36 |
import java.util.ResourceBundle.Control; |
|
2 | 37 |
import java.util.Set; |
38 |
import java.util.concurrent.ConcurrentHashMap; |
|
10710
b18db2d63e3b
7027061: Testcase failure: java/util/Locale/Bug6989440.java - java.util.ConcurrentModificationException
naoto
parents:
6835
diff
changeset
|
39 |
import java.util.concurrent.ConcurrentMap; |
2 | 40 |
import java.util.spi.LocaleServiceProvider; |
3861
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
2
diff
changeset
|
41 |
import sun.util.logging.PlatformLogger; |
2 | 42 |
|
43 |
/** |
|
44 |
* An instance of this class holds a set of the third party implementations of a particular |
|
45 |
* locale sensitive service, such as {@link java.util.spi.LocaleNameProvider}. |
|
46 |
* |
|
13583 | 47 |
* @author Naoto Sato |
48 |
* @author Masayoshi Okutsu |
|
2 | 49 |
*/ |
50 |
public final class LocaleServiceProviderPool { |
|
51 |
||
52 |
/** |
|
53 |
* A Map that holds singleton instances of this class. Each instance holds a |
|
54 |
* set of provider implementations of a particular locale sensitive service. |
|
55 |
*/ |
|
11138
9121a1a92512
7117469: Warning cleanup for j.u.Currency and j.u.Locale related classes
naoto
parents:
10710
diff
changeset
|
56 |
private static ConcurrentMap<Class<? extends LocaleServiceProvider>, LocaleServiceProviderPool> poolOfPools = |
10710
b18db2d63e3b
7027061: Testcase failure: java/util/Locale/Bug6989440.java - java.util.ConcurrentModificationException
naoto
parents:
6835
diff
changeset
|
57 |
new ConcurrentHashMap<>(); |
2 | 58 |
|
59 |
/** |
|
13583 | 60 |
* A Map containing locale service providers that implement the |
61 |
* specified provider SPI, keyed by a LocaleProviderAdapter.Type |
|
2 | 62 |
*/ |
13583 | 63 |
private ConcurrentMap<LocaleProviderAdapter.Type, LocaleServiceProvider> providers = |
64 |
new ConcurrentHashMap<>(); |
|
2 | 65 |
|
66 |
/** |
|
67 |
* A Map that retains Locale->provider mapping |
|
68 |
*/ |
|
13583 | 69 |
private ConcurrentMap<Locale, List<LocaleProviderAdapter.Type>> providersCache = |
70 |
new ConcurrentHashMap<>(); |
|
2 | 71 |
|
72 |
/** |
|
73 |
* Available locales for this locale sensitive service. This also contains |
|
74 |
* JRE's available locales |
|
75 |
*/ |
|
76 |
private Set<Locale> availableLocales = null; |
|
77 |
||
78 |
/** |
|
13583 | 79 |
* Provider class |
2 | 80 |
*/ |
13583 | 81 |
private Class<? extends LocaleServiceProvider> providerClass; |
2 | 82 |
|
83 |
/** |
|
13583 | 84 |
* Array of all Locale Sensitive SPI classes. |
85 |
* |
|
86 |
* We know "spiClasses" contains classes that extends LocaleServiceProvider, |
|
87 |
* but generic array creation is not allowed, thus the "unchecked" warning |
|
88 |
* is suppressed here. |
|
6501 | 89 |
*/ |
13583 | 90 |
@SuppressWarnings("unchecked") |
91 |
static final Class<LocaleServiceProvider>[] spiClasses = |
|
92 |
(Class<LocaleServiceProvider>[]) new Class<?>[] { |
|
93 |
java.text.spi.BreakIteratorProvider.class, |
|
94 |
java.text.spi.CollatorProvider.class, |
|
95 |
java.text.spi.DateFormatProvider.class, |
|
96 |
java.text.spi.DateFormatSymbolsProvider.class, |
|
97 |
java.text.spi.DecimalFormatSymbolsProvider.class, |
|
98 |
java.text.spi.NumberFormatProvider.class, |
|
99 |
java.util.spi.CurrencyNameProvider.class, |
|
100 |
java.util.spi.LocaleNameProvider.class, |
|
101 |
java.util.spi.TimeZoneNameProvider.class, |
|
102 |
java.util.spi.CalendarDataProvider.class |
|
103 |
}; |
|
6501 | 104 |
|
105 |
/** |
|
2 | 106 |
* A factory method that returns a singleton instance |
107 |
*/ |
|
108 |
public static LocaleServiceProviderPool getPool(Class<? extends LocaleServiceProvider> providerClass) { |
|
109 |
LocaleServiceProviderPool pool = poolOfPools.get(providerClass); |
|
110 |
if (pool == null) { |
|
111 |
LocaleServiceProviderPool newPool = |
|
112 |
new LocaleServiceProviderPool(providerClass); |
|
10710
b18db2d63e3b
7027061: Testcase failure: java/util/Locale/Bug6989440.java - java.util.ConcurrentModificationException
naoto
parents:
6835
diff
changeset
|
113 |
pool = poolOfPools.putIfAbsent(providerClass, newPool); |
2 | 114 |
if (pool == null) { |
115 |
pool = newPool; |
|
116 |
} |
|
117 |
} |
|
118 |
||
119 |
return pool; |
|
120 |
} |
|
121 |
||
122 |
/** |
|
123 |
* The sole constructor. |
|
124 |
* |
|
125 |
* @param c class of the locale sensitive service |
|
126 |
*/ |
|
127 |
private LocaleServiceProviderPool (final Class<? extends LocaleServiceProvider> c) { |
|
13583 | 128 |
providerClass = c; |
129 |
||
17944
bbd67fc49daa
8013903: Japanese calendar field names are not displayed with -Djava.locale.providers=HOST on Windows
naoto
parents:
14418
diff
changeset
|
130 |
for (LocaleProviderAdapter.Type type : LocaleProviderAdapter.getAdapterPreference()) { |
bbd67fc49daa
8013903: Japanese calendar field names are not displayed with -Djava.locale.providers=HOST on Windows
naoto
parents:
14418
diff
changeset
|
131 |
LocaleProviderAdapter lda = LocaleProviderAdapter.forType(type); |
bbd67fc49daa
8013903: Japanese calendar field names are not displayed with -Djava.locale.providers=HOST on Windows
naoto
parents:
14418
diff
changeset
|
132 |
if (lda != null) { |
bbd67fc49daa
8013903: Japanese calendar field names are not displayed with -Djava.locale.providers=HOST on Windows
naoto
parents:
14418
diff
changeset
|
133 |
LocaleServiceProvider provider = lda.getLocaleServiceProvider(c); |
bbd67fc49daa
8013903: Japanese calendar field names are not displayed with -Djava.locale.providers=HOST on Windows
naoto
parents:
14418
diff
changeset
|
134 |
if (provider != null) { |
bbd67fc49daa
8013903: Japanese calendar field names are not displayed with -Djava.locale.providers=HOST on Windows
naoto
parents:
14418
diff
changeset
|
135 |
providers.putIfAbsent(type, provider); |
bbd67fc49daa
8013903: Japanese calendar field names are not displayed with -Djava.locale.providers=HOST on Windows
naoto
parents:
14418
diff
changeset
|
136 |
} |
13583 | 137 |
} |
2 | 138 |
} |
139 |
} |
|
140 |
||
13583 | 141 |
static void config(Class<? extends Object> caller, String message) { |
142 |
PlatformLogger logger = PlatformLogger.getLogger(caller.getCanonicalName()); |
|
3861
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
2
diff
changeset
|
143 |
logger.config(message); |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
2
diff
changeset
|
144 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
2
diff
changeset
|
145 |
|
2 | 146 |
/** |
147 |
* Lazy loaded set of available locales. |
|
148 |
* Loading all locales is a very long operation. |
|