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

Gavin King gavin.king at jboss.com
Wed May 30 23:41:03 EDT 2007


  User: gavin   
  Date: 07/05/30 23:41:03

  Modified:    src/main/org/jboss/seam/core  Expressions.java
  Log:
  cache compiled expressions
  
  Revision  Changes    Path
  1.30      +60 -7     jboss-seam/src/main/org/jboss/seam/core/Expressions.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: Expressions.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/core/Expressions.java,v
  retrieving revision 1.29
  retrieving revision 1.30
  diff -u -b -r1.29 -r1.30
  --- Expressions.java	30 May 2007 00:35:15 -0000	1.29
  +++ Expressions.java	31 May 2007 03:41:03 -0000	1.30
  @@ -1,4 +1,4 @@
  -//$Id: Expressions.java,v 1.29 2007/05/30 00:35:15 gavin Exp $
  +//$Id: Expressions.java,v 1.30 2007/05/31 03:41:03 gavin Exp $
   package org.jboss.seam.core;
   
   import static org.jboss.seam.InterceptionType.NEVER;
  @@ -70,49 +70,102 @@
      
      public <T> ValueExpression<T> createValueExpression(final String expression, final Class<T> type)
      {
  -      //TODO: cache the VEs
  +      
         return new ValueExpression<T>()
         {
  +         private javax.el.ValueExpression facesValueExpression;
  +         private javax.el.ValueExpression seamValueExpression;
  +         
  +         private javax.el.ValueExpression getExpression()
  +         {
  +            if ( FacesContext.getCurrentInstance()==null )
  +            {
  +               if (seamValueExpression==null)
  +               {
  +                  seamValueExpression = createExpression();
  +               }
  +               return seamValueExpression;
  +            }
  +            else
  +            {
  +               if (facesValueExpression==null)
  +               {
  +                  facesValueExpression = createExpression();
  +               }
  +               return facesValueExpression;
  +            }
  +         }
  +         
            private javax.el.ValueExpression createExpression()
            {
               return getExpressionFactory().createValueExpression( getELContext(), expression, type );
            }
  +         
            public T getValue()
            {
  -            return (T) createExpression().getValue( getELContext() );
  +            return (T) getExpression().getValue( getELContext() );
            }
  +         
            public void setValue(T value)
            {
  -            createExpression().setValue( getELContext(), value );
  +            getExpression().setValue( getELContext(), value );
            }
  +         
            public String getExpressionString()
            {
               return expression;
            }
  +         
            public Class<T> getType()
            {
  -            return (Class<T>) createExpression().getType( getELContext() );
  +            return (Class<T>) getExpression().getType( getELContext() );
            }
  +         
         };
      }
      
      public <T> MethodExpression<T> createMethodExpression(final String expression, final Class<T> type, final Class... argTypes)
      {
  -      //TODO: cache the MEs
         return new MethodExpression<T>()
         {
  +         private javax.el.MethodExpression facesMethodExpression;
  +         private javax.el.MethodExpression seamMethodExpression;
  +         
  +         private javax.el.MethodExpression getExpression()
  +         {
  +            if ( FacesContext.getCurrentInstance()==null )
  +            {
  +               if (seamMethodExpression==null)
  +               {
  +                  seamMethodExpression = createExpression();
  +               }
  +               return seamMethodExpression;
  +            }
  +            else
  +            {
  +               if (facesMethodExpression==null)
  +               {
  +                  facesMethodExpression = createExpression();
  +               }
  +               return facesMethodExpression;
  +            }
  +         }
  +         
            private javax.el.MethodExpression createExpression()
            {
               return getExpressionFactory().createMethodExpression( getELContext(), expression, type, argTypes );
            }
  +         
            public T invoke(Object... args)
            {
  -            return (T) createExpression().invoke( getELContext(), args );
  +            return (T) getExpression().invoke( getELContext(), args );
            }
  +         
            public String getExpressionString()
            {
               return expression;
            }
  +         
         };
      }
      
  
  
  



More information about the jboss-cvs-commits mailing list