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
25
26 /*
27 * (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved
28 * (C) Copyright IBM Corp. 1996 - 1998 - All Rights Reserved
29 *
30 * The original version of this source code and documentation
31 * is copyrighted and owned by Taligent, Inc., a wholly-owned
32 * subsidiary of IBM. These materials are provided under terms
33 * of a License Agreement between Taligent and Sun. This technology
34 * is protected by multiple US and International patents.
35 *
36 * This notice and attribution to Taligent may not be removed.
37 * Taligent is a registered trademark of Taligent, Inc.
38 *
39 */
40
41 package sun.util.locale.provider;
42
43 import java.lang.ref.ReferenceQueue;
44 import java.lang.ref.SoftReference;
45 import java.lang.reflect.Module;
46 import java.text.MessageFormat;
47 import java.util.Calendar;
48 import java.util.LinkedHashSet;
49 import java.util.Locale;
50 import java.util.Map;
51 import java.util.Objects;
52 import java.util.ResourceBundle;
53 import java.util.Set;
54 import java.util.concurrent.ConcurrentHashMap;
55 import java.util.concurrent.ConcurrentMap;
56 import sun.util.calendar.ZoneInfo;
57 import sun.util.resources.LocaleData;
58 import sun.util.resources.OpenListResourceBundle;
59 import sun.util.resources.ParallelListResourceBundle;
60 import sun.util.resources.TimeZoneNamesBundle;
61
62 /**
63 * Central accessor to locale-dependent resources for JRE/CLDR provider adapters.
64 *
65 * @author Masayoshi Okutsu
101 Object ref;
102 while ((ref = referenceQueue.poll()) != null) {
103 cache.remove(((ResourceReference)ref).getCacheKey());
104 }
105 }
106
107 Object getBreakIteratorInfo(String key) {
108 Object biInfo;
109 String cacheKey = BREAK_ITERATOR_INFO + key;
110
111 removeEmptyReferences();
112 ResourceReference data = cache.get(cacheKey);
113 if (data == null || ((biInfo = data.get()) == null)) {
114 biInfo = localeData.getBreakIteratorInfo(locale).getObject(key);
115 cache.put(cacheKey, new ResourceReference(cacheKey, biInfo, referenceQueue));
116 }
117
118 return biInfo;
119 }
120
121 Module getBreakIteratorDataModule() {
122 return localeData.getBreakIteratorInfo(locale).getClass().getModule();
123 }
124
125 int getCalendarData(String key) {
126 Integer caldata;
127 String cacheKey = CALENDAR_DATA + key;
128
129 removeEmptyReferences();
130
131 ResourceReference data = cache.get(cacheKey);
132 if (data == null || ((caldata = (Integer) data.get()) == null)) {
133 ResourceBundle rb = localeData.getCalendarData(locale);
134 if (rb.containsKey(key)) {
135 caldata = Integer.parseInt(rb.getString(key));
136 } else {
137 caldata = 0;
138 }
139
140 cache.put(cacheKey,
141 new ResourceReference(cacheKey, (Object) caldata, referenceQueue));
142 }
|
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
25
26 /*
27 * (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved
28 * (C) Copyright IBM Corp. 1996 - 1998 - All Rights Reserved
29 *
30 * The original version of this source code and documentation
31 * is copyrighted and owned by Taligent, Inc., a wholly-owned
32 * subsidiary of IBM. These materials are provided under terms
33 * of a License Agreement between Taligent and Sun. This technology
34 * is protected by multiple US and International patents.
35 *
36 * This notice and attribution to Taligent may not be removed.
37 * Taligent is a registered trademark of Taligent, Inc.
38 *
39 */
40
41 package sun.util.locale.provider;
42
43 import java.lang.ref.ReferenceQueue;
44 import java.lang.ref.SoftReference;
45 import java.text.MessageFormat;
46 import java.util.Calendar;
47 import java.util.LinkedHashSet;
48 import java.util.Locale;
49 import java.util.Map;
50 import java.util.Objects;
51 import java.util.ResourceBundle;
52 import java.util.Set;
53 import java.util.concurrent.ConcurrentHashMap;
54 import java.util.concurrent.ConcurrentMap;
55 import sun.util.calendar.ZoneInfo;
56 import sun.util.resources.LocaleData;
57 import sun.util.resources.OpenListResourceBundle;
58 import sun.util.resources.ParallelListResourceBundle;
59 import sun.util.resources.TimeZoneNamesBundle;
60
61 /**
62 * Central accessor to locale-dependent resources for JRE/CLDR provider adapters.
63 *
64 * @author Masayoshi Okutsu
100 Object ref;
101 while ((ref = referenceQueue.poll()) != null) {
102 cache.remove(((ResourceReference)ref).getCacheKey());
103 }
104 }
105
106 Object getBreakIteratorInfo(String key) {
107 Object biInfo;
108 String cacheKey = BREAK_ITERATOR_INFO + key;
109
110 removeEmptyReferences();
111 ResourceReference data = cache.get(cacheKey);
112 if (data == null || ((biInfo = data.get()) == null)) {
113 biInfo = localeData.getBreakIteratorInfo(locale).getObject(key);
114 cache.put(cacheKey, new ResourceReference(cacheKey, biInfo, referenceQueue));
115 }
116
117 return biInfo;
118 }
119
120 @SuppressWarnings("unchecked")
121 byte[] getBreakIteratorResources(String key) {
122 return (byte[]) localeData.getBreakIteratorResources(locale).getObject(key);
123 }
124
125 int getCalendarData(String key) {
126 Integer caldata;
127 String cacheKey = CALENDAR_DATA + key;
128
129 removeEmptyReferences();
130
131 ResourceReference data = cache.get(cacheKey);
132 if (data == null || ((caldata = (Integer) data.get()) == null)) {
133 ResourceBundle rb = localeData.getCalendarData(locale);
134 if (rb.containsKey(key)) {
135 caldata = Integer.parseInt(rb.getString(key));
136 } else {
137 caldata = 0;
138 }
139
140 cache.put(cacheKey,
141 new ResourceReference(cacheKey, (Object) caldata, referenceQueue));
142 }
|