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

Gavin King gavin.king at jboss.com
Mon Jul 16 08:57:59 EDT 2007


  User: gavin   
  Date: 07/07/16 08:57:59

  Modified:    src/main/org/jboss/seam/el  SeamELResolver.java
  Log:
  JBSEAM-1490 Namespace no longer a Map
  
  Revision  Changes    Path
  1.5       +117 -76   jboss-seam/src/main/org/jboss/seam/el/SeamELResolver.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: SeamELResolver.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/el/SeamELResolver.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -b -r1.4 -r1.5
  --- SeamELResolver.java	10 Jul 2007 08:57:37 -0000	1.4
  +++ SeamELResolver.java	16 Jul 2007 12:57:59 -0000	1.5
  @@ -11,14 +11,16 @@
   import javax.el.ELResolver;
   
   import org.jboss.seam.Component;
  +import org.jboss.seam.Namespace;
   import org.jboss.seam.contexts.Context;
   import org.jboss.seam.contexts.Contexts;
   import org.jboss.seam.core.Init;
   
   /**
  - * Allows the use of #{dataModel.size}, #{dataModel.empty},
  + * Resolves Seam components and namespaces. Also
  + * allows the use of #{dataModel.size}, #{dataModel.empty},
    * #{collection.size}, #{map.size}, #{map.values}, #{map.keySet},
  - * and #{map.entrySet}.
  + * and #{map.entrySet}. Also allows #{sessionContext['name']}.
    * 
    * @author Gavin King
    *
  @@ -49,54 +51,49 @@
      {
         if (base==null)
         {
  -         if ( !Contexts.isApplicationContextActive() )
  -         {
  -            //if no Seam contexts, bypass straight through to JSF
  -            return null;
  +         return resolveBase(context, property);
            }
  -         
  -         String name = (String) property;
  -         Object result = Component.getInstance(name);
  -         if (result==null)
  +      else if ( base instanceof Namespace )
            {
  -            result = Init.instance().getRootNamespace().getChild(name);
  +         return resolveInNamespace(context, base, property);
            }
  -         if (result!=null)
  +      else if ( DATA_MODEL.isInstance(base) )
            {
  -            context.setPropertyResolved(true);
  -         }
  -         return result;
  +         return resolveInDataModel(context, base, property);
         }
  -      else if ( DATA_MODEL.isInstance(base) )
  +      else if (base instanceof Collection)
         {
  -         if ( "size".equals(property) )
  +         return resolveInCollection(context, base, property);
  +      }
  +      else if (base instanceof Map)
            {
  -            context.setPropertyResolved(true);
  -            return getRowCount(base);
  +         return resolveInMap(context, base, property);
            }
  -         else if ( "empty".equals(property) )
  +      else if (base instanceof Context)
            {
  -            context.setPropertyResolved(true);
  -            return getRowCount(base)==0;
  +         return resolveInContextObject(context, base, property);
            }
            else
            {
               return null;
            }
         }
  -      else if (base instanceof Collection)
  +
  +   private Object resolveInContextObject(ELContext context, Object base, Object property)
         {
  -         if ( "size".equals(property) )
  +      Context seamContext = (Context) base;
  +      if ( seamContext.isSet( (String) property ) )
            {
               context.setPropertyResolved(true);
  -            return ( (Collection) base ).size();
  +         return seamContext.get( (String) property );
            }
            else
            {
               return null;
            }
         }
  -      else if (base instanceof Map)
  +
  +   private Object resolveInMap(ELContext context, Object base, Object property)
         {
            if ( "size".equals(property) )
            {
  @@ -123,25 +120,69 @@
               return null;
            }
         }
  -      else if (base instanceof Context)
  +
  +   private Object resolveInCollection(ELContext context, Object base, Object property)
         {
  -         Context seamContext = (Context) base;
  -         if ( seamContext.isSet( (String) property ) )
  +      if ( "size".equals(property) )
            {
               context.setPropertyResolved(true);
  -            return seamContext.get( (String) property );
  +         return ( (Collection) base ).size();
            }
            else
            {
               return null;
            }
         }
  +
  +   private Object resolveInDataModel(ELContext context, Object base, Object property)
  +   {
  +      if ( "size".equals(property) )
  +      {
  +         context.setPropertyResolved(true);
  +         return getRowCount(base);
  +      }
  +      else if ( "empty".equals(property) )
  +      {
  +         context.setPropertyResolved(true);
  +         return getRowCount(base)==0;
  +      }
         else
         {
            return null;
         }
      }
   
  +   private Object resolveBase(ELContext context, Object property)
  +   {
  +      if ( !Contexts.isApplicationContextActive() )
  +      {
  +         //if no Seam contexts, bypass straight through to JSF
  +         return null;
  +      }
  +      
  +      String name = (String) property;
  +      Object result = Component.getInstance(name);
  +      if (result==null)
  +      {
  +         result = Init.instance().getRootNamespace().getChild(name);
  +      }
  +      if (result!=null)
  +      {
  +         context.setPropertyResolved(true);
  +      }
  +      return result;
  +   }
  +
  +   private Object resolveInNamespace(ELContext context, Object base, Object property)
  +   {
  +      Object result = ( (Namespace) base ).get( (String) property );
  +      if (result!=null)
  +      {
  +         context.setPropertyResolved(true);
  +      }
  +      return result;
  +   }
  +
      @Override
      public boolean isReadOnly(ELContext context, Object base, Object property)
      {
  
  
  



More information about the jboss-cvs-commits mailing list