[seam-commits] Seam SVN: r8990 - in trunk/src: main/org/jboss/seam/core and 1 other directories.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Sun Sep 14 12:40:41 EDT 2008


Author: jacob.orshalick
Date: 2008-09-14 12:40:40 -0400 (Sun, 14 Sep 2008)
New Revision: 8990

Modified:
   trunk/src/main/org/jboss/seam/annotations/End.java
   trunk/src/main/org/jboss/seam/core/ConversationInterceptor.java
   trunk/src/test/unit/org/jboss/seam/test/unit/Foo.java
   trunk/src/test/unit/org/jboss/seam/test/unit/InterceptorTest.java
Log:
JBSEAM-1943 annotational support for ending root conversation

Modified: trunk/src/main/org/jboss/seam/annotations/End.java
===================================================================
--- trunk/src/main/org/jboss/seam/annotations/End.java	2008-09-14 13:13:08 UTC (rev 8989)
+++ trunk/src/main/org/jboss/seam/annotations/End.java	2008-09-14 16:40:40 UTC (rev 8990)
@@ -40,4 +40,15 @@
     * @return false by default
     */
    boolean beforeRedirect() default false;
+   
+   /**
+    * If the conversation is nested, should the root
+    * of the conversation be destroyed?  (The default
+    * behavior is to simply pop the conversation
+    * stack.)
+    * 
+    * @return false by default
+    */
+   boolean root() default false;
+
 }

Modified: trunk/src/main/org/jboss/seam/core/ConversationInterceptor.java
===================================================================
--- trunk/src/main/org/jboss/seam/core/ConversationInterceptor.java	2008-09-14 13:13:08 UTC (rev 8989)
+++ trunk/src/main/org/jboss/seam/core/ConversationInterceptor.java	2008-09-14 16:40:40 UTC (rev 8990)
@@ -69,7 +69,7 @@
       {
          if ( isEndConversationRequired(e) )
          {
-            endConversation(false);
+            endConversation(false, false);
          }
          throw e;
       }
@@ -253,6 +253,8 @@
       boolean beforeRedirect = ( isEndAnnotation && method.getAnnotation(End.class).beforeRedirect() ) ||
             ( isEndTaskAnnotation && method.getAnnotation(EndTask.class).beforeRedirect() );
       
+      boolean endRoot = ( isEndAnnotation && method.getAnnotation(End.class).root() );
+
       boolean simpleEnd = 
             ( isEndAnnotation && method.getAnnotation(End.class).ifOutcome().length==0 ) || 
             ( isEndTaskAnnotation && method.getAnnotation(EndTask.class).ifOutcome().length==0 );
@@ -260,7 +262,7 @@
       {
          if ( result!=null || method.getReturnType().equals(void.class) ) //null outcome interpreted as redisplay
          {
-            endConversation(beforeRedirect);
+            endConversation(beforeRedirect, endRoot);
          }
       }
       else if ( isEndAnnotation )
@@ -268,7 +270,7 @@
          String[] outcomes = method.getAnnotation(End.class).ifOutcome();
          if ( Arrays.asList(outcomes).contains(result) )
          {
-            endConversation(beforeRedirect);
+            endConversation(beforeRedirect, endRoot);
          }
       }
       else if ( isEndTaskAnnotation )
@@ -277,14 +279,24 @@
          String[] outcomes = method.getAnnotation(EndTask.class).ifOutcome();
          if ( Arrays.asList(outcomes).contains(result) )
          {
-            endConversation(beforeRedirect);
+            endConversation(beforeRedirect, endRoot);
          }
       }
    }
 
-   private void endConversation(boolean beforeRedirect)
+   private void endConversation(boolean beforeRedirect, boolean endRoot)
    {
-      Manager.instance().endConversation(beforeRedirect);
+      Manager manager = Manager.instance();
+      
+      if(endRoot)
+      {
+         if(manager.isNestedConversation())
+         {
+            manager.switchConversation(manager.getRootConversationId());
+         }
+      }
+
+      manager.endConversation(beforeRedirect);
    }
    
    public boolean isInterceptorEnabled()

Modified: trunk/src/test/unit/org/jboss/seam/test/unit/Foo.java
===================================================================
--- trunk/src/test/unit/org/jboss/seam/test/unit/Foo.java	2008-09-14 13:13:08 UTC (rev 8989)
+++ trunk/src/test/unit/org/jboss/seam/test/unit/Foo.java	2008-09-14 16:40:40 UTC (rev 8990)
@@ -73,6 +73,17 @@
       return null;
    }
    
+   @Begin(nested=true)
+   public String beginNested()
+   {
+      return "begunNested";
+   }
+   @End(root=true)
+   public String endRoot()
+   {
+      return "endedRoot";
+   }
+   
    @Begin
    public void beginVoid() { }
    @End

Modified: trunk/src/test/unit/org/jboss/seam/test/unit/InterceptorTest.java
===================================================================
--- trunk/src/test/unit/org/jboss/seam/test/unit/InterceptorTest.java	2008-09-14 13:13:08 UTC (rev 8989)
+++ trunk/src/test/unit/org/jboss/seam/test/unit/InterceptorTest.java	2008-09-14 16:40:40 UTC (rev 8990)
@@ -741,8 +741,96 @@
       
       assert !Manager.instance().isLongRunningConversation();
       assert "success".equals(result);
+      
+      ///////////////////////////////////////////////
+      // Test @End(root=true) for nested conversation
+      ///////////////////////////////////////////////
+      
+      result = (String) ci.aroundInvoke( new MockInvocationContext() {
+         @Override
+         public Method getMethod()
+         {
+            return InterceptorTest.getMethod("begin");
+         }
+         @Override
+         public Object proceed() throws Exception
+         {
+            return "begun";
+         }
+      });
+      
+      assert Manager.instance().isLongRunningConversation();
+      assert "begun".equals(result);
+      
+      result = (String) ci.aroundInvoke( new MockInvocationContext() {
+         @Override
+         public Method getMethod()
+         {
+            return InterceptorTest.getMethod("beginNested");
+         }
+         @Override
+         public Object proceed() throws Exception
+         {
+            return "begunNested";
+         }
+      });
+      
+      assert Manager.instance().isNestedConversation();
+      assert "begunNested".equals(result);
 
-      ServletLifecycle.endApplication();
+      result = (String) ci.aroundInvoke( new MockInvocationContext() {
+         @Override
+         public Method getMethod()
+         {
+            return InterceptorTest.getMethod("endRoot");
+         }
+         @Override
+         public Object proceed() throws Exception
+         {
+            return "endedRoot";
+         }
+      });
+
+      assert !Manager.instance().isNestedConversation();
+      assert !Manager.instance().isLongRunningConversation();
+      assert "endedRoot".equals(result);
+
+      /////////////////////////////////////////////////////
+      // Test @End(root=true) for a non-nested conversation
+      /////////////////////////////////////////////////////
+      
+      result = (String) ci.aroundInvoke( new MockInvocationContext() {
+         @Override
+         public Method getMethod()
+         {
+            return InterceptorTest.getMethod("begin");
+         }
+         @Override
+         public Object proceed() throws Exception
+         {
+            return "begun";
+         }
+      });
+      
+      assert Manager.instance().isLongRunningConversation();
+      assert "begun".equals(result);
+      
+      result = (String) ci.aroundInvoke( new MockInvocationContext() {
+         @Override
+         public Method getMethod()
+         {
+            return InterceptorTest.getMethod("endRoot");
+         }
+         @Override
+         public Object proceed() throws Exception
+         {
+            return "endedRoot";
+         }
+      });
+
+      assert !Manager.instance().isNestedConversation();
+      assert !Manager.instance().isLongRunningConversation();
+      assert "endedRoot".equals(result);
    }
    
    @Test




More information about the seam-commits mailing list