Package javaa.beans.beancontext
Class BeanContextServicesSupport
java.lang.Object
javaa.beans.beancontext.BeanContextChildSupport
javaa.beans.beancontext.BeanContextSupport
javaa.beans.beancontext.BeanContextServicesSupport
- All Implemented Interfaces:
Serializable
,Iterable
,Collection
,EventListener
,BeanContext
,BeanContextChild
,BeanContextServiceRevokedListener
,BeanContextServices
,BeanContextServicesListener
,DesignMode
,PropertyChangeListener
,VetoableChangeListener
,Visibility
public class BeanContextServicesSupport
extends BeanContextSupport
implements BeanContextServices, Serializable
This support class implements
BeanContextServices
interface.
This class can be used directly, or be a super class of your class, or be a
delegate of your implementation that needs to support
BeanContextServices
interface.- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected class
Every child of context is companied with aBCSSChild
instance.protected class
This class implements theBeanContextServiceProvider
interface by wrapping aBeanContextServices
.protected static class
Every servie registered in this context is companied with aBCSSServiceProvider
instance.Nested classes/interfaces inherited from class javaa.beans.beancontext.BeanContextSupport
BeanContextSupport.BCSChild, BeanContextSupport.BCSIterator
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ArrayList
A list of registeredBeanContextServicesListener
s.A proxy service provider that delegates service requests to the parent context.protected int
The number of serializable service providers currently registered.protected HashMap
A map of all registered services - key is service class, value isBCSSServiceProvider
object.Fields inherited from class javaa.beans.beancontext.BeanContextSupport
bcmListeners, children, designTime, locale, okToUseGui
Fields inherited from class javaa.beans.beancontext.BeanContextChildSupport
beanContext, beanContextChildPeer, pcSupport, rejectedSetBCOnce, vcSupport
Fields inherited from interface javaa.beans.beancontext.BeanContext
globalHierarchyLock
Fields inherited from interface javaa.beans.DesignMode
PROPERTYNAME
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a standardBeanContextServicesSupport
.Constructs aBeanContextServicesSupport
which is a delegate of the given peer.BeanContextServicesSupport
(BeanContextServices peer, Locale locale) Constructs aBeanContextServicesSupport
which is a delegate of the given peer.BeanContextServicesSupport
(BeanContextServices peer, Locale locale, boolean designTime) Constructs aBeanContextServicesSupport
which is a delegate of the given peer.BeanContextServicesSupport
(BeanContextServices peer, Locale locale, boolean designTime, boolean okToUseGui) Constructs aBeanContextServicesSupport
which is a delegate of the given peer. -
Method Summary
Modifier and TypeMethodDescriptionvoid
boolean
addService
(Class serviceClass, BeanContextServiceProvider provider) Add a service to this context.protected boolean
addService
(Class serviceClass, BeanContextServiceProvider provider, boolean fireEvent) Add a service to this context.protected void
Deserializes all serializable services and their providers before the children of this context is deserialized.protected void
Serializes all serializable services and their providers before the children of this context is serialized.protected void
childJustRemovedHook
(Object child, BeanContextSupport.BCSChild bcsChild) This method is called everytime a child is removed from this context.protected BeanContextSupport.BCSChild
createBCSChild
(Object child, Object proxyPeer) Creates aBCSSChild
object to company the given child.createBCSSServiceProvider
(Class serviceClass, BeanContextServiceProvider provider) Creates aBCSSServiceProvider
to company the given service.protected final void
fireServiceAdded
(Class serviceClass) Fires aBeanContextServiceAvailableEvent
to registeredBeanContextServicesListener
s.protected final void
Fires aBeanContextServiceAvailableEvent
to registeredBeanContextServicesListener
s.protected final void
fireServiceRevoked
(Class serviceClass, boolean revokeNow) Fires aBeanContextServiceRevokedEvent
to registeredBeanContextServicesListener
s.protected final void
Fires aBeanContextServiceRevokedEvent
to registeredBeanContextServicesListener
s.Returns the peer of this context casted asBeanContextServices
.protected static final BeanContextServicesListener
Returns the given child casted toBeanContextServicesListener
, or null if it does not implements the interface.Returns an iterator of all registered service classes, withremoved()
disabled.getCurrentServiceSelectors
(Class serviceClass) Returns the service selectors of the specified service.getService
(BeanContextChild child, Object requestor, Class serviceClass, Object serviceSelector, BeanContextServiceRevokedListener bcsrl) Get a service instance on behalf of the specified child of this context, by calling the registered service provider, or by delegating to the parent context.boolean
hasService
(Class serviceClass) Checks whether a service is registed in this context or the parent context.void
Initializes all transient fields of this instance, called by constructors andreadObject()
.protected void
Called after the parent context is updated.protected void
Called before the parent context is updated.void
releaseService
(BeanContextChild child, Object requestor, Object service) Release a service which has been requested previously.void
void
revokeService
(Class serviceClass, BeanContextServiceProvider serviceProvider, boolean revokeCurrentServicesNow) Revokes a service in this bean context.void
Notify all listeners and children that implementsBeanContextServices
of the event.void
Notify all listeners and children that implementsBeanContextServices
of the event.Methods inherited from class javaa.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 javaa.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 javaa.beans.beancontext.BeanContext
addBeanContextMembershipListener, getResource, getResourceAsStream, instantiateChild, removeBeanContextMembershipListener
Methods inherited from interface javaa.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, parallelStream, remove, removeAll, removeIf, retainAll, size, spliterator, stream, toArray, toArray, toArray
Methods inherited from interface javaa.beans.DesignMode
isDesignTime, setDesignTime
Methods inherited from interface javaa.beans.Visibility
avoidingGui, dontUseGui, needsGui, okToUseGui
-
Field Details
-
services
A map of all registered services - key is service class, value isBCSSServiceProvider
object. All access to this object should be synchronized on itself. -
serializable
protected transient int serializableThe number of serializable service providers currently registered. -
proxy
A proxy service provider that delegates service requests to the parent context. -
bcsListeners
A list of registeredBeanContextServicesListener
s. All access to this object should be synchronized on itself.
-
-
Constructor Details
-
BeanContextServicesSupport
public BeanContextServicesSupport()Constructs a standardBeanContextServicesSupport
. -
BeanContextServicesSupport
Constructs aBeanContextServicesSupport
which is a delegate of the given peer.- Parameters:
peer
- the peer of this context
-
BeanContextServicesSupport
Constructs aBeanContextServicesSupport
which is a delegate of the given peer.- Parameters:
peer
- the peer of this contextlocale
- the locale of this context
-
BeanContextServicesSupport
Constructs aBeanContextServicesSupport
which is a delegate of the given peer.- Parameters:
peer
- the peer of this contextlocale
- the locale of this contextdesignTime
- whether in design mode or not
-
BeanContextServicesSupport
public BeanContextServicesSupport(BeanContextServices peer, Locale locale, boolean designTime, boolean okToUseGui) Constructs aBeanContextServicesSupport
which is a delegate of the given peer.- Parameters:
peer
- the peer of this contextlocale
- the locale of this contextdesignTime
- whether in design mode or notokToUseGui
- whether GUI is usable or not
-
-
Method Details
-
addBeanContextServicesListener
- Specified by:
addBeanContextServicesListener
in interfaceBeanContextServices
-
addService
Add a service to this context.Delegate to
addService(serviceClass, provider, true)
.- Specified by:
addService
in interfaceBeanContextServices
- See Also:
-
addService
protected boolean addService(Class serviceClass, BeanContextServiceProvider provider, boolean fireEvent) Add a service to this context.If the service already exists in the context, simply return false. Otherwise, the service is added and event is fired if required.
- Parameters:
serviceClass
- the service classprovider
- the provider of the servicefireEvent
- the flag indicating to fire event or not- Returns:
- true if the service is added; or false if the context already has this service
-
bcsPreDeserializationHook
protected void bcsPreDeserializationHook(ObjectInputStream ois) throws IOException, ClassNotFoundException Deserializes all serializable services and their providers before the children of this context is deserialized.First a
int
is read, indicating the number of services to read. Then pairs of service class and service provider are read one by one.- Overrides:
bcsPreDeserializationHook
in classBeanContextSupport
- Parameters:
ois
- the object input stream- Throws:
IOException
ClassNotFoundException
- See Also:
-
bcsPreSerializationHook
Serializes all serializable services and their providers before the children of this context is serialized.First a
int
is writtern, indicating the number of serializable services. Then pairs of service class and service provider are writtern one by one.- Overrides:
bcsPreSerializationHook
in classBeanContextSupport
- Parameters:
oos
- the object output stream- Throws:
IOException
- See Also:
-
childJustRemovedHook
This method is called everytime a child is removed from this context.The implementation releases all services requested by the child.
- Overrides:
childJustRemovedHook
in classBeanContextSupport
- Parameters:
child
- the child just removedbcsChild
- theBCSChild
just removed- See Also:
-
createBCSChild
Creates aBCSSChild
object to company the given child.- Overrides:
createBCSChild
in classBeanContextSupport
- Parameters:
child
- the childproxyPeer
- the proxy peer of the child if there is one- Returns:
- a
BCSChild
object to company the given child - See Also:
-
createBCSSServiceProvider
protected BeanContextServicesSupport.BCSSServiceProvider createBCSSServiceProvider(Class serviceClass, BeanContextServiceProvider provider) Creates aBCSSServiceProvider
to company the given service.- Parameters:
serviceClass
- the service classprovider
- the service provider- Returns:
- a
BCSSServiceProvider
to company the given service
-
fireServiceAdded
Fires aBeanContextServiceAvailableEvent
to registeredBeanContextServicesListener
s.- Parameters:
serviceClass
- the service that has been added
-
fireServiceAdded
Fires aBeanContextServiceAvailableEvent
to registeredBeanContextServicesListener
s.- Parameters:
event
- the event
-
fireServiceRevoked
Fires aBeanContextServiceRevokedEvent
to registeredBeanContextServicesListener
s.- Parameters:
serviceClass
- the service that has been revokedrevokeNow
- whether to terminate service immediately
-
fireServiceRevoked
Fires aBeanContextServiceRevokedEvent
to registeredBeanContextServicesListener
s.- Parameters:
event
- the event
-
getBeanContextServicesPeer
Returns the peer of this context casted asBeanContextServices
.- Returns:
- the peer of this context casted as
BeanContextServices
-
getChildBeanContextServicesListener
protected static final BeanContextServicesListener getChildBeanContextServicesListener(Object child) Returns the given child casted toBeanContextServicesListener
, or null if it does not implements the interface.- Parameters:
child
- a child- Returns:
- the given child casted to
BeanContextServicesListener
, or null if it does not implements the interface
-
getCurrentServiceClasses
Returns an iterator of all registered service classes, withremoved()
disabled.- Specified by:
getCurrentServiceClasses
in interfaceBeanContextServices
- Returns:
- an iterator of all registered service classes
- See Also:
-
getCurrentServiceSelectors
Returns the service selectors of the specified service. The iterator'sremove()
operation is disabled.- Specified by:
getCurrentServiceSelectors
in interfaceBeanContextServices
- See Also:
-
getService
public Object getService(BeanContextChild child, Object requestor, Class serviceClass, Object serviceSelector, BeanContextServiceRevokedListener bcsrl) throws TooManyListenersException Get a service instance on behalf of the specified child of this context, by calling the registered service provider, or by delegating to the parent context.- Specified by:
getService
in interfaceBeanContextServices
- Parameters:
child
- the child that request servicerequestor
- the requestor objectserviceClass
- the service classserviceSelector
- the service selectorsbcsrl
- theBeanContextServiceRevokedListener
- Returns:
- a service instance on behalf of the specified child of this context
- Throws:
IllegalArgumentException
- ifchild
is not a child of this contextTooManyListenersException
- See Also:
-
hasService
Checks whether a service is registed in this context or the parent context.- Specified by:
hasService
in interfaceBeanContextServices
- Parameters:
serviceClass
- the service class- Returns:
- true if the service is registered
- See Also:
-
initialize
public void initialize()Description copied from class:BeanContextSupport
Initializes all transient fields of this instance, called by constructors andreadObject()
.- Overrides:
initialize
in classBeanContextSupport
-
initializeBeanContextResources
protected void initializeBeanContextResources()Called after the parent context is updated. The implementation checks if the parent context is aBeanContextServices
. If it is, then aBCSSProxyServiceProvider
is created to delegate service requests to the parent context.- Overrides:
initializeBeanContextResources
in classBeanContextChildSupport
- See Also:
-
releaseBeanContextResources
protected void releaseBeanContextResources()Called before the parent context is updated. The implementation releases any service that is currently provided by the parent context.- Overrides:
releaseBeanContextResources
in classBeanContextChildSupport
- See Also:
-
releaseService
Release a service which has been requested previously.- Specified by:
releaseService
in interfaceBeanContextServices
- Parameters:
child
- the child that request the servicerequestor
- the requestor objectservice
- the service instance- Throws:
IllegalArgumentException
- ifchild
is not a child of this context
-
removeBeanContextServicesListener
- Specified by:
removeBeanContextServicesListener
in interfaceBeanContextServices
-
revokeService
public void revokeService(Class serviceClass, BeanContextServiceProvider serviceProvider, boolean revokeCurrentServicesNow) Revokes a service in this bean context.The given service provider is unregistered and a
BeanContextServiceRevokedEvent
is fired. All registered service listeners and current service users get notified.- Specified by:
revokeService
in interfaceBeanContextServices
- Parameters:
serviceClass
- the service classserviceProvider
- the service providerrevokeCurrentServicesNow
- true if service should be terminated immediantly- See Also:
-
serviceAvailable
Notify all listeners and children that implementsBeanContextServices
of the event.- Specified by:
serviceAvailable
in interfaceBeanContextServicesListener
- Overrides:
serviceAvailable
in classBeanContextChildSupport
- See Also:
-
serviceRevoked
Notify all listeners and children that implementsBeanContextServices
of the event.- Specified by:
serviceRevoked
in interfaceBeanContextServiceRevokedListener
- Overrides:
serviceRevoked
in classBeanContextChildSupport
- See Also:
-