openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kelap...@apache.org
Subject svn commit: r1296509 - in /openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/event/ObserverMethodImpl.java test/java/org/apache/webbeans/test/component/event/normal/ComponentWithObserves1.java
Date Fri, 02 Mar 2012 23:07:25 GMT
Author: kelapure
Date: Fri Mar  2 23:07:23 2012
New Revision: 1296509

URL: http://svn.apache.org/viewvc?rev=1296509&view=rev
Log:
OWB-628 Event injection does nott work in observer methods.

Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/event/normal/ComponentWithObserves1.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java?rev=1296509&r1=1296508&r2=1296509&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java
Fri Mar  2 23:07:23 2012
@@ -21,6 +21,7 @@ package org.apache.webbeans.event;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
+import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
 import java.util.ArrayList;
 import java.util.HashSet;
@@ -31,6 +32,7 @@ import javax.enterprise.context.ContextN
 import javax.enterprise.context.Dependent;
 import javax.enterprise.context.spi.Context;
 import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.event.Event;
 import javax.enterprise.event.Observes;
 import javax.enterprise.event.Reception;
 import javax.enterprise.event.TransactionPhase;
@@ -45,6 +47,7 @@ import org.apache.webbeans.annotation.An
 import org.apache.webbeans.annotation.DefaultLiteral;
 import org.apache.webbeans.component.AbstractOwbBean;
 import org.apache.webbeans.component.AbstractInjectionTargetBean;
+import org.apache.webbeans.component.EventBean;
 import org.apache.webbeans.component.InjectionPointBean;
 import org.apache.webbeans.component.InjectionTargetBean;
 import org.apache.webbeans.component.WebBeansType;
@@ -395,7 +398,12 @@ public class ObserverMethodImpl<T> imple
                         {
                             injectionPointBeanLocalSetOnStack = InjectionPointBean.setThreadLocal(point);
                         }
-                    }                           
+                    }
+                    
+                    if (isEventProviderInjection(point))
+                    {
+                        EventBean.local.set(point);
+                    }
                     
                     CreationalContext<Object> creational = manager.createCreationalContext(injectedBean);
                     Object instance = manager.getInstance(injectedBean, creational); 
@@ -464,6 +472,11 @@ public class ObserverMethodImpl<T> imple
                         injectionPointBeanLocalSetOnStack = InjectionPointBean.setThreadLocal(point);
                     }
                 }                    
+
+                if (isEventProviderInjection(point))
+                {
+                    EventBean.local.set(point);
+                }
                 
                 CreationalContext<Object> creational = manager.createCreationalContext(injectedBean);
                 Object instance = manager.getInstance(injectedBean, creational); 
@@ -484,6 +497,24 @@ public class ObserverMethodImpl<T> imple
                 
         return list;
     }
+    
+    private boolean isEventProviderInjection(InjectionPoint injectionPoint)
+    {
+        Type type = injectionPoint.getType();
+
+        if (type instanceof ParameterizedType)
+        {
+            ParameterizedType pt = (ParameterizedType) type;
+            Class<?> clazz = (Class<?>) pt.getRawType();
+
+            if (clazz.isAssignableFrom(Event.class))
+            {
+                return true;
+            }
+        }
+
+        return false;
+    }
 
     /**
      * Returns observer owner bean.

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/event/normal/ComponentWithObserves1.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/event/normal/ComponentWithObserves1.java?rev=1296509&r1=1296508&r2=1296509&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/event/normal/ComponentWithObserves1.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/event/normal/ComponentWithObserves1.java
Fri Mar  2 23:07:23 2012
@@ -19,6 +19,7 @@
 package org.apache.webbeans.test.component.event.normal;
 
 import javax.enterprise.context.RequestScoped;
+import javax.enterprise.event.Event;
 import javax.enterprise.event.Observes;
 import javax.enterprise.inject.Any;
 
@@ -37,9 +38,10 @@ public class ComponentWithObserves1
         this.userName = event.getUserName();
     }
 
-    private void afterLoggedInWithMember(@Observes @Check(type = "CHECK") LoggedInEvent event)
+    private void afterLoggedInWithMember(@Observes @Check(type = "CHECK") LoggedInEvent event,
Event<String> myEvent)
     {
         this.userNameWithMember = event.getUserName();
+        myEvent.fire("Rohit Kelapure");
     }
 
     public String getUserName()



Mime
View raw message