public class BeanContextServicesSupport extends BeanContextSupport implements BeanContextServices, java.io.Serializable
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.Modifier and Type | Class and Description |
---|---|
protected class |
BeanContextServicesSupport.BCSSChild
Every child of context is companied with a
BCSSChild
instance. |
protected class |
BeanContextServicesSupport.BCSSProxyServiceProvider
This class implements the
BeanContextServiceProvider
interface by wrapping a BeanContextServices . |
protected static class |
BeanContextServicesSupport.BCSSServiceProvider
Every servie registered in this context is companied with a
BCSSServiceProvider instance. |
BeanContextSupport.BCSChild, BeanContextSupport.BCSIterator
Modifier and Type | Field and Description |
---|---|
protected java.util.ArrayList |
bcsListeners
A list of registered
BeanContextServicesListener 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 is
BCSSServiceProvider object. |
bcmListeners, children, designTime, locale, okToUseGui
beanContext, beanContextChildPeer, pcSupport, rejectedSetBCOnce, vcSupport
globalHierarchyLock
PROPERTYNAME
Constructor and Description |
---|
BeanContextServicesSupport()
Constructs a standard
BeanContextServicesSupport . |
BeanContextServicesSupport(BeanContextServices peer)
Constructs a
BeanContextServicesSupport which is a
delegate of the given peer. |
BeanContextServicesSupport(BeanContextServices peer,
java.util.Locale locale)
Constructs a
BeanContextServicesSupport which is a
delegate of the given peer. |
BeanContextServicesSupport(BeanContextServices peer,
java.util.Locale locale,
boolean designTime)
Constructs a
BeanContextServicesSupport which is a
delegate of the given peer. |
BeanContextServicesSupport(BeanContextServices peer,
java.util.Locale locale,
boolean designTime,
boolean okToUseGui)
Constructs a
BeanContextServicesSupport which is a
delegate of the given peer. |
Modifier and Type | Method and 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 a
BCSSChild object to company the given child. |
protected BeanContextServicesSupport.BCSSServiceProvider |
createBCSSServiceProvider(java.lang.Class serviceClass,
BeanContextServiceProvider provider)
Creates a
BCSSServiceProvider to company the given
service. |
protected void |
fireServiceAdded(BeanContextServiceAvailableEvent event)
Fires a
BeanContextServiceAvailableEvent to registered
BeanContextServicesListener s. |
protected void |
fireServiceAdded(java.lang.Class serviceClass)
Fires a
BeanContextServiceAvailableEvent to registered
BeanContextServicesListener s. |
protected void |
fireServiceRevoked(BeanContextServiceRevokedEvent event)
Fires a
BeanContextServiceRevokedEvent to registered
BeanContextServicesListener s. |
protected void |
fireServiceRevoked(java.lang.Class serviceClass,
boolean revokeNow)
Fires a
BeanContextServiceRevokedEvent to registered
BeanContextServicesListener s. |
BeanContextServices |
getBeanContextServicesPeer()
Returns the peer of this context casted as
BeanContextServices . |
protected static BeanContextServicesListener |
getChildBeanContextServicesListener(java.lang.Object child)
Returns the given child casted to
BeanContextServicesListener , or null if it does not
implements the interface. |
java.util.Iterator |
getCurrentServiceClasses()
Returns an iterator of all registered service classes, with
removed() 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 and
readObject() . |
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 implements
BeanContextServices of the event. |
void |
serviceRevoked(BeanContextServiceRevokedEvent event)
Notify all listeners and children that implements
BeanContextServices of the event. |
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
addPropertyChangeListener, addVetoableChangeListener, firePropertyChange, fireVetoableChange, getBeanContext, getBeanContextChildPeer, isDelegated, removePropertyChangeListener, removeVetoableChangeListener, setBeanContext, validatePendingSetBeanContext
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
addBeanContextMembershipListener, getResource, getResourceAsStream, instantiateChild, removeBeanContextMembershipListener
addPropertyChangeListener, addVetoableChangeListener, getBeanContext, removePropertyChangeListener, removeVetoableChangeListener, setBeanContext
add, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, iterator, parallelStream, remove, removeAll, removeIf, retainAll, size, spliterator, stream, toArray, toArray
isDesignTime, setDesignTime
avoidingGui, dontUseGui, needsGui, okToUseGui
protected transient java.util.HashMap services
BCSSServiceProvider
object. All access to this object
should be synchronized on itself.protected transient int serializable
protected transient BeanContextServicesSupport.BCSSProxyServiceProvider proxy
protected transient java.util.ArrayList bcsListeners
BeanContextServicesListener
s. All
access to this object should be synchronized on itself.public BeanContextServicesSupport()
BeanContextServicesSupport
.public BeanContextServicesSupport(BeanContextServices peer)
BeanContextServicesSupport
which is a
delegate of the given peer.peer
- the peer of this contextpublic BeanContextServicesSupport(BeanContextServices peer, java.util.Locale locale)
BeanContextServicesSupport
which is a
delegate of the given peer.peer
- the peer of this contextlocale
- the locale of this contextpublic BeanContextServicesSupport(BeanContextServices peer, java.util.Locale locale, boolean designTime)
BeanContextServicesSupport
which is a
delegate of the given peer.peer
- the peer of this contextlocale
- the locale of this contextdesignTime
- whether in design mode or notpublic BeanContextServicesSupport(BeanContextServices peer, java.util.Locale locale, boolean designTime, boolean okToUseGui)
BeanContextServicesSupport
which is a
delegate of the given peer.peer
- the peer of this contextlocale
- the locale of this contextdesignTime
- whether in design mode or notokToUseGui
- whether GUI is usable or notpublic void addBeanContextServicesListener(BeanContextServicesListener listener)
addBeanContextServicesListener
in interface BeanContextServices
public boolean addService(java.lang.Class serviceClass, BeanContextServiceProvider provider)
addService(serviceClass, provider, true).
addService
in interface BeanContextServices
BeanContextServices.addService(java.lang.Class,
jadex.commons.beans.beancontext.BeanContextServiceProvider)
protected boolean addService(java.lang.Class serviceClass, BeanContextServiceProvider provider, boolean fireEvent)
serviceClass
- the service classprovider
- the provider of the servicefireEvent
- the flag indicating to fire event or notprotected void bcsPreDeserializationHook(java.io.ObjectInputStream ois) throws java.io.IOException, java.lang.ClassNotFoundException
int is read, indicating the number of services to read. Then pairs of service class and service provider are read one by one.
bcsPreDeserializationHook
in class BeanContextSupport
ois
- the object input streamjava.io.IOException
java.lang.ClassNotFoundException
BeanContextSupport.bcsPreDeserializationHook(java.io.ObjectInputStream)
protected void bcsPreSerializationHook(java.io.ObjectOutputStream oos) throws java.io.IOException
int is writtern, indicating the number of serializable services. Then pairs of service class and service provider are writtern one by one.
bcsPreSerializationHook
in class BeanContextSupport
oos
- the object output streamjava.io.IOException
BeanContextSupport.bcsPreSerializationHook(java.io.ObjectOutputStream)
protected void childJustRemovedHook(java.lang.Object child, BeanContextSupport.BCSChild bcsChild)
childJustRemovedHook
in class BeanContextSupport
child
- the child just removedbcsChild
- the BCSChild
just removedBeanContextSupport.childJustRemovedHook(java.lang.Object,
jadex.commons.beans.beancontext.BeanContextSupport.BCSChild)
protected BeanContextSupport.BCSChild createBCSChild(java.lang.Object child, java.lang.Object proxyPeer)
BCSSChild
object to company the given child.createBCSChild
in class BeanContextSupport
child
- the childproxyPeer
- the proxy peer of the child if there is oneBCSChild
object to company the given childBeanContextSupport.createBCSChild(java.lang.Object,
java.lang.Object)
protected BeanContextServicesSupport.BCSSServiceProvider createBCSSServiceProvider(java.lang.Class serviceClass, BeanContextServiceProvider provider)
BCSSServiceProvider
to company the given
service.serviceClass
- the service classprovider
- the service providerBCSSServiceProvider
to company the given serviceprotected final void fireServiceAdded(java.lang.Class serviceClass)
BeanContextServiceAvailableEvent
to registered
BeanContextServicesListener
s.serviceClass
- the service that has been addedprotected final void fireServiceAdded(BeanContextServiceAvailableEvent event)
BeanContextServiceAvailableEvent
to registered
BeanContextServicesListener
s.event
- the eventprotected final void fireServiceRevoked(java.lang.Class serviceClass, boolean revokeNow)
BeanContextServiceRevokedEvent
to registered
BeanContextServicesListener
s.serviceClass
- the service that has been revokedrevokeNow
- whether to terminate service immediatelyprotected final void fireServiceRevoked(BeanContextServiceRevokedEvent event)
BeanContextServiceRevokedEvent
to registered
BeanContextServicesListener
s.event
- the eventpublic BeanContextServices getBeanContextServicesPeer()
BeanContextServices
.BeanContextServices
protected static final BeanContextServicesListener getChildBeanContextServicesListener(java.lang.Object child)
BeanContextServicesListener
, or null if it does not
implements the interface.child
- a childBeanContextServicesListener
, or null if it does
not implements the interfacepublic java.util.Iterator getCurrentServiceClasses()
removed()
disabled.getCurrentServiceClasses
in interface BeanContextServices
BeanContextServices.getCurrentServiceClasses()
public java.util.Iterator getCurrentServiceSelectors(java.lang.Class serviceClass)
remove()
operation is disabled.getCurrentServiceSelectors
in interface BeanContextServices
BeanContextServices.getCurrentServiceSelectors(java.lang.Class)
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
getService
in interface BeanContextServices
child
- the child that request servicerequestor
- the requestor objectserviceClass
- the service classserviceSelector
- the service selectorsbcsrl
- the BeanContextServiceRevokedListener
java.lang.IllegalArgumentException
- if child
is not a child of this contextjava.util.TooManyListenersException
BeanContextServices.getService(jadex.commons.beans.beancontext.BeanContextChild,
java.lang.Object, java.lang.Class, java.lang.Object,
jadex.commons.beans.beancontext.BeanContextServiceRevokedListener)
public boolean hasService(java.lang.Class serviceClass)
hasService
in interface BeanContextServices
serviceClass
- the service classBeanContextServices.hasService(java.lang.Class)
public void initialize()
BeanContextSupport
readObject()
.initialize
in class BeanContextSupport
protected void initializeBeanContextResources()
BeanContextServices
. If it is,
then a BCSSProxyServiceProvider
is created to delegate
service requests to the parent context.initializeBeanContextResources
in class BeanContextChildSupport
BeanContextChildSupport.initializeBeanContextResources()
protected void releaseBeanContextResources()
releaseBeanContextResources
in class BeanContextChildSupport
BeanContextChildSupport.releaseBeanContextResources()
public void releaseService(BeanContextChild child, java.lang.Object requestor, java.lang.Object service)
releaseService
in interface BeanContextServices
child
- the child that request the servicerequestor
- the requestor objectservice
- the service instancejava.lang.IllegalArgumentException
- if child
is not a child of this contextpublic void removeBeanContextServicesListener(BeanContextServicesListener listener)
removeBeanContextServicesListener
in interface BeanContextServices
public void revokeService(java.lang.Class serviceClass, BeanContextServiceProvider serviceProvider, boolean revokeCurrentServicesNow)
BeanContextServiceRevokedEvent is fired. All registered service listeners and current service users get notified.
revokeService
in interface BeanContextServices
serviceClass
- the service classserviceProvider
- the service providerrevokeCurrentServicesNow
- true if service should be terminated immediantlyBeanContextServices.revokeService(java.lang.Class,
jadex.commons.beans.beancontext.BeanContextServiceProvider, boolean)
public void serviceAvailable(BeanContextServiceAvailableEvent event)
BeanContextServices
of the event.serviceAvailable
in interface BeanContextServicesListener
serviceAvailable
in class BeanContextChildSupport
BeanContextServicesListener.serviceAvailable(jadex.commons.beans.beancontext.BeanContextServiceAvailableEvent)
public void serviceRevoked(BeanContextServiceRevokedEvent event)
BeanContextServices
of the event.serviceRevoked
in interface BeanContextServiceRevokedListener
serviceRevoked
in class BeanContextChildSupport
BeanContextServiceRevokedListener.serviceRevoked(jadex.commons.beans.beancontext.BeanContextServiceRevokedEvent)