Richard S. Hall | 930fecc | 2005-08-16 18:33:34 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2005 The Apache Software Foundation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | * |
| 16 | */ |
| 17 | package org.apache.osgi.framework.util; |
| 18 | |
| 19 | import java.util.EventListener; |
| 20 | import java.util.EventObject; |
| 21 | |
| 22 | /** |
| 23 | * This interface is used by <tt>DispatchQueue</tt> to dispatch events. |
| 24 | * Generally speaking, each type of event to dispatch will have an instance |
| 25 | * of a <tt>Dispatcher</tt> so that the dispatch queue can dispatch to |
| 26 | * the appropriate listener method for the specific listener type, |
| 27 | * for example: |
| 28 | * <pre> |
| 29 | * Dispatcher d = new Dispatcher() { |
| 30 | * public void dispatch(EventListener l, EventObject eventObj) |
| 31 | * { |
| 32 | * ((FooListener) l).fooXXX((FooEvent) eventObj); |
| 33 | * } |
| 34 | * }; |
| 35 | * FooEvent event = new FooEvent(this); |
| 36 | * dispatchQueue.dispatch(d, FooListener.class, event); |
| 37 | * </pre> |
| 38 | * In the above code substitute a specific listener and event for the |
| 39 | * <tt>Foo</tt> listener and event. <tt>Dispatcher</tt>s can be reused, so |
| 40 | * it is a good idea to cache them to avoid unnecessary memory allocations. |
| 41 | **/ |
| 42 | public interface Dispatcher |
| 43 | { |
| 44 | /** |
| 45 | * Dispatch an event to a specified event listener. |
| 46 | * |
| 47 | * @param l the event listener to receive the event. |
| 48 | * @param eventObj the event to dispatch. |
| 49 | **/ |
| 50 | public void dispatch(EventListener l, EventObject eventObj); |
| 51 | } |