mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Jean-Noel Rouvignac
27.30.2015 aa81c5f0063887acf2f91f162bc1abe123b57050
opendj-config/src/main/java/org/forgerock/opendj/config/ManagedObjectDefinitionI18NResource.java
@@ -22,6 +22,7 @@
 *
 *
 *      Copyright 2008 Sun Microsystems, Inc.
 *      Portions Copyright 2015 ForgeRock AS.
 */
package org.forgerock.opendj.config;
@@ -42,8 +43,7 @@
public final class ManagedObjectDefinitionI18NResource {
    /** Application-wide set of instances. */
    private static final Map<String, ManagedObjectDefinitionI18NResource> INSTANCES =
        new HashMap<String, ManagedObjectDefinitionI18NResource>();
    private static final Map<String, ManagedObjectDefinitionI18NResource> INSTANCES = new HashMap<>();
    /**
     * Gets the internationalized resource instance which can be used to
@@ -80,14 +80,13 @@
    }
    /** Mapping from definition to locale-based resource bundle. */
    private final Map<AbstractManagedObjectDefinition<?, ?>, Map<Locale, ResourceBundle>> resources;
    private final Map<AbstractManagedObjectDefinition<?, ?>, Map<Locale, ResourceBundle>> resources = new HashMap<>();
    /** The resource name prefix. */
    private final String prefix;
    /** Private constructor. */
    private ManagedObjectDefinitionI18NResource(String prefix) {
        this.resources = new HashMap<AbstractManagedObjectDefinition<?, ?>, Map<Locale, ResourceBundle>>();
        this.prefix = prefix;
    }
@@ -247,16 +246,8 @@
     */
    synchronized void setResourceBundle(AbstractManagedObjectDefinition<?, ?> d, Locale locale,
        ResourceBundle resoureBundle) {
        // First get the locale-resource mapping, creating it if
        // necessary.
        Map<Locale, ResourceBundle> map = resources.get(d);
        if (map == null) {
            map = new HashMap<Locale, ResourceBundle>();
            resources.put(d, map);
        }
        // Add the resource bundle.
        map.put(locale, resoureBundle);
        getMapping(d).put(locale, resoureBundle);
    }
    /**
@@ -269,16 +260,9 @@
                + "Top configuration definition");
        }
        // First get the locale-resource mapping, creating it if
        // necessary.
        Map<Locale, ResourceBundle> map = resources.get(d);
        if (map == null) {
            map = new HashMap<Locale, ResourceBundle>();
            resources.put(d, map);
        }
        Map<Locale, ResourceBundle> map = getMapping(d);
        // Now get the resource based on the locale, loading it if
        // necessary.
        // Now get the resource based on the locale, loading it if necessary.
        ResourceBundle resourceBundle = map.get(locale);
        if (resourceBundle == null) {
            String baseName = prefix + "." + d.getClass().getName();
@@ -289,4 +273,14 @@
        return resourceBundle;
    }
    private Map<Locale, ResourceBundle> getMapping(AbstractManagedObjectDefinition<?, ?> d) {
        // First get the locale-resource mapping, creating it if necessary.
        Map<Locale, ResourceBundle> map = resources.get(d);
        if (map == null) {
            map = new HashMap<>();
            resources.put(d, map);
        }
        return map;
    }
}