svn commit: r618941 - in /ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util: UtilProperties.java collections/ResourceBundleMapWrapper.java

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

svn commit: r618941 - in /ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util: UtilProperties.java collections/ResourceBundleMapWrapper.java

adrianc
Author: adrianc
Date: Wed Feb  6 01:49:55 2008
New Revision: 618941

URL: http://svn.apache.org/viewvc?rev=618941&view=rev
Log:
Bug fix for the ResourceBundleMapWrapper - eliminate redundant Map Stack entries. Duplicate copies of ResourceBundles were being added to the MapStack.

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

Modified: ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilProperties.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilProperties.java?rev=618941&r1=618940&r2=618941&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilProperties.java (original)
+++ ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilProperties.java Wed Feb  6 01:49:55 2008
@@ -801,13 +801,19 @@
         protected static UtilCache<String, UtilResourceBundle> bundleCache = new UtilCache<String, UtilResourceBundle>("properties.UtilPropertiesBundleCache");
         protected Properties properties = null;
         protected Locale locale = null;
+        protected int hashCode = hashCode();
 
         protected UtilResourceBundle() {}
         
-        public UtilResourceBundle(Properties properties, Locale locale, ResourceBundle parent) {
+        public UtilResourceBundle(Properties properties, Locale locale, UtilResourceBundle parent) {
             this.properties = properties;
             this.locale = locale;
             setParent(parent);
+            String hashString = properties.toString();
+            if (parent != null) {
+                hashString += parent.properties;
+            }
+            this.hashCode = hashString.hashCode();
         }
 
         public static ResourceBundle getBundle(String resource, Locale locale, ClassLoader loader) throws MissingResourceException {
@@ -820,7 +826,7 @@
                     }
                     double startTime = System.currentTimeMillis();
                     FastList<Locale> candidateLocales = (FastList<Locale>) getCandidateLocales(locale);
-                    ResourceBundle parentBundle = null;
+                    UtilResourceBundle parentBundle = null;
                     while (candidateLocales.size() > 0) {
                         Locale candidateLocale = candidateLocales.removeLast();
                         // ResourceBundles are connected together as a singly-linked list
@@ -830,6 +836,9 @@
                             Properties newProps = getProperties(resource, candidateLocale);
                             if (UtilValidate.isNotEmpty(newProps)) {
                                 bundle = new UtilResourceBundle(newProps, candidateLocale, parentBundle);
+                                UtilResourceBundle testBundle = new UtilResourceBundle(newProps, candidateLocale, parentBundle);
+                                Debug.logInfo("bundle = testBundle: " + bundle.equals(testBundle), module);
+                                Debug.logInfo("bundle = null: " + bundle.equals(null), module);
                                 bundleCache.put(parentName, bundle);
                                 parentBundle = bundle;
                             }
@@ -852,6 +861,14 @@
             return bundle;
         }
         
+        public int hashCode() {
+            return this.hashCode;
+        }
+        
+        public boolean equals(Object obj) {
+            return obj == null ? false : obj.hashCode() == this.hashCode;
+        }
+
         public Locale getLocale() {
             return this.locale;
         }

Modified: ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/collections/ResourceBundleMapWrapper.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/collections/ResourceBundleMapWrapper.java?rev=618941&r1=618940&r2=618941&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/collections/ResourceBundleMapWrapper.java (original)
+++ ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/collections/ResourceBundleMapWrapper.java Wed Feb  6 01:49:55 2008
@@ -20,6 +20,7 @@
 
 import java.util.Enumeration;
 import java.util.HashMap;
+import java.util.Map;
 import java.util.MissingResourceException;
 import java.util.ResourceBundle;
 
@@ -59,6 +60,18 @@
         push(new InternalRbmWrapper(initialResourceBundle));
     }
     
+    public void addToBottom(Map<String, Object> existingMap) {
+        if (!stackList.contains(existingMap)) {
+            super.addToBottom(existingMap);
+        }
+    }
+    
+    public void push(Map<String, Object> existingMap) {
+        if (!stackList.contains(existingMap)) {
+            super.push(existingMap);
+        }
+    }
+    
     /** Puts ResourceBundle on the BOTTOM of the stack - meaning the bundle will
      * be overriden by higher layers on the stack.
      */
@@ -135,6 +148,14 @@
             put("_RESOURCE_BUNDLE_", resourceBundle); // Is this being used anywhere?
         }
         
+        public boolean equals(Object obj) {
+            return resourceBundle.equals(obj);
+        }
+
+        public int hashCode() {
+            return resourceBundle.hashCode();
+        }
+
         /*
          * (non-Javadoc)
          *