harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mloe...@apache.org
Subject svn commit: r396863 - in /incubator/harmony/enhanced/classlib/trunk/modules/beans/src: main/java/java/beans/VetoableChangeSupport.java test/java/tests/api/java/beans/VetoableChangeSupportTest.java
Date Tue, 25 Apr 2006 12:32:41 GMT
Author: mloenko
Date: Tue Apr 25 05:32:38 2006
New Revision: 396863

URL: http://svn.apache.org/viewcvs?rev=396863&view=rev
Log:
fixes for HARMONY-321:
VetoableChangeSupport: the reverting event is not fired if the change is vetoed

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/VetoableChangeSupport.java
    incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/VetoableChangeSupportTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/VetoableChangeSupport.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/VetoableChangeSupport.java?rev=396863&r1=396862&r2=396863&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/VetoableChangeSupport.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/VetoableChangeSupport.java
Tue Apr 25 05:32:38 2006
@@ -318,7 +318,7 @@
     
     private void doFirePropertyChange(PropertyChangeEvent event)
             throws PropertyVetoException {
-        String propertyName = event.getPropertyName();
+        String propName = event.getPropertyName();
         Object oldValue = event.getOldValue();
         Object newValue = event.getNewValue();
         
@@ -326,23 +326,38 @@
             return;
         }
 
-        Iterator iterator = allVetoableChangeListeners.iterator();
+        try {
+            notifyAllListeners(event);
+        } catch (PropertyVetoException pve) {
+            PropertyChangeEvent rEvent = createPropertyChangeEvent(propName,
+                    newValue, oldValue);
+            notifyAllListeners(rEvent);
+            throw pve;
+        }
+    }
+
+    private void notifyListeners(Iterator iterator, PropertyChangeEvent event)
+            throws PropertyVetoException {
+
+        VetoableChangeListener listener = null;
         while (iterator.hasNext()) {
-            VetoableChangeListener listener =
-                    (VetoableChangeListener) iterator.next();
+            listener = (VetoableChangeListener) iterator.next();
             listener.vetoableChange(event);
         }
-        
-        ArrayList listeners = (ArrayList) selectedVetoableChangeListeners.get(
-                propertyName);
-        if (listeners != null) {
-            iterator = listeners.iterator();
-            while (iterator.hasNext()) {
-                VetoableChangeListener listener =
-                        (VetoableChangeListener) iterator.next();
-                listener.vetoableChange(event);
-            }
+
+    }
+
+    private void notifyAllListeners(PropertyChangeEvent event)
+            throws PropertyVetoException {
+
+        notifyListeners(allVetoableChangeListeners.iterator(), event);
+        String propertyName = event.getPropertyName();
+        ArrayList listeners = (ArrayList) selectedVetoableChangeListeners
+                .get(propertyName);
+        if (listeners == null) {
+            return;
         }
+        notifyListeners(listeners.iterator(), event);
     }
     
     private static VetoableChangeListener[] getAsVetoableChangeListenerArray(

Modified: incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/VetoableChangeSupportTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/VetoableChangeSupportTest.java?rev=396863&r1=396862&r2=396863&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/VetoableChangeSupportTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/VetoableChangeSupportTest.java
Tue Apr 25 05:32:38 2006
@@ -1510,6 +1510,24 @@
 		assertEquals(0, support.getVetoableChangeListeners().length);
 	}
 
+    /*
+     * Regression test for HARMONY-321
+     */
+    public void testFireVetoableChange_regression() {
+        VetoableChangeSupport vcs = new VetoableChangeSupport(this);
+        MockVetoListener2 vlistener = new MockVetoListener2();
+
+        vcs.addVetoableChangeListener(vlistener);
+        try {
+            vcs.fireVetoableChange(vlistener.vetoedPropName, 0, 1);
+            fail("PropertyVetoException expected");
+        } catch (PropertyVetoException ok) {}
+
+        assertEquals(1, vlistener.event.getOldValue());
+        assertEquals(0, vlistener.event.getNewValue());
+    } 
+
+    
 	/*
 	 * no this listener
 	 */
@@ -1747,5 +1765,26 @@
 		}
 
 	}
+
+    public static class MockVetoListener2 implements VetoableChangeListener {
+
+        public PropertyChangeEvent event;
+
+        public final String vetoedPropName = "prop";
+
+        public void vetoableChange(PropertyChangeEvent e)
+                throws PropertyVetoException {
+
+            event = e;
+            String propName = e.getPropertyName();
+
+            if (propName.equals(vetoedPropName)
+                    && e.getNewValue().equals(new Integer(1))) {
+                throw new PropertyVetoException(
+                        propName + " change is vetoed!", e);
+            }
+        }
+
+    }
 
 }



Mime
View raw message