001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *     http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.configuration2.event;
018
019/**
020 * <p>
021 * An interface for configuration implementations which support registration of event listeners.
022 * </p>
023 * <p>
024 * Through the methods provided by this interface it is possible to register and remove listeners for different events
025 * supported by this library. The event type to be handled by a listener must be provided; the specified event listener
026 * must be compatible with this event type. By using generic type parameters, the compiler can check this.
027 * </p>
028 *
029 * @since 2.0
030 */
031public interface EventSource {
032    /**
033     * Adds an event listener for the specified event type. This listener is notified about events of this type and all its
034     * sub types.
035     *
036     * @param eventType the event type (must not be <b>null</b>)
037     * @param listener the listener to be registered (must not be <b>null</b>)
038     * @param <T> the type of events processed by this listener
039     * @throws IllegalArgumentException if a required parameter is <b>null</b>
040     */
041    <T extends Event> void addEventListener(EventType<T> eventType, EventListener<? super T> listener);
042
043    /**
044     * Removes the event listener registration for the given event type and listener. An event listener instance may be
045     * registered multiple times for different event types. Therefore, when removing a listener the event type of the
046     * registration in question has to be specified. The return value indicates whether a registration was removed. A value
047     * of <b>false</b> means that no such combination of event type and listener was found.
048     *
049     * @param eventType the event type
050     * @param listener the event listener to be removed
051     * @param <T> the type of events processed by this listener
052     * @return a flag whether a listener registration was removed
053     */
054    <T extends Event> boolean removeEventListener(EventType<T> eventType, EventListener<? super T> listener);
055}