KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > controls > runtime > bean > EventNotifier


1 package org.apache.beehive.controls.runtime.bean;
2 /*
3  * Copyright 2004 The Apache Software Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * $Header:$
18  */

19
20 import java.util.ArrayList JavaDoc;
21 import java.util.Iterator JavaDoc;
22
23 /**
24  * The EventNotifier class provides basic callback listener management and event delivery
25  * services for ControlBean instances.
26  */

27 public class EventNotifier implements java.io.Serializable JavaDoc
28 {
29     /**
30      * Adds a new callback event listener for this EventNotifier
31      */

32     synchronized public void addListener(Object JavaDoc listener)
33     {
34         _listeners.add(listener);
35     }
36
37     /**
38      * Remove an existing callback event listener for this EventNotifier
39      */

40     synchronized public void removeListener(Object JavaDoc listener)
41     {
42         if (!_listeners.contains(listener))
43             throw new IllegalStateException JavaDoc("Invalid listener, not currently registered");
44
45         _listeners.remove(listener);
46     }
47
48     /**
49      * Returns an iterator over the full set of listeners
50      */

51     public Iterator JavaDoc listenerIterator()
52     {
53         return _listeners.iterator();
54     }
55
56     /**
57      * Returns the number of registered listeners
58      */

59     public int getListenerCount()
60     {
61         return _listeners.size();
62     }
63
64     /**
65      * Returns the listener list in array form
66      */

67     public void getListeners(Object JavaDoc [] listeners)
68     {
69         _listeners.toArray(listeners);
70     }
71
72     private ArrayList JavaDoc _listeners = new ArrayList JavaDoc();
73 }
74
Popular Tags