[seam-commits] Seam SVN: r10118 - trunk/src/main/org/jboss/seam/theme.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Thu Mar 5 15:36:32 EST 2009


Author: norman.richards at jboss.com
Date: 2009-03-05 15:36:32 -0500 (Thu, 05 Mar 2009)
New Revision: 10118

Modified:
   trunk/src/main/org/jboss/seam/theme/Theme.java
Log:
JBSEAM-3994

Modified: trunk/src/main/org/jboss/seam/theme/Theme.java
===================================================================
--- trunk/src/main/org/jboss/seam/theme/Theme.java	2009-03-05 18:15:22 UTC (rev 10117)
+++ trunk/src/main/org/jboss/seam/theme/Theme.java	2009-03-05 20:36:32 UTC (rev 10118)
@@ -3,12 +3,7 @@
 import static org.jboss.seam.ScopeType.EVENT;
 import static org.jboss.seam.annotations.Install.BUILT_IN;
 
-import java.util.AbstractMap;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.MissingResourceException;
-import java.util.Set;
+import java.util.*;
 
 import org.jboss.seam.Component;
 import org.jboss.seam.ScopeType;
@@ -20,102 +15,88 @@
 import org.jboss.seam.core.Interpolator;
 
 /**
- * Factory for a Map of resources that may be
- * used for skinning the user interface.
+ * Factory for a Map of resources that may be used for skinning the user
+ * interface.
  * 
  * @author Gavin King
  */
 @Scope(ScopeType.STATELESS)
 @BypassInterceptors
 @Name("org.jboss.seam.theme.themeFactory")
- at Install(precedence=BUILT_IN)
-public class Theme
-{
-   
-   protected Map<String, String> createMap() 
-   {
-      final java.util.ResourceBundle bundle = ThemeSelector.instance().getThemeResourceBundle();
-      if (bundle!=null) 
-      {
-      
-         return new AbstractMap<String, String>()
-         {
-            //private Map<String, String> cache = new HashMap<String, String>();
-   
-            @Override
-            public String get(Object key) 
-            {
-               if (key instanceof String)
-               {
-                  String resourceKey = (String) key;
-                  /*String cachedValue = cache.get(key);
-                  if (cachedValue==null)
-                  {*/
-                     String resource;
-                     try
-                     {
+ at Install(precedence = BUILT_IN)
+public class Theme {
+
+    protected Map<String, String> createMap() {
+        final java.util.ResourceBundle bundle = ThemeSelector.instance().getThemeResourceBundle();
+
+        if (bundle == null) {
+            return null;
+        }
+
+        return new AbstractMap<String, String>() {
+            public String lookup(Object key) {
+                if (key instanceof String) {
+                    String resourceKey = (String) key;
+
+                    String resource;
+                    try {
                         resource = bundle.getString(resourceKey);
-                     }
-                     catch (MissingResourceException mre)
-                     {
+                    } catch (MissingResourceException mre) {
                         return resourceKey;
-                     }
-                     if (resource==null)
-                     {
+                    }
+                    if (resource == null) {
                         return resourceKey;
-                     }
-                     else
-                     {
-                        //cache.put(resourceKey, resource);
+                    } else {
                         return Interpolator.instance().interpolate(resource);
-                     }
-                  /*}
-                  else
-                  {
-                     return Interpolator.instance().interpolate(cachedValue);
-                  }*/
-               }
-               else
-               {
-                  return null;
-               }
+                    }
+                } else {
+                    return null;
+                }
             }
-            
+
             @Override
-            public Set<Map.Entry<String, String>> entrySet() 
-            {
-               Enumeration<String> keys = bundle.getKeys();
-               Map<String, String> map = new HashMap<String, String>();
-               while ( keys.hasMoreElements() )
-               {
-                  String key = keys.nextElement();
-                  map.put( key, get(key) );
-               }
-               return map.entrySet();
+            public Set<Map.Entry<String, String>> entrySet() {
+                Set<Map.Entry<String, String>> entrySet = new HashSet<Map.Entry<String, String>>();
+                
+                Enumeration<String> keys = bundle.getKeys();
+
+                while (keys.hasMoreElements()) {                
+                    final String key = keys.nextElement();
+                    
+                    entrySet.add(new Map.Entry<String, String>() {
+
+                        public String getKey() {
+                            return key;
+                        }
+
+                        public String getValue() {
+                            return lookup(key);
+                        }
+
+                        public String setValue(String arg0) {
+                            throw new UnsupportedOperationException("not implemented");
+                        }
+                    });
+                }
+                   
+                return entrySet;
             }
-            
-         };
-      
-      }
-      else
-      {
-         return null;
-      }
-   }
-   
-   /**
-    * Create a Map in the event scope. When the theme is changed, ThemeSelector
-    * is responsible for removing the Map from the event context.
-    * 
-    */
-   @Factory(value="org.jboss.seam.theme.theme", autoCreate=true, scope=EVENT)
-   public java.util.Map getTheme()
-   {
-      return createMap();
-   }
-   
-   public static java.util.Map instance()
-   {
-      return (java.util.Map) Component.getInstance("org.jboss.seam.theme.theme", true);
-   }
+
+        };
+
+    }
+
+    /**
+     * Create a Map in the event scope. When the theme is changed, ThemeSelector
+     * is responsible for removing the Map from the event context.
+     * 
+     */
+    @Factory(value = "org.jboss.seam.theme.theme", autoCreate = true, scope = EVENT)
+    public java.util.Map getTheme() {
+        return createMap();
+    }
+
+    public static java.util.Map instance() {
+        return (java.util.Map) Component.getInstance("org.jboss.seam.theme.theme", true);
+    }
 }




More information about the seam-commits mailing list