    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
    022 * event listeners.
    023 * </p>
    024 * <p>
    025 * Through the methods provided by this interface it is possible to register and
    026 * remove listeners for different events supported by this library. The event
    027 * type to be handled by a listener must be provided; the specified event listener
    028 * must be compatible with this event type. By using generic type parameters, the
    029 * compiler can check this.
    030 * </p>
    031 *
    032 * @since 2.0
    033 */
    034public interface EventSource
    035{
    036    /**
    037     * Adds an event listener for the specified event type. This listener is
    038     * notified about events of this type and all its sub types.
    039     *
    040     * @param eventType the event type (must not be <b>null</b>)
    041     * @param listener the listener to be registered (must not be <b>null</b>)
    042     * @param <T> the type of events processed by this listener
    043     * @throws IllegalArgumentException if a required parameter is <b>null</b>
    044     */
    045    <T extends Event> void addEventListener(EventType<T> eventType,
    046            EventListener<? super T> listener);
    047
    048    /**
    049     * Removes the event listener registration for the given event type and
    050     * listener. An event listener instance may be registered multiple times for
    051     * different event types. Therefore, when removing a listener the event type
    052     * of the registration in question has to be specified. The return value
    053     * indicates whether a registration was removed. A value of <b>false</b>
    054     * means that no such combination of event type and listener was found.
    055     *
    056     * @param eventType the event type
    057     * @param listener the event listener to be removed
    058     * @param <T> the type of events processed by this listener
    059     * @return a flag whether a listener registration was removed
    060     */
    061    <T extends Event> boolean removeEventListener(EventType<T> eventType,
    062            EventListener<? super T> listener);
    063}