Author: oheger
Date: Fri Jul 11 20:13:34 2014
New Revision: 1609787
URL: http://svn.apache.org/r1609787
Log:
Reworked ConfigurationEvent to conform to the new event mechanism.
The class now extends Event and can handle an EventType. The old numeric type
is still stored; it will be removed when the refactoring is complete.
Modified:
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/event/ConfigurationEvent.java
Modified:
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/event/ConfigurationEvent.java
URL:
http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/event/ConfigurationEvent.java?rev=1609787&r1=1609786&r2=1609787&view=diff
==============================================================================
---
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/event/ConfigurationEvent.java
(original)
+++
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/event/ConfigurationEvent.java
Fri Jul 11 20:13:34 2014
@@ -16,8 +16,6 @@
*/
package org.apache.commons.configuration.event;
-import java.util.EventObject;
-
/**
* <p>
* An event class for reporting updates on a configuration object.
@@ -33,9 +31,9 @@ import java.util.EventObject;
* <ul>
* <li>A source object, which is usually the configuration object that was
* modified.</li>
- * <li>The event's type. This is a numeric value that corresponds to constant
- * declarations in concrete configuration classes. It describes what exactly
has
- * happended.</li>
+ * <li>The event's type. This is an object that corresponds to constant
+ * declarations in specific event classes. It describes what exactly has
+ * happened.</li>
* <li>If available, the name of the property whose modification caused the
* event.</li>
* <li>If available, the value of the property that caused this event.</li>
@@ -48,41 +46,42 @@ import java.util.EventObject;
* <p>
* The following standard events are generated by typical configuration
* implementations (the constants for the event types are defined in
- * {@link org.apache.commons.configuration.AbstractConfiguration}):
+ * this class:
* <dl>
- * <dt>EVENT_ADD_PROPERTY</dt>
+ * <dt>ADD_PROPERTY</dt>
* <dd>This event is triggered for each call of the {@code addProperty()}
* method of a configuration object. It contains the name of the property, to
* which new data is added, and the value object that is added to this property
* (this may be an array or a list if multiple values are added).</dd>
- * <dt>EVENT_SET_PROPERTY</dt>
+ * <dt>SET_PROPERTY</dt>
* <dd>Calling the {@code setProperty()} method triggers this event. The
* event object stores the name of the affected property and its new
value.</dd>
- * <dt>EVENT_CLEAR_PROPERTY</dt>
+ * <dt>CLEAR_PROPERTY</dt>
* <dd>If a property is removed from a configuration (by calling the
* {@code clearProperty()} method), an event of this type is fired. In
* this case the event object only stores the name of the removed property, the
* value is <b>null</b>.</dd>
- * <dt>EVENT_CLEAR</dt>
+ * <dt>CLEAR</dt>
* <dd>This event is fired when the whole configuration is cleared. The
* corresponding event object contains no additional data.</dd>
* </dl>
* </p>
*
- * @author <a
- * href="http://commons.apache.org/configuration/team-list.html">Commons
- * Configuration team</a>
* @version $Id$
* @since 1.3
*/
-public class ConfigurationEvent extends EventObject
+public class ConfigurationEvent extends Event
{
/**
* The serial version UID.
*/
- private static final long serialVersionUID = 3277238219073504136L;
+ private static final long serialVersionUID = 20140703L;
+
+ /** Constant for the common super type of all configuration update events.
*/
+ public static final EventType<ConfigurationEvent> ANY =
+ new EventType<ConfigurationEvent>(Event.ANY,
"CONFIGURATION_UPDATE");
- /** Stores the event type. */
+ /** The legacy event type. */
private final int type;
/** Stores the property name. */
@@ -104,14 +103,47 @@ public class ConfigurationEvent extends
* @param propertyValue the value of the affected property
* @param beforeUpdate the before update flag
*/
+ public ConfigurationEvent(Object source,
+ EventType<? extends ConfigurationEvent> type, String propertyName,
+ Object propertyValue, boolean beforeUpdate)
+ {
+ super(source, type);
+ this.propertyName = propertyName;
+ this.propertyValue = propertyValue;
+ this.beforeUpdate = beforeUpdate;
+ this.type = 0;
+ }
+
+ /**
+ * Creates a new instance of {@code ConfigurationEvent} and initializes it
+ * with a legacy event type.
+ *
+ * @param source the event source
+ * @param type the numeric event type
+ * @param propertyName the name of the affected property
+ * @param propertyValue the value of the affected property
+ * @param beforeUpdate the before update flag
+ * @deprecated use the constructor which expects an {@code EventType}
+ */
public ConfigurationEvent(Object source, int type, String propertyName,
Object propertyValue, boolean beforeUpdate)
{
- super(source);
- this.type = type;
+ super(source, ANY);
this.propertyName = propertyName;
this.propertyValue = propertyValue;
this.beforeUpdate = beforeUpdate;
+ this.type = type;
+ }
+
+ /**
+ * Returns the numeric event type.
+ *
+ * @return the numeric event type
+ * @deprecated use {@code getEventType}
+ */
+ public int getType()
+ {
+ return type;
}
/**
@@ -136,17 +168,6 @@ public class ConfigurationEvent extends
}
/**
- * Returns the type of this event. This describes the update process that
- * caused this event.
- *
- * @return the event's type
- */
- public int getType()
- {
- return type;
- }
-
- /**
* Returns a flag if this event was generated before or after an update.
*
* @return <b>true</b> if this event was generated before an update;