[jboss-cvs] jboss-seam/src/main/org/jboss/seam/theme ...

Gavin King gavin.king at jboss.com
Sun Jul 8 17:13:37 EDT 2007


  User: gavin   
  Date: 07/07/08 17:13:37

  Modified:    src/main/org/jboss/seam/theme   Theme.java
                        ThemeSelector.java
  Log:
  use @Factory instead of @Unwrap where that makes more sense
  
  Revision  Changes    Path
  1.7       +27 -19    jboss-seam/src/main/org/jboss/seam/theme/Theme.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: Theme.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/theme/Theme.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -b -r1.6 -r1.7
  --- Theme.java	21 Jun 2007 04:36:14 -0000	1.6
  +++ Theme.java	8 Jul 2007 21:13:37 -0000	1.7
  @@ -1,8 +1,8 @@
   package org.jboss.seam.theme;
   
  +import static org.jboss.seam.ScopeType.SESSION;
   import static org.jboss.seam.annotations.Install.BUILT_IN;
   
  -import java.io.Serializable;
   import java.util.AbstractMap;
   import java.util.Enumeration;
   import java.util.HashMap;
  @@ -12,42 +12,39 @@
   
   import org.jboss.seam.Component;
   import org.jboss.seam.ScopeType;
  +import org.jboss.seam.annotations.Factory;
   import org.jboss.seam.annotations.Install;
   import org.jboss.seam.annotations.Name;
   import org.jboss.seam.annotations.Scope;
  -import org.jboss.seam.annotations.Unwrap;
   import org.jboss.seam.annotations.intercept.BypassInterceptors;
   import org.jboss.seam.core.Interpolator;
   
   /**
  - * Support for a session-global resource bundle that may be
  - * used for skinning of the user interface.
  + * Factory for a Map of resources that may be
  + * used for skinning the user interface.
    * 
    * @author Gavin King
    */
  - at Scope(ScopeType.SESSION)
  + at Scope(ScopeType.STATELESS)
   @BypassInterceptors
  - at Name("org.jboss.seam.theme.theme")
  + at Name("org.jboss.seam.theme.themeFactory")
   @Install(precedence=BUILT_IN)
  -public class Theme implements Serializable 
  +public class Theme
   {
      
  -   private static final long serialVersionUID = -7003055918970882103L;
  -   
  -   private transient Map messages;
  -   
  -   private void init() 
  +   protected Map<String, String> createMap() 
      {
         final java.util.ResourceBundle bundle = ThemeSelector.instance().getThemeResourceBundle();
         if (bundle!=null) 
         {
         
  -         messages = new AbstractMap<String, String>()
  +         return new AbstractMap<String, String>()
            {
               //private Map<String, String> cache = new HashMap<String, String>();
      
               @Override
  -            public String get(Object key) {
  +            public String get(Object key) 
  +            {
                  if (key instanceof String)
                  {
                     String resourceKey = (String) key;
  @@ -85,7 +82,8 @@
               }
               
               @Override
  -            public Set<Map.Entry<String, String>> entrySet() {
  +            public Set<Map.Entry<String, String>> entrySet() 
  +            {
                  Enumeration<String> keys = bundle.getKeys();
                  Map<String, String> map = new HashMap<String, String>();
                  while ( keys.hasMoreElements() )
  @@ -99,17 +97,27 @@
            };
         
         }
  +      else
  +      {
  +         return null;
  +      }
      }
      
  -   @Unwrap
  +   /**
  +    * Create a Map in the session scope. The session scope is used because
  +    * creating the bundles is somewhat expensive, so it can be cached there because
  +    * the session theme changes infrequently. When the theme is changed, ThemeSelector
  +    * is responsible for removing the Map from the session context.
  +    * 
  +    */
  +   @Factory(value="org.jboss.seam.theme.theme", autoCreate=true, scope=SESSION)
      public java.util.Map getTheme()
      {
  -      if (messages==null) init();
  -      return messages;
  +      return createMap();
      }
      
      public static java.util.Map instance()
      {
  -      return (java.util.Map) Component.getInstance(Theme.class, true );
  +      return (java.util.Map) Component.getInstance("org.jboss.seam.theme.theme", true);
      }
   }
  
  
  
  1.22      +1 -2      jboss-seam/src/main/org/jboss/seam/theme/ThemeSelector.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ThemeSelector.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/theme/ThemeSelector.java,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -b -r1.21 -r1.22
  --- ThemeSelector.java	29 Jun 2007 00:41:37 -0000	1.21
  +++ ThemeSelector.java	8 Jul 2007 21:13:37 -0000	1.22
  @@ -17,7 +17,6 @@
   
   import org.jboss.seam.Component;
   import org.jboss.seam.ScopeType;
  -import org.jboss.seam.Seam;
   import org.jboss.seam.annotations.Create;
   import org.jboss.seam.annotations.Install;
   import org.jboss.seam.annotations.Name;
  @@ -83,7 +82,7 @@
       */
      public void select()
      {
  -      Contexts.removeFromAllContexts( Seam.getComponentName(Theme.class) );
  +      Contexts.removeFromAllContexts("org.jboss.seam.theme.theme");
         FacesContext facesContext = FacesContext.getCurrentInstance();
         String viewId = Pages.getViewId(facesContext);
         UIViewRoot viewRoot = facesContext.getApplication().getViewHandler().createView(facesContext, viewId);
  
  
  



More information about the jboss-cvs-commits mailing list