From 41d357679b3cea5b26ea2c0cf3ed04b246353b70 Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Mon, 17 Nov 2014 15:57:53 +0000
Subject: [PATCH] OPENDJ-1634 CollationMatching rules output an error message with OpenJDK 6
---
opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CoreSchemaImpl.java | 41 ++++++++++++++++++++++++++++++++++++++++-
1 files changed, 40 insertions(+), 1 deletions(-)
diff --git a/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CoreSchemaImpl.java b/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CoreSchemaImpl.java
index 4a12f2f..ba8d86a 100644
--- a/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CoreSchemaImpl.java
+++ b/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CoreSchemaImpl.java
@@ -84,6 +84,16 @@
* value.
*/
private static final Map<String, String> LOCALE_NAMES_TO_OIDS = new HashMap<String, String>();
+ /**
+ * Same as {@link CoreSchemaImpl#LOCALE_NAMES_TO_OIDS}, but it contains the old locale names
+ * that will be used for the registration of collation matching rules.
+ * It is automatically populated on static initialization of current class.
+ * It allows the initialization process to complete when newer locales are referenced by config.ldif,
+ * but the JVM only works with the old locale names.
+ *
+ * @see CoreSchemaImpl#LOCALE_NAMES_TO_OIDS
+ */
+ private static final Map<String, String> JVM_SUPPORTED_LOCALE_NAMES_TO_OIDS = new HashMap<String, String>();
static {
LOCALE_NAMES_TO_OIDS.put("af", "1.3.6.1.4.1.42.2.27.9.4.1.1");
@@ -245,6 +255,34 @@
LOCALE_NAMES_TO_OIDS.put("zh-MO", "1.3.6.1.4.1.42.2.27.9.4.146.1");
LOCALE_NAMES_TO_OIDS.put("zh-SG", "1.3.6.1.4.1.42.2.27.9.4.147.1");
LOCALE_NAMES_TO_OIDS.put("zh-TW", "1.3.6.1.4.1.42.2.27.9.4.148.1");
+
+ initializeJvmSupportedLocaleNamesToOids();
+ }
+
+ private static void initializeJvmSupportedLocaleNamesToOids() {
+ for (Entry<String, String> entry : LOCALE_NAMES_TO_OIDS.entrySet()) {
+ final String localeName = entry.getKey();
+ final String oid = entry.getValue();
+ final String oldLocaleName = new Locale(localeName).toString();
+
+ final int idx = oldLocaleName.indexOf('-');
+ if (idx == -1) {
+ // no dash, oldLocaleName is lowercase, which is correct for the language tag
+ JVM_SUPPORTED_LOCALE_NAMES_TO_OIDS.put(oldLocaleName, oid);
+ } else if (oldLocaleName.equalsIgnoreCase(localeName)) {
+ // fast path to avoid the string computation in the else clause
+ JVM_SUPPORTED_LOCALE_NAMES_TO_OIDS.put(localeName, oid);
+ } else {
+ // Old locale is different from locale and there are country, and/or variants.
+ // Ensure the country and variants are uppercase as in LOCALE_NAMES_TO_OIDS
+ // to avoid problems during matching rules initialization.
+ // e.g. locale name "zh-SG" is converted to "zh-sg" in old locale name
+ final StringBuilder sb = new StringBuilder();
+ sb.append(oldLocaleName, 0, idx + 1)
+ .append(oldLocaleName.substring(idx + 1, oldLocaleName.length()).toUpperCase(Locale.ENGLISH));
+ JVM_SUPPORTED_LOCALE_NAMES_TO_OIDS.put(sb.toString(), oid);
+ }
+ }
}
static {
@@ -896,11 +934,12 @@
for (Locale locale : Locale.getAvailableLocales()) {
localesCache.put(localeName(locale), locale);
}
+
// Build a intermediate map to list all available oids with their locale names
// An oid can be associated to multiple locale names
final Map<String, List<String>> oidsCache = new HashMap<String, List<String>>();
for (final String localeName: localesCache.keySet()) {
- String oid = LOCALE_NAMES_TO_OIDS.get(localeName);
+ String oid = JVM_SUPPORTED_LOCALE_NAMES_TO_OIDS.get(localeName);
if (oid != null) {
List<String> names = oidsCache.get(oid);
if (names == null) {
--
Gitblit v1.10.0