[seam-commits] Seam SVN: r8482 - in trunk: examples/wicket/src/web/org/jboss/seam/example/wicket and 2 other directories.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Sat Jul 19 11:02:45 EDT 2008


Author: pete.muir at jboss.org
Date: 2008-07-19 11:02:45 -0400 (Sat, 19 Jul 2008)
New Revision: 8482

Added:
   trunk/src/wicket/org/jboss/seam/wicket/ioc/ConversationInterceptor.java
   trunk/src/wicket/org/jboss/seam/wicket/ioc/EventInterceptor.java
Modified:
   trunk/examples/wicket/src/action/org/jboss/seam/example/wicket/action/HotelBooking.java
   trunk/examples/wicket/src/action/org/jboss/seam/example/wicket/action/HotelBookingAction.java
   trunk/examples/wicket/src/action/org/jboss/seam/example/wicket/action/Register.java
   trunk/examples/wicket/src/action/org/jboss/seam/example/wicket/action/RegisterAction.java
   trunk/examples/wicket/src/web/org/jboss/seam/example/wicket/Book.java
   trunk/examples/wicket/src/web/org/jboss/seam/example/wicket/Confirm.java
   trunk/examples/wicket/src/web/org/jboss/seam/example/wicket/Hotel.java
   trunk/examples/wicket/src/web/org/jboss/seam/example/wicket/Main.java
   trunk/examples/wicket/src/web/org/jboss/seam/example/wicket/Register.java
   trunk/src/wicket/org/jboss/seam/wicket/SeamWebApplication.java
   trunk/src/wicket/org/jboss/seam/wicket/ioc/InvocationContext.java
   trunk/src/wicket/org/jboss/seam/wicket/ioc/JavassistInstrumentor.java
   trunk/src/wicket/org/jboss/seam/wicket/ioc/WicketHandler.java
Log:
Add support for conversation control, task/process control and events

Modified: trunk/examples/wicket/src/action/org/jboss/seam/example/wicket/action/HotelBooking.java
===================================================================
--- trunk/examples/wicket/src/action/org/jboss/seam/example/wicket/action/HotelBooking.java	2008-07-19 12:43:17 UTC (rev 8481)
+++ trunk/examples/wicket/src/action/org/jboss/seam/example/wicket/action/HotelBooking.java	2008-07-19 15:02:45 UTC (rev 8482)
@@ -6,7 +6,7 @@
 @Local
 public interface HotelBooking
 {
-   public Hotel selectHotel(Long hotelId);
+   public void selectHotel(Hotel hotel);
    
    public void bookHotel();
    

Modified: trunk/examples/wicket/src/action/org/jboss/seam/example/wicket/action/HotelBookingAction.java
===================================================================
--- trunk/examples/wicket/src/action/org/jboss/seam/example/wicket/action/HotelBookingAction.java	2008-07-19 12:43:17 UTC (rev 8481)
+++ trunk/examples/wicket/src/action/org/jboss/seam/example/wicket/action/HotelBookingAction.java	2008-07-19 15:02:45 UTC (rev 8482)
@@ -10,14 +10,12 @@
 import javax.persistence.EntityManager;
 import javax.persistence.PersistenceContext;
 
-import org.jboss.seam.annotations.Begin;
 import org.jboss.seam.annotations.End;
 import org.jboss.seam.annotations.In;
 import org.jboss.seam.annotations.Logger;
 import org.jboss.seam.annotations.Name;
 import org.jboss.seam.annotations.Out;
 import org.jboss.seam.annotations.security.Restrict;
-import org.jboss.seam.core.Events;
 import org.jboss.seam.international.StatusMessages;
 import org.jboss.seam.log.Log;
 
@@ -42,21 +40,15 @@
    
    @In(create=true)
    private StatusMessages statusMessages;
-      
-   @In
-   private Events events;
    
    @Logger 
    private Log log;
    
    private boolean bookingValid;
    
-   // TODO Use outjection
-   @Begin
-   public Hotel selectHotel(Long hotelId)
+   public void selectHotel(Hotel hotel)
    {
-      hotel = em.find(Hotel.class, hotelId);
-      return hotel;
+      this.hotel = hotel;
    }
    
    public void bookHotel()
@@ -99,7 +91,6 @@
       em.persist(booking);
       statusMessages.add("Thank you, #{user.name}, your confimation number for #{hotel.name} is #{booking.id}");
       log.info("New booking: #{booking.id} for #{user.username}");
-      events.raiseTransactionSuccessEvent("bookingConfirmed");
    }
    
    @End

Modified: trunk/examples/wicket/src/action/org/jboss/seam/example/wicket/action/Register.java
===================================================================
--- trunk/examples/wicket/src/action/org/jboss/seam/example/wicket/action/Register.java	2008-07-19 12:43:17 UTC (rev 8481)
+++ trunk/examples/wicket/src/action/org/jboss/seam/example/wicket/action/Register.java	2008-07-19 15:02:45 UTC (rev 8482)
@@ -8,8 +8,6 @@
 {
    public void register();
    public void invalid();
-   public String getVerify();
-   public void setVerify(String verify);
    public boolean isRegistered();
    
    public void destroy();

Modified: trunk/examples/wicket/src/action/org/jboss/seam/example/wicket/action/RegisterAction.java
===================================================================
--- trunk/examples/wicket/src/action/org/jboss/seam/example/wicket/action/RegisterAction.java	2008-07-19 12:43:17 UTC (rev 8481)
+++ trunk/examples/wicket/src/action/org/jboss/seam/example/wicket/action/RegisterAction.java	2008-07-19 15:02:45 UTC (rev 8482)
@@ -29,6 +29,7 @@
    @In(create=true)
    private StatusMessages statusMessages;
    
+   @In
    private String verify;
    
    private boolean registered;
@@ -66,14 +67,7 @@
    {
       return registered;
    }
-   public String getVerify()
-   {
-      return verify;
-   }
-   public void setVerify(String verify)
-   {
-      this.verify = verify;
-   }
+
    
    @Remove
    public void destroy() {}

Modified: trunk/examples/wicket/src/web/org/jboss/seam/example/wicket/Book.java
===================================================================
--- trunk/examples/wicket/src/web/org/jboss/seam/example/wicket/Book.java	2008-07-19 12:43:17 UTC (rev 8481)
+++ trunk/examples/wicket/src/web/org/jboss/seam/example/wicket/Book.java	2008-07-19 15:02:45 UTC (rev 8482)
@@ -32,6 +32,7 @@
 import org.apache.wicket.markup.html.link.Link;
 import org.apache.wicket.markup.html.panel.ComponentFeedbackPanel;
 import org.apache.wicket.model.PropertyModel;
+import org.jboss.seam.annotations.End;
 import org.jboss.seam.annotations.In;
 import org.jboss.seam.annotations.security.Restrict;
 import org.jboss.seam.example.wicket.action.Booking;
@@ -114,6 +115,7 @@
          {
 
             @Override
+            @End
             public void onClick()
             {
                setResponsePage(Main.class);

Modified: trunk/examples/wicket/src/web/org/jboss/seam/example/wicket/Confirm.java
===================================================================
--- trunk/examples/wicket/src/web/org/jboss/seam/example/wicket/Confirm.java	2008-07-19 12:43:17 UTC (rev 8481)
+++ trunk/examples/wicket/src/web/org/jboss/seam/example/wicket/Confirm.java	2008-07-19 15:02:45 UTC (rev 8482)
@@ -10,6 +10,7 @@
 import org.apache.wicket.markup.html.basic.Label;
 import org.apache.wicket.markup.html.link.Link;
 import org.jboss.seam.annotations.In;
+import org.jboss.seam.annotations.RaiseEvent;
 import org.jboss.seam.annotations.security.Restrict;
 import org.jboss.seam.core.Conversation;
 import org.jboss.seam.example.wicket.action.Booking;
@@ -45,6 +46,7 @@
       body.add(new Link("confirm")
       {
          @Override
+         @RaiseEvent("bookingConfirmed")
          public void onClick()
          {
             hotelBooking.confirm();

Modified: trunk/examples/wicket/src/web/org/jboss/seam/example/wicket/Hotel.java
===================================================================
--- trunk/examples/wicket/src/web/org/jboss/seam/example/wicket/Hotel.java	2008-07-19 12:43:17 UTC (rev 8481)
+++ trunk/examples/wicket/src/web/org/jboss/seam/example/wicket/Hotel.java	2008-07-19 15:02:45 UTC (rev 8482)
@@ -4,6 +4,7 @@
 import org.apache.wicket.PageParameters;
 import org.apache.wicket.markup.html.WebPage;
 import org.apache.wicket.markup.html.link.Link;
+import org.jboss.seam.annotations.End;
 import org.jboss.seam.annotations.In;
 import org.jboss.seam.annotations.security.Restrict;
 import org.jboss.seam.example.wicket.action.HotelBooking;
@@ -12,6 +13,7 @@
 public class Hotel extends WebPage 
 {
 
+   @In
    private org.jboss.seam.example.wicket.action.Hotel hotel;
    
    @In(create=true)
@@ -33,14 +35,13 @@
 	   body.add(new Link("cancel")
       {
          @Override
+         @End
          public void onClick()
          {
-            hotelBooking.cancel();
             setResponsePage(Main.class);
          }
          
       });
-	   initHotel();
 	   body.add(new HotelViewPanel("hotel", hotel));
 	   add(body);
 	}
@@ -48,17 +49,8 @@
 	@Override
 	protected void onBeforeRender()
 	{
-	   initHotel();
 	   super.onBeforeRender();
 	}
 	
-	private void initHotel()
-	{
-	   if (hotel == null)
-      {
-         hotel = hotelBooking.selectHotel(getPageParameters().getLong("hotelId"));
-      }
-	}
 	
-	
 }

Modified: trunk/examples/wicket/src/web/org/jboss/seam/example/wicket/Main.java
===================================================================
--- trunk/examples/wicket/src/web/org/jboss/seam/example/wicket/Main.java	2008-07-19 12:43:17 UTC (rev 8481)
+++ trunk/examples/wicket/src/web/org/jboss/seam/example/wicket/Main.java	2008-07-19 15:02:45 UTC (rev 8482)
@@ -31,17 +31,18 @@
 import org.apache.wicket.markup.html.form.DropDownChoice;
 import org.apache.wicket.markup.html.form.Form;
 import org.apache.wicket.markup.html.form.TextField;
-import org.apache.wicket.markup.html.link.BookmarkablePageLink;
 import org.apache.wicket.markup.html.link.Link;
 import org.apache.wicket.markup.html.panel.ComponentFeedbackPanel;
 import org.apache.wicket.markup.repeater.Item;
 import org.apache.wicket.markup.repeater.data.DataView;
 import org.apache.wicket.model.PropertyModel;
+import org.jboss.seam.annotations.Begin;
 import org.jboss.seam.annotations.In;
 import org.jboss.seam.annotations.security.Restrict;
 import org.jboss.seam.example.wicket.action.Booking;
 import org.jboss.seam.example.wicket.action.BookingList;
 import org.jboss.seam.example.wicket.action.Hotel;
+import org.jboss.seam.example.wicket.action.HotelBooking;
 import org.jboss.seam.example.wicket.action.HotelSearching;
 import org.jboss.seam.security.Identity;
 import org.jboss.seam.wicket.SeamPropertyModel;
@@ -58,6 +59,9 @@
    
    @In(create=true)
    private BookingList bookingList;
+   
+   @In(create=true)
+   private HotelBooking hotelBooking;
 
    private DataView       hotelDataView;
    private DataView       bookedHotelDataView;
@@ -113,12 +117,24 @@
          @Override
          protected void populateItem(Item item)
          {
-            Hotel hotel = (Hotel) item.getModelObject();
+            final Hotel hotel = (Hotel) item.getModelObject();
             item.add(new Label("hotelName", hotel.getName()));
             item.add(new Label("hotelAddress", hotel.getAddress()));
             item.add(new Label("hotelCityStateCountry", hotel.getCity() + ", " + hotel.getState() + ", " + hotel.getCountry()));
             item.add(new Label("hotelZip", hotel.getZip()));
-            item.add(new BookmarkablePageLink("viewHotel", org.jboss.seam.example.wicket.Hotel.class).setParameter("hotelId", hotel.getId()));
+            //item.add(new BookmarkablePageLink("viewHotel", org.jboss.seam.example.wicket.Hotel.class).setParameter("hotelId", hotel.getId()));
+            item.add(new Link("viewHotel")
+            {
+
+               @Override
+               @Begin
+               public void onClick()
+               {
+                  hotelBooking.selectHotel(hotel);
+                  setResponsePage(org.jboss.seam.example.wicket.Hotel.class);
+               }
+            
+            });
          }
          
       };

Modified: trunk/examples/wicket/src/web/org/jboss/seam/example/wicket/Register.java
===================================================================
--- trunk/examples/wicket/src/web/org/jboss/seam/example/wicket/Register.java	2008-07-19 12:43:17 UTC (rev 8481)
+++ trunk/examples/wicket/src/web/org/jboss/seam/example/wicket/Register.java	2008-07-19 15:02:45 UTC (rev 8482)
@@ -10,7 +10,9 @@
 import org.apache.wicket.markup.html.panel.ComponentFeedbackPanel;
 import org.apache.wicket.model.IModel;
 import org.apache.wicket.model.PropertyModel;
+import org.jboss.seam.ScopeType;
 import org.jboss.seam.annotations.In;
+import org.jboss.seam.annotations.Out;
 import org.jboss.seam.example.wicket.action.User;
 import org.jboss.seam.wicket.SeamPropertyModel;
 
@@ -36,6 +38,19 @@
 	public class RegisterForm extends Form
 	{
 
+	   @Out(scope=ScopeType.EVENT, required=false)
+	   private String verify;
+	   
+	   public String getVerify()
+      {
+         return verify;
+      }
+	   
+	   public void setVerify(String verify)
+      {
+         this.verify = verify;
+      }
+	   
       public RegisterForm(String id)
       {
          super(id);
@@ -70,14 +85,7 @@
                return user;
             }
          }));
-         add(new FormInputBorder("verifyDecorate", "Verify Password", verify, new SeamPropertyModel("verify")
-         {
-            @Override
-            public Object getTarget()
-            {
-               return register;
-            }
-         }));
+         add(new FormInputBorder("verifyDecorate", "Verify Password", verify, new PropertyModel(this, "verify")));
          add(new EqualPasswordInputValidator(password, verify));
       }
       

Modified: trunk/src/wicket/org/jboss/seam/wicket/SeamWebApplication.java
===================================================================
--- trunk/src/wicket/org/jboss/seam/wicket/SeamWebApplication.java	2008-07-19 12:43:17 UTC (rev 8481)
+++ trunk/src/wicket/org/jboss/seam/wicket/SeamWebApplication.java	2008-07-19 15:02:45 UTC (rev 8482)
@@ -91,18 +91,13 @@
                @Override
                protected CharSequence encode(RequestCycle requestCycle, IBookmarkablePageRequestTarget requestTarget)
                {
-                  if (requestCycle.getRequest().getParameter("cid") != null)
+                  // TODO Do this nicely
+                  StringBuilder stringBuilder = new StringBuilder(super.encode(requestCycle, requestTarget));
+                  if (Manager.instance().isLongRunningConversation())
                   {
-                     // TODO Do this nicely
-                     StringBuilder stringBuilder = new StringBuilder(super.encode(requestCycle, requestTarget));
-                     if (Manager.instance().isReallyLongRunningConversation())
-                     {
-                        stringBuilder.append("&" + Manager.instance().getConversationIdParameter() + "=" + Conversation.instance().getId());
-                     }
-                     return stringBuilder.subSequence(0, stringBuilder.length());
-
+                     stringBuilder.append("&" + Manager.instance().getConversationIdParameter() + "=" + Conversation.instance().getId());
                   }
-                  return super.encode(requestCycle, requestTarget);
+                  return stringBuilder.subSequence(0, stringBuilder.length());
                }
 
             };

Added: trunk/src/wicket/org/jboss/seam/wicket/ioc/ConversationInterceptor.java
===================================================================
--- trunk/src/wicket/org/jboss/seam/wicket/ioc/ConversationInterceptor.java	                        (rev 0)
+++ trunk/src/wicket/org/jboss/seam/wicket/ioc/ConversationInterceptor.java	2008-07-19 15:02:45 UTC (rev 8482)
@@ -0,0 +1,283 @@
+package org.jboss.seam.wicket.ioc;
+
+import java.lang.reflect.Method;
+import java.util.Arrays;
+
+import org.jboss.seam.annotations.ApplicationException;
+import org.jboss.seam.annotations.Begin;
+import org.jboss.seam.annotations.End;
+import org.jboss.seam.annotations.FlushModeType;
+import org.jboss.seam.annotations.bpm.BeginTask;
+import org.jboss.seam.annotations.bpm.EndTask;
+import org.jboss.seam.annotations.bpm.StartTask;
+import org.jboss.seam.core.ConversationEntries;
+import org.jboss.seam.core.ConversationEntry;
+import org.jboss.seam.core.ConversationPropagation;
+import org.jboss.seam.core.Interpolator;
+import org.jboss.seam.core.Manager;
+import org.jboss.seam.navigation.ConversationIdParameter;
+import org.jboss.seam.navigation.Pages;
+import org.jboss.seam.pageflow.Pageflow;
+import org.jboss.seam.persistence.PersistenceContexts;
+
+public class ConversationInterceptor<T> implements Interceptor<T>
+{
+   
+   private boolean isConversationManagement(InvocationContext<T> invocationContext)
+   {
+      return invocationContext.getAccessibleObject().isAnnotationPresent(Begin.class) ||
+            invocationContext.getAccessibleObject().isAnnotationPresent(End.class) ||
+            invocationContext.getAccessibleObject().isAnnotationPresent(BeginTask.class) ||
+            invocationContext.getAccessibleObject().isAnnotationPresent(EndTask.class) ||
+            invocationContext.getAccessibleObject().isAnnotationPresent(StartTask.class);
+   }
+   
+   public void beforeInvoke(InvocationContext<T> invocationContext)
+   {
+      if (isConversationManagement(invocationContext))
+      {
+         if ( isMissingJoin(invocationContext) )
+         {
+            throw new IllegalStateException("begin method invoked from a long-running conversation, try using @Begin(join=true) on method: " + invocationContext.getMember().getName());
+         }
+         
+         
+         /*if ( redirectToExistingConversation(invocationContext.getMethod()) ) 
+         {
+            return null;
+         }*/
+      }
+   }
+   
+   public Object afterInvoke(InvocationContext<T> invocationContext, Object result)
+   {
+      if (isConversationManagement(invocationContext))
+      {
+         beginConversationIfNecessary(invocationContext, result);
+         endConversationIfNecessary(invocationContext, result);
+      }
+      return result;
+   }
+   
+   public Exception handleException(InvocationContext<T> invocationContext, Exception exception)
+   {
+      if ( isEndConversationRequired(exception) )
+      {
+         endConversation(false);
+      }
+      return exception;
+   }
+
+   private boolean isEndConversationRequired(Exception e)
+   {
+      Class<? extends Exception> clazz = e.getClass();
+      return clazz.isAnnotationPresent(ApplicationException.class)
+            && clazz.getAnnotation(ApplicationException.class).end();
+   }
+   
+   @SuppressWarnings("deprecation")
+   public boolean redirectToExistingConversation(Method method)
+   {
+      if ( !Manager.instance().isLongRunningConversation() )
+      {
+         String id = null;
+         ConversationPropagation propagation = ConversationPropagation.instance(); 
+         String conversation = propagation != null ? propagation.getConversationName() : null;
+         
+         if ( method.isAnnotationPresent(Begin.class) )
+         {
+            id = method.getAnnotation(Begin.class).id();
+         }
+         else if ( method.isAnnotationPresent(BeginTask.class) )
+         {
+            id = method.getAnnotation(BeginTask.class).id();
+         }
+         else if ( method.isAnnotationPresent(StartTask.class) )
+         {
+            id = method.getAnnotation(StartTask.class).id();
+         }
+         
+         if ( id!=null && !"".equals(id) )
+         {
+            id = Interpolator.instance().interpolate(id);
+            ConversationEntry ce = ConversationEntries.instance().getConversationEntry(id);
+            if (ce==null) 
+            {
+               Manager.instance().updateCurrentConversationId(id);
+            }
+            else
+            {
+               return ce.redirect();
+            }
+         }
+         else if (conversation != null && !"".equals(conversation))
+         {
+            ConversationIdParameter param = Pages.instance().getConversationIdParameter(conversation);
+            if (param != null)
+            {
+               ConversationEntry ce = ConversationEntries.instance().getConversationEntry(param.getConversationId());
+               if (ce != null)
+               {
+                  return ce.redirect();
+               }
+            }            
+         }
+      }
+      
+      return false;
+   }
+
+   private boolean isMissingJoin(InvocationContext invocationContext) {
+      return Manager.instance().isLongRunningOrNestedConversation() && ( 
+            ( 
+                  invocationContext.getAccessibleObject().isAnnotationPresent(Begin.class) && 
+                  !invocationContext.getAccessibleObject().getAnnotation(Begin.class).join() && 
+                  !invocationContext.getAccessibleObject().getAnnotation(Begin.class).nested() 
+            ) ||
+            invocationContext.getAccessibleObject().isAnnotationPresent(BeginTask.class) ||
+            invocationContext.getAccessibleObject().isAnnotationPresent(StartTask.class) 
+         );
+   }
+
+   @SuppressWarnings("deprecation")
+   private void beginConversationIfNecessary(InvocationContext invocationContext, Object result)
+   {
+      
+      boolean simpleBegin = 
+            invocationContext.getAccessibleObject().isAnnotationPresent(StartTask.class) || 
+            invocationContext.getAccessibleObject().isAnnotationPresent(BeginTask.class) ||
+            ( invocationContext.getAccessibleObject().isAnnotationPresent(Begin.class) && invocationContext.getAccessibleObject().getAnnotation(Begin.class).ifOutcome().length==0 );
+      if ( simpleBegin )
+      {
+         if ( result!=null || ( invocationContext.getMethod() != null && invocationContext.getMethod().getReturnType().equals(void.class)) || invocationContext.getConstructor() != null )
+         {
+            boolean nested = false;
+            if ( invocationContext.getAccessibleObject().isAnnotationPresent(Begin.class) )
+            {
+               nested = invocationContext.getAccessibleObject().getAnnotation(Begin.class).nested();
+            }
+            beginConversation( nested, getProcessDefinitionName(invocationContext) );
+            setFlushMode(invocationContext); //TODO: what if conversation already exists? Or a nested conversation?
+         }
+      }
+      else if ( invocationContext.getAccessibleObject().isAnnotationPresent(Begin.class) )
+      {
+         String[] outcomes = invocationContext.getAccessibleObject().getAnnotation(Begin.class).ifOutcome();
+         if ( outcomes.length==0 || Arrays.asList(outcomes).contains(result) )
+         {
+            beginConversation( 
+                  invocationContext.getAccessibleObject().getAnnotation(Begin.class).nested(), 
+                  getProcessDefinitionName(invocationContext) 
+               );
+            setFlushMode(invocationContext); //TODO: what if conversation already exists? Or a nested conversation?
+         }
+      }
+      
+   }
+   
+   private void setFlushMode(InvocationContext<T> invocationContext)
+   {
+      FlushModeType flushMode;
+      if (invocationContext.getAccessibleObject().isAnnotationPresent(Begin.class))
+      {
+         flushMode = invocationContext.getAccessibleObject().getAnnotation(Begin.class).flushMode();
+      }
+      else if (invocationContext.getAccessibleObject().isAnnotationPresent(BeginTask.class))
+      {
+         flushMode = invocationContext.getAccessibleObject().getAnnotation(BeginTask.class).flushMode();
+      }
+      else if (invocationContext.getAccessibleObject().isAnnotationPresent(StartTask.class))
+      {
+         flushMode = invocationContext.getAccessibleObject().getAnnotation(StartTask.class).flushMode();
+      }
+      else
+      {
+         return;
+      }
+      
+      PersistenceContexts.instance().changeFlushMode(flushMode);
+   }
+
+   private String getProcessDefinitionName(InvocationContext invocationContext) {
+      if ( invocationContext.getAccessibleObject().isAnnotationPresent(Begin.class) )
+      {
+         return invocationContext.getAccessibleObject().getAnnotation(Begin.class).pageflow();
+      }
+      if ( invocationContext.getAccessibleObject().isAnnotationPresent(BeginTask.class) )
+      {
+         return invocationContext.getAccessibleObject().getAnnotation(BeginTask.class).pageflow();
+      }
+      if ( invocationContext.getAccessibleObject().isAnnotationPresent(StartTask.class) )
+      {
+         return invocationContext.getAccessibleObject().getAnnotation(StartTask.class).pageflow();
+      }
+      //TODO: let them pass a pageflow name as a request parameter
+      return "";
+   }
+
+   private void beginConversation(boolean nested, String pageflowName)
+   {
+      if ( !Manager.instance().isLongRunningOrNestedConversation() )
+      {
+         Manager.instance().beginConversation( );
+         beginNavigation(pageflowName);
+      }
+      else if (nested)
+      {
+         Manager.instance().beginNestedConversation();
+         beginNavigation(pageflowName);
+      }
+   }
+   
+   private void beginNavigation(String pageflowName)
+   {
+      if ( !pageflowName.equals("") )
+      {
+         Pageflow.instance().begin(pageflowName);
+      }
+   }
+
+   @SuppressWarnings("deprecation")
+   private void endConversationIfNecessary(InvocationContext<T> invocationContext, Object result)
+   {
+      boolean isEndAnnotation = invocationContext.getAccessibleObject().isAnnotationPresent(End.class);
+      boolean isEndTaskAnnotation = invocationContext.getAccessibleObject().isAnnotationPresent(EndTask.class);
+      
+      boolean beforeRedirect = ( isEndAnnotation && invocationContext.getAccessibleObject().getAnnotation(End.class).beforeRedirect() ) ||
+            ( isEndTaskAnnotation && invocationContext.getAccessibleObject().getAnnotation(EndTask.class).beforeRedirect() );
+      
+      boolean simpleEnd = 
+            ( isEndAnnotation && invocationContext.getAccessibleObject().getAnnotation(End.class).ifOutcome().length==0 ) || 
+            ( isEndTaskAnnotation && invocationContext.getAccessibleObject().getAnnotation(EndTask.class).ifOutcome().length==0 );
+      if ( simpleEnd )
+      {
+         if ( result!=null || invocationContext.getConstructor() != null || (invocationContext.getMethod() != null && invocationContext.getMethod().getReturnType().equals(void.class)) ) //null outcome interpreted as redisplay
+         {
+            endConversation(beforeRedirect);
+         }
+      }
+      else if ( isEndAnnotation )
+      {
+         String[] outcomes = invocationContext.getAccessibleObject().getAnnotation(End.class).ifOutcome();
+         if ( Arrays.asList(outcomes).contains(result) )
+         {
+            endConversation(beforeRedirect);
+         }
+      }
+      else if ( isEndTaskAnnotation )
+      {
+         //TODO: fix minor code duplication
+         String[] outcomes = invocationContext.getAccessibleObject().getAnnotation(EndTask.class).ifOutcome();
+         if ( Arrays.asList(outcomes).contains(result) )
+         {
+            endConversation(beforeRedirect);
+         }
+      }
+   }
+
+   private void endConversation(boolean beforeRedirect)
+   {
+      Manager.instance().endConversation(beforeRedirect);
+   }
+
+}


Property changes on: trunk/src/wicket/org/jboss/seam/wicket/ioc/ConversationInterceptor.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/src/wicket/org/jboss/seam/wicket/ioc/EventInterceptor.java
===================================================================
--- trunk/src/wicket/org/jboss/seam/wicket/ioc/EventInterceptor.java	                        (rev 0)
+++ trunk/src/wicket/org/jboss/seam/wicket/ioc/EventInterceptor.java	2008-07-19 15:02:45 UTC (rev 8482)
@@ -0,0 +1,41 @@
+package org.jboss.seam.wicket.ioc;
+
+import org.jboss.seam.annotations.RaiseEvent;
+import org.jboss.seam.core.Events;
+
+public class EventInterceptor<T> implements Interceptor<T>
+{
+
+   public Object afterInvoke(InvocationContext<T> invocationContext, Object result)
+   {
+      if ( result!=null || invocationContext.getConstructor() != null || (invocationContext.getMethod() != null && invocationContext.getMethod().getReturnType().equals(void.class)) )
+      {
+         if ( invocationContext.getAccessibleObject().isAnnotationPresent(RaiseEvent.class) )
+         {
+            String[] types = invocationContext.getAccessibleObject().getAnnotation(RaiseEvent.class).value();
+            if ( types.length==0 )
+            {
+               Events.instance().raiseEvent( invocationContext.getMember().getName() );
+            }
+            else
+            {
+               for (String type: types )
+               {
+                  Events.instance().raiseEvent(type);
+               }
+            }
+         }
+      }
+      return result;
+   }
+
+   public void beforeInvoke(InvocationContext<T> invocationContext)
+   {
+      
+   }
+
+   public Exception handleException(InvocationContext<T> invocationContext, Exception exception)
+   {
+      return exception;
+   }
+}
\ No newline at end of file


Property changes on: trunk/src/wicket/org/jboss/seam/wicket/ioc/EventInterceptor.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: trunk/src/wicket/org/jboss/seam/wicket/ioc/InvocationContext.java
===================================================================
--- trunk/src/wicket/org/jboss/seam/wicket/ioc/InvocationContext.java	2008-07-19 12:43:17 UTC (rev 8481)
+++ trunk/src/wicket/org/jboss/seam/wicket/ioc/InvocationContext.java	2008-07-19 15:02:45 UTC (rev 8482)
@@ -1,6 +1,8 @@
 package org.jboss.seam.wicket.ioc;
 
+import java.lang.reflect.AccessibleObject;
 import java.lang.reflect.Constructor;
+import java.lang.reflect.Member;
 import java.lang.reflect.Method;
 
 import org.jboss.seam.wicket.WicketComponent;
@@ -32,14 +34,49 @@
    {
       return constructor;
    }
+   
    public Method getMethod()
    {
       return method;
    }
+   
+   public Member getMember()
+   {
+      if (method != null)
+      {
+         return method;
+      }
+      else if (constructor != null)
+      {
+         return constructor;
+      }
+      else
+      {
+         throw new IllegalStateException("No member");
+      }
+   }
+   
+   public AccessibleObject getAccessibleObject()
+   {
+      if (method != null)
+      {
+         return method;
+      }
+      else if (constructor != null)
+      {
+         return constructor;
+      }
+      else
+      {
+         throw new IllegalStateException("No member");
+      }
+   }
+   
    public T getBean()
    {
       return bean;
    }
+   
    public WicketComponent<T> getComponent()
    {
       return component;

Modified: trunk/src/wicket/org/jboss/seam/wicket/ioc/JavassistInstrumentor.java
===================================================================
--- trunk/src/wicket/org/jboss/seam/wicket/ioc/JavassistInstrumentor.java	2008-07-19 12:43:17 UTC (rev 8481)
+++ trunk/src/wicket/org/jboss/seam/wicket/ioc/JavassistInstrumentor.java	2008-07-19 15:02:45 UTC (rev 8482)
@@ -152,7 +152,7 @@
                   
                   CtMethod newMethod = CtNewMethod.copy(method, newName, implementation, null);
                   implementation.addMethod(newMethod);
-                  method.setBody(createBody(implementation, newMethod));
+                  method.setBody(createBody(implementation, method, newMethod));
                   log.trace("instrumented method " + method.getName());
                }
             }
@@ -180,10 +180,10 @@
       return classLoader;
    }
    
-   private static String createBody(CtClass clazz, CtMethod method) throws NotFoundException
+   private static String createBody(CtClass clazz, CtMethod method, CtMethod newMethod) throws NotFoundException
    {
-      String src = "{" + createMethodObject(method) + "handler.beforeInvoke(this, method);" + createMethodDelegation(method) + "return ($r) handler.afterInvoke(this, method, ($w) result);}";
-      log.trace("Creating method " + clazz.getName() + "." + method.getName() + "(" + method.getSignature() + ")" + src);
+      String src = "{" + createMethodObject(method) + "handler.beforeInvoke(this, method);" + createMethodDelegation(newMethod) + "return ($r) handler.afterInvoke(this, method, ($w) result);}";
+      log.trace("Creating method " + clazz.getName() + "." + newMethod.getName() + "(" + newMethod.getSignature() + ")" + src);
       return src;
    }
    

Modified: trunk/src/wicket/org/jboss/seam/wicket/ioc/WicketHandler.java
===================================================================
--- trunk/src/wicket/org/jboss/seam/wicket/ioc/WicketHandler.java	2008-07-19 12:43:17 UTC (rev 8481)
+++ trunk/src/wicket/org/jboss/seam/wicket/ioc/WicketHandler.java	2008-07-19 15:02:45 UTC (rev 8482)
@@ -26,7 +26,6 @@
    private List<Interceptor> interceptors;
    private Class<?> type;
    private transient WicketComponent component;
-   private boolean callInProgress;
    private int reentrant = 0;
    
    private WicketComponent getComponent()
@@ -44,6 +43,8 @@
       {
          interceptors = new ArrayList<Interceptor>();
          interceptors.add(new BijectionInterceptor());
+         interceptors.add(new ConversationInterceptor());
+         interceptors.add(new EventInterceptor());
       }
       return interceptors;
    }
@@ -93,6 +94,7 @@
    
    private Exception doHandleException(InvocationContext invocationContext, Exception exception)
    {
+      reentrant--;
       if (reentrant == 0)
       {
          for (Interceptor interceptor : getInterceptors())




More information about the seam-commits mailing list