Class ConfigurationEvent
java.lang.Object
java.util.EventObject
org.apache.commons.configuration.event.ConfigurationEvent
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
ConfigurationErrorEvent
An event class for reporting updates on a configuration object.
Event objects of this type are used for "raw" events, i.e. unfiltered modifications of any kind. A level with semantically higher events (e.g. for property changes) may be built on top of this fundamental event mechanism.
Each event can contain the following data:
- A source object, which is usually the configuration object that was modified.
- The event's type. This is a numeric value that corresponds to constant declarations in concrete configuration classes. It describes what exactly has happended.
- If available, the name of the property whose modification caused the event.
- If available, the value of the property that caused this event.
- A flag whether this event was generated before or after the update of the source configuration. A modification of a configuration typically causes two events: one event before and one event after the modification is performed. This allows event listeners to react at the correct point of time.
The following standard events are generated by typical configuration
implementations (the constants for the event types are defined in
AbstractConfiguration
):
- EVENT_ADD_PROPERTY
- This event is triggered for each call of the
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). - EVENT_SET_PROPERTY
- Calling the
setProperty()
method triggers this event. The event object stores the name of the affected property and its new value. - EVENT_CLEAR_PROPERTY
- If a property is removed from a configuration (by calling the
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 null. - EVENT_CLEAR
- This event is fired when the whole configuration is cleared. The corresponding event object contains no additional data.
- Since:
- 1.3
- Version:
- $Id: ConfigurationEvent.java 1207610 2011-11-28 21:06:22Z oheger $
- Author:
- Commons Configuration team
- See Also:
-
Field Summary
Fields inherited from class java.util.EventObject
source
-
Constructor Summary
ConstructorsConstructorDescriptionConfigurationEvent
(Object source, int type, String propertyName, Object propertyValue, boolean beforeUpdate) Creates a new instance ofConfigurationEvent
and initializes it. -
Method Summary
Modifier and TypeMethodDescriptionReturns the name of the affected property.Returns the value of the affected property if available.int
getType()
Returns the type of this event.boolean
Returns a flag if this event was generated before or after an update.Methods inherited from class java.util.EventObject
getSource, toString
-
Constructor Details
-
ConfigurationEvent
public ConfigurationEvent(Object source, int type, String propertyName, Object propertyValue, boolean beforeUpdate) Creates a new instance ofConfigurationEvent
and initializes it.- Parameters:
source
- the event sourcetype
- the event's typepropertyName
- the name of the affected propertypropertyValue
- the value of the affected propertybeforeUpdate
- the before update flag
-
-
Method Details
-
getPropertyName
Returns the name of the affected property. This can be null if no property change has lead to this event.- Returns:
- the name of the property
-
getPropertyValue
Returns the value of the affected property if available.- Returns:
- the value of the property; can be null
-
getType
Returns the type of this event. This describes the update process that caused this event.- Returns:
- the event's type
-
isBeforeUpdate
Returns a flag if this event was generated before or after an update.- Returns:
- true if this event was generated before an update; false otherwise
-