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

Gavin King gavin.king at jboss.com
Fri Jun 22 11:28:56 EDT 2007


  User: gavin   
  Date: 07/06/22 11:28:56

  Modified:    src/main/org/jboss/seam/core       
                        ConversationPropagation.java
                        EjbTransactionListener.java Events.java
                        Expressions.java TransactionListener.java
  Added:       src/main/org/jboss/seam/core       
                        BasicTransactionListener.java
  Removed:     src/main/org/jboss/seam/core       
                        AbstractTransactionListener.java
  Log:
  a basic TransactionListener that works all the time
  javadoc
  
  Revision  Changes    Path
  1.6       +13 -0     jboss-seam/src/main/org/jboss/seam/core/ConversationPropagation.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ConversationPropagation.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/core/ConversationPropagation.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -b -r1.5 -r1.6
  --- ConversationPropagation.java	22 Jun 2007 09:28:51 -0000	1.5
  +++ ConversationPropagation.java	22 Jun 2007 15:28:56 -0000	1.6
  @@ -166,6 +166,9 @@
         }
      }
   
  +   /**
  +    * @return the id of the current conversation
  +    */
      public String getConversationId()
      {
         return conversationId;
  @@ -176,6 +179,9 @@
         this.conversationId = conversationId;
      }
   
  +   /**
  +    * @return the id of the parent of the current conversation
  +    */
      public String getParentConversationId()
      {
         return parentConversationId;
  @@ -186,6 +192,10 @@
         this.parentConversationId = parentConversationId;
      }
   
  +   /**
  +    * Specifies that a redirect will occur if there is no
  +    * conversation found on the server.
  +    */
      public boolean isValidateLongRunningConversation()
      {
         return validateLongRunningConversation;
  @@ -205,6 +215,9 @@
         return (ConversationPropagation) Component.getInstance(ConversationPropagation.class, ScopeType.EVENT);
      }
   
  +   /**
  +    * @return the conversation propagation type specified in the request
  +    */
      public String getPropagationType()
      {
         return propagationType;
  
  
  
  1.2       +16 -4     jboss-seam/src/main/org/jboss/seam/core/EjbTransactionListener.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: EjbTransactionListener.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/core/EjbTransactionListener.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -b -r1.1 -r1.2
  --- EjbTransactionListener.java	20 Jun 2007 21:44:41 -0000	1.1
  +++ EjbTransactionListener.java	22 Jun 2007 15:28:56 -0000	1.2
  @@ -15,9 +15,9 @@
   import org.jboss.seam.annotations.Scope;
   
   /**
  - * Temporary solution for getting JTA transaction lifecycle
  - * callbacks. Once all appservers support the new EE5 APIs,
  - * this will be removed.
  + * A TransactionListener that works in an EJB container.
  + * Once all appservers support the new EE5 APIs, this can 
  + * be removed.
    * 
    * @author Gavin King
    *
  @@ -26,7 +26,7 @@
   @Scope(ScopeType.EVENT)
   @Name("org.jboss.seam.core.transactionListener")
   @Install(precedence=FRAMEWORK, value=false)
  -public class EjbTransactionListener extends AbstractTransactionListener 
  +public class EjbTransactionListener extends BasicTransactionListener 
         implements LocalTransactionListener, SessionSynchronization
   {
      public void afterCompletion(boolean success) throws EJBException, RemoteException
  @@ -41,6 +41,18 @@
      
      public void afterBegin() throws EJBException, RemoteException {}
      
  +   @Override
  +   public void afterSeamManagedTransactionCompletion(boolean success)
  +   {
  +      //nopop, let JTA call
  +   }
  +   
  +   @Override
  +   public void beforeSeamManagedTransactionCompletion() 
  +   {
  +      //nopop, let JTA call
  +   }
  +   
      @Remove
      public void destroy() {}
   
  
  
  
  1.33      +1 -1      jboss-seam/src/main/org/jboss/seam/core/Events.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: Events.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/core/Events.java,v
  retrieving revision 1.32
  retrieving revision 1.33
  diff -u -b -r1.32 -r1.33
  --- Events.java	20 Jun 2007 21:44:41 -0000	1.32
  +++ Events.java	22 Jun 2007 15:28:56 -0000	1.33
  @@ -125,7 +125,7 @@
   
      private TransactionListener getTransactionListener()
      {
  -      TransactionListener transactionListener = AbstractTransactionListener.instance();
  +      TransactionListener transactionListener = BasicTransactionListener.instance();
         if (transactionListener==null)
         {
            throw new IllegalStateException("org.jboss.seam.core.transactionListener is not installed");
  
  
  
  1.37      +43 -3     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.36
  retrieving revision 1.37
  diff -u -b -r1.36 -r1.37
  --- Expressions.java	20 Jun 2007 17:45:55 -0000	1.36
  +++ Expressions.java	22 Jun 2007 15:28:56 -0000	1.37
  @@ -1,4 +1,4 @@
  -//$Id: Expressions.java,v 1.36 2007/06/20 17:45:55 gavin Exp $
  +//$Id: Expressions.java,v 1.37 2007/06/22 15:28:56 gavin Exp $
   package org.jboss.seam.core;
   
   import static org.jboss.seam.annotations.Install.BUILT_IN;
  @@ -21,7 +21,9 @@
   import org.jboss.seam.el.SeamExpressionFactory;
   
   /**
  - * Factory for method and value bindings
  + * Factory for EL method and value expressions.
  + * 
  + * This default implementation uses JBoss EL.
    * 
    * @author Gavin King
    */
  @@ -49,16 +51,32 @@
         return EL_CONTEXT;
      }
   
  +   /**
  +    * Create a value expression.
  +    * 
  +    * @param expression a JBoss EL value expression
  +    */
      public ValueExpression<Object> createValueExpression(String expression)
      {
         return createValueExpression(expression, Object.class);
      }
      
  +   /**
  +    * Create a method expression.
  +    * 
  +    * @param expression a JBoss EL method expression
  +    */
      public MethodExpression<Object> createMethodExpression(String expression)
      {
         return createMethodExpression(expression, Object.class);
      }
      
  +   /**
  +    * Create a value expression.
  +    * 
  +    * @param expression a JBoss EL value expression
  +    * @param type the type of the value 
  +    */
      public <T> ValueExpression<T> createValueExpression(final String expression, final Class<T> type)
      {
         
  @@ -115,6 +133,13 @@
         };
      }
      
  +   /**
  +    * Create a method expression.
  +    * 
  +    * @param expression a JBoss EL method expression
  +    * @param type the method return type
  +    * @param argTypes the method parameter types
  +    */
      public <T> MethodExpression<T> createMethodExpression(final String expression, final Class<T> type, final Class... argTypes)
      {
         return new MethodExpression<T>()
  @@ -160,6 +185,14 @@
         };
      }
      
  +   /**
  +    * A value expression, an EL expression that evaluates to
  +    * an attribute getter or get/set pair.
  +    * 
  +    * @author Gavin King
  +    *
  +    * @param <T> the type of the value
  +    */
      public static interface ValueExpression<T> extends Serializable
      {
         public T getValue();
  @@ -168,6 +201,14 @@
         public Class<T> getType();
      }
      
  +   /**
  +    * A method expression, an EL expression that evaluates to
  +    * a method.
  +    * 
  +    * @author Gavin King
  +    *
  +    * @param <T> the method return type
  +    */
      public static interface MethodExpression<T> extends Serializable
      {
         public T invoke(Object... args);
  @@ -179,7 +220,6 @@
         return false;
      }
      
  -
      /**
       * Validate that a value can be assigned to the property
       * identified by a value expression.
  
  
  
  1.11      +26 -0     jboss-seam/src/main/org/jboss/seam/core/TransactionListener.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: TransactionListener.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/core/TransactionListener.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -b -r1.10 -r1.11
  --- TransactionListener.java	20 Jun 2007 21:44:41 -0000	1.10
  +++ TransactionListener.java	22 Jun 2007 15:28:56 -0000	1.11
  @@ -2,8 +2,34 @@
   
   import javax.transaction.Synchronization;
   
  +/**
  + * API for scheduling work that happens in concert
  + * with the JTA transaction commit.
  + * 
  + * @author Gavin King
  + *
  + */
   public interface TransactionListener
   {
  +   /**
  +    * Schedule an event that will be processed after the
  +    * current transaction completes.
  +    * 
  +    * @param type the event type
  +    * @param parameters parameters to be passes to the listener method
  +    */
      public void scheduleEvent(String type, Object... parameters);
  +   /**
  +    * Register a Synchronization with the current transaction
  +    */
      public void registerSynchronization(Synchronization sync);
  +   /**
  +    * Called by Seam before it commits a transaction
  +    */
  +   public void beforeSeamManagedTransactionCompletion();
  +   /**
  +    * Called by Seam after it commits a transaction
  +    * @param success was the commit successful?
  +    */
  +   public void afterSeamManagedTransactionCompletion(boolean success);
   }
  
  
  
  1.1      date: 2007/06/22 15:28:56;  author: gavin;  state: Exp;jboss-seam/src/main/org/jboss/seam/core/BasicTransactionListener.java
  
  Index: BasicTransactionListener.java
  ===================================================================
  package org.jboss.seam.core;
  
  import static org.jboss.seam.annotations.Install.BUILT_IN;
  
  import java.io.Serializable;
  import java.util.ArrayList;
  import java.util.List;
  
  import javax.transaction.Status;
  import javax.transaction.Synchronization;
  
  import org.jboss.seam.Component;
  import org.jboss.seam.ScopeType;
  import org.jboss.seam.annotations.Install;
  import org.jboss.seam.annotations.Logger;
  import org.jboss.seam.annotations.Name;
  import org.jboss.seam.annotations.Scope;
  import org.jboss.seam.contexts.Contexts;
  import org.jboss.seam.log.Log;
  
  /**
   * Base implementation of the TransactionListener interface.
   * This one only works for Seam-managed transactions, but
   * works in any environment.
   * 
   * @see EjbTransactionListener
   * 
   * @author Gavin King
   *
   */
  @Scope(ScopeType.EVENT)
  @Name("org.jboss.seam.core.transactionListener")
  @Install(precedence=BUILT_IN, classDependencies="javax.transaction.Status")
  public class BasicTransactionListener implements TransactionListener
  {
     private static @Logger Log log;
     
     private List<Event> events = new ArrayList<Event>();
     private List<Synchronization> synchronizations = new ArrayList<Synchronization>();
     
     private static class Event implements Serializable
     {
        private String type;
        private Object[] parameters;
        
        public Event(String type, Object[] parameters)
        {
           this.type = type;
           this.parameters = parameters;
        }
        public void call()
        {
           Events.instance().raiseEvent(type, parameters);
        }
     }
  
     public static TransactionListener instance()
     {
        if ( !Contexts.isEventContextActive() )
        {
           throw new IllegalStateException("no event context active");
        }
        return (TransactionListener) Component.getInstance(BasicTransactionListener.class, ScopeType.EVENT);         
     }
        
     public void scheduleEvent(String type, Object... parameters)
     {
        events.add( new Event(type, parameters) );
     }
     
     public void registerSynchronization(Synchronization sync)
     {
        synchronizations.add(sync);
     }
  
     protected void afterTransactionCompletion(boolean success)
     {
        Events.instance().raiseEvent("org.jboss.seam.afterTransactionCompletion", success);
        for (Synchronization sync: synchronizations)
        {
           try
           {
              sync.afterCompletion(success ? Status.STATUS_COMMITTED : Status.STATUS_ROLLEDBACK);
           }
           catch (Exception e)
           {
              log.error("Exception processing transaction Synchronization after completion", e);
           }
        }
        synchronizations.clear();
        if (success)
        {
           for (Event event: events)
           {
              try
              {
                 event.call();
              }
              catch (Exception e)
              {
                 log.error("Exception processing transaction success event", e);
              }
           }
           events.clear();
        }
     }
     
     protected void beforeTransactionCompletion()
     {
        Events.instance().raiseEvent("org.jboss.seam.beforeTransactionCompletion");
        for (Synchronization sync: synchronizations)
        {
           try
           {
              sync.beforeCompletion();
           }
           catch (Exception e)
           {
              log.error("Exception processing transaction Synchronization before completion", e);
           }
        }
     }
     
     public void beforeSeamManagedTransactionCompletion()
     {
        beforeTransactionCompletion();
     }
     
     public void afterSeamManagedTransactionCompletion(boolean success)
     {
        afterTransactionCompletion(success);
     }
     
  }
  
  
  



More information about the jboss-cvs-commits mailing list