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