Author: oheger
Date: Wed Aug  5 20:31:01 2009
New Revision: 801402

URL: http://svn.apache.org/viewvc?rev=801402&view=rev
Log:
Added an event listener interface for configuration sources.

Added:
    
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/base/ConfigurationSourceEvent.java
   (with props)
    
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/base/ConfigurationSourceListener.java
   (with props)

Added: 
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/base/ConfigurationSourceEvent.java
URL: 
http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/base/ConfigurationSourceEvent.java?rev=801402&view=auto
==============================================================================
--- 
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/base/ConfigurationSourceEvent.java
 (added)
+++ 
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/base/ConfigurationSourceEvent.java
 Wed Aug  5 20:31:01 2009
@@ -0,0 +1,174 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.configuration2.base;
+
+import java.util.EventObject;
+
+/**
+ * <p>
+ * An event class for reporting changes on a {...@link ConfigurationSource}.
+ * </p>
+ * <p>
+ * Events of this type are generated by modifications on
+ * {...@link ConfigurationSource} objects. They allow interested listeners to 
keep
+ * track on changes of a source. Each event can contain the following data:
+ * <ul>
+ * <li>A source object, which is usually the {...@code ConfigurationSource} 
object
+ * that was modified.</li>
+ * <li>The event's type. This is a constant of the nested {...@code Type}
+ * enumeration class. It describes the nature of the current change.</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>
+ * <li>An additional object with information specific to a concrete
+ * implementation of {...@link ConfigurationSource}.</li>
+ * <li>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.</li>
+ * </ul>
+ * </p>
+ *
+ * @author Commons Configuration team
+ * @version $Id$
+ */
+public class ConfigurationSourceEvent extends EventObject
+{
+    /**
+     * The serial version UID.
+     */
+    private static final long serialVersionUID = -2061962830139289603L;
+
+    /** Stores the property name. */
+    private final String propertyName;
+
+    /** Stores the property value. */
+    private final Object propertyValue;
+
+    /** The type of this event. */
+    private final Type type;
+
+    /** An object with additional data. */
+    private final Object data;
+
+    /** Stores the before update flag. */
+    private final boolean beforeUpdate;
+
+    /**
+     * Creates a new instance of {...@code ConfigurationSourceEvent} and
+     * initializes it.
+     *
+     * @param source the source of this event
+     * @param type the event type
+     * @param name the name of the affected property
+     * @param value the value of the affected property if available
+     * @param data additional data
+     * @param before a flag whether this event was triggered before
+     *        (<b>true</b>) or after (<b>false</b>) the actual modification
+     */
+    public ConfigurationSourceEvent(Object source, Type type, String name,
+            Object value, Object data, boolean before)
+    {
+        super(source);
+        this.type = type;
+        propertyName = name;
+        propertyValue = value;
+        this.data = data;
+        beforeUpdate = before;
+    }
+
+    /**
+     * Returns the name of the property affected by this event. This 
information
+     * is available for all event types related to properties.
+     *
+     * @return the name of the affected property
+     */
+    public String getPropertyName()
+    {
+        return propertyName;
+    }
+
+    /**
+     * Returns the value of the property affected by this event. This
+     * information is available only for some event types: If a new property is
+     * added or the value of a property is changed, the new value is returned.
+     *
+     * @return the value of the affected property
+     */
+    public Object getPropertyValue()
+    {
+        return propertyValue;
+    }
+
+    /**
+     * Returns the type of this event. The type determines in which way the
+     * {...@link ConfigurationSource} was manipulated.
+     *
+     * @return the event type
+     */
+    public Type getType()
+    {
+        return type;
+    }
+
+    /**
+     * Returns additional data about this event. The object returned by this
+     * method is specific for a concrete implementation of
+     * {...@link ConfigurationSource}. Some implementations may be able to 
provide
+     * interesting data related to the event.
+     *
+     * @return additional data about this event
+     */
+    public Object getData()
+    {
+        return data;
+    }
+
+    /**
+     * Returns a flag whether this event was generated before or after an
+     * update.
+     *
+     * @return <b>true</b> if this event was generated before an update;
+     *         <b>false</b> otherwise
+     */
+    public boolean isBeforeUpdate()
+    {
+        return beforeUpdate;
+    }
+
+    /**
+     * An enumeration class defining the event types supported by configuration
+     * sources. The constants defined by this class can appear in the {...@code
+     * type} property of {...@code ConfigurationSourceEvent} objects.
+     *
+     * @author Commons Configuration team
+     * @version $Id$
+     */
+    public enum Type {
+        /** A property was added to a {...@code ConfigurationSource}. */
+        ADD_PROPERTY,
+
+        /** The value of a property was changed. */
+        MODIFY_PROPERTY,
+
+        /** A property was removed from a {...@code ConfigurationSource}. */
+        CLEAR_PROPERTY,
+
+        /** The source was cleared. */
+        CLEAR_SOURCE
+    }
+}

Propchange: 
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/base/ConfigurationSourceEvent.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/base/ConfigurationSourceEvent.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: 
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/base/ConfigurationSourceEvent.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: 
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/base/ConfigurationSourceListener.java
URL: 
http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/base/ConfigurationSourceListener.java?rev=801402&view=auto
==============================================================================
--- 
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/base/ConfigurationSourceListener.java
 (added)
+++ 
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/base/ConfigurationSourceListener.java
 Wed Aug  5 20:31:01 2009
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.configuration2.base;
+
+import java.util.EventListener;
+
+/**
+ * <p>
+ * An event listener interface to be implemented by observers of
+ * {...@link ConfigurationSource} objects.
+ * </p>
+ * <p>
+ * This interface defines a callback method that is invoked on each 
manipulation
+ * of a {...@link ConfigurationSource}. It allows interested components to keep
+ * track on the changes of a {...@link ConfigurationSource}. The exact nature 
of
+ * the change can be determined by inspecting the
+ * {...@link ConfigurationSourceEvent} object passed to the event listener 
method.
+ * </p>
+ *
+ * @author Commons Configuration team
+ * @version $Id$
+ * @see ConfigurationSourceEvent
+ */
+public interface ConfigurationSourceListener extends EventListener
+{
+    /**
+     * Notifies this listener about a change on a monitored
+     * {...@link ConfigurationSource} object.
+     *
+     * @param event the event describing the change
+     */
+    void configurationSourceChanged(ConfigurationSourceEvent event);
+}

Propchange: 
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/base/ConfigurationSourceListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/base/ConfigurationSourceListener.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: 
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/base/ConfigurationSourceListener.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain


Reply via email to