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

Gavin King gavin.king at jboss.com
Sun Jul 8 07:23:09 EDT 2007


  User: gavin   
  Date: 07/07/08 07:23:09

  Modified:    src/main/org/jboss/seam/jsf 
                        SeamApplicationMessageBundle.java
  Log:
  don't blow up when getting messages outside contexts
  
  Revision  Changes    Path
  1.5       +25 -5     jboss-seam/src/main/org/jboss/seam/jsf/SeamApplicationMessageBundle.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: SeamApplicationMessageBundle.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/jsf/SeamApplicationMessageBundle.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -b -r1.4 -r1.5
  --- SeamApplicationMessageBundle.java	19 Jun 2007 19:41:44 -0000	1.4
  +++ SeamApplicationMessageBundle.java	8 Jul 2007 11:23:09 -0000	1.5
  @@ -3,10 +3,13 @@
    */
   package org.jboss.seam.jsf;
   
  +import java.util.Collections;
   import java.util.Enumeration;
   import java.util.ResourceBundle;
   
  +import org.jboss.seam.contexts.Contexts;
   import org.jboss.seam.core.Interpolator;
  +import org.jboss.seam.util.IteratorEnumeration;
   
   /**
    * Adaptor allow use of #{messages} for JSF application messages - 
  @@ -16,19 +19,36 @@
   public class SeamApplicationMessageBundle extends ResourceBundle
   {
   
  +   private ResourceBundle getBundle()
  +   {
  +      return Contexts.isApplicationContextActive() && Contexts.isSessionContextActive() ?
  +               org.jboss.seam.core.ResourceBundle.instance() : null;
  +   }
  +
      @Override
      public Enumeration<String> getKeys()
      {
  -      return org.jboss.seam.core.ResourceBundle.instance().getKeys();
  +      ResourceBundle bundle = getBundle();
  +      return bundle==null ? 
  +            new IteratorEnumeration( Collections.EMPTY_LIST.iterator() ) :
  +            bundle.getKeys();
      }
   
      @Override
      protected Object handleGetObject(String key)
      {
  -      Object resource = org.jboss.seam.core.ResourceBundle.instance().getObject(key);
  +      ResourceBundle bundle = getBundle();
  +      if (bundle==null)
  +      {
  +         return null;
  +      }
  +      else
  +      {
  +         Object resource = bundle.getObject(key);
         return resource!=null && ( resource instanceof String ) ?
               Interpolator.instance().interpolate( (String) resource ) :
               resource;
      }
  +   }
   
   }
  \ No newline at end of file
  
  
  



More information about the jboss-cvs-commits mailing list