svn commit: r898648 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilProperties.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r898648 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilProperties.java

adrianc
Author: adrianc
Date: Wed Jan 13 04:41:03 2010
New Revision: 898648

URL: http://svn.apache.org/viewvc?rev=898648&view=rev
Log:
A less aggressive UtilProperties.java update, suggested by Adam Heath.

Modified:
    ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilProperties.java

Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilProperties.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilProperties.java?rev=898648&r1=898647&r2=898648&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilProperties.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilProperties.java Wed Jan 13 04:41:03 2010
@@ -57,20 +57,24 @@
  * (see the <a href="#xmlToProperties(java.io.InputStream,%20java.util.Locale,%20java.util.Properties)">xmlToProperties</a>
  * method).</p>
  */
-public class UtilProperties {
+@SuppressWarnings("serial")
+public class UtilProperties implements java.io.Serializable {
 
     public static final String module = UtilProperties.class.getName();
+
     /** An instance of the generic cache for storing the non-locale-specific properties.
      *  Each Properties instance is keyed by the resource String.
      */
-    protected static final UtilCache<String, Properties> resourceCache = UtilCache.createUtilCache("properties.UtilPropertiesResourceCache");
+    protected static UtilCache<String, Properties> resourceCache = UtilCache.createUtilCache("properties.UtilPropertiesResourceCache");
+
     /** An instance of the generic cache for storing the non-locale-specific properties.
      *  Each Properties instance is keyed by the file's URL.
      */
-    protected static final UtilCache<String, Properties> urlCache = UtilCache.createUtilCache("properties.UtilPropertiesUrlCache");
-    protected static final Set<String> propertiesNotFound = FastSet.newInstance();
-    protected static final Locale fallbackLocale = createFallbackLocale();
-    protected static final Set<Locale> defaultCandidateLocales = createDefaultCandidateLocales();
+    protected static UtilCache<String, Properties> urlCache = UtilCache.createUtilCache("properties.UtilPropertiesUrlCache");
+
+    protected static Locale fallbackLocale = null;
+    protected static Set<Locale> defaultCandidateLocales = null;
+    protected static Set<String> propertiesNotFound = FastSet.newInstance();
 
     /** Compares the specified property to the compareString, returns true if they are the same, false otherwise
      * @param resource The name of the resource - if the properties file is 'webevent.properties', the resource name is 'webevent'
@@ -599,17 +603,24 @@
      * configured using the <code>locale.properties.fallback</code> property in
      * <code>general.properties</code>.
      * @return The configured fallback locale
+     * @deprecated Use <code>java.util.ResourceBundle.Control.getFallbackLocale(...)</code>
      */
-    protected static Locale createFallbackLocale() {
-        String locale = getPropertyValue("general", "locale.properties.fallback");
-        Locale result = null;
-        if (UtilValidate.isNotEmpty(locale)) {
-            result = UtilMisc.parseLocale(locale);
-        }
-        if (result == null) {
-            result = UtilMisc.parseLocale("en");
+    @Deprecated
+    public static Locale getFallbackLocale() {
+        if (fallbackLocale == null) {
+            synchronized (UtilProperties.class) {
+                if (fallbackLocale == null) {
+                    String locale = getPropertyValue("general", "locale.properties.fallback");
+                    if (UtilValidate.isNotEmpty(locale)) {
+                        fallbackLocale = UtilMisc.parseLocale(locale);
+                    }
+                    if (fallbackLocale == null) {
+                        fallbackLocale = UtilMisc.parseLocale("en");
+                    }
+                }
+            }
         }
-        return result;
+        return fallbackLocale;
     }
 
     /** Converts a Locale instance to a candidate Locale list. The list
@@ -636,12 +647,18 @@
      * the <code>LOCALE_ROOT</code> (empty) locale - in that order.
      * @return A list of default candidate locales.
      */
-    protected static Set<Locale> createDefaultCandidateLocales() {
-        Set<Locale> result = FastSet.newInstance();
-        result.addAll(localeToCandidateList(Locale.getDefault()));
-        result.addAll(localeToCandidateList(fallbackLocale));
-        result.add(Locale.ROOT);
-        return result;
+    public static Set<Locale> getDefaultCandidateLocales() {
+        if (defaultCandidateLocales == null) {
+            synchronized (UtilProperties.class) {
+                if (defaultCandidateLocales == null) {
+                    defaultCandidateLocales = FastSet.newInstance();
+                    defaultCandidateLocales.addAll(localeToCandidateList(Locale.getDefault()));
+                    defaultCandidateLocales.addAll(localeToCandidateList(getFallbackLocale()));
+                    defaultCandidateLocales.add(Locale.ROOT);
+                }
+            }
+        }
+        return defaultCandidateLocales;
     }
 
     /** Returns a list of candidate locales based on a supplied locale.
@@ -650,7 +667,9 @@
      * - in that order.
      * @param locale The desired locale
      * @return A list of candidate locales
+     * @deprecated Use <code>java.util.ResourceBundle.Control.getCandidateLocales(...)</code>
      */
+    @Deprecated
     public static List<Locale> getCandidateLocales(Locale locale) {
         // Java 6 conformance
         if (Locale.ROOT.equals(locale)) {
@@ -658,7 +677,7 @@
         }
         Set<Locale> localeSet = FastSet.newInstance();
         localeSet.addAll(localeToCandidateList(locale));
-        localeSet.addAll(defaultCandidateLocales);
+        localeSet.addAll(getDefaultCandidateLocales());
         List<Locale> localeList = FastList.newInstance();
         localeList.addAll(localeSet);
         return localeList;