Author: ekoneil
Date: Thu Mar 24 10:18:12 2005
New Revision: 158931

URL: http://svn.apache.org/viewcvs?view=rev&rev=158931
Log:
Cleanup in the Bundle* support classes.

Just simplifying the way that ResourceBundle and Struts MessageResources 
objects are treated.  Performance work in binding to the messages is coming 
next.

BB: self
DRT: NetUI pass
BVT: NetUI pass (1 failure)


Modified:
    
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/script/common/BundleContext.java
    
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/script/common/BundleMap.java

Modified: 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/script/common/BundleContext.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/script/common/BundleContext.java?view=diff&r1=158930&r2=158931
==============================================================================
--- 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/script/common/BundleContext.java
 (original)
+++ 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/script/common/BundleContext.java
 Thu Mar 24 10:18:12 2005
@@ -36,7 +36,6 @@
  * and is re-created on every page that declares a bundle with the
  * [EMAIL PROTECTED] 
org.apache.beehive.netui.tags.databinding.bundle.DeclareBundle} tag.
  *
- * @exclude
  */
 public class BundleContext {
 
@@ -45,14 +44,13 @@
      * PageContext attribute map during the rendering of the page.
      */
     public static final String KEY = "_netui_pageContext_bundleContext";
-
     public static final String DEFAULT_STRUTS_BUNDLE_NAME = "default";
 
-    private static final Logger _logger = 
Logger.getInstance(BundleContext.class);
-
+    private static final Logger LOGGER = 
Logger.getInstance(BundleContext.class);
     private static final Locale DEFAULT_LOCALE = Locale.getDefault();
+    private static final Iterator EMPTY_ITERATOR = 
Collections.EMPTY_LIST.iterator();
 
-    private Map bundles = null;
+    private Map _bundles = null;
 
     public BundleContext() {
         super();
@@ -71,47 +69,53 @@
     }
 
     public void addBundle(String name, String bundleName, Locale 
localeOverride) {
-        if(bundles == null)
-            bundles = new HashMap();
+        if(_bundles == null)
+            _bundles = new HashMap();
 
-        if(bundles.containsKey(name))
-            if(_logger.isInfoEnabled())
-                _logger.info("The bundle map already contains a key \"" + name 
+ "\" overwriting the previous value.");
+        if(_bundles.containsKey(name))
+            LOGGER.info("The bundle map already contains a key \"" + name + 
"\" overwriting the previous value.");
 
-        BundleNode node = new NetUIBundleNode(bundleName, (localeOverride != 
null ? localeOverride : DEFAULT_LOCALE));
+        Locale locale = (localeOverride != null ? localeOverride : 
DEFAULT_LOCALE);
+        ResourceBundle resourceBundle = createResourceBundle(bundleName, 
locale);
+        BundleNode node = new NetUIBundleNode(bundleName, locale, 
resourceBundle);
+
+        _bundles.put(name, node);
+    }
 
-        bundles.put(name, node);
+    private ResourceBundle createResourceBundle(String bundleName, Locale 
locale) {
+        return ResourceBundle.getBundle(bundleName, locale);
     }
 
     public Iterator getBundleNames() {
-        if(bundles == null)
-            return Collections.EMPTY_LIST.iterator();
-        else
-            return bundles.keySet().iterator();
+        if(_bundles == null)
+            return EMPTY_ITERATOR;
+        else return _bundles.keySet().iterator();
     }
 
     public boolean containsBundle(String name) {
-        if(bundles == null)
+        if(_bundles == null)
             return false;
-        else
-            return bundles.containsKey(name);
+        else return _bundles.containsKey(name);
     }
 
     /**
      * @throws MissingResourceException if an error occurs while loading a 
properties file
      */
     public BundleNode getBundle(String name) {
-        if(bundles == null)
+        if(_bundles == null)
             return null;
 
-        BundleNode bn = (BundleNode)bundles.get(name);
-
-        if(bn == null)
-            return null;
+        BundleNode bn = (BundleNode)_bundles.get(name);
+        return bn;
+    }
 
-        bn.init();
+    public static BundleNode createBundleNode(String name, Object 
messageResource, Locale locale) {
+        if(messageResource instanceof MessageResources) {
+            return new StrutsBundleNode(name, locale, 
(MessageResources)messageResource);
+        }
 
-        return bn;
+        // only called from one place; just want the interface to be correct.  
this won't _ever_ happen in V1.
+        return null;
     }
 
     public String toString() {
@@ -121,7 +125,7 @@
         if(iterator.hasNext()) {
             while(iterator.hasNext()) {
                 Object key = iterator.next();
-                buf.append("bundle name: " + key + " bundle path: " + 
((BundleNode)bundles.get(key)).bundleName + "\n");
+                buf.append("bundle name: " + key + " bundle path: " + 
((BundleNode)_bundles.get(key))._bundleName + "\n");
             }
         } else {
             buf.append("No registered bundles.\n");
@@ -130,28 +134,14 @@
         return buf.toString();
     }
 
-    public static BundleNode createBundleNode(String name, Object 
messageResource, Locale locale) {
-        if(messageResource instanceof MessageResources) {
-            return new StrutsBundleNode(name, locale, 
(MessageResources)messageResource);
-        }
-        
-        // only called from one place; just want the interface to be correct.  
this won't _ever_ happen in V1.
-        return null;
-    }
-
     public static abstract class BundleNode {
 
-        protected String bundleName;
-        protected Locale locale;
+        protected String _bundleName;
+        protected Locale _locale;
 
-        /* package */
         BundleNode(String bundleName, Locale locale) {
-            this.bundleName = bundleName;
-            this.locale = locale;
-        }
-
-        // if necessary
-        public void init() {
+            _bundleName = bundleName;
+            _locale = locale;
         }
 
         public abstract boolean containsKey(String key);
@@ -161,54 +151,54 @@
         public abstract Enumeration getKeys();
     }
 
-    public static class NetUIBundleNode
+    static class NetUIBundleNode
         extends BundleNode {
 
-        private ResourceBundle bundle;
+        private ResourceBundle _bundle;
 
-        /* package */
-        NetUIBundleNode(String bundleName, Locale locale) {
+        NetUIBundleNode(String bundleName, Locale locale, ResourceBundle 
resourceBundle) {
             super(bundleName, locale);
-        }
-
-        public void init() {
-            if(bundle == null)
-                bundle = ResourceBundle.getBundle(bundleName, locale);
+            _bundle = resourceBundle;
         }
 
         public boolean containsKey(String key) {
-            return (bundle.getString(key) != null);
+            if(_bundle == null)
+                return false;
+            else return _bundle.getString(key) != null;
         }
 
         public String getString(String key) {
-            return bundle.getString(key);
+            if(_bundle == null)
+                return null;
+            else return _bundle.getString(key);
         }
 
         public Enumeration getKeys() {
-            return bundle.getKeys();
+            if(_bundle == null)
+                return null;
+            else return _bundle.getKeys();
         }
     }
 
-    public static class StrutsBundleNode
+    static class StrutsBundleNode
         extends BundleNode {
 
-        private String name;
-        private MessageResources messageResource;
+        private String _name;
+        private MessageResources _messageResource;
 
-        /* package */
         StrutsBundleNode(String name, Locale locale, MessageResources 
messageResource) {
             super(null, locale);
 
-            this.name = name;
-            this.messageResource = messageResource;
+            _name = name;
+            _messageResource = messageResource;
         }
 
         public boolean containsKey(String key) {
-            return (messageResource.getMessage(locale, key) != null);
+            return (_messageResource.getMessage(_locale, key) != null);
         }
 
         public String getString(String key) {
-            return messageResource.getMessage(locale, key);
+            return _messageResource.getMessage(_locale, key);
         }
 
         public Enumeration getKeys() {

Modified: 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/script/common/BundleMap.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/script/common/BundleMap.java?view=diff&r1=158930&r2=158931
==============================================================================
--- 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/script/common/BundleMap.java
 (original)
+++ 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/script/common/BundleMap.java
 Thu Mar 24 10:18:12 2005
@@ -271,10 +271,7 @@
      *         binding
      */
     private final Locale retrieveUserLocale() {
-        /*
-         * todo: this code is duped in the codebase and needs to be localized
-         * into a utility
-         */
+        /* todo: centralize the user locale lookup code */
         String locale = null;
         Locale userLocale = null;
 


Reply via email to