J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 1997-2004 Sun Microsystems, Inc. All Rights Reserved. |
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 only, as |
| 7 | * published by the Free Software Foundation. Sun designates this |
| 8 | * particular file as subject to the "Classpath" exception as provided |
| 9 | * by Sun in the LICENSE file that accompanied this code. |
| 10 | * |
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 14 | * version 2 for more details (a copy is included in the LICENSE file that |
| 15 | * accompanied this code). |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License version |
| 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | * |
| 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 22 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 23 | * have any questions. |
| 24 | */ |
| 25 | |
| 26 | package java.beans.beancontext; |
| 27 | |
| 28 | import java.util.EventObject; |
| 29 | |
| 30 | import java.beans.beancontext.BeanContext; |
| 31 | import java.beans.beancontext.BeanContextEvent; |
| 32 | |
| 33 | import java.util.Arrays; |
| 34 | import java.util.Collection; |
| 35 | import java.util.Iterator; |
| 36 | |
| 37 | /** |
| 38 | * A <code>BeanContextMembershipEvent</code> encapsulates |
| 39 | * the list of children added to, or removed from, |
| 40 | * the membership of a particular <code>BeanContext</code>. |
| 41 | * An instance of this event is fired whenever a successful |
| 42 | * add(), remove(), retainAll(), removeAll(), or clear() is |
| 43 | * invoked on a given <code>BeanContext</code> instance. |
| 44 | * Objects interested in receiving events of this type must |
| 45 | * implement the <code>BeanContextMembershipListener</code> |
| 46 | * interface, and must register their intent via the |
| 47 | * <code>BeanContext</code>'s |
| 48 | * <code>addBeanContextMembershipListener(BeanContextMembershipListener bcml) |
| 49 | * </code> method. |
| 50 | * |
| 51 | * @author Laurence P. G. Cable |
| 52 | * @since 1.2 |
| 53 | * @see java.beans.beancontext.BeanContext |
| 54 | * @see java.beans.beancontext.BeanContextEvent |
| 55 | * @see java.beans.beancontext.BeanContextMembershipListener |
| 56 | */ |
| 57 | public class BeanContextMembershipEvent extends BeanContextEvent { |
| 58 | |
| 59 | /** |
| 60 | * Contruct a BeanContextMembershipEvent |
| 61 | * |
| 62 | * @param bc The BeanContext source |
| 63 | * @param changes The Children affected |
| 64 | * @throws NullPointerException if <CODE>changes</CODE> is <CODE>null</CODE> |
| 65 | */ |
| 66 | |
| 67 | public BeanContextMembershipEvent(BeanContext bc, Collection changes) { |
| 68 | super(bc); |
| 69 | |
| 70 | if (changes == null) throw new NullPointerException( |
| 71 | "BeanContextMembershipEvent constructor: changes is null."); |
| 72 | |
| 73 | children = changes; |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Contruct a BeanContextMembershipEvent |
| 78 | * |
| 79 | * @param bc The BeanContext source |
| 80 | * @param changes The Children effected |
| 81 | * @exception NullPointerException if changes associated with this |
| 82 | * event are null. |
| 83 | */ |
| 84 | |
| 85 | public BeanContextMembershipEvent(BeanContext bc, Object[] changes) { |
| 86 | super(bc); |
| 87 | |
| 88 | if (changes == null) throw new NullPointerException( |
| 89 | "BeanContextMembershipEvent: changes is null."); |
| 90 | |
| 91 | children = Arrays.asList(changes); |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * Gets the number of children affected by the notification. |
| 96 | * @return the number of children affected by the notification |
| 97 | */ |
| 98 | public int size() { return children.size(); } |
| 99 | |
| 100 | /** |
| 101 | * Is the child specified affected by the event? |
| 102 | * @return <code>true</code> if affected, <code>false</code> |
| 103 | * if not |
| 104 | */ |
| 105 | public boolean contains(Object child) { |
| 106 | return children.contains(child); |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * Gets the array of children affected by this event. |
| 111 | * @return the array of children affected |
| 112 | */ |
| 113 | public Object[] toArray() { return children.toArray(); } |
| 114 | |
| 115 | /** |
| 116 | * Gets the array of children affected by this event. |
| 117 | * @return the array of children effected |
| 118 | */ |
| 119 | public Iterator iterator() { return children.iterator(); } |
| 120 | |
| 121 | /* |
| 122 | * fields |
| 123 | */ |
| 124 | |
| 125 | /** |
| 126 | * The list of children affected by this |
| 127 | * event notification. |
| 128 | */ |
| 129 | protected Collection children; |
| 130 | } |