KickJava   Java API By Example, From Geeks To Geeks.

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


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.TooManyListenersException JavaDoc;
21
22 /**
23  * The UnicastEventNotifier class provides basic callback listener management and event delivery
24  * services for unicast EventSets on ControlBean instances.
25  */

26 public class UnicastEventNotifier implements java.io.Serializable JavaDoc
27 {
28     /**
29      * Adds a new callback event listener for this EventNotifier. This method will also
30      * perform a check to see if there is already a register listener, and throw a
31      * <code>java.util.TooManyListenersException</code> if there is already a registered
32      * listener.
33      */

34     synchronized public void addListener(Object JavaDoc listener) throws TooManyListenersException JavaDoc
35     {
36         if (_listener != null)
37              throw new TooManyListenersException JavaDoc("Callback listener is already registered");
38         _listener = listener;
39     }
40
41     /**
42      * Remove an existing callback event listener for this EventNotifier
43      */

44     synchronized public void removeListener(Object JavaDoc listener)
45     {
46         if (_listener != listener)
47         {
48             throw new IllegalStateException JavaDoc("Invalid listener, not currently registered");
49         }
50         _listener = null;
51     }
52                                                                                                     
53     /**
54      * Returns the listener associated with this EventNotifier
55      */

56     public Object JavaDoc getListener()
57     {
58         return _listener;
59     }
60
61    /**
62      * Returns the number of registered listeners
63      */

64     public int getListenerCount()
65     {
66         return (_listener != null) ? 1 : 0;
67     }
68
69     /**
70      * Returns the listener list in array form
71      */

72     public void getListeners(Object JavaDoc [] listeners)
73     {
74         if (_listener != null)
75             listeners[0] = _listener;
76     }
77
78     private Object JavaDoc _listener;
79 }
80
Popular Tags