Package jadex.commons.beans.beancontext
Class BeanContextServicesSupport
- java.lang.Object
-
- jadex.commons.beans.beancontext.BeanContextChildSupport
-
- jadex.commons.beans.beancontext.BeanContextSupport
-
- jadex.commons.beans.beancontext.BeanContextServicesSupport
-
- All Implemented Interfaces:
BeanContext
,BeanContextChild
,BeanContextServiceRevokedListener
,BeanContextServices
,BeanContextServicesListener
,DesignMode
,PropertyChangeListener
,VetoableChangeListener
,Visibility
,java.io.Serializable
,java.lang.Iterable
,java.util.Collection
,java.util.EventListener
public class BeanContextServicesSupport extends BeanContextSupport implements BeanContextServices, java.io.Serializable
This support class implementsBeanContextServices
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 supportBeanContextServices
interface.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
BeanContextServicesSupport.BCSSChild
Every child of context is companied with aBCSSChild
instance.protected class
BeanContextServicesSupport.BCSSProxyServiceProvider
This class implements theBeanContextServiceProvider
interface by wrapping aBeanContextServices
.protected static class
BeanContextServicesSupport.BCSSServiceProvider
Every servie registered in this context is companied with aBCSSServiceProvider
instance.-
Nested classes/interfaces inherited from class jadex.commons.beans.beancontext.BeanContextSupport
BeanContextSupport.BCSChild, BeanContextSupport.BCSIterator
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.ArrayList
bcsListeners
A list of registeredBeanContextServicesListener
s.protected BeanContextServicesSupport.BCSSProxyServiceProvider
proxy
A proxy service provider that delegates service requests to the parent context.protected int
serializable
The number of serializable service providers currently registered.protected java.util.HashMap
services
A map of all registered services - key is service class, value isBCSSServiceProvider
object.-
Fields inherited from class jadex.commons.beans.beancontext.BeanContextSupport
bcmListeners, children, designTime, locale, okToUseGui
-
Fields inherited from class jadex.commons.beans.beancontext.BeanContextChildSupport
beanContext, beanContextChildPeer, pcSupport, rejectedSetBCOnce, vcSupport
-
Fields inherited from interface jadex.commons.beans.beancontext.BeanContext
globalHierarchyLock
-
Fields inherited from interface jadex.commons.beans.DesignMode
PROPERTYNAME
-
-
Constructor Summary
Constructors Constructor Description BeanContextServicesSupport()
Constructs a standardBeanContextServicesSupport
.BeanContextServicesSupport(BeanContextServices peer)
Constructs aBeanContextServicesSupport
which is a delegate of the given peer.BeanContextServicesSupport(BeanContextServices peer, java.util.Locale locale)
Constructs aBeanContextServicesSupport
which is a delegate of the given peer.BeanContextServicesSupport(BeanContextServices peer, java.util.Locale locale, boolean designTime)
Constructs aBeanContextServicesSupport
which is a delegate of the given peer.BeanContextServicesSupport(BeanContextServices peer, java.util.Locale locale, boolean designTime, boolean okToUseGui)
Constructs aBeanContextServicesSupport
which is a delegate of the given peer.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addBeanContextServicesListener(BeanContextServicesListener listener)
boolean
addService(java.lang.Class serviceClass, BeanContextServiceProvider provider)
Add a service to this context.protected boolean
addService(java.lang.Class serviceClass, BeanContextServiceProvider provider, boolean fireEvent)
Add a service to this context.protected void
bcsPreDeserializationHook(java.io.ObjectInputStream ois)
Deserializes all serializable services and their providers before the children of this context is deserialized.protected void
bcsPreSerializationHook(java.io.ObjectOutputStream oos)
Serializes all serializable services and their providers before the children of this context is serialized.protected void
childJustRemovedHook(java.lang.Object child, BeanContextSupport.BCSChild bcsChild)
This method is called everytime a child is removed from this context.protected BeanContextSupport.BCSChild
createBCSChild(java.lang.Object child, java.lang.Object proxyPeer)
Creates aBCSSChild
object to company the given child.protected BeanContextServicesSupport.BCSSServiceProvider
createBCSSServiceProvider(java.lang.Class serviceClass, BeanContextServiceProvider provider)
Creates aBCSSServiceProvider
to company the given service.protected void
fireServiceAdded(BeanContextServiceAvailableEvent event)
Fires aBeanContextServiceAvailableEvent
to registeredBeanContextServicesListener
s.protected void
fireServiceAdded(java.lang.Class serviceClass)
Fires aBeanContextServiceAvailableEvent
to registeredBeanContextServicesListener
s.protected void
fireServiceRevoked(BeanContextServiceRevokedEvent event)
Fires aBeanContextServiceRevokedEvent
to registeredBeanContextServicesListener
s.protected void
fireServiceRevoked(java.lang.Class serviceClass, boolean revokeNow)
Fires aBeanContextServiceRevokedEvent
to registeredBeanContextServicesListener
s.BeanContextServices
getBeanContextServicesPeer()
Returns the peer of this context casted asBeanContextServices
.protected static BeanContextServicesListener
getChildBeanContextServicesListener(java.lang.Object child)
Returns the given child casted toBeanContextServicesListener
, or null if it does not implements the interface.java.util.Iterator
getCurrentServiceClasses()
Returns an iterator of all registered service classes, withremoved()
disabled.java.util.Iterator
getCurrentServiceSelectors(java.lang.Class serviceClass)
Returns the service selectors of the specified service.java.lang.Object
getService(BeanContextChild child, java.lang.Object requestor, java.lang.Class serviceClass, java.lang.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(java.lang.Class serviceClass)
Checks whether a service is registed in this context or the parent context.void
initialize()
Initializes all transient fields of this instance, called by constructors andreadObject()
.protected void
initializeBeanContextResources()
Called after the parent context is updated.protected void
releaseBeanContextResources()
Called before the parent context is updated.void
releaseService(BeanContextChild child, java.lang.Object requestor, java.lang.Object service)
Release a service which has been requested previously.void
removeBeanContextServicesListener(BeanContextServicesListener listener)
void
revokeService(java.lang.Class serviceClass, BeanContextServiceProvider serviceProvider, boolean revokeCurrentServicesNow)
Revokes a service in this bean context.void
serviceAvailable(BeanContextServiceAvailableEvent event)
Notify all listeners and children that implementsBeanContextServices
of the event.void
serviceRevoked(BeanContextServiceRevokedEvent event)
Notify all listeners and children that implementsBeanContextServices
of the event.-
Methods inherited from class jadex.commons.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 jadex.commons.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 jadex.commons.beans.beancontext.BeanContext
addBeanContextMembershipListener, getResource, getResourceAsStream, instantiateChild, removeBeanContextMembershipListener
-
Methods inherited from interface jadex.commons.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 jadex.commons.beans.DesignMode
isDesignTime, setDesignTime
-
Methods inherited from interface jadex.commons.beans.Visibility
avoidingGui, dontUseGui, needsGui, okToUseGui
-
-
-
-
Field Detail
-
services
protected transient java.util.HashMap 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 serializable
The number of serializable service providers currently registered.
-
proxy
protected transient BeanContextServicesSupport.BCSSProxyServiceProvider proxy
A proxy service provider that delegates service requests to the parent context.
-
bcsListeners
protected transient java.util.ArrayList bcsListeners
A list of registeredBeanContextServicesListener
s. All access to this object should be synchronized on itself.
-
-
Constructor Detail
-
BeanContextServicesSupport
public BeanContextServicesSupport()
Constructs a standardBeanContextServicesSupport
.
-
BeanContextServicesSupport
public BeanContextServicesSupport(BeanContextServices peer)
Constructs aBeanContextServicesSupport
which is a delegate of the given peer.- Parameters:
peer
- the peer of this context
-
BeanContextServicesSupport
public BeanContextServicesSupport(BeanContextServices peer, java.util.Locale locale)
Constructs aBeanContextServicesSupport
which is a delegate of the given peer.- Parameters:
peer
- the peer of this contextlocale
- the locale of this context
-
BeanContextServicesSupport
public BeanContextServicesSupport(BeanContextServices peer, java.util.Locale locale, boolean designTime)
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, java.util.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 Detail
-
addBeanContextServicesListener
public void addBeanContextServicesListener(BeanContextServicesListener listener)
- Specified by:
addBeanContextServicesListener
in interfaceBeanContextServices
-
addService
public boolean addService(java.lang.Class serviceClass, BeanContextServiceProvider provider)
Add a service to this context.addService(serviceClass, provider, true).
- Specified by:
addService
in interfaceBeanContextServices
- See Also:
BeanContextServices.addService(java.lang.Class, jadex.commons.beans.beancontext.BeanContextServiceProvider)
-
addService
protected boolean addService(java.lang.Class serviceClass, BeanContextServiceProvider provider, boolean fireEvent)
Add a service to this context.- 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(java.io.ObjectInputStream ois) throws java.io.IOException, java.lang.ClassNotFoundException
Deserializes all serializable services and their providers before the children of this context is deserialized.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:
java.io.IOException
java.lang.ClassNotFoundException
- See Also:
BeanContextSupport.bcsPreDeserializationHook(java.io.ObjectInputStream)
-
bcsPreSerializationHook
protected void bcsPreSerializationHook(java.io.ObjectOutputStream oos) throws java.io.IOException
Serializes all serializable services and their providers before the children of this context is serialized.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:
java.io.IOException
- See Also:
BeanContextSupport.bcsPreSerializationHook(java.io.ObjectOutputStream)
-
childJustRemovedHook
protected void childJustRemovedHook(java.lang.Object child, BeanContextSupport.BCSChild bcsChild)
This method is called everytime a child is removed from this context.- Overrides:
childJustRemovedHook
in classBeanContextSupport
- Parameters:
child
- the child just removedbcsChild
- theBCSChild
just removed- See Also:
BeanContextSupport.childJustRemovedHook(java.lang.Object, jadex.commons.beans.beancontext.BeanContextSupport.BCSChild)
-
createBCSChild
protected BeanContextSupport.BCSChild createBCSChild(java.lang.Object child, java.lang.Object proxyPeer)
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:
BeanContextSupport.createBCSChild(java.lang.Object, java.lang.Object)
-
createBCSSServiceProvider
protected BeanContextServicesSupport.BCSSServiceProvider createBCSSServiceProvider(java.lang.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
protected final void fireServiceAdded(java.lang.Class serviceClass)
Fires aBeanContextServiceAvailableEvent
to registeredBeanContextServicesListener
s.- Parameters:
serviceClass
- the service that has been added
-
fireServiceAdded
protected final void fireServiceAdded(BeanContextServiceAvailableEvent event)
Fires aBeanContextServiceAvailableEvent
to registeredBeanContextServicesListener
s.- Parameters:
event
- the event
-
fireServiceRevoked
protected final void fireServiceRevoked(java.lang.Class serviceClass, boolean revokeNow)
Fires aBeanContextServiceRevokedEvent
to registeredBeanContextServicesListener
s.- Parameters:
serviceClass
- the service that has been revokedrevokeNow
- whether to terminate service immediately
-
fireServiceRevoked
protected final void fireServiceRevoked(BeanContextServiceRevokedEvent event)
Fires aBeanContextServiceRevokedEvent
to registeredBeanContextServicesListener
s.- Parameters:
event
- the event
-
getBeanContextServicesPeer
public BeanContextServices getBeanContextServicesPeer()
Returns the peer of this context casted asBeanContextServices
.- Returns:
- the peer of this context casted as
BeanContextServices
-
getChildBeanContextServicesListener
protected static final BeanContextServicesListener getChildBeanContextServicesListener(java.lang.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
public java.util.Iterator 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:
BeanContextServices.getCurrentServiceClasses()
-
getCurrentServiceSelectors
public java.util.Iterator getCurrentServiceSelectors(java.lang.Class serviceClass)
Returns the service selectors of the specified service. The iterator'sremove()
operation is disabled.- Specified by:
getCurrentServiceSelectors
in interfaceBeanContextServices
- See Also:
BeanContextServices.getCurrentServiceSelectors(java.lang.Class)
-
getService
public java.lang.Object getService(BeanContextChild child, java.lang.Object requestor, java.lang.Class serviceClass, java.lang.Object serviceSelector, BeanContextServiceRevokedListener bcsrl) throws java.util.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:
java.lang.IllegalArgumentException
- ifchild
is not a child of this contextjava.util.TooManyListenersException
- See Also:
BeanContextServices.getService(jadex.commons.beans.beancontext.BeanContextChild, java.lang.Object, java.lang.Class, java.lang.Object, jadex.commons.beans.beancontext.BeanContextServiceRevokedListener)
-
hasService
public boolean hasService(java.lang.Class serviceClass)
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:
BeanContextServices.hasService(java.lang.Class)
-
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:
BeanContextChildSupport.initializeBeanContextResources()
-
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:
BeanContextChildSupport.releaseBeanContextResources()
-
releaseService
public void releaseService(BeanContextChild child, java.lang.Object requestor, java.lang.Object service)
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:
java.lang.IllegalArgumentException
- ifchild
is not a child of this context
-
removeBeanContextServicesListener
public void removeBeanContextServicesListener(BeanContextServicesListener listener)
- Specified by:
removeBeanContextServicesListener
in interfaceBeanContextServices
-
revokeService
public void revokeService(java.lang.Class serviceClass, BeanContextServiceProvider serviceProvider, boolean revokeCurrentServicesNow)
Revokes a service in this bean context.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:
BeanContextServices.revokeService(java.lang.Class, jadex.commons.beans.beancontext.BeanContextServiceProvider, boolean)
-
serviceAvailable
public void serviceAvailable(BeanContextServiceAvailableEvent event)
Notify all listeners and children that implementsBeanContextServices
of the event.- Specified by:
serviceAvailable
in interfaceBeanContextServicesListener
- Overrides:
serviceAvailable
in classBeanContextChildSupport
- See Also:
BeanContextServicesListener.serviceAvailable(jadex.commons.beans.beancontext.BeanContextServiceAvailableEvent)
-
serviceRevoked
public void serviceRevoked(BeanContextServiceRevokedEvent event)
Notify all listeners and children that implementsBeanContextServices
of the event.- Specified by:
serviceRevoked
in interfaceBeanContextServiceRevokedListener
- Overrides:
serviceRevoked
in classBeanContextChildSupport
- See Also:
BeanContextServiceRevokedListener.serviceRevoked(jadex.commons.beans.beancontext.BeanContextServiceRevokedEvent)
-
-