textbender.g.beans.beancontext
Class ServiceRegistryCIU

java.lang.Object
  extended by java.beans.beancontext.BeanContextChildSupport
      extended by java.beans.beancontext.BeanContextSupport
          extended by java.beans.beancontext.BeanContextServicesSupport
              extended by ServiceRegistryCIU
All Implemented Interfaces:
BeanContext, BeanContextChild, BeanContextServiceRevokedListener, BeanContextServices, BeanContextServicesListener, DesignMode, PropertyChangeListener, VetoableChangeListener, Visibility, Serializable, Iterable, Collection, EventListener

public final class ServiceRegistryCIU
extends BeanContextServicesSupport

A simplified registry for childless, irrevocable and unique services. Service clients are not registered as BeanContextChildren, so services are 'childless'. Once registered, they may never be revoked. And service classes are unique; there is at most one instance of each.

Providers register each service by calling addSimpleService(). Clients listen for these registrations via addBeanContextServicesListener(), and subsequently fetch the services they need via getService().

Thread safe, though individual services are not (unless you know better).

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.beans.beancontext.BeanContextServicesSupport
BeanContextServicesSupport.BCSSChild, BeanContextServicesSupport.BCSSProxyServiceProvider, BeanContextServicesSupport.BCSSServiceProvider
 
Nested classes/interfaces inherited from class java.beans.beancontext.BeanContextSupport
BeanContextSupport.BCSChild, BeanContextSupport.BCSIterator
 
Field Summary
 
Fields inherited from class java.beans.beancontext.BeanContextServicesSupport
bcsListeners, proxy, serializable, services
 
Fields inherited from class java.beans.beancontext.BeanContextSupport
bcmListeners, children, designTime, locale, okToUseGui
 
Fields inherited from class java.beans.beancontext.BeanContextChildSupport
beanContext, beanContextChildPeer, pcSupport, rejectedSetBCOnce, vcSupport
 
Fields inherited from interface java.beans.beancontext.BeanContext
globalHierarchyLock
 
Fields inherited from interface java.beans.DesignMode
PROPERTYNAME
 
Constructor Summary
ServiceRegistryCIU()
           
 
Method Summary
 void addBeanContextServicesListener(BeanContextServicesListener listener, boolean fireUp)
          Registers a new bean context services listener.
 void addSimpleService(Class serviceClass, Object service)
          Adds a new service to the registry.
 Object getService(Class serviceClass)
          Returns a service previously added to the registry.
static ServiceRegistryCIU i()
          The common instance of ServiceRegistryCIU.
 void revokeService(Class serviceClass, BeanContextServiceProvider serviceProvider, boolean revokeCurrentServicesNow)
           
 
Methods inherited from class java.beans.beancontext.BeanContextServicesSupport
addBeanContextServicesListener, addService, addService, bcsPreDeserializationHook, bcsPreSerializationHook, childJustRemovedHook, createBCSChild, createBCSSServiceProvider, fireServiceAdded, fireServiceAdded, fireServiceRevoked, fireServiceRevoked, getBeanContextServicesPeer, getChildBeanContextServicesListener, getCurrentServiceClasses, getCurrentServiceSelectors, getService, hasService, initialize, initializeBeanContextResources, releaseBeanContextResources, releaseService, removeBeanContextServicesListener, serviceAvailable, serviceRevoked
 
Methods inherited from class java.beans.beancontext.BeanContextSupport
add, addAll, addBeanContextMembershipListener, avoidingGui, bcsChildren, childDeserializedHook, childJustAddedHook, classEquals, clear, contains, containsAll, containsKey, copyChildren, deserialize, dontUseGui, fireChildrenAdded, fireChildrenRemoved, getBeanContextPeer, getChildBeanContextChild, getChildBeanContextMembershipListener, getChildPropertyChangeListener, getChildSerializable, getChildVetoableChangeListener, getChildVisibility, getLocale, getResource, getResourceAsStream, instantiateChild, isDesignTime, isEmpty, isSerializing, iterator, needsGui, okToUseGui, propertyChange, readChildren, remove, remove, removeAll, removeBeanContextMembershipListener, retainAll, serialize, setDesignTime, setLocale, size, toArray, toArray, validatePendingAdd, validatePendingRemove, vetoableChange, writeChildren
 
Methods inherited from class java.beans.beancontext.BeanContextChildSupport
addPropertyChangeListener, addVetoableChangeListener, firePropertyChange, fireVetoableChange, getBeanContext, getBeanContextChildPeer, isDelegated, removePropertyChangeListener, removeVetoableChangeListener, setBeanContext, validatePendingSetBeanContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.beans.beancontext.BeanContext
addBeanContextMembershipListener, getResource, getResourceAsStream, instantiateChild, removeBeanContextMembershipListener
 
Methods inherited from interface java.beans.beancontext.BeanContextChild
addPropertyChangeListener, addVetoableChangeListener, getBeanContext, removePropertyChangeListener, removeVetoableChangeListener, setBeanContext
 
Methods inherited from interface java.util.Collection
add, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray
 
Methods inherited from interface java.beans.DesignMode
isDesignTime, setDesignTime
 
Methods inherited from interface java.beans.Visibility
avoidingGui, dontUseGui, needsGui, okToUseGui
 

Constructor Detail

ServiceRegistryCIU

public ServiceRegistryCIU()
Method Detail

i

public static ServiceRegistryCIU i()
The common instance of ServiceRegistryCIU. Other instances may be created, but one is enough for most purposes.


addBeanContextServicesListener

public void addBeanContextServicesListener(BeanContextServicesListener listener,
                                           boolean fireUp)
Registers a new bean context services listener.

Parameters:
listener - to register
fireUp - if true, listener is immediately fired up to the current state; otherwise it is not

addSimpleService

public void addSimpleService(Class serviceClass,
                             Object service)
Adds a new service to the registry. Once added, the service cannot be removed or revoked.

Parameters:
serviceClass - specifying the Java class of the service, or one of its parent classes/interfaces (for which the service will be the sole registrant)
service - instance that actually implements the service class (of which the service must be an instance)
Throws:
IllegalStateException - if a service was already added for that serviceClass

getService

public Object getService(Class serviceClass)
Returns a service previously added to the registry.

Parameters:
serviceClass - per addSimpleService()
Returns:
service; or null if none yet added to the registry

revokeService

public void revokeService(Class serviceClass,
                          BeanContextServiceProvider serviceProvider,
                          boolean revokeCurrentServicesNow)
Specified by:
revokeService in interface BeanContextServices
Overrides:
revokeService in class BeanContextServicesSupport