commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r1609794 - in /commons/proper/configuration/trunk/src: main/java/org/apache/commons/configuration/ test/java/org/apache/commons/configuration/
Date Fri, 11 Jul 2014 20:18:43 GMT
Author: oheger
Date: Fri Jul 11 20:18:42 2014
New Revision: 1609794

URL: http://svn.apache.org/r1609794
Log:
Adapted PropertiesConfigurationLayout to new event mechanism.

Modified:
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/PropertiesConfiguration.java
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/PropertiesConfigurationLayout.java
    commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestPropertiesConfigurationLayout.java

Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/PropertiesConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/PropertiesConfiguration.java?rev=1609794&r1=1609793&r2=1609794&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/PropertiesConfiguration.java
(original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/PropertiesConfiguration.java
Fri Jul 11 20:18:42 2014
@@ -32,6 +32,7 @@ import java.util.regex.Pattern;
 import org.apache.commons.configuration.convert.DefaultListDelimiterHandler;
 import org.apache.commons.configuration.convert.ListDelimiterHandler;
 import org.apache.commons.configuration.convert.ValueTransformer;
+import org.apache.commons.configuration.event.ConfigurationEvent;
 import org.apache.commons.configuration.ex.ConfigurationException;
 import org.apache.commons.configuration.ex.ConfigurationRuntimeException;
 import org.apache.commons.configuration.io.FileHandler;
@@ -417,7 +418,7 @@ public class PropertiesConfiguration ext
         // only one layout must exist
         if (this.layout != null)
         {
-            removeConfigurationListener(this.layout);
+            removeEventListener(ConfigurationEvent.ANY, this.layout);
         }
 
         if (layout == null)
@@ -428,7 +429,7 @@ public class PropertiesConfiguration ext
         {
             this.layout = layout;
         }
-        addConfigurationListener(this.layout);
+        addEventListener(ConfigurationEvent.ANY, this.layout);
     }
 
     /**

Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/PropertiesConfigurationLayout.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/PropertiesConfigurationLayout.java?rev=1609794&r1=1609793&r2=1609794&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/PropertiesConfigurationLayout.java
(original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/PropertiesConfigurationLayout.java
Fri Jul 11 20:18:42 2014
@@ -25,7 +25,7 @@ import java.util.Map;
 import java.util.Set;
 
 import org.apache.commons.configuration.event.ConfigurationEvent;
-import org.apache.commons.configuration.event.ConfigurationListener;
+import org.apache.commons.configuration.event.EventListener;
 import org.apache.commons.configuration.ex.ConfigurationException;
 import org.apache.commons.configuration.ex.ConfigurationRuntimeException;
 import org.apache.commons.lang3.StringUtils;
@@ -110,13 +110,10 @@ import org.apache.commons.lang3.StringUt
  * </ul>
  * </p>
  *
- * @author <a
- * href="http://commons.apache.org/configuration/team-list.html">Commons
- * Configuration team</a>
  * @version $Id$
  * @since 1.3
  */
-public class PropertiesConfigurationLayout implements ConfigurationListener
+public class PropertiesConfigurationLayout implements EventListener<ConfigurationEvent>
 {
     /** Constant for the line break character. */
     private static final String CR = "\n";
@@ -485,7 +482,7 @@ public class PropertiesConfigurationLayo
     {
         if (++loadCounter == 1)
         {
-            config.removeConfigurationListener(this);
+            config.removeEventListener(ConfigurationEvent.ANY, this);
         }
         PropertiesConfiguration.PropertiesReader reader =
                 config.getIOFactory().createPropertiesReader(in);
@@ -536,7 +533,7 @@ public class PropertiesConfigurationLayo
         {
             if (--loadCounter == 0)
             {
-                config.addConfigurationListener(this);
+                config.addEventListener(ConfigurationEvent.ANY, this);
             }
         }
     }
@@ -606,28 +603,31 @@ public class PropertiesConfigurationLayo
      * @param event the event object
      */
     @Override
-    public void configurationChanged(ConfigurationEvent event)
+    public void onEvent(ConfigurationEvent event)
     {
         if (!event.isBeforeUpdate())
         {
-            switch (event.getType())
+            if (ConfigurationEvent.ADD_PROPERTY.equals(event.getEventType()))
             {
-            case AbstractConfiguration.EVENT_ADD_PROPERTY:
-                boolean contained = layoutData.containsKey(event
-                        .getPropertyName());
-                PropertyLayoutData data = fetchLayoutData(event
-                        .getPropertyName());
+                boolean contained =
+                        layoutData.containsKey(event.getPropertyName());
+                PropertyLayoutData data =
+                        fetchLayoutData(event.getPropertyName());
                 data.setSingleLine(!contained);
-                break;
-            case AbstractConfiguration.EVENT_CLEAR_PROPERTY:
+            }
+            else if (ConfigurationEvent.CLEAR_PROPERTY.equals(event
+                    .getEventType()))
+            {
                 layoutData.remove(event.getPropertyName());
-                break;
-            case AbstractConfiguration.EVENT_CLEAR:
+            }
+            else if (ConfigurationEvent.CLEAR.equals(event.getEventType()))
+            {
                 clear();
-                break;
-            case AbstractConfiguration.EVENT_SET_PROPERTY:
+            }
+            else if (ConfigurationEvent.SET_PROPERTY.equals(event
+                    .getEventType()))
+            {
                 fetchLayoutData(event.getPropertyName());
-                break;
             }
         }
     }

Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestPropertiesConfigurationLayout.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestPropertiesConfigurationLayout.java?rev=1609794&r1=1609793&r2=1609794&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestPropertiesConfigurationLayout.java
(original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestPropertiesConfigurationLayout.java
Fri Jul 11 20:18:42 2014
@@ -31,7 +31,7 @@ import java.util.Iterator;
 import org.apache.commons.configuration.convert.DefaultListDelimiterHandler;
 import org.apache.commons.configuration.convert.LegacyListDelimiterHandler;
 import org.apache.commons.configuration.event.ConfigurationEvent;
-import org.apache.commons.configuration.event.ConfigurationListener;
+import org.apache.commons.configuration.event.EventListener;
 import org.apache.commons.configuration.ex.ConfigurationException;
 import org.junit.Before;
 import org.junit.Test;
@@ -88,7 +88,8 @@ public class TestPropertiesConfiguration
     {
         assertTrue("Object contains keys", layout.getKeys().isEmpty());
         assertNull("Header comment not null", layout.getHeaderComment());
-        Iterator<ConfigurationListener> it = config.getConfigurationListeners().iterator();
+        Iterator<EventListener<? super ConfigurationEvent>> it =
+                config.getEventListeners(ConfigurationEvent.ANY).iterator();
         assertTrue("No event listener registered", it.hasNext());
         assertSame("Layout not registered as event listener", layout, it.next());
         assertFalse("Multiple event listeners registered", it.hasNext());
@@ -268,9 +269,9 @@ public class TestPropertiesConfiguration
     public void testEventAdd()
     {
         ConfigurationEvent event = new ConfigurationEvent(this,
-                AbstractConfiguration.EVENT_ADD_PROPERTY, TEST_KEY, TEST_VALUE,
+                ConfigurationEvent.ADD_PROPERTY, TEST_KEY, TEST_VALUE,
                 false);
-        layout.configurationChanged(event);
+        layout.onEvent(event);
         assertTrue("Property not stored", layout.getKeys().contains(TEST_KEY));
         assertEquals("Blanc lines before new property", 0, layout
                 .getBlancLinesBefore(TEST_KEY));
@@ -286,10 +287,10 @@ public class TestPropertiesConfiguration
     public void testEventAddMultiple()
     {
         ConfigurationEvent event = new ConfigurationEvent(this,
-                AbstractConfiguration.EVENT_ADD_PROPERTY, TEST_KEY, TEST_VALUE,
+                ConfigurationEvent.ADD_PROPERTY, TEST_KEY, TEST_VALUE,
                 false);
-        layout.configurationChanged(event);
-        layout.configurationChanged(event);
+        layout.onEvent(event);
+        layout.onEvent(event);
         assertFalse("No multi-line property", layout.isSingleLine(TEST_KEY));
     }
 
@@ -304,9 +305,9 @@ public class TestPropertiesConfiguration
         builder.addProperty(TEST_KEY, TEST_VALUE);
         layout.load(config, builder.getReader());
         ConfigurationEvent event = new ConfigurationEvent(this,
-                AbstractConfiguration.EVENT_ADD_PROPERTY, TEST_KEY, TEST_VALUE,
+                ConfigurationEvent.ADD_PROPERTY, TEST_KEY, TEST_VALUE,
                 false);
-        layout.configurationChanged(event);
+        layout.onEvent(event);
         assertFalse("No multi-line property", layout.isSingleLine(TEST_KEY));
         assertEquals("Comment was modified", TEST_COMMENT, layout
                 .getCanonicalComment(TEST_KEY, false));
@@ -320,9 +321,9 @@ public class TestPropertiesConfiguration
     public void testEventSetNonExisting()
     {
         ConfigurationEvent event = new ConfigurationEvent(this,
-                AbstractConfiguration.EVENT_SET_PROPERTY, TEST_KEY, TEST_VALUE,
+                ConfigurationEvent.SET_PROPERTY, TEST_KEY, TEST_VALUE,
                 false);
-        layout.configurationChanged(event);
+        layout.onEvent(event);
         assertTrue("New property was not found", layout.getKeys().contains(
                 TEST_KEY));
     }
@@ -334,13 +335,13 @@ public class TestPropertiesConfiguration
     public void testEventDelete()
     {
         ConfigurationEvent event = new ConfigurationEvent(this,
-                AbstractConfiguration.EVENT_ADD_PROPERTY, TEST_KEY, TEST_VALUE,
+                ConfigurationEvent.ADD_PROPERTY, TEST_KEY, TEST_VALUE,
                 false);
-        layout.configurationChanged(event);
+        layout.onEvent(event);
         event = new ConfigurationEvent(this,
-                AbstractConfiguration.EVENT_CLEAR_PROPERTY, TEST_KEY, null,
+                ConfigurationEvent.CLEAR_PROPERTY, TEST_KEY, null,
                 false);
-        layout.configurationChanged(event);
+        layout.onEvent(event);
         assertFalse("Property still existing", layout.getKeys().contains(
                 TEST_KEY));
     }
@@ -353,8 +354,8 @@ public class TestPropertiesConfiguration
     {
         fillLayout();
         ConfigurationEvent event = new ConfigurationEvent(this,
-                AbstractConfiguration.EVENT_CLEAR, null, null, false);
-        layout.configurationChanged(event);
+                ConfigurationEvent.CLEAR, null, null, false);
+        layout.onEvent(event);
         assertTrue("Keys not empty", layout.getKeys().isEmpty());
         assertNull("Header comment was not reset", layout.getHeaderComment());
     }
@@ -366,9 +367,9 @@ public class TestPropertiesConfiguration
     public void testEventAddBefore()
     {
         ConfigurationEvent event = new ConfigurationEvent(this,
-                AbstractConfiguration.EVENT_ADD_PROPERTY, TEST_KEY, TEST_VALUE,
+                ConfigurationEvent.ADD_PROPERTY, TEST_KEY, TEST_VALUE,
                 true);
-        layout.configurationChanged(event);
+        layout.onEvent(event);
         assertFalse("Property already stored", layout.getKeys().contains(
                 TEST_KEY));
     }
@@ -547,10 +548,8 @@ public class TestPropertiesConfiguration
         fillLayout();
         layout.setComment("NonExistingKey", "NonExistingComment");
         String output = getLayoutString();
-        assertTrue("Non existing key was found", output
-                .indexOf("NonExistingKey") < 0);
-        assertTrue("Non existing comment was found", output
-                .indexOf("NonExistingComment") < 0);
+        assertTrue("Non existing key was found", !output.contains("NonExistingKey"));
+        assertTrue("Non existing comment was found", !output.contains("NonExistingComment"));
     }
 
     /**



Mime
View raw message