openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r1397922 - in /openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/event/ main/java/org/apache/webbeans/util/ test/java/org/apache/webbeans/newtests/specalization/observer/
Date Sat, 13 Oct 2012 18:55:09 GMT
Author: arne
Date: Sat Oct 13 18:55:08 2012
New Revision: 1397922

URL: http://svn.apache.org/viewvc?rev=1397922&view=rev
Log:
OWB-711 Implemented disabling of observer methods of classes that are specialized

Removed:
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/specalization/observer/BeanF.java
Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/NotificationManager.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/specalization/observer/BeanB.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/specalization/observer/ObserverTest.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/NotificationManager.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/NotificationManager.java?rev=1397922&r1=1397921&r2=1397922&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/NotificationManager.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/NotificationManager.java
Sat Oct 13 18:55:08 2012
@@ -26,6 +26,7 @@ import java.lang.reflect.ParameterizedTy
 import java.lang.reflect.Type;
 import java.lang.reflect.TypeVariable;
 import java.util.HashSet;
+import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
@@ -39,6 +40,7 @@ import javax.enterprise.inject.spi.Annot
 import javax.enterprise.inject.spi.ObserverMethod;
 import javax.enterprise.inject.spi.ProcessProducer;
 import javax.enterprise.util.TypeLiteral;
+
 import org.apache.webbeans.annotation.AnyLiteral;
 import org.apache.webbeans.component.InjectionTargetBean;
 import org.apache.webbeans.config.OWBLogConst;
@@ -88,6 +90,22 @@ public final class NotificationManager
         addObserver(observer, typeLiteral.getType());
     }
 
+    public void disableObservers(Class<?> declaringClass)
+    {
+        for (Set<ObserverMethod<?>> observerMethods: observers.values())
+        {
+            for (Iterator<ObserverMethod<?>> i = observerMethods.iterator();
i.hasNext();)
+            {
+                ObserverMethod<?> observer = i.next();
+                if (observer instanceof ObserverMethodImpl
+                        && ((ObserverMethodImpl<?>)observer).getObserverMethod().getDeclaringClass().equals(declaringClass))
+                {
+                    i.remove();
+                }
+            }
+        }
+    }
+
     public <T> Set<ObserverMethod<? super T>> resolveObservers(T event,
Annotation... eventQualifiers)
     {
         EventUtil.checkEventBindings(webBeansContext, eventQualifiers);

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java?rev=1397922&r1=1397921&r2=1397922&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
Sat Oct 13 18:55:08 2012
@@ -1478,11 +1478,13 @@ public final class WebBeansUtil
                 {
                     //disable superbean if the current bean is not an alternative
                     ((AbstractOwbBean<?>)superBean).setEnabled(false);
+                    webBeansContext.getBeanManagerImpl().getNotificationManager().disableObservers(superClass);
                 }
                 else if(altManager.isClassAlternative(specializedClass))
                 {
                     //disable superbean if the current bean is an enabled alternative
                     ((AbstractOwbBean<?>)superBean).setEnabled(false);
+                    webBeansContext.getBeanManagerImpl().getNotificationManager().disableObservers(superClass);
                 }
 
                 AbstractOwbBean<?> comp = (AbstractOwbBean<?>)specialized;

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/specalization/observer/BeanB.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/specalization/observer/BeanB.java?rev=1397922&r1=1397921&r2=1397922&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/specalization/observer/BeanB.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/specalization/observer/BeanB.java
Sat Oct 13 18:55:08 2012
@@ -20,6 +20,7 @@ package org.apache.webbeans.newtests.spe
 
 
 import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.event.Observes;
 import javax.enterprise.inject.Specializes;
 
 @Specializes
@@ -28,6 +29,11 @@ public class BeanB extends BeanA
 {
     private static final long serialVersionUID = 821164664338581947L;
 
+    protected void observeTestEvent(@Observes TestEvent testEvent)
+    {
+        testEvent.addInvocation(getBeanName());
+    }
+
     @Override
     public String getBeanName()
     {

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/specalization/observer/ObserverTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/specalization/observer/ObserverTest.java?rev=1397922&r1=1397921&r2=1397922&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/specalization/observer/ObserverTest.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/specalization/observer/ObserverTest.java
Sat Oct 13 18:55:08 2012
@@ -32,68 +32,89 @@ import org.junit.Test;
 public class ObserverTest extends AbstractUnitTest
 {
     private static final String PACKAGE_NAME = ObserverTest.class.getPackage().getName();
-
+    
     @Test
-    public void testObserverMethodsInSpecializedBeans()
+    public void testObserverMethodsInParentOfAlternativeAndSpecializedBeans()
     {
-        Collection<Class<?>> beanClasses = new ArrayList<Class<?>>();
-        beanClasses.add(BeanA.class);
-        beanClasses.add(BeanB.class);
-        startContainer(beanClasses, null);
+    	Collection<String> beanXmls = new ArrayList<String>();
+        beanXmls.add(getXmlPath(PACKAGE_NAME, "AlternativeSpecializes"));
 
+    	Collection<Class<?>> beanClasses = new ArrayList<Class<?>>();
+        beanClasses.add(BeanA.class);
+        beanClasses.add(BeanC.class);
+        startContainer(beanClasses, beanXmls);
+        
         Set<Bean<?>> beans = getBeanManager().getBeans(BeanA.class);
         Assert.assertEquals(1, beans.size());
-
+        
         TestEvent testEvent = new TestEvent();
         getBeanManager().fireEvent(testEvent);
-
-        Assert.assertEquals(1, testEvent.getCalledObservers().size());
-        Assert.assertTrue(testEvent.getCalledObservers().iterator().next().endsWith(":[specialize]"));
-
+        
+        Assert.assertEquals(0, testEvent.getCalledObservers().size());
+        
         shutDownContainer();
     }
-       
+    
     @Test
     public void testOverrideObserverMethodsInAlternativeAndSpecializedBeans()
     {
-        Collection<String> beanXmls = new ArrayList<String>();
+    	Collection<String> beanXmls = new ArrayList<String>();
         beanXmls.add(getXmlPath(PACKAGE_NAME, "AlternativeSpecializes"));
-   
-        Collection<Class<?>> beanClasses = new ArrayList<Class<?>>();
+
+    	Collection<Class<?>> beanClasses = new ArrayList<Class<?>>();
         beanClasses.add(BeanA.class);
         beanClasses.add(BeanD.class);
         startContainer(beanClasses, beanXmls);
-           
+        
         Set<Bean<?>> beans = getBeanManager().getBeans(BeanA.class);
         Assert.assertEquals(1, beans.size());
-           
+        
         TestEvent testEvent = new TestEvent();
         getBeanManager().fireEvent(testEvent);
-           
+        
         Assert.assertEquals(1, testEvent.getCalledObservers().size());
         Assert.assertTrue(testEvent.getCalledObservers().iterator().next().endsWith(":[alternative]:[specialize]"));
-           
+        
+        shutDownContainer();
+    }
+    
+    @Test
+    public void testObserverMethodsInParentOfSpecializedBeans()
+    {
+        Collection<Class<?>> beanClasses = new ArrayList<Class<?>>();
+        beanClasses.add(BeanA.class);
+        beanClasses.add(BeanE.class);
+        startContainer(beanClasses, null);
+
+        Set<Bean<?>> beans = getBeanManager().getBeans(BeanA.class);
+        Assert.assertEquals(1, beans.size());
+
+        TestEvent testEvent = new TestEvent();
+        getBeanManager().fireEvent(testEvent);
+
+        Assert.assertEquals(BeanE.class, beans.toArray(new Bean<?>[0])[0].getBeanClass());
+        Assert.assertEquals(0, testEvent.getCalledObservers().size());
+
         shutDownContainer();
     }
-   
+
     @Test
     public void testOverrideObserverMethodsInSpecializedBeans()
     {
         Collection<Class<?>> beanClasses = new ArrayList<Class<?>>();
         beanClasses.add(BeanA.class);
-        beanClasses.add(BeanF.class);
+        beanClasses.add(BeanB.class);
         startContainer(beanClasses, null);
-   
+
         Set<Bean<?>> beans = getBeanManager().getBeans(BeanA.class);
         Assert.assertEquals(1, beans.size());
-   
+
         TestEvent testEvent = new TestEvent();
         getBeanManager().fireEvent(testEvent);
-   
-        Assert.assertEquals(BeanF.class, beans.toArray(new Bean<?>[0])[0].getBeanClass());
+
         Assert.assertEquals(1, testEvent.getCalledObservers().size());
         Assert.assertTrue(testEvent.getCalledObservers().iterator().next().endsWith(":[specialize]"));
-   
+
         shutDownContainer();
     }
 }



Mime
View raw message