openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1405764 - 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 Mon, 05 Nov 2012 12:11:39 GMT
Author: struberg
Date: Mon Nov  5 12:11:39 2012
New Revision: 1405764

URL: http://svn.apache.org/viewvc?rev=1405764&view=rev
Log:
OWB-711 remove overridden observer methods

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/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=1405764&r1=1405763&r2=1405764&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
Mon Nov  5 12:11:39 2012
@@ -90,17 +90,37 @@ public final class NotificationManager
         addObserver(observer, typeLiteral.getType());
     }
 
-    public void disableObservers(Class<?> declaringClass)
+    /**
+     * <p>This method shall only be called for subclasses.
+     * It will disable all observer methods which are overridden
+     * in the given subclass.</p>
+     */
+    public void disableOverriddenObservers(Class<?> subClass)
     {
         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))
+                if (observer instanceof ObserverMethodImpl)
                 {
-                    i.remove();
+                    Method observerMethod = ((ObserverMethodImpl<?>)observer).getObserverMethod();
+
+                    // we only remove methods from a superclass
+                    if (!observerMethod.getDeclaringClass().equals(subClass))
+                    {
+                        try
+                        {
+                            subClass.getMethod(observerMethod.getName(), observerMethod.getParameterTypes());
+                            i.remove();
+                        }
+                        catch(NoSuchMethodException nsme)
+                        {
+                            // that's perfectly fine.
+                            // it means that we don't need to remove anything becasue the
+                            // observer method didn't get overridden.
+                        }
+                    }
                 }
             }
         }

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=1405764&r1=1405763&r2=1405764&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
Mon Nov  5 12:11:39 2012
@@ -1467,6 +1467,8 @@ public final class WebBeansUtil
 
             if (superBean != null)
             {
+                webBeansContext.getBeanManagerImpl().getNotificationManager().disableOverriddenObservers(superClass);
+
                 // Recursively configure super class first if super class is also a special
bean.
                 // So the name and bean meta data could be populated to this beanclass.
                 if (beanClasses.contains(superClass) && ((AbstractOwbBean<?>)superBean).isEnabled())
@@ -1478,13 +1480,11 @@ 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/ObserverTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/specalization/observer/ObserverTest.java?rev=1405764&r1=1405763&r2=1405764&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
Mon Nov  5 12:11:39 2012
@@ -36,10 +36,10 @@ public class ObserverTest extends Abstra
     @Test
     public void testObserverMethodsInParentOfAlternativeAndSpecializedBeans()
     {
-    	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(BeanC.class);
         startContainer(beanClasses, beanXmls);
@@ -49,19 +49,20 @@ public class ObserverTest extends Abstra
         
         TestEvent testEvent = new TestEvent();
         getBeanManager().fireEvent(testEvent);
-        
-        Assert.assertEquals(0, testEvent.getCalledObservers().size());
-        
+
+        Assert.assertEquals(1, testEvent.getCalledObservers().size());
+        Assert.assertTrue(testEvent.getCalledObservers().iterator().next().endsWith(":[specialize]"));
+
         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);
@@ -93,7 +94,8 @@ public class ObserverTest extends Abstra
         getBeanManager().fireEvent(testEvent);
 
         Assert.assertEquals(BeanE.class, beans.toArray(new Bean<?>[0])[0].getBeanClass());
-        Assert.assertEquals(0, testEvent.getCalledObservers().size());
+        Assert.assertEquals(1, testEvent.getCalledObservers().size());
+        Assert.assertTrue(testEvent.getCalledObservers().iterator().next().endsWith(":[specialize]"));
 
         shutDownContainer();
     }



Mime
View raw message