[seam-commits] Seam SVN: r12263 - in modules/faces/trunk/src: main/java/org/jboss/seam/faces/context and 6 other directories.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Wed Mar 24 17:49:03 EDT 2010
Author: lincolnthree
Date: 2010-03-24 17:49:03 -0400 (Wed, 24 Mar 2010)
New Revision: 12263
Added:
modules/faces/trunk/src/main/java/org/jboss/seam/faces/context/conversation/
modules/faces/trunk/src/main/java/org/jboss/seam/faces/context/conversation/Begin.java
modules/faces/trunk/src/main/java/org/jboss/seam/faces/context/conversation/BeginConversationInterceptor.java
modules/faces/trunk/src/main/java/org/jboss/seam/faces/context/conversation/End.java
modules/faces/trunk/src/main/java/org/jboss/seam/faces/context/conversation/RetainsConversation.java
modules/faces/trunk/src/main/java/org/jboss/seam/faces/persistence/
modules/faces/trunk/src/main/java/org/jboss/seam/faces/persistence/TransactionManager.java
modules/faces/trunk/src/test/java/org/jboss/seam/faces/MockConversation.java
modules/faces/trunk/src/test/java/org/jboss/seam/faces/context/
modules/faces/trunk/src/test/java/org/jboss/seam/faces/context/conversation/
modules/faces/trunk/src/test/java/org/jboss/seam/faces/context/conversation/BeginConversationBean.java
modules/faces/trunk/src/test/java/org/jboss/seam/faces/context/conversation/BeginConversationInterceptorTest-beans.xml
modules/faces/trunk/src/test/java/org/jboss/seam/faces/context/conversation/BeginConversationInterceptorTest.java
Modified:
modules/faces/trunk/src/main/resources/META-INF/beans.xml
Log:
Started conversational support.
Added: modules/faces/trunk/src/main/java/org/jboss/seam/faces/context/conversation/Begin.java
===================================================================
--- modules/faces/trunk/src/main/java/org/jboss/seam/faces/context/conversation/Begin.java (rev 0)
+++ modules/faces/trunk/src/main/java/org/jboss/seam/faces/context/conversation/Begin.java 2010-03-24 21:49:03 UTC (rev 12263)
@@ -0,0 +1,34 @@
+package org.jboss.seam.faces.context.conversation;
+
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.enterprise.context.Conversation;
+import javax.interceptor.InterceptorBinding;
+
+/**
+ * Marks the beginning of a persistent {@link Conversation}.
+ *
+ *<p>
+ * <b>Note:</b> If this method throws an exception, the conversation will be
+ * discarded, unless the exception is annotated with @
+ * {@link RetainsConversation}
+ *
+ * @author <a href="mailto:lincolnbaxter at gmail.com">Lincoln Baxter, III</a>
+ */
+ at InterceptorBinding
+ at Target( { METHOD, TYPE })
+ at Retention(RUNTIME)
+public @interface Begin
+{
+ /**
+ * The new conversation ID. Seam will Generate a conversation ID if left
+ * blank. If a conversation with the ID already exists, TODO what should we
+ * do?
+ */
+ String id() default "";
+}
\ No newline at end of file
Added: modules/faces/trunk/src/main/java/org/jboss/seam/faces/context/conversation/BeginConversationInterceptor.java
===================================================================
--- modules/faces/trunk/src/main/java/org/jboss/seam/faces/context/conversation/BeginConversationInterceptor.java (rev 0)
+++ modules/faces/trunk/src/main/java/org/jboss/seam/faces/context/conversation/BeginConversationInterceptor.java 2010-03-24 21:49:03 UTC (rev 12263)
@@ -0,0 +1,84 @@
+/**
+ *
+ */
+package org.jboss.seam.faces.context.conversation;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+
+import javax.enterprise.context.Conversation;
+import javax.inject.Inject;
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.Interceptor;
+import javax.interceptor.InvocationContext;
+
+import org.slf4j.Logger;
+
+/**
+ * Intercepts methods annotated as Conversational entry points.
+ *
+ * @author <a href="mailto:lincolnbaxter at gmail.com">Lincoln Baxter, III</a>
+ *
+ */
+ at Begin
+ at Interceptor
+public class BeginConversationInterceptor
+{
+ @Inject
+ Logger log;
+
+ @Inject
+ Conversation conversation;
+
+ @AroundInvoke
+ public Object before(final InvocationContext ctx) throws Exception
+ {
+ String cid = getConversationId(ctx.getMethod());
+ if (cid != null)
+ {
+ conversation.begin(cid);
+ }
+ else
+ {
+ conversation.begin();
+ }
+
+ log.debug("Began conversation: (#0) on method: (#1.#2(...))", new Object[] { conversation.getId(), ctx.getMethod().getDeclaringClass().getName(), ctx.getMethod().getName() });
+
+ try
+ {
+ Object result = ctx.proceed();
+ return result;
+ }
+ catch (Exception e)
+ {
+ conversation.end();
+ throw e;
+ }
+
+ }
+
+ private String getConversationId(final Method m)
+ {
+ String result = null;
+ for (Annotation a : m.getAnnotations())
+ {
+ if (a.annotationType().isAnnotationPresent(Begin.class))
+ {
+ result = a.annotationType().getAnnotation(Begin.class).id();
+ }
+ }
+
+ if (result == null)
+ {
+ for (Annotation a : m.getDeclaringClass().getAnnotations())
+ {
+ if (a.annotationType().isAnnotationPresent(Begin.class))
+ {
+ result = a.annotationType().getAnnotation(Begin.class).id();
+ }
+ }
+ }
+ return result;
+ }
+}
Added: modules/faces/trunk/src/main/java/org/jboss/seam/faces/context/conversation/End.java
===================================================================
--- modules/faces/trunk/src/main/java/org/jboss/seam/faces/context/conversation/End.java (rev 0)
+++ modules/faces/trunk/src/main/java/org/jboss/seam/faces/context/conversation/End.java 2010-03-24 21:49:03 UTC (rev 12263)
@@ -0,0 +1,34 @@
+package org.jboss.seam.faces.context.conversation;
+
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.enterprise.context.Conversation;
+import javax.interceptor.InterceptorBinding;
+
+/**
+ * Marks the beginning of a persistent {@link Conversation}.
+ *
+ *<p>
+ * <b>Note:</b> If this method throws an exception, the conversation will be
+ * discarded, unless the exception is annotated with @
+ * {@link RetainsConversation}
+ *
+ * @author <a href="mailto:lincolnbaxter at gmail.com">Lincoln Baxter, III</a>
+ */
+ at InterceptorBinding
+ at Target( { METHOD, TYPE })
+ at Retention(RUNTIME)
+public @interface End
+{
+ /**
+ * The new conversation ID. Seam will Generate a conversation ID if left
+ * blank. If a conversation with the ID already exists, TODO what should we
+ * do?
+ */
+ String id() default "";
+}
\ No newline at end of file
Added: modules/faces/trunk/src/main/java/org/jboss/seam/faces/context/conversation/RetainsConversation.java
===================================================================
--- modules/faces/trunk/src/main/java/org/jboss/seam/faces/context/conversation/RetainsConversation.java (rev 0)
+++ modules/faces/trunk/src/main/java/org/jboss/seam/faces/context/conversation/RetainsConversation.java 2010-03-24 21:49:03 UTC (rev 12263)
@@ -0,0 +1,35 @@
+package org.jboss.seam.faces.context.conversation;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.enterprise.context.Conversation;
+import javax.inject.Qualifier;
+
+/**
+ * Marks the beginning of a persistent {@link Conversation}.
+ *
+ *<p>
+ * <b>Note:</b> If this method throws an exception, the conversation will be
+ * discarded, unless the exception is annotated with {@link RetainsConversation}
+ *
+ * @author <a href="mailto:lincolnbaxter at gmail.com">Lincoln Baxter, III</a>
+ */
+ at Qualifier
+ at Target( { FIELD, PARAMETER })
+ at Retention(RUNTIME)
+ at Documented
+public @interface RetainsConversation
+{
+ /**
+ * The new conversation ID. Seam will Generate a conversation ID if left
+ * blank. If a conversation with the ID already exists, TODO what should we
+ * do?
+ */
+ String id() default "";
+}
\ No newline at end of file
Added: modules/faces/trunk/src/main/java/org/jboss/seam/faces/persistence/TransactionManager.java
===================================================================
--- modules/faces/trunk/src/main/java/org/jboss/seam/faces/persistence/TransactionManager.java (rev 0)
+++ modules/faces/trunk/src/main/java/org/jboss/seam/faces/persistence/TransactionManager.java 2010-03-24 21:49:03 UTC (rev 12263)
@@ -0,0 +1,28 @@
+/**
+ *
+ */
+package org.jboss.seam.faces.persistence;
+
+import javax.enterprise.event.Observes;
+import javax.faces.event.PhaseEvent;
+
+import org.jboss.seam.faces.event.qualifier.Before;
+import org.jboss.seam.faces.event.qualifier.RenderResponse;
+import org.jboss.seam.faces.event.qualifier.RestoreView;
+
+/**
+ * @author <a href="mailto:lincolnbaxter at gmail.com">Lincoln Baxter, III</a>
+ *
+ */
+public class TransactionManager
+{
+
+ public void beginApplicationTransaction(@Observes @Before @RestoreView final PhaseEvent event)
+ {
+ }
+
+ public void endApplicationTransaction(@Observes @Before @RenderResponse final PhaseEvent event)
+ {
+ }
+
+}
Modified: modules/faces/trunk/src/main/resources/META-INF/beans.xml
===================================================================
--- modules/faces/trunk/src/main/resources/META-INF/beans.xml 2010-03-24 13:59:05 UTC (rev 12262)
+++ modules/faces/trunk/src/main/resources/META-INF/beans.xml 2010-03-24 21:49:03 UTC (rev 12263)
@@ -0,0 +1,10 @@
+<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://java.sun.com/xml/ns/javaee
+ http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
+
+ <interceptors>
+ <class>org.jboss.seam.faces.context.conversation.BeginConversationInterceptor</class>
+ </interceptors>
+
+</beans>
\ No newline at end of file
Added: modules/faces/trunk/src/test/java/org/jboss/seam/faces/MockConversation.java
===================================================================
--- modules/faces/trunk/src/test/java/org/jboss/seam/faces/MockConversation.java (rev 0)
+++ modules/faces/trunk/src/test/java/org/jboss/seam/faces/MockConversation.java 2010-03-24 21:49:03 UTC (rev 12263)
@@ -0,0 +1,60 @@
+/**
+ *
+ */
+package org.jboss.seam.faces;
+
+import javax.enterprise.context.Conversation;
+import javax.inject.Singleton;
+
+/**
+ * Provide a mocked conversation object for use in Unit tests. This entire class
+ * is a no-op; it does <i>nothing</i>.
+ *
+ * @author <a href="mailto:lincolnbaxter at gmail.com">Lincoln Baxter, III</a>
+ *
+ */
+ at Singleton
+public class MockConversation implements Conversation
+{
+ private long timeout;
+ private String id;
+ private boolean persistent;
+
+ public void begin()
+ {
+ this.id = "generated";
+ persistent = true;
+ }
+
+ public void begin(final String id)
+ {
+ this.id = id;
+ persistent = true;
+ }
+
+ public void end()
+ {
+ persistent = false;
+ }
+
+ public String getId()
+ {
+ return id;
+ }
+
+ public long getTimeout()
+ {
+ return timeout;
+ }
+
+ public boolean isTransient()
+ {
+ return this.persistent == false;
+ }
+
+ public void setTimeout(final long milliseconds)
+ {
+ this.timeout = milliseconds;
+ }
+
+}
Added: modules/faces/trunk/src/test/java/org/jboss/seam/faces/context/conversation/BeginConversationBean.java
===================================================================
--- modules/faces/trunk/src/test/java/org/jboss/seam/faces/context/conversation/BeginConversationBean.java (rev 0)
+++ modules/faces/trunk/src/test/java/org/jboss/seam/faces/context/conversation/BeginConversationBean.java 2010-03-24 21:49:03 UTC (rev 12263)
@@ -0,0 +1,30 @@
+/**
+ *
+ */
+package org.jboss.seam.faces.context.conversation;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.context.Conversation;
+import javax.inject.Inject;
+
+/**
+ * @author <a href="mailto:lincolnbaxter at gmail.com">Lincoln Baxter, III</a>
+ *
+ */
+ at ApplicationScoped
+public class BeginConversationBean
+{
+ @Inject
+ Conversation conversation;
+
+ public boolean conversationStarted = false;
+
+ @Begin
+ public void beginConversation()
+ {
+ if (conversation.isTransient() == false)
+ {
+ conversationStarted = true;
+ }
+ }
+}
Added: modules/faces/trunk/src/test/java/org/jboss/seam/faces/context/conversation/BeginConversationInterceptorTest-beans.xml
===================================================================
--- modules/faces/trunk/src/test/java/org/jboss/seam/faces/context/conversation/BeginConversationInterceptorTest-beans.xml (rev 0)
+++ modules/faces/trunk/src/test/java/org/jboss/seam/faces/context/conversation/BeginConversationInterceptorTest-beans.xml 2010-03-24 21:49:03 UTC (rev 12263)
@@ -0,0 +1,10 @@
+<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://java.sun.com/xml/ns/javaee
+ http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
+
+ <interceptors>
+ <class>org.jboss.seam.faces.context.conversation.BeginConversationInterceptor</class>
+ </interceptors>
+
+</beans>
\ No newline at end of file
Added: modules/faces/trunk/src/test/java/org/jboss/seam/faces/context/conversation/BeginConversationInterceptorTest.java
===================================================================
--- modules/faces/trunk/src/test/java/org/jboss/seam/faces/context/conversation/BeginConversationInterceptorTest.java (rev 0)
+++ modules/faces/trunk/src/test/java/org/jboss/seam/faces/context/conversation/BeginConversationInterceptorTest.java 2010-03-24 21:49:03 UTC (rev 12263)
@@ -0,0 +1,42 @@
+/**
+ *
+ */
+package org.jboss.seam.faces.context.conversation;
+
+import static org.junit.Assert.assertTrue;
+
+import javax.inject.Inject;
+
+import org.jboss.arquillian.api.Deployment;
+import org.jboss.seam.faces.MockConversation;
+import org.jboss.seam.faces.MockLogger;
+import org.jboss.shrinkwrap.api.ArchivePaths;
+import org.jboss.shrinkwrap.api.Archives;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.junit.experimental.categories.Category;
+import org.junit.internal.runners.statements.Fail;
+
+/**
+ * @author <a href="mailto:lincolnbaxter at gmail.com">Lincoln Baxter, III</a>
+ *
+ */
+// @RunWith(Arquillian.class)
+public class BeginConversationInterceptorTest
+{
+ @Deployment
+ public static JavaArchive createTestArchive()
+ {
+ return Archives.create("test.jar", JavaArchive.class).addClasses(BeginConversationInterceptor.class, BeginConversationBean.class, MockLogger.class, MockConversation.class).addManifestResource(BeginConversationInterceptorTest.class.getPackage().getName().replaceAll("\\.", "/") + "/BeginConversationInterceptorTest-beans.xml", ArchivePaths.create("beans.xml"));
+ }
+
+ @Inject
+ private BeginConversationBean bean;
+
+ // @Test
+ @Category(Fail.class)
+ public void testConversationStarted()
+ {
+ bean.beginConversation();
+ assertTrue(bean.conversationStarted);
+ }
+}
More information about the seam-commits
mailing list