KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > beans > beancontext > BeanContextMembershipEvent


1 /*
2  * @(#)BeanContextMembershipEvent.java 1.15 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package java.beans.beancontext;
9
10 import java.util.EventObject JavaDoc;
11
12 import java.beans.beancontext.BeanContext JavaDoc;
13 import java.beans.beancontext.BeanContextEvent JavaDoc;
14
15 import java.util.Arrays JavaDoc;
16 import java.util.Collection JavaDoc;
17 import java.util.Iterator JavaDoc;
18
19 /**
20  * A <code>BeanContextMembershipEvent</code> encapsulates
21  * the list of children added to, or removed from,
22  * the membership of a particular <code>BeanContext</code>.
23  * An instance of this event is fired whenever a successful
24  * add(), remove(), retainAll(), removeAll(), or clear() is
25  * invoked on a given <code>BeanContext</code> instance.
26  * Objects interested in receiving events of this type must
27  * implement the <code>BeanContextMembershipListener</code>
28  * interface, and must register their intent via the
29  * <code>BeanContext</code>'s
30  * <code>addBeanContextMembershipListener(BeanContextMembershipListener bcml)
31  * </code> method.
32  *
33  * @author Laurence P. G. Cable
34  * @version 1.15
35  * @since 1.2
36  * @see java.beans.beancontext.BeanContext
37  * @see java.beans.beancontext.BeanContextEvent
38  * @see java.beans.beancontext.BeanContextMembershipListener
39  */

40 public class BeanContextMembershipEvent extends BeanContextEvent JavaDoc {
41
42     /**
43      * Contruct a BeanContextMembershipEvent
44      *
45      * @param bc The BeanContext source
46      * @param changes The Children affected
47      * @throws NullPointerException if <CODE>changes</CODE> is <CODE>null</CODE>
48      */

49
50     public BeanContextMembershipEvent(BeanContext JavaDoc bc, Collection JavaDoc changes) {
51     super(bc);
52
53     if (changes == null) throw new NullPointerException JavaDoc(
54         "BeanContextMembershipEvent constructor: changes is null.");
55
56     children = changes;
57     }
58
59     /**
60      * Contruct a BeanContextMembershipEvent
61      *
62      * @param bc The BeanContext source
63      * @param changes The Children effected
64      * @exception NullPointerException if changes associated with this
65      * event are null.
66      */

67
68     public BeanContextMembershipEvent(BeanContext JavaDoc bc, Object JavaDoc[] changes) {
69     super(bc);
70
71     if (changes == null) throw new NullPointerException JavaDoc(
72         "BeanContextMembershipEvent: changes is null.");
73
74     children = Arrays.asList(changes);
75     }
76
77     /**
78      * Gets the number of children affected by the notification.
79      * @return the number of children affected by the notification
80      */

81     public int size() { return children.size(); }
82
83     /**
84      * Is the child specified affected by the event?
85      * @return <code>true</code> if affected, <code>false</code>
86      * if not
87      */

88     public boolean contains(Object JavaDoc child) {
89     return children.contains(child);
90     }
91
92     /**
93      * Gets the array of children affected by this event.
94      * @return the array of children affected
95      */

96     public Object JavaDoc[] toArray() { return children.toArray(); }
97
98     /**
99      * Gets the array of children affected by this event.
100      * @return the array of children effected
101      */

102     public Iterator JavaDoc iterator() { return children.iterator(); }
103
104     /*
105      * fields
106      */

107
108    /**
109     * The list of children affected by this
110     * event notification.
111     */

112     protected Collection JavaDoc children;
113 }
114
115
116
117
118
119
Popular Tags