1. /*
  2. * @(#)BeanContextChild.java 1.20 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.beans.PropertyChangeListener;
  9. import java.beans.VetoableChangeListener;
  10. import java.beans.PropertyVetoException;
  11. import java.beans.beancontext.BeanContext;
  12. /**
  13. * <p>
  14. * JavaBeans wishing to be nested within, and obtain a reference to their
  15. * execution environment, or context, as defined by the BeanContext
  16. * sub-interface shall implement this interface.
  17. * </p>
  18. * <p>
  19. * Conformant BeanContexts shall as a side effect of adding a BeanContextChild
  20. * object shall pass a reference to itself via the setBeanContext() method of
  21. * this interface.
  22. * </p>
  23. * <p>
  24. * Note that a BeanContextChild may refuse a change in state by throwing
  25. * PropertyVetoedException in response.
  26. * </p>
  27. * <p>
  28. * In order for persistence mechanisms to function properly on BeanContextChild
  29. * instances across a broad variety of scenarios, implementing classes of this
  30. * interface are required to define as transient, any or all fields, or
  31. * instance variables, that may contain, or represent, references to the
  32. * nesting BeanContext instance or other resources obtained
  33. * from the BeanContext via any unspecified mechanisms.
  34. * </p>
  35. *
  36. * @author Laurence P. G. Cable
  37. * @version 1.20, 12/19/03
  38. * @since 1.2
  39. *
  40. * @see java.beans.beancontext.BeanContext
  41. * @see java.beans.PropertyChangeEvent
  42. * @see java.beans.PropertyChangeListener
  43. * @see java.beans.PropertyVetoEvent
  44. * @see java.beans.PropertyVetoListener
  45. * @see java.beans.PropertyVetoException
  46. */
  47. public interface BeanContextChild {
  48. /**
  49. * <p>
  50. * Objects that implement this interface,
  51. * shall fire a java.beans.PropertyChangeEvent, with parameters:
  52. *
  53. * propertyName "beanContext", oldValue (the previous nesting
  54. * <code>BeanContext</code> instance, or <code>null</code>),
  55. * newValue (the current nesting
  56. * <code>BeanContext</code> instance, or <code>null</code>).
  57. * <p>
  58. * A change in the value of the nesting BeanContext property of this
  59. * BeanContextChild may be vetoed by throwing the appropriate exception.
  60. * </p>
  61. * @param bc The <code>BeanContext</code> with which
  62. * to associate this <code>BeanContextChild</code>.
  63. * @throws <code>PropertyVetoException</code> if the
  64. * addition of the specified <code>BeanContext</code> is refused.
  65. */
  66. void setBeanContext(BeanContext bc) throws PropertyVetoException;
  67. /**
  68. * Gets the <code>BeanContext</code> associated
  69. * with this <code>BeanContextChild</code>.
  70. * @return the <code>BeanContext</code> associated
  71. * with this <code>BeanContextChild</code>.
  72. */
  73. BeanContext getBeanContext();
  74. /**
  75. * Adds a <code>PropertyChangeListener</code>
  76. * to this <code>BeanContextChild</code>
  77. * in order to receive a <code>PropertyChangeEvent</code>
  78. * whenever the specified property has changed.
  79. * @param name the name of the property to listen on
  80. * @param pcl the <code>PropertyChangeListener</code> to add
  81. */
  82. void addPropertyChangeListener(String name, PropertyChangeListener pcl);
  83. /**
  84. * Removes a <code>PropertyChangeListener</code> from this
  85. * <code>BeanContextChild</code> so that it no longer
  86. * receives <code>PropertyChangeEvents</code> when the
  87. * specified property is changed.
  88. *
  89. * @param name the name of the property that was listened on
  90. * @param pcl the <code>PropertyChangeListener</code> to remove
  91. */
  92. void removePropertyChangeListener(String name, PropertyChangeListener pcl);
  93. /**
  94. * Adds a <code>VetoableChangeListener</code> to
  95. * this <code>BeanContextChild</code>
  96. * to receive events whenever the specified property changes.
  97. * @param name the name of the property to listen on
  98. * @param vcl the <code>VetoableChangeListener</code> to add
  99. */
  100. void addVetoableChangeListener(String name, VetoableChangeListener vcl);
  101. /**
  102. * Removes a <code>VetoableChangeListener</code> from this
  103. * <code>BeanContextChild</code> so that it no longer receives
  104. * events when the specified property changes.
  105. * @param name the name of the property that was listened on.
  106. * @param vcl the <code>VetoableChangeListener</code> to remove.
  107. */
  108. void removeVetoableChangeListener(String name, VetoableChangeListener vcl);
  109. }