[seam-commits] Seam SVN: r12391 - in modules/faces/trunk: impl and 4 other directories.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Mon Apr 5 15:22:20 EDT 2010


Author: lincolnthree
Date: 2010-04-05 15:22:20 -0400 (Mon, 05 Apr 2010)
New Revision: 12391

Modified:
   modules/faces/trunk/api/src/main/java/org/jboss/seam/faces/context/conversation/Begin.java
   modules/faces/trunk/impl/pom.xml
   modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/context/conversation/ConversationBoundaryInterceptor.java
   modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/util/Annotations.java
   modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/context/conversation/ConversationBoundaryInterceptorTest.java
   modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/context/conversation/ConversationalBean.java
   modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/util/AnnotationsTest.java
Log:
@Begin supports timeout()

Modified: modules/faces/trunk/api/src/main/java/org/jboss/seam/faces/context/conversation/Begin.java
===================================================================
--- modules/faces/trunk/api/src/main/java/org/jboss/seam/faces/context/conversation/Begin.java	2010-04-05 19:01:03 UTC (rev 12390)
+++ modules/faces/trunk/api/src/main/java/org/jboss/seam/faces/context/conversation/Begin.java	2010-04-05 19:22:20 UTC (rev 12391)
@@ -41,7 +41,6 @@
     * Sets the {@link Conversation} timeout period, in milliseconds (E.g.: 5000
     * = 5 seconds.)
     * <p>
-    * TODO implement timeout support on @Begin
     */
    @Nonbinding
    long timeout() default -1;

Modified: modules/faces/trunk/impl/pom.xml
===================================================================
--- modules/faces/trunk/impl/pom.xml	2010-04-05 19:01:03 UTC (rev 12390)
+++ modules/faces/trunk/impl/pom.xml	2010-04-05 19:22:20 UTC (rev 12391)
@@ -36,6 +36,7 @@
 			<artifactId>seam-faces-api</artifactId>
 			<groupId>org.jboss.seam.faces</groupId>
 			<version>${project.version}</version>
+			<scope>compile</scope>
 		</dependency>
 	</dependencies>
 

Modified: modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/context/conversation/ConversationBoundaryInterceptor.java
===================================================================
--- modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/context/conversation/ConversationBoundaryInterceptor.java	2010-04-05 19:01:03 UTC (rev 12390)
+++ modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/context/conversation/ConversationBoundaryInterceptor.java	2010-04-05 19:22:20 UTC (rev 12391)
@@ -42,14 +42,14 @@
 
       try
       {
-         if (Annotations.hasAnnotation(ctx.getMethod(), Begin.class))
+         if (Annotations.has(ctx.getMethod(), Begin.class))
          {
             beginConversation(ctx);
          }
 
          result = ctx.proceed();
 
-         if (Annotations.hasAnnotation(ctx.getMethod(), End.class))
+         if (Annotations.has(ctx.getMethod(), End.class))
          {
             endConversation(ctx);
          }
@@ -66,7 +66,7 @@
 
    private void handleExceptionBegin(final InvocationContext ctx, final Exception e)
    {
-      if (Annotations.hasAnnotation(ctx.getMethod(), Begin.class))
+      if (Annotations.has(ctx.getMethod(), Begin.class))
       {
          List<? extends Class<? extends Exception>> typesPermittedByBegin = getPermittedExceptionTypesBegin(ctx.getMethod());
          for (Class<? extends Exception> type : typesPermittedByBegin)
@@ -83,7 +83,7 @@
 
    private void handleExceptionEnd(final InvocationContext ctx, final Exception e)
    {
-      if (Annotations.hasAnnotation(ctx.getMethod(), End.class))
+      if (Annotations.has(ctx.getMethod(), End.class))
       {
          List<? extends Class<? extends Exception>> typesPermittedByEnd = getPermittedExceptionTypesEnd(ctx.getMethod());
          boolean permitted = false;
@@ -104,7 +104,7 @@
 
    private void beginConversation(final InvocationContext ctx) throws Exception
    {
-      String cid = getConversationId(ctx.getMethod());
+      String cid = Annotations.get(ctx.getMethod(), Begin.class).id();
       if ((cid != null) && !"".equals(cid))
       {
          conversation.begin(cid);
@@ -113,6 +113,13 @@
       {
          conversation.begin();
       }
+
+      long timeout = Annotations.get(ctx.getMethod(), Begin.class).timeout();
+      if (timeout != -1)
+      {
+         conversation.setTimeout(timeout);
+      }
+
       log.debug("Began conversation: (#0) before method: (#1.#2(...))", new Object[] { conversation.getId(), ctx.getMethod().getDeclaringClass().getName(), ctx.getMethod().getName() });
    }
 
@@ -122,18 +129,13 @@
       conversation.end();
    }
 
-   private String getConversationId(final Method m)
-   {
-      return Annotations.getAnnotation(m, Begin.class).id();
-   }
-
    private List<? extends Class<? extends Exception>> getPermittedExceptionTypesBegin(final Method m)
    {
-      return Arrays.asList(Annotations.getAnnotation(m, Begin.class).permit());
+      return Arrays.asList(Annotations.get(m, Begin.class).permit());
    }
 
    private List<? extends Class<? extends Exception>> getPermittedExceptionTypesEnd(final Method m)
    {
-      return Arrays.asList(Annotations.getAnnotation(m, End.class).permit());
+      return Arrays.asList(Annotations.get(m, End.class).permit());
    }
 }

Modified: modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/util/Annotations.java
===================================================================
--- modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/util/Annotations.java	2010-04-05 19:01:03 UTC (rev 12390)
+++ modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/util/Annotations.java	2010-04-05 19:22:20 UTC (rev 12391)
@@ -27,7 +27,7 @@
     *         the declaring class of the method. Returns false if the annotation
     *         is not present.
     */
-   public static boolean hasAnnotation(final Method m, final Class<? extends Annotation> type)
+   public static boolean has(final Method m, final Class<? extends Annotation> type)
    {
       boolean result = false;
       if (m.isAnnotationPresent(type))
@@ -47,7 +47,7 @@
 
       if (result == false)
       {
-         result = hasAnnotation(m.getDeclaringClass(), type);
+         result = has(m.getDeclaringClass(), type);
       }
       return result;
    }
@@ -62,7 +62,7 @@
     * @return True if annotation is present either on class, false if the
     *         annotation is not present.
     */
-   public static boolean hasAnnotation(final Class<?> c, final Class<? extends Annotation> type)
+   public static boolean has(final Class<?> c, final Class<? extends Annotation> type)
    {
       boolean result = false;
       if (c.isAnnotationPresent(type))
@@ -92,7 +92,7 @@
     * @return The annotation instance found on this method or enclosing class,
     *         or null if no matching annotation was found.
     */
-   public static <A extends Annotation> A getAnnotation(final Method m, final Class<A> type)
+   public static <A extends Annotation> A get(final Method m, final Class<A> type)
    {
       A result = m.getAnnotation(type);
       if (result == null)
@@ -107,7 +107,7 @@
       }
       if (result == null)
       {
-         result = getAnnotation(m.getDeclaringClass(), type);
+         result = get(m.getDeclaringClass(), type);
       }
       return result;
    }
@@ -122,7 +122,7 @@
     * @return The annotation instance found on this class, or null if no
     *         matching annotation was found.
     */
-   public static <A extends Annotation> A getAnnotation(final Class<?> c, final Class<A> type)
+   public static <A extends Annotation> A get(final Class<?> c, final Class<A> type)
    {
       A result = c.getAnnotation(type);
       if (result == null)

Modified: modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/context/conversation/ConversationBoundaryInterceptorTest.java
===================================================================
--- modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/context/conversation/ConversationBoundaryInterceptorTest.java	2010-04-05 19:01:03 UTC (rev 12390)
+++ modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/context/conversation/ConversationBoundaryInterceptorTest.java	2010-04-05 19:22:20 UTC (rev 12391)
@@ -3,6 +3,7 @@
  */
 package org.jboss.seam.faces.context.conversation;
 
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
@@ -51,6 +52,19 @@
    }
 
    @Test
+   public void testConversationStartedWithTimeout()
+   {
+      assertTrue(conversation.isTransient());
+      assertFalse(interceptedBean.isConversationLongRunningInsideMethodCall());
+
+      interceptedBean.beginConversation();
+
+      assertEquals(1000, conversation.getTimeout());
+      assertFalse(conversation.isTransient());
+      assertTrue(interceptedBean.isConversationLongRunningInsideMethodCall());
+   }
+
+   @Test
    public void testConversationBeginsAndEnds()
    {
       assertTrue(conversation.isTransient());

Modified: modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/context/conversation/ConversationalBean.java
===================================================================
--- modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/context/conversation/ConversationalBean.java	2010-04-05 19:01:03 UTC (rev 12390)
+++ modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/context/conversation/ConversationalBean.java	2010-04-05 19:22:20 UTC (rev 12391)
@@ -32,7 +32,7 @@
    {
    }
 
-   @Begin
+   @Begin(timeout = 1000)
    public void beginConversation()
    {
       if (!conversation.isTransient())

Modified: modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/util/AnnotationsTest.java
===================================================================
--- modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/util/AnnotationsTest.java	2010-04-05 19:01:03 UTC (rev 12390)
+++ modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/util/AnnotationsTest.java	2010-04-05 19:22:20 UTC (rev 12391)
@@ -21,8 +21,8 @@
    {
       Method begin = AnnotationTestObject.class.getMethod("begin", new Class[] {});
 
-      assertTrue(Annotations.hasAnnotation(begin, Begin.class));
-      assertFalse(Annotations.hasAnnotation(begin, End.class));
+      assertTrue(Annotations.has(begin, Begin.class));
+      assertFalse(Annotations.has(begin, End.class));
    }
 
    @Test
@@ -30,7 +30,7 @@
    {
       Method end = AnnotationTestObject.class.getMethod("end", new Class[] {});
 
-      assertTrue(Annotations.hasAnnotation(end, End.class));
+      assertTrue(Annotations.has(end, End.class));
    }
 
    @Test
@@ -39,14 +39,14 @@
       Method begin = AnnotationTestObject.class.getMethod("begin", new Class[] {});
       Method end = AnnotationTestObject.class.getMethod("end", new Class[] {});
 
-      assertTrue(Annotations.hasAnnotation(begin, Begin.class));
-      assertTrue(Annotations.hasAnnotation(end, Begin.class));
+      assertTrue(Annotations.has(begin, Begin.class));
+      assertTrue(Annotations.has(end, Begin.class));
    }
 
    public void testGetAnnotationOnMethodDirectly() throws Exception
    {
       Method end = AnnotationTestObject.class.getMethod("end", new Class[] {});
-      End anno = Annotations.getAnnotation(end, End.class);
+      End anno = Annotations.get(end, End.class);
 
       assertTrue(anno instanceof End);
    }
@@ -54,7 +54,7 @@
    public void testGetAnnotationOnMethodIndirectlyFromClass() throws Exception
    {
       Method end = AnnotationTestObject.class.getMethod("begin", new Class[] {});
-      Begin anno = Annotations.getAnnotation(end, Begin.class);
+      Begin anno = Annotations.get(end, Begin.class);
 
       assertTrue(anno instanceof Begin);
    }



More information about the seam-commits mailing list