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 * @version $Id: EventSource.java 1678629 2015-05-10 20:19:08Z oheger $ 033 * @since 2.0 034 */ 035public interface EventSource 036{ 037 /** 038 * Adds an event listener for the specified event type. This listener is 039 * notified about events of this type and all its sub types. 040 * 041 * @param eventType the event type (must not be <b>null</b>) 042 * @param listener the listener to be registered (must not be <b>null</b>) 043 * @param <T> the type of events processed by this listener 044 * @throws IllegalArgumentException if a required parameter is <b>null</b> 045 */ 046 <T extends Event> void addEventListener(EventType<T> eventType, 047 EventListener<? super T> listener); 048 049 /** 050 * Removes the event listener registration for the given event type and 051 * listener. An event listener instance may be registered multiple times for 052 * different event types. Therefore, when removing a listener the event type 053 * of the registration in question has to be specified. The return value 054 * indicates whether a registration was removed. A value of <b>false</b> 055 * means that no such combination of event type and listener was found. 056 * 057 * @param eventType the event type 058 * @param listener the event listener to be removed 059 * @param <T> the type of events processed by this listener 060 * @return a flag whether a listener registration was removed 061 */ 062 <T extends Event> boolean removeEventListener(EventType<T> eventType, 063 EventListener<? super T> listener); 064}