deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject deltaspike git commit: DELTASPIKE-874 optional cdi 1.1+ support for JsfRequestBroadcaster
Date Tue, 14 Apr 2015 20:02:31 GMT
Repository: deltaspike
Updated Branches:
  refs/heads/master a40c71da6 -> 1ee2193e2


DELTASPIKE-874 optional cdi 1.1+ support for JsfRequestBroadcaster


Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/1ee2193e
Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/1ee2193e
Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/1ee2193e

Branch: refs/heads/master
Commit: 1ee2193e225fff8e4e4b57fa2eb445cc04524413
Parents: a40c71d
Author: gpetracek <gpetracek@apache.org>
Authored: Tue Apr 14 21:52:05 2015 +0200
Committer: gpetracek <gpetracek@apache.org>
Committed: Tue Apr 14 22:00:13 2015 +0200

----------------------------------------------------------------------
 .../listener/request/JsfRequestBroadcaster.java | 72 ++++++++++++++++----
 1 file changed, 60 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/1ee2193e/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/listener/request/JsfRequestBroadcaster.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/listener/request/JsfRequestBroadcaster.java
b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/listener/request/JsfRequestBroadcaster.java
index 4b677b6..8306839 100644
--- a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/listener/request/JsfRequestBroadcaster.java
+++ b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/listener/request/JsfRequestBroadcaster.java
@@ -18,46 +18,94 @@
  */
 package org.apache.deltaspike.jsf.impl.listener.request;
 
-import org.apache.deltaspike.core.api.lifecycle.Destroyed;
-import org.apache.deltaspike.core.api.lifecycle.Initialized;
+import org.apache.deltaspike.core.api.literal.DestroyedLiteral;
+import org.apache.deltaspike.core.api.literal.InitializedLiteral;
 import org.apache.deltaspike.core.spi.activation.Deactivatable;
+import org.apache.deltaspike.core.util.ClassUtils;
+import org.apache.deltaspike.core.util.metadata.AnnotationInstanceProvider;
 
+import javax.annotation.PostConstruct;
 import javax.enterprise.context.ApplicationScoped;
 import javax.enterprise.event.Event;
+import javax.faces.bean.RequestScoped;
 import javax.faces.context.FacesContext;
 import javax.inject.Inject;
+import java.lang.annotation.Annotation;
+import java.util.HashMap;
+import java.util.Map;
 
 /**
- * Broadcaster for {@link Initialized} and {@link Destroyed}
+ * Broadcaster for
+ * {@link org.apache.deltaspike.core.api.lifecycle.Initialized}
+ * {@link org.apache.deltaspike.core.api.lifecycle.Destroyed}
+ * with
+ * {@link FacesContext} as event-payload
+ * and/or in case of CDI 1.1+
+ * {@link javax.enterprise.context.Initialized}
+ * {@link javax.enterprise.context.Destroyed}
+ * with
+ * {@link javax.faces.bean.RequestScoped} as annotation-parameter and
+ * {@link FacesContext} as event-payload
  */
 @ApplicationScoped
 public class JsfRequestBroadcaster implements Deactivatable
 {
     @Inject
-    @Initialized
-    private Event<FacesContext> initializedJsfRequestEvent;
+    private Event<FacesContext> jsfRequestEvent;
 
-    @Inject
-    @Destroyed
-    private Event<FacesContext> destroyedJsfRequestEvent;
+    /*
+     * annotation-instances for the optional cdi 1.1+ support
+     */
+    private Annotation initializedAnnotationInstance;
+    private Annotation destroyedAnnotationInstance;
+
+    @PostConstruct
+    protected void init()
+    {
+        Map<String, Class> values = new HashMap<String, Class>();
+        values.put("value", RequestScoped.class);
+        Class<? extends Annotation> initializedAnnotationClass =
+            ClassUtils.tryToLoadClassForName("javax.enterprise.context.Initialized");
+        if (initializedAnnotationClass != null)
+        {
+            this.initializedAnnotationInstance = AnnotationInstanceProvider.of(initializedAnnotationClass,
values);
+        }
+
+        Class<? extends Annotation> destroyedAnnotationClass =
+            ClassUtils.tryToLoadClassForName("javax.enterprise.context.Destroyed");
+        if (destroyedAnnotationClass != null)
+        {
+            this.destroyedAnnotationInstance = AnnotationInstanceProvider.of(destroyedAnnotationClass,
values);
+        }
+    }
 
     /**
-     * Broadcasts the {@link Initialized} event
+     * Broadcasts @Initialized-event(s)
      *
      * @param facesContext current faces-context
      */
     public void broadcastInitializedJsfRequestEvent(FacesContext facesContext)
     {
-        this.initializedJsfRequestEvent.fire(facesContext);
+        this.jsfRequestEvent.select(new InitializedLiteral()).fire(facesContext);
+
+        if (this.initializedAnnotationInstance != null)
+        {
+            this.jsfRequestEvent.select(this.initializedAnnotationInstance).fire(facesContext);
+        }
     }
 
     /**
-     * Broadcasts the {@link Destroyed} event
+     * Broadcasts @Destroyed-event(s)
      *
      * @param facesContext current faces-context
      */
     public void broadcastDestroyedJsfRequestEvent(FacesContext facesContext)
     {
-        this.destroyedJsfRequestEvent.fire(facesContext);
+        this.jsfRequestEvent.select(new DestroyedLiteral()).fire(facesContext);
+
+        if (this.destroyedAnnotationInstance != null)
+        {
+            this.jsfRequestEvent.select(this.destroyedAnnotationInstance).fire(facesContext);
+        }
     }
 }


Mime
View raw message