01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: package org.apache.beehive.controls.runtime.bean;
20:
21: import java.util.TooManyListenersException;
22:
23: /**
24: * The UnicastEventNotifier class provides basic callback listener management and event delivery
25: * services for unicast EventSets on ControlBean instances.
26: */
27: public class UnicastEventNotifier implements java.io.Serializable {
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 listener)
35: throws TooManyListenersException {
36: if (_listener != null)
37: throw new TooManyListenersException(
38: "Callback listener is already registered");
39: _listener = listener;
40: }
41:
42: /**
43: * Remove an existing callback event listener for this EventNotifier
44: */
45: synchronized public void removeListener(Object listener) {
46: if (_listener != listener) {
47: throw new IllegalStateException(
48: "Invalid listener, not currently registered");
49: }
50: _listener = null;
51: }
52:
53: /**
54: * Returns the listener associated with this EventNotifier
55: */
56: public Object getListener() {
57: return _listener;
58: }
59:
60: /**
61: * Returns the number of registered listeners
62: */
63: public int getListenerCount() {
64: return (_listener != null) ? 1 : 0;
65: }
66:
67: /**
68: * Returns the listener list in array form
69: */
70: public void getListeners(Object[] listeners) {
71: if (_listener != null)
72: listeners[0] = _listener;
73: }
74:
75: private Object _listener;
76: }
|