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.Iterator;
22: import java.util.LinkedList;
23:
24: /**
25: * The EventNotifier class provides basic callback listener management and event delivery
26: * services for ControlBean instances.
27: */
28: public class EventNotifier implements java.io.Serializable {
29: /**
30: * Adds a new callback event listener for this EventNotifier
31: */
32: synchronized public void addListener(Object listener) {
33: _listeners.add(listener);
34: }
35:
36: /**
37: * Remove an existing callback event listener for this EventNotifier
38: */
39: synchronized public void removeListener(Object listener) {
40: if (!_listeners.contains(listener))
41: throw new IllegalStateException(
42: "Invalid listener, not currently registered");
43:
44: _listeners.remove(listener);
45: }
46:
47: /**
48: * Returns an iterator over the full set of listeners
49: */
50: public Iterator listenerIterator() {
51: return _listeners.iterator();
52: }
53:
54: /**
55: * Returns the number of registered listeners
56: */
57: public int getListenerCount() {
58: return _listeners.size();
59: }
60:
61: /**
62: * Returns the listener list in array form
63: */
64: public void getListeners(Object[] listeners) {
65: _listeners.toArray(listeners);
66: }
67:
68: private LinkedList _listeners = new LinkedList();
69: }
|