Author: bergmark
Date: Wed Jun 22 17:29:42 2011
New Revision: 1138559

URL: http://svn.apache.org/viewvc?rev=1138559&view=rev
Log:
[OWB-580] Lookup contextual for Observer methods in EJBs using bean type 
information.  Also, replace the method in ObserverMethodImpl with the method 
from the interface during EjbValidator as that method should be valid on the 
ejb proxy.

Modified:
    
openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/util/EjbValidator.java
    
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java

Modified: 
openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/util/EjbValidator.java
URL: 
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/util/EjbValidator.java?rev=1138559&r1=1138558&r2=1138559&view=diff
==============================================================================
--- 
openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/util/EjbValidator.java
 (original)
+++ 
openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/util/EjbValidator.java
 Wed Jun 22 17:29:42 2011
@@ -150,6 +150,8 @@ public final class EjbValidator
                     }
                     else
                     {
+                        //Should only be a single method that matches the 
names & params
+                        obs.setObserverMethod(methods.get(0));
                         found = true;
                         break;
                     }

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=1138559&r1=1138558&r2=1138559&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
 Wed Jun 22 17:29:42 2011
@@ -47,6 +47,7 @@ import org.apache.webbeans.component.Abs
 import org.apache.webbeans.component.AbstractInjectionTargetBean;
 import org.apache.webbeans.component.InjectionPointBean;
 import org.apache.webbeans.component.InjectionTargetBean;
+import org.apache.webbeans.component.WebBeansType;
 import org.apache.webbeans.config.OWBLogConst;
 import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.container.BeanManagerImpl;
@@ -89,7 +90,7 @@ public class ObserverMethodImpl<T> imple
     private final InjectionTargetBean<?> bean;
 
     /**Event observer method*/
-    private final Method observerMethod;
+    private Method observerMethod;
 
     /**Using existing bean instance or not*/
     private final boolean ifExist;
@@ -272,7 +273,17 @@ public class ObserverMethodImpl<T> imple
                     // we need to pick the contextual reference because of 
section 7.2:
                     //  "Invocations of producer, disposer and observer 
methods by the container are
                     //  business method invocations and are in- tercepted by 
method interceptors and decorators."
-                    object = manager.getReference(component, 
component.getBeanClass(), creationalContext);
+                    
+                    Type t = component.getBeanClass();
+
+                    // If the bean is an EJB, its beanClass may not be one of
+                    // its types. Instead pick a local interface
+                    if (component.getWebBeansType() == WebBeansType.ENTERPRISE)
+                    {
+                        t = (Type) component.getTypes().toArray()[0];
+                    }
+
+                    object = manager.getReference(component, t, 
creationalContext);
                 }
 
                 if (object != null)
@@ -511,4 +522,16 @@ public class ObserverMethodImpl<T> imple
     {
         return bean.getWebBeansContext();
     }
+    
+    /**
+     * Provides a way to set the observer method. This may need to be done for
+     * EJBs so that the method used will be from an interface and not the
+     * EJB class that likely can not be invoked on the EJB proxy
+     * 
+     * @param method to be invoked as the observer
+     */
+    public void setObserverMethod(Method m)
+    {
+        this.observerMethod = m;
+    }
 }


Reply via email to