java.lang.Object | +--java.util.EventListener | +--java.beans.beancontext.BeanContextServiceRevokedListener | +--java.beans.beancontext.BeanContextServicesListener | +--java.beans.beancontext.BeanContextServicesAll Implemented Interfaces:
void | addBeanContextServicesListener(java.beans.beancontext.BeanContextServicesListener listener) Add a listener on all adds and removes of services. |
boolean | addService(java.lang.Class serviceClass, java.beans.beancontext.BeanContextServiceProvider provider) Register a service to make it available to others. |
java.util.Iterator | getCurrentServiceClasses() Get a list of all service classes supported. |
java.util.Iterator | getCurrentServiceSelectors(java.lang.Class serviceClass) Get a list of valid service selectors for the specified service class. |
java.lang.Object | getService(java.beans.beancontext.BeanContextChild requestorChild, java.lang.Object requestor, java.lang.Class serviceClass, java.lang.Object serviceSelector, java.beans.beancontext.BeanContextServiceRevokedListener listener) Get a service from this |
boolean | hasService(java.lang.Class serviceClass) Tell whether the specified service class is available. |
void | releaseService(java.beans.beancontext.BeanContextChild requestorChild, java.lang.Object requestor, java.lang.Object service) Release your copy of this service. |
void | removeBeanContextServicesListener(java.beans.beancontext.BeanContextServicesListener listener) Remove a listener on all adds and removes of services. |
void | revokeService(java.lang.Class serviceClass, java.beans.beancontext.BeanContextServiceProvider provider, boolean revokeNow) Make it so that no one else can use this service. |
public void addBeanContextServicesListener(java.beans.beancontext.BeanContextServicesListener listener)
listener
- the listener to add.public boolean addService(java.lang.Class serviceClass, java.beans.beancontext.BeanContextServiceProvider provider)
serviceClass
- the service class.provider
- the factory that will actually provide the service.public Iterator getCurrentServiceClasses()
This method must synchronize on
BeanContext.globalHierarchyLock
.
public Iterator getCurrentServiceSelectors(java.lang.Class serviceClass)
If the specified service class does not have a finite number of
valid service selectors, it should return null
.
If it takes a general Integer
parameter, for
example, you may as well return null
or the poor
soul who called this method will be iterating all day.
If it has no valid service selectors, it should still return an empty
Iterator
.
serviceClass
- the service class to get selectors for.null
.public Object getService(java.beans.beancontext.BeanContextChild requestorChild, java.lang.Object requestor, java.lang.Class serviceClass, java.lang.Object serviceSelector, java.beans.beancontext.BeanContextServiceRevokedListener listener)
BeanContextServices
.
The specified listener will be registered to receive a revocation notice for the specified serviceClass. One notification per service class per requestor object will be sent.
The listener will be unregistered when all services that were obtained by that requestor for that service class are released.
If the requested service class is not available, or if this
BeanContextServices
object chooses not honor the
request because the service class has been revoked or for some
other reason, then this method will return null
.
This method may throw unchecked exceptions, so watch out.
requestorChild
- the BeanContextChild
associated with the requestor.requestor
- the actual requestor of the service.serviceClass
- the Class
of the service being
requested.serviceSelector
- a parameter to customize the service
returned with.listener
- a listener that will be notified if the service
being requested is revoked.serviceClass
(such that
instanceof
serviceClass is true), or
null
.public boolean hasService(java.lang.Class serviceClass)
true
.
serviceClass
- the service class to check on.public void releaseService(java.beans.beancontext.BeanContextChild requestorChild, java.lang.Object requestor, java.lang.Object service)
If all copies of the service's class have been relinquished by
the requestor, the BeanContextServiceRevokedListener
previously registered by getService()
will be
unregistered.
requestorChild
- the original BeanContextChild
requesting the service.requestor
- the original requestor of the service.service
- the service to relinquishpublic void removeBeanContextServicesListener(java.beans.beancontext.BeanContextServicesListener listener)
listener
- the listener to add.public void revokeService(java.lang.Class serviceClass, java.beans.beancontext.BeanContextServiceProvider provider, boolean revokeNow)
If revokeNow
is false
, the only
effect of this method is to make all subsequent calls to
getService()
on this service class fail.
If it is true
, a message is also sent out to all
listeners on the service and all references to it are released.
serviceClass
- the service class to revoke.provider
- the service provider providing the service class.revokeNow
- whether to release all current references to
the service.
BeanContext
to provide services to its children.