- java.lang.Object
-
- java.beans.beancontext.BeanContextChildSupport
-
- java.beans.beancontext.BeanContextSupport
-
- java.beans.beancontext.BeanContextServicesSupport
-
- All Implemented Interfaces:
BeanContext
,BeanContextChild
,BeanContextServiceRevokedListener
,BeanContextServices
,BeanContextServicesListener
,DesignMode
,PropertyChangeListener
,VetoableChangeListener
,Visibility
,Serializable
,Iterable<E>
,Collection
,EventListener
public class BeanContextServicesSupport extends BeanContextSupport implements BeanContextServices
This helper class provides a utility implementation of the java.beans.beancontext.BeanContextServices interface.
Since this class directly implements the BeanContextServices interface, the class can, and is intended to be used either by subclassing this implementation, or via delegation of an instance of this class from another through the BeanContextProxy interface.
- Since:
- 1.2
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
BeanContextServicesSupport.BCSSChild
protected class
BeanContextServicesSupport.BCSSProxyServiceProvider
protected static class
BeanContextServicesSupport.BCSSServiceProvider
subclasses may subclass this nested class to add behaviors for each BeanContextServicesProvider.-
Nested classes/interfaces inherited from class java.beans.beancontext.BeanContextSupport
BeanContextSupport.BCSChild, BeanContextSupport.BCSIterator
-
-
Field Summary
Fields Modifier and Type Field Description protected ArrayList<BeanContextServicesListener>
bcsListeners
List ofBeanContextServicesListener
objects.protected BeanContextServicesSupport.BCSSProxyServiceProvider
proxy
Delegate for theBeanContextServiceProvider
.protected int
serializable
The number of instances of a serializableBeanContextServceProvider
.protected HashMap<Object,BeanContextServicesSupport.BCSSServiceProvider>
services
all accesses to theprotected transient HashMap services
field should be synchronized on that object-
Fields inherited from interface java.beans.beancontext.BeanContext
globalHierarchyLock
-
Fields inherited from class java.beans.beancontext.BeanContextChildSupport
beanContext, beanContextChildPeer, pcSupport, rejectedSetBCOnce, vcSupport
-
Fields inherited from class java.beans.beancontext.BeanContextSupport
bcmListeners, children, designTime, locale, okToUseGui
-
Fields inherited from interface java.beans.DesignMode
PROPERTYNAME
-
-
Constructor Summary
Constructors Constructor Description BeanContextServicesSupport()
Create an instance that is not a delegate of another objectBeanContextServicesSupport(BeanContextServices peer)
Create an instance with a peerBeanContextServicesSupport(BeanContextServices peer, Locale lcle)
Create an instance using the specified localeBeanContextServicesSupport(BeanContextServices peer, Locale lcle, boolean dtime)
Create an instance using the specified Locale and design mode.BeanContextServicesSupport(BeanContextServices peer, Locale lcle, boolean dTime, boolean visible)
Construct a BeanContextServicesSupport instance
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addBeanContextServicesListener(BeanContextServicesListener bcsl)
add a BeanContextServicesListenerboolean
addService(Class<?> serviceClass, BeanContextServiceProvider bcsp)
add a serviceprotected boolean
addService(Class<?> serviceClass, BeanContextServiceProvider bcsp, boolean fireEvent)
add a serviceprotected void
bcsPreDeserializationHook(ObjectInputStream ois)
called from BeanContextSupport readObject before it deserializes the children ...protected void
bcsPreSerializationHook(ObjectOutputStream oos)
called from BeanContextSupport writeObject before it serializes the children ...protected void
childJustRemovedHook(Object child, BeanContextSupport.BCSChild bcsc)
called from superclass child removal operations after a child has been successfully removed. called with child synchronized.protected BeanContextSupport.BCSChild
createBCSChild(Object targetChild, Object peer)
Subclasses can override this method to insert their own subclass of Child without having to override add() or the other Collection methods that add children to the set.protected BeanContextServicesSupport.BCSSServiceProvider
createBCSSServiceProvider(Class<?> sc, BeanContextServiceProvider bcsp)
subclasses can override this method to create new subclasses of BCSSServiceProvider without having to override addService() in order to instantiate.protected void
fireServiceAdded(BeanContextServiceAvailableEvent bcssae)
Fires aBeanContextServiceAvailableEvent
indicating that a new service has become available.protected void
fireServiceAdded(Class<?> serviceClass)
Fires aBeanContextServiceEvent
notifying of a new service.protected void
fireServiceRevoked(BeanContextServiceRevokedEvent bcsre)
Fires aBeanContextServiceEvent
notifying of a service being revoked.protected void
fireServiceRevoked(Class<?> serviceClass, boolean revokeNow)
Fires aBeanContextServiceRevokedEvent
indicating that a particular service is no longer available.BeanContextServices
getBeanContextServicesPeer()
Gets theBeanContextServices
associated with thisBeanContextServicesSupport
.protected static BeanContextServicesListener
getChildBeanContextServicesListener(Object child)
Gets theBeanContextServicesListener
(if any) of the specified child.Iterator<Object>
getCurrentServiceClasses()
Gets the currently available services for this context.Iterator<?>
getCurrentServiceSelectors(Class<?> serviceClass)
Gets the list of service dependent service parameters (Service Selectors) for the specified service, by calling getCurrentServiceSelectors() on the underlying BeanContextServiceProvider.Object
getService(BeanContextChild child, Object requestor, Class<?> serviceClass, Object serviceSelector, BeanContextServiceRevokedListener bcsrl)
obtain a service which may be delegatedboolean
hasService(Class<?> serviceClass)
has a service, which may be delegatedvoid
initialize()
called by BeanContextSupport superclass during construction and deserialization to initialize subclass transient state.protected void
initializeBeanContextResources()
called from setBeanContext to notify a BeanContextChild to allocate resources obtained from the nesting BeanContext.protected void
releaseBeanContextResources()
called from setBeanContext to notify a BeanContextChild to release resources obtained from the nesting BeanContext.void
releaseService(BeanContextChild child, Object requestor, Object service)
release a servicevoid
removeBeanContextServicesListener(BeanContextServicesListener bcsl)
remove a BeanContextServicesListenervoid
revokeService(Class<?> serviceClass, BeanContextServiceProvider bcsp, boolean revokeCurrentServicesNow)
remove a servicevoid
serviceAvailable(BeanContextServiceAvailableEvent bcssae)
BeanContextServicesListener callback, propagates event to all currently registered listeners and BeanContextServices children, if this BeanContextService does not already implement this service itself.void
serviceRevoked(BeanContextServiceRevokedEvent bcssre)
BeanContextServicesListener callback, propagates event to all currently registered listeners and BeanContextServices children, if this BeanContextService does not already implement this service itself.-
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 class java.beans.beancontext.BeanContextChildSupport
addPropertyChangeListener, addVetoableChangeListener, firePropertyChange, fireVetoableChange, getBeanContext, getBeanContextChildPeer, isDelegated, removePropertyChangeListener, removeVetoableChangeListener, setBeanContext, validatePendingSetBeanContext
-
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 interface java.util.Collection
add, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, iterator, parallelStream, remove, removeAll, removeIf, retainAll, size, spliterator, stream, toArray, toArray
-
Methods inherited from interface java.beans.DesignMode
isDesignTime, setDesignTime
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.beans.Visibility
avoidingGui, dontUseGui, needsGui, okToUseGui
-
-
-
-
Field Detail
-
services
protected transient HashMap<Object,BeanContextServicesSupport.BCSSServiceProvider> services
all accesses to theprotected transient HashMap services
field should be synchronized on that object
-
serializable
protected transient int serializable
The number of instances of a serializableBeanContextServceProvider
.
-
proxy
protected transient BeanContextServicesSupport.BCSSProxyServiceProvider proxy
Delegate for theBeanContextServiceProvider
.
-
bcsListeners
protected transient ArrayList<BeanContextServicesListener> bcsListeners
List ofBeanContextServicesListener
objects.
-
-
Constructor Detail
-
BeanContextServicesSupport
public BeanContextServicesSupport(BeanContextServices peer, Locale lcle, boolean dTime, boolean visible)
Construct a BeanContextServicesSupport instance
- Parameters:
peer
- The peer BeanContext we are supplying an implementation for, if null the this object is its own peerlcle
- The current Locale for this BeanContext.dTime
- The initial state, true if in design mode, false if runtime.visible
- The initial visibility.
-
BeanContextServicesSupport
public BeanContextServicesSupport(BeanContextServices peer, Locale lcle, boolean dtime)
Create an instance using the specified Locale and design mode.- Parameters:
peer
- The peer BeanContext we are supplying an implementation for, if null the this object is its own peerlcle
- The current Locale for this BeanContext.dtime
- The initial state, true if in design mode, false if runtime.
-
BeanContextServicesSupport
public BeanContextServicesSupport(BeanContextServices peer, Locale lcle)
Create an instance using the specified locale- Parameters:
peer
- The peer BeanContext we are supplying an implementation for, if null the this object is its own peerlcle
- The current Locale for this BeanContext.
-
BeanContextServicesSupport
public BeanContextServicesSupport(BeanContextServices peer)
Create an instance with a peer- Parameters:
peer
- The peer BeanContext we are supplying an implementation for, if null the this object is its own peer
-
BeanContextServicesSupport
public BeanContextServicesSupport()
Create an instance that is not a delegate of another object
-
-
Method Detail
-
initialize
public void initialize()
called by BeanContextSupport superclass during construction and deserialization to initialize subclass transient state. subclasses may envelope this method, but should not override it or call it directly.- Overrides:
initialize
in classBeanContextSupport
-
getBeanContextServicesPeer
public BeanContextServices getBeanContextServicesPeer()
Gets theBeanContextServices
associated with thisBeanContextServicesSupport
.- Returns:
- the instance of
BeanContext
this object is providing the implementation for.
-
createBCSChild
protected BeanContextSupport.BCSChild createBCSChild(Object targetChild, Object peer)
Subclasses can override this method to insert their own subclass of Child without having to override add() or the other Collection methods that add children to the set.
- Overrides:
createBCSChild
in classBeanContextSupport
- Parameters:
targetChild
- the child to create the Child on behalf ofpeer
- the peer if the targetChild and peer are related by BeanContextProxy- Returns:
- Subtype-specific subclass of Child without overriding collection methods
-
createBCSSServiceProvider
protected BeanContextServicesSupport.BCSSServiceProvider createBCSSServiceProvider(Class<?> sc, BeanContextServiceProvider bcsp)
subclasses can override this method to create new subclasses of BCSSServiceProvider without having to override addService() in order to instantiate.- Parameters:
sc
- the classbcsp
- the service provider- Returns:
- a service provider without overriding addService()
-
addBeanContextServicesListener
public void addBeanContextServicesListener(BeanContextServicesListener bcsl)
add a BeanContextServicesListener- Specified by:
addBeanContextServicesListener
in interfaceBeanContextServices
- Parameters:
bcsl
- theBeanContextServicesListener
to add- Throws:
NullPointerException
- if the argument is null
-
removeBeanContextServicesListener
public void removeBeanContextServicesListener(BeanContextServicesListener bcsl)
remove a BeanContextServicesListener- Specified by:
removeBeanContextServicesListener
in interfaceBeanContextServices
- Parameters:
bcsl
- theBeanContextServicesListener
to remove from this context
-
addService
public boolean addService(Class<?> serviceClass, BeanContextServiceProvider bcsp)
add a service- Specified by:
addService
in interfaceBeanContextServices
- Parameters:
serviceClass
- the service classbcsp
- the service provider- Returns:
- true if the service was successful added, false otherwise
-
addService
protected boolean addService(Class<?> serviceClass, BeanContextServiceProvider bcsp, boolean fireEvent)
add a service- Parameters:
serviceClass
- the service classbcsp
- the service providerfireEvent
- whether or not an event should be fired- Returns:
- true if the service was successfully added
-
revokeService
public void revokeService(Class<?> serviceClass, BeanContextServiceProvider bcsp, boolean revokeCurrentServicesNow)
remove a service- Specified by:
revokeService
in interfaceBeanContextServices
- Parameters:
serviceClass
- the service classbcsp
- the service providerrevokeCurrentServicesNow
- whether or not to revoke the service
-
hasService
public boolean hasService(Class<?> serviceClass)
has a service, which may be delegated- Specified by:
hasService
in interfaceBeanContextServices
- Parameters:
serviceClass
- the service in question- Returns:
- true if the service is available
-
getService
public Object getService(BeanContextChild child, Object requestor, Class<?> serviceClass, Object serviceSelector, BeanContextServiceRevokedListener bcsrl) throws TooManyListenersException
obtain a service which may be delegated- Specified by:
getService
in interfaceBeanContextServices
- Parameters:
child
- theBeanContextChild
associated with this requestrequestor
- the object requesting the serviceserviceClass
- class of the requested serviceserviceSelector
- the service dependent parameterbcsrl
- theBeanContextServiceRevokedListener
to notify if the service should later become revoked- Returns:
- a reference to this context's named
Service as requested or
null
- Throws:
TooManyListenersException
- if there are too many listeners
-
releaseService
public void releaseService(BeanContextChild child, Object requestor, Object service)
release a service- Specified by:
releaseService
in interfaceBeanContextServices
- Parameters:
child
- theBeanContextChild
requestor
- the requestorservice
- the service
-
getCurrentServiceClasses
public Iterator<Object> getCurrentServiceClasses()
Description copied from interface:BeanContextServices
Gets the currently available services for this context.- Specified by:
getCurrentServiceClasses
in interfaceBeanContextServices
- Returns:
- an iterator for all the currently registered service classes.
-
getCurrentServiceSelectors
public Iterator<?> getCurrentServiceSelectors(Class<?> serviceClass)
Description copied from interface:BeanContextServices
Gets the list of service dependent service parameters (Service Selectors) for the specified service, by calling getCurrentServiceSelectors() on the underlying BeanContextServiceProvider.- Specified by:
getCurrentServiceSelectors
in interfaceBeanContextServices
- Parameters:
serviceClass
- the specified service- Returns:
- an iterator for all the currently available service selectors (if any) available for the specified service.
-
serviceAvailable
public void serviceAvailable(BeanContextServiceAvailableEvent bcssae)
BeanContextServicesListener callback, propagates event to all currently registered listeners and BeanContextServices children, if this BeanContextService does not already implement this service itself. subclasses may override or envelope this method to implement their own propagation semantics.- Specified by:
serviceAvailable
in interfaceBeanContextServicesListener
- Overrides:
serviceAvailable
in classBeanContextChildSupport
- Parameters:
bcssae
- The BeanContextServiceAvailableEvent fired as a result of a service becoming available
-
serviceRevoked
public void serviceRevoked(BeanContextServiceRevokedEvent bcssre)
BeanContextServicesListener callback, propagates event to all currently registered listeners and BeanContextServices children, if this BeanContextService does not already implement this service itself. subclasses may override or envelope this method to implement their own propagation semantics.- Specified by:
serviceRevoked
in interfaceBeanContextServiceRevokedListener
- Overrides:
serviceRevoked
in classBeanContextChildSupport
- Parameters:
bcssre
- TheBeanContextServiceRevokedEvent
fired as a result of a service being revoked
-
getChildBeanContextServicesListener
protected static final BeanContextServicesListener getChildBeanContextServicesListener(Object child)
Gets theBeanContextServicesListener
(if any) of the specified child.- Parameters:
child
- the specified child- Returns:
- the BeanContextServicesListener (if any) of the specified child
-
childJustRemovedHook
protected void childJustRemovedHook(Object child, BeanContextSupport.BCSChild bcsc)
called from superclass child removal operations after a child has been successfully removed. called with child synchronized. This subclass uses this hook to immediately revoke any services being used by this child if it is a BeanContextChild. subclasses may envelope this method in order to implement their own child removal side-effects.- Overrides:
childJustRemovedHook
in classBeanContextSupport
- Parameters:
child
- the childbcsc
- the BCSChild
-
releaseBeanContextResources
protected void releaseBeanContextResources()
called from setBeanContext to notify a BeanContextChild to release resources obtained from the nesting BeanContext. This method revokes any services obtained from its parent. subclasses may envelope this method to implement their own semantics.- Overrides:
releaseBeanContextResources
in classBeanContextChildSupport
-
initializeBeanContextResources
protected void initializeBeanContextResources()
called from setBeanContext to notify a BeanContextChild to allocate resources obtained from the nesting BeanContext. subclasses may envelope this method to implement their own semantics.- Overrides:
initializeBeanContextResources
in classBeanContextChildSupport
-
fireServiceAdded
protected final void fireServiceAdded(Class<?> serviceClass)
Fires aBeanContextServiceEvent
notifying of a new service.- Parameters:
serviceClass
- the service class
-
fireServiceAdded
protected final void fireServiceAdded(BeanContextServiceAvailableEvent bcssae)
Fires aBeanContextServiceAvailableEvent
indicating that a new service has become available.- Parameters:
bcssae
- theBeanContextServiceAvailableEvent
-
fireServiceRevoked
protected final void fireServiceRevoked(BeanContextServiceRevokedEvent bcsre)
Fires aBeanContextServiceEvent
notifying of a service being revoked.- Parameters:
bcsre
- theBeanContextServiceRevokedEvent
-
fireServiceRevoked
protected final void fireServiceRevoked(Class<?> serviceClass, boolean revokeNow)
Fires aBeanContextServiceRevokedEvent
indicating that a particular service is no longer available.- Parameters:
serviceClass
- the service classrevokeNow
- whether or not the event should be revoked now
-
bcsPreSerializationHook
protected void bcsPreSerializationHook(ObjectOutputStream oos) throws IOException
called from BeanContextSupport writeObject before it serializes the children ... This class will serialize any Serializable BeanContextServiceProviders herein. subclasses may envelope this method to insert their own serialization processing that has to occur prior to serialization of the children- Overrides:
bcsPreSerializationHook
in classBeanContextSupport
- Parameters:
oos
- theObjectOutputStream
to use during serialization- Throws:
IOException
- if serialization failed
-
bcsPreDeserializationHook
protected void bcsPreDeserializationHook(ObjectInputStream ois) throws IOException, ClassNotFoundException
called from BeanContextSupport readObject before it deserializes the children ... This class will deserialize any Serializable BeanContextServiceProviders serialized earlier thus making them available to the children when they deserialized. subclasses may envelope this method to insert their own serialization processing that has to occur prior to serialization of the children- Overrides:
bcsPreDeserializationHook
in classBeanContextSupport
- Parameters:
ois
- theObjectInputStream
to use during deserialization- Throws:
IOException
- if deserialization failedClassNotFoundException
- if needed classes are not found
-
-