1. /*
  2. * @(#)BeanContextServices.java 1.6 00/02/02
  3. *
  4. * Copyright 1998-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.Iterator;
  12. import java.util.TooManyListenersException;
  13. import java.beans.beancontext.BeanContext;
  14. import java.beans.beancontext.BeanContextServiceProvider;
  15. import java.beans.beancontext.BeanContextServicesListener;
  16. /**
  17. * <p>
  18. * The BeanContextServices interface provides a mechanism for a BeanContext
  19. * to expose generic "services" to the BeanContextChild objects within.
  20. * </p>
  21. */
  22. public interface BeanContextServices extends BeanContext, BeanContextServicesListener {
  23. /**
  24. * Adds a service to this BeanContext.
  25. * <code>BeanContextServiceProvider</code>s call this method
  26. * to register a particular service with this context.
  27. * If the service has not previously been added, the
  28. * <code>BeanContextServices</code> associates
  29. * the service with the <code>BeanContextServiceProvider</code> and
  30. * fires a <code>BeanContextServiceAvailableEvent</code> to all
  31. * currently registered <code>BeanContextServicesListeners</code>.
  32. * The method then returns <code>true</code>, indicating that
  33. * the addition of the service was successful.
  34. * If the given service has already been added, this method
  35. * simply returns <code>false</code>.
  36. * @param <code>serviceClass</code> the service to add
  37. * @param serviceProvider the <code>BeanContextServiceProvider</code>
  38. * associated with the service
  39. */
  40. boolean addService(Class serviceClass, BeanContextServiceProvider serviceProvider);
  41. /**
  42. * BeanContextServiceProviders wishing to remove
  43. * a currently registered service from this context
  44. * may do so via invocation of this method. Upon revocation of
  45. * the service, the <code>BeanContextServices</code> fires a
  46. * <code>BeanContextServiceRevokedEvent</code> to its
  47. * list of currently registered
  48. * <code>BeanContextServiceRevokedListeners</code> and
  49. * <code>BeanContextServicesListeners</code>.
  50. * @param serviceClass the service to revoke from this BeanContextServices
  51. * @param serviceProvider the BeanContextServiceProvider associated with
  52. * this particular service that is being revoked
  53. * @param revokeCurrentServicesNow a value of <code>true</code>
  54. * indicates an exceptional circumstance where the
  55. * <code>BeanContextServiceProvider</code> or
  56. * <code>BeanContextServices</code> wishes to immediately
  57. * terminate service to all currently outstanding references
  58. * to the specified service.
  59. */
  60. void revokeService(Class serviceClass, BeanContextServiceProvider serviceProvider, boolean revokeCurrentServicesNow);
  61. /**
  62. * Reports whether or not a given service is
  63. * currently available from this context.
  64. * @param serviceClass the service in question
  65. * @return true if the service is available
  66. */
  67. boolean hasService(Class serviceClass);
  68. /**
  69. * A <code>BeanContextChild</code>, or any arbitrary object
  70. * associated with a <code>BeanContextChild</code>, may obtain
  71. * a reference to a currently registered service from its
  72. * nesting <code>BeanContextServices</code>
  73. * via invocation of this method. When invoked, this method
  74. * gets the service by calling the getService() method on the
  75. * underlying <code>BeanContextServiceProvider</code>.
  76. * @param child the <code>BeanContextChild</code>
  77. * associated with this request
  78. * @param requestor the object requesting the service
  79. * @param serviceClass class of the requested service
  80. * @param serviceSelector the service dependent parameter
  81. * @param bcsrl the
  82. * <code>BeanContextServiceRevokedListener</code> to notify
  83. * if the service should later become revoked
  84. * @throws TooManyListenersException
  85. * @return a reference to this context's named
  86. * Service as requested or <code>null</code>
  87. */
  88. Object getService(BeanContextChild child, Object requestor, Class serviceClass, Object serviceSelector, BeanContextServiceRevokedListener bcsrl) throws TooManyListenersException;
  89. /**
  90. * Releases a <code>BeanContextChild</code>'s
  91. * (or any arbitrary object associated with a BeanContextChild)
  92. * reference to the specified service by calling releaseService()
  93. * on the underlying <code>BeanContextServiceProvider</code>.
  94. * @param child the <code>BeanContextChild</code>
  95. * @param requestor the requestor
  96. * @param service the service
  97. */
  98. void releaseService(BeanContextChild child, Object requestor, Object service);
  99. /**
  100. * Gets the currently available services for this context.
  101. * @return an <code>Iterator</code> consisting of the
  102. * currently available services
  103. */
  104. Iterator getCurrentServiceClasses();
  105. /**
  106. * Gets the list of service dependent service parameters
  107. * (Service Selectors) for the specified service, by
  108. * calling getCurrentServiceSelectors() on the
  109. * underlying BeanContextServiceProvider.
  110. * @param serviceClass the specified service
  111. * @return the currently available service selectors
  112. * for the named serviceClass
  113. */
  114. Iterator getCurrentServiceSelectors(Class serviceClass);
  115. /**
  116. * Adds a <code>BeanContextServicesListener</code> to this BeanContext
  117. * @param bcsl the <code>BeanContextServicesListener</code> to add
  118. */
  119. void addBeanContextServicesListener(BeanContextServicesListener bcsl);
  120. /**
  121. * Removes a <code>BeanContextServicesListener</code>
  122. * from this <code>BeanContext</code>
  123. * @param bcsl the <code>BeanContextServicesListener</code>
  124. * to remove from this context
  125. */
  126. void removeBeanContextServicesListener(BeanContextServicesListener bcsl);
  127. }