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. package java.beans.beancontext;
  8. import java.util.EventObject;
  9. import java.beans.beancontext.BeanContext;
  10. import java.beans.beancontext.BeanContextEvent;
  11. import java.util.Arrays;
  12. import java.util.Collection;
  13. import java.util.Iterator;
  14. /**
  15. * A <code>BeanContextMembershipEvent</code> encapsulates
  16. * the list of children added to, or removed from,
  17. * the membership of a particular <code>BeanContext</code>.
  18. * An instance of this event is fired whenever a successful
  19. * add(), remove(), retainAll(), removeAll(), or clear() is
  20. * invoked on a given <code>BeanContext</code> instance.
  21. * Objects interested in receiving events of this type must
  22. * implement the <code>BeanContextMembershipListener</code>
  23. * interface, and must register their intent via the
  24. * <code>BeanContext</code>'s
  25. * <code>addBeanContextMembershipListener(BeanContextMembershipListener bcml)
  26. * </code> method.
  27. *
  28. * @author Laurence P. G. Cable
  29. * @version 1.15
  30. * @since 1.2
  31. * @see java.beans.beancontext.BeanContext
  32. * @see java.beans.beancontext.BeanContextEvent
  33. * @see java.beans.beancontext.BeanContextMembershipListener
  34. */
  35. public class BeanContextMembershipEvent extends BeanContextEvent {
  36. /**
  37. * Contruct a BeanContextMembershipEvent
  38. *
  39. * @param bc The BeanContext source
  40. * @param changes The Children affected
  41. * @throws NullPointerException if <CODE>changes</CODE> is <CODE>null</CODE>
  42. */
  43. public BeanContextMembershipEvent(BeanContext bc, Collection changes) {
  44. super(bc);
  45. if (changes == null) throw new NullPointerException(
  46. "BeanContextMembershipEvent constructor: changes is null.");
  47. children = changes;
  48. }
  49. /**
  50. * Contruct a BeanContextMembershipEvent
  51. *
  52. * @param bc The BeanContext source
  53. * @param changes The Children effected
  54. * @exception NullPointerException if changes associated with this
  55. * event are null.
  56. */
  57. public BeanContextMembershipEvent(BeanContext bc, Object[] changes) {
  58. super(bc);
  59. if (changes == null) throw new NullPointerException(
  60. "BeanContextMembershipEvent: changes is null.");
  61. children = Arrays.asList(changes);
  62. }
  63. /**
  64. * Gets the number of children affected by the notification.
  65. * @return the number of children affected by the notification
  66. */
  67. public int size() { return children.size(); }
  68. /**
  69. * Is the child specified affected by the event?
  70. * @return <code>true</code> if affected, <code>false</code>
  71. * if not
  72. */
  73. public boolean contains(Object child) {
  74. return children.contains(child);
  75. }
  76. /**
  77. * Gets the array of children affected by this event.
  78. * @return the array of children affected
  79. */
  80. public Object[] toArray() { return children.toArray(); }
  81. /**
  82. * Gets the array of children affected by this event.
  83. * @return the array of children effected
  84. */
  85. public Iterator iterator() { return children.iterator(); }
  86. /*
  87. * fields
  88. */
  89. /**
  90. * The list of children affected by this
  91. * event notification.
  92. */
  93. protected Collection children;
  94. }