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 implementsBeanContextServicesinterface. This class can be used directly, or be a super class of your class, or be a delegate of your implementation that needs to supportBeanContextServicesinterface.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classBeanContextServicesSupport.BCSSChildEvery child of context is companied with aBCSSChildinstance.protected classBeanContextServicesSupport.BCSSProxyServiceProviderThis class implements theBeanContextServiceProviderinterface by wrapping aBeanContextServices.protected static classBeanContextServicesSupport.BCSSServiceProviderEvery servie registered in this context is companied with aBCSSServiceProviderinstance.-
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.ArrayListbcsListenersA list of registeredBeanContextServicesListeners.protected BeanContextServicesSupport.BCSSProxyServiceProviderproxyA proxy service provider that delegates service requests to the parent context.protected intserializableThe number of serializable service providers currently registered.protected java.util.HashMapservicesA map of all registered services - key is service class, value isBCSSServiceProviderobject.-
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 aBeanContextServicesSupportwhich is a delegate of the given peer.BeanContextServicesSupport(BeanContextServices peer, java.util.Locale locale)Constructs aBeanContextServicesSupportwhich is a delegate of the given peer.BeanContextServicesSupport(BeanContextServices peer, java.util.Locale locale, boolean designTime)Constructs aBeanContextServicesSupportwhich is a delegate of the given peer.BeanContextServicesSupport(BeanContextServices peer, java.util.Locale locale, boolean designTime, boolean okToUseGui)Constructs aBeanContextServicesSupportwhich is a delegate of the given peer.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddBeanContextServicesListener(BeanContextServicesListener listener)booleanaddService(java.lang.Class serviceClass, BeanContextServiceProvider provider)Add a service to this context.protected booleanaddService(java.lang.Class serviceClass, BeanContextServiceProvider provider, boolean fireEvent)Add a service to this context.protected voidbcsPreDeserializationHook(java.io.ObjectInputStream ois)Deserializes all serializable services and their providers before the children of this context is deserialized.protected voidbcsPreSerializationHook(java.io.ObjectOutputStream oos)Serializes all serializable services and their providers before the children of this context is serialized.protected voidchildJustRemovedHook(java.lang.Object child, BeanContextSupport.BCSChild bcsChild)This method is called everytime a child is removed from this context.protected BeanContextSupport.BCSChildcreateBCSChild(java.lang.Object child, java.lang.Object proxyPeer)Creates aBCSSChildobject to company the given child.protected BeanContextServicesSupport.BCSSServiceProvidercreateBCSSServiceProvider(java.lang.Class serviceClass, BeanContextServiceProvider provider)Creates aBCSSServiceProviderto company the given service.protected voidfireServiceAdded(BeanContextServiceAvailableEvent event)Fires aBeanContextServiceAvailableEventto registeredBeanContextServicesListeners.protected voidfireServiceAdded(java.lang.Class serviceClass)Fires aBeanContextServiceAvailableEventto registeredBeanContextServicesListeners.protected voidfireServiceRevoked(BeanContextServiceRevokedEvent event)Fires aBeanContextServiceRevokedEventto registeredBeanContextServicesListeners.protected voidfireServiceRevoked(java.lang.Class serviceClass, boolean revokeNow)Fires aBeanContextServiceRevokedEventto registeredBeanContextServicesListeners.BeanContextServicesgetBeanContextServicesPeer()Returns the peer of this context casted asBeanContextServices.protected static BeanContextServicesListenergetChildBeanContextServicesListener(java.lang.Object child)Returns the given child casted toBeanContextServicesListener, or null if it does not implements the interface.java.util.IteratorgetCurrentServiceClasses()Returns an iterator of all registered service classes, withremoved()disabled.java.util.IteratorgetCurrentServiceSelectors(java.lang.Class serviceClass)Returns the service selectors of the specified service.java.lang.ObjectgetService(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.booleanhasService(java.lang.Class serviceClass)Checks whether a service is registed in this context or the parent context.voidinitialize()Initializes all transient fields of this instance, called by constructors andreadObject().protected voidinitializeBeanContextResources()Called after the parent context is updated.protected voidreleaseBeanContextResources()Called before the parent context is updated.voidreleaseService(BeanContextChild child, java.lang.Object requestor, java.lang.Object service)Release a service which has been requested previously.voidremoveBeanContextServicesListener(BeanContextServicesListener listener)voidrevokeService(java.lang.Class serviceClass, BeanContextServiceProvider serviceProvider, boolean revokeCurrentServicesNow)Revokes a service in this bean context.voidserviceAvailable(BeanContextServiceAvailableEvent event)Notify all listeners and children that implementsBeanContextServicesof the event.voidserviceRevoked(BeanContextServiceRevokedEvent event)Notify all listeners and children that implementsBeanContextServicesof 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 isBCSSServiceProviderobject. 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 registeredBeanContextServicesListeners. All access to this object should be synchronized on itself.
-
-
Constructor Detail
-
BeanContextServicesSupport
public BeanContextServicesSupport()
Constructs a standardBeanContextServicesSupport.
-
BeanContextServicesSupport
public BeanContextServicesSupport(BeanContextServices peer)
Constructs aBeanContextServicesSupportwhich is a delegate of the given peer.- Parameters:
peer- the peer of this context
-
BeanContextServicesSupport
public BeanContextServicesSupport(BeanContextServices peer, java.util.Locale locale)
Constructs aBeanContextServicesSupportwhich 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 aBeanContextServicesSupportwhich 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 aBeanContextServicesSupportwhich 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:
addBeanContextServicesListenerin interfaceBeanContextServices
-
addService
public boolean addService(java.lang.Class serviceClass, BeanContextServiceProvider provider)Add a service to this context.addService(serviceClass, provider, true).
- Specified by:
addServicein 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.ClassNotFoundExceptionDeserializes 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:
bcsPreDeserializationHookin classBeanContextSupport- Parameters:
ois- the object input stream- Throws:
java.io.IOExceptionjava.lang.ClassNotFoundException- See Also:
BeanContextSupport.bcsPreDeserializationHook(java.io.ObjectInputStream)
-
bcsPreSerializationHook
protected void bcsPreSerializationHook(java.io.ObjectOutputStream oos) throws java.io.IOExceptionSerializes 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:
bcsPreSerializationHookin 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:
childJustRemovedHookin classBeanContextSupport- Parameters:
child- the child just removedbcsChild- theBCSChildjust 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 aBCSSChildobject to company the given child.- Overrides:
createBCSChildin classBeanContextSupport- Parameters:
child- the childproxyPeer- the proxy peer of the child if there is one- Returns:
- a
BCSChildobject 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 aBCSSServiceProviderto company the given service.- Parameters:
serviceClass- the service classprovider- the service provider- Returns:
- a
BCSSServiceProviderto company the given service
-
fireServiceAdded
protected final void fireServiceAdded(java.lang.Class serviceClass)
Fires aBeanContextServiceAvailableEventto registeredBeanContextServicesListeners.- Parameters:
serviceClass- the service that has been added
-
fireServiceAdded
protected final void fireServiceAdded(BeanContextServiceAvailableEvent event)
Fires aBeanContextServiceAvailableEventto registeredBeanContextServicesListeners.- Parameters:
event- the event
-
fireServiceRevoked
protected final void fireServiceRevoked(java.lang.Class serviceClass, boolean revokeNow)Fires aBeanContextServiceRevokedEventto registeredBeanContextServicesListeners.- Parameters:
serviceClass- the service that has been revokedrevokeNow- whether to terminate service immediately
-
fireServiceRevoked
protected final void fireServiceRevoked(BeanContextServiceRevokedEvent event)
Fires aBeanContextServiceRevokedEventto registeredBeanContextServicesListeners.- 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:
getCurrentServiceClassesin 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:
getCurrentServiceSelectorsin 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:
getServicein 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- ifchildis 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:
hasServicein 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:BeanContextSupportInitializes all transient fields of this instance, called by constructors andreadObject().- Overrides:
initializein 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 aBCSSProxyServiceProvideris created to delegate service requests to the parent context.- Overrides:
initializeBeanContextResourcesin 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:
releaseBeanContextResourcesin 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:
releaseServicein interfaceBeanContextServices- Parameters:
child- the child that request the servicerequestor- the requestor objectservice- the service instance- Throws:
java.lang.IllegalArgumentException- ifchildis not a child of this context
-
removeBeanContextServicesListener
public void removeBeanContextServicesListener(BeanContextServicesListener listener)
- Specified by:
removeBeanContextServicesListenerin 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:
revokeServicein 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 implementsBeanContextServicesof the event.- Specified by:
serviceAvailablein interfaceBeanContextServicesListener- Overrides:
serviceAvailablein classBeanContextChildSupport- See Also:
BeanContextServicesListener.serviceAvailable(jadex.commons.beans.beancontext.BeanContextServiceAvailableEvent)
-
serviceRevoked
public void serviceRevoked(BeanContextServiceRevokedEvent event)
Notify all listeners and children that implementsBeanContextServicesof the event.- Specified by:
serviceRevokedin interfaceBeanContextServiceRevokedListener- Overrides:
serviceRevokedin classBeanContextChildSupport- See Also:
BeanContextServiceRevokedListener.serviceRevoked(jadex.commons.beans.beancontext.BeanContextServiceRevokedEvent)
-
-