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 classEvery child of context is companied with aBCSSChildinstance.protected classThis class implements theBeanContextServiceProviderinterface by wrapping aBeanContextServices.protected static classEvery servie registered in this context is companied with aBCSSServiceProviderinstance.Nested classes/interfaces inherited from class javaa.beans.beancontext.BeanContextSupport
BeanContextSupport.BCSChild, BeanContextSupport.BCSIterator -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ArrayListA list of registeredBeanContextServicesListeners.A proxy service provider that delegates service requests to the parent context.protected intThe number of serializable service providers currently registered.protected HashMapA map of all registered services - key is service class, value isBCSSServiceProviderobject.Fields inherited from class javaa.beans.beancontext.BeanContextSupport
bcmListeners, children, designTime, locale, okToUseGuiFields inherited from class javaa.beans.beancontext.BeanContextChildSupport
beanContext, beanContextChildPeer, pcSupport, rejectedSetBCOnce, vcSupportFields inherited from interface javaa.beans.beancontext.BeanContext
globalHierarchyLockFields inherited from interface javaa.beans.DesignMode
PROPERTYNAME -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a standardBeanContextServicesSupport.Constructs aBeanContextServicesSupportwhich is a delegate of the given peer.BeanContextServicesSupport(BeanContextServices peer, Locale locale) Constructs aBeanContextServicesSupportwhich is a delegate of the given peer.BeanContextServicesSupport(BeanContextServices peer, Locale locale, boolean designTime) Constructs aBeanContextServicesSupportwhich is a delegate of the given peer.BeanContextServicesSupport(BeanContextServices peer, Locale locale, boolean designTime, boolean okToUseGui) Constructs aBeanContextServicesSupportwhich is a delegate of the given peer. -
Method Summary
Modifier and TypeMethodDescriptionvoidbooleanaddService(Class serviceClass, BeanContextServiceProvider provider) Add a service to this context.protected booleanaddService(Class serviceClass, BeanContextServiceProvider provider, boolean fireEvent) Add a service to this context.protected voidDeserializes all serializable services and their providers before the children of this context is deserialized.protected voidSerializes all serializable services and their providers before the children of this context is serialized.protected voidchildJustRemovedHook(Object child, BeanContextSupport.BCSChild bcsChild) This method is called everytime a child is removed from this context.protected BeanContextSupport.BCSChildcreateBCSChild(Object child, Object proxyPeer) Creates aBCSSChildobject to company the given child.createBCSSServiceProvider(Class serviceClass, BeanContextServiceProvider provider) Creates aBCSSServiceProviderto company the given service.protected final voidfireServiceAdded(Class serviceClass) Fires aBeanContextServiceAvailableEventto registeredBeanContextServicesListeners.protected final voidFires aBeanContextServiceAvailableEventto registeredBeanContextServicesListeners.protected final voidfireServiceRevoked(Class serviceClass, boolean revokeNow) Fires aBeanContextServiceRevokedEventto registeredBeanContextServicesListeners.protected final voidFires aBeanContextServiceRevokedEventto registeredBeanContextServicesListeners.Returns the peer of this context casted asBeanContextServices.protected static final BeanContextServicesListenerReturns 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.booleanhasService(Class serviceClass) Checks whether a service is registed in this context or the parent context.voidInitializes all transient fields of this instance, called by constructors andreadObject().protected voidCalled after the parent context is updated.protected voidCalled before the parent context is updated.voidreleaseService(BeanContextChild child, Object requestor, Object service) Release a service which has been requested previously.voidvoidrevokeService(Class serviceClass, BeanContextServiceProvider serviceProvider, boolean revokeCurrentServicesNow) Revokes a service in this bean context.voidNotify all listeners and children that implementsBeanContextServicesof the event.voidNotify all listeners and children that implementsBeanContextServicesof 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, writeChildrenMethods inherited from class javaa.beans.beancontext.BeanContextChildSupport
addPropertyChangeListener, addVetoableChangeListener, firePropertyChange, fireVetoableChange, getBeanContext, getBeanContextChildPeer, isDelegated, removePropertyChangeListener, removeVetoableChangeListener, setBeanContext, validatePendingSetBeanContextMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface javaa.beans.beancontext.BeanContext
addBeanContextMembershipListener, getResource, getResourceAsStream, instantiateChild, removeBeanContextMembershipListenerMethods inherited from interface javaa.beans.beancontext.BeanContextChild
addPropertyChangeListener, addVetoableChangeListener, getBeanContext, removePropertyChangeListener, removeVetoableChangeListener, setBeanContextMethods 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, toArrayMethods inherited from interface javaa.beans.DesignMode
isDesignTime, setDesignTimeMethods inherited from interface javaa.beans.Visibility
avoidingGui, dontUseGui, needsGui, okToUseGui
-
Field Details
-
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 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 registeredBeanContextServicesListeners. All access to this object should be synchronized on itself.
-
-
Constructor Details
-
BeanContextServicesSupport
public BeanContextServicesSupport()Constructs a standardBeanContextServicesSupport. -
BeanContextServicesSupport
Constructs aBeanContextServicesSupportwhich is a delegate of the given peer.- Parameters:
peer- the peer of this context
-
BeanContextServicesSupport
Constructs aBeanContextServicesSupportwhich is a delegate of the given peer.- Parameters:
peer- the peer of this contextlocale- the locale of this context
-
BeanContextServicesSupport
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, 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 Details
-
addBeanContextServicesListener
- Specified by:
addBeanContextServicesListenerin interfaceBeanContextServices
-
addService
Add a service to this context.Delegate to
addService(serviceClass, provider, true).- Specified by:
addServicein 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
intis 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:
IOExceptionClassNotFoundException- See Also:
-
bcsPreSerializationHook
Serializes all serializable services and their providers before the children of this context is serialized.First a
intis 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:
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:
childJustRemovedHookin classBeanContextSupport- Parameters:
child- the child just removedbcsChild- theBCSChildjust removed- See Also:
-
createBCSChild
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:
-
createBCSSServiceProvider
protected BeanContextServicesSupport.BCSSServiceProvider createBCSSServiceProvider(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
Fires aBeanContextServiceAvailableEventto registeredBeanContextServicesListeners.- Parameters:
serviceClass- the service that has been added
-
fireServiceAdded
Fires aBeanContextServiceAvailableEventto registeredBeanContextServicesListeners.- Parameters:
event- the event
-
fireServiceRevoked
Fires aBeanContextServiceRevokedEventto registeredBeanContextServicesListeners.- Parameters:
serviceClass- the service that has been revokedrevokeNow- whether to terminate service immediately
-
fireServiceRevoked
Fires aBeanContextServiceRevokedEventto registeredBeanContextServicesListeners.- 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:
getCurrentServiceClassesin 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:
getCurrentServiceSelectorsin 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:
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:
IllegalArgumentException- ifchildis not a child of this contextTooManyListenersException- See Also:
-
hasService
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:
-
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:
-
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:
-
releaseService
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:
IllegalArgumentException- ifchildis not a child of this context
-
removeBeanContextServicesListener
- Specified by:
removeBeanContextServicesListenerin 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
BeanContextServiceRevokedEventis 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:
-
serviceAvailable
Notify all listeners and children that implementsBeanContextServicesof the event.- Specified by:
serviceAvailablein interfaceBeanContextServicesListener- Overrides:
serviceAvailablein classBeanContextChildSupport- See Also:
-
serviceRevoked
Notify all listeners and children that implementsBeanContextServicesof the event.- Specified by:
serviceRevokedin interfaceBeanContextServiceRevokedListener- Overrides:
serviceRevokedin classBeanContextChildSupport- See Also:
-