|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjava.beans.beancontext.BeanContextChildSupport
java.beans.beancontext.BeanContextSupport
java.beans.beancontext.BeanContextServicesSupport
public class BeanContextServicesSupport
This is a helper class for implementing a bean context which supplies services. It is intended to be used either by subclassing or by calling methods of this implementation from another.
| Nested Class Summary | |
|---|---|
protected class |
BeanContextServicesSupport.BCSSChild
|
protected class |
BeanContextServicesSupport.BCSSProxyServiceProvider
|
protected static class |
BeanContextServicesSupport.BCSSServiceProvider
|
| Nested classes/interfaces inherited from class java.beans.beancontext.BeanContextSupport |
|---|
BeanContextSupport.BCSChild, BeanContextSupport.BCSIterator |
| Field Summary | |
|---|---|
protected ArrayList |
bcsListeners
A collection of listeners who receive availability and revocation notifications. |
protected BeanContextServicesSupport.BCSSProxyServiceProvider |
proxy
|
protected int |
serializable
The number of serializable service providers. |
protected HashMap |
services
A map of registered services, linking the service class to its associated BeanContextServicesSupport.BCSSServiceProvider. |
| Fields inherited from class java.beans.beancontext.BeanContextSupport |
|---|
bcmListeners, children, designTime, locale, okToUseGui |
| Fields inherited from class java.beans.beancontext.BeanContextChildSupport |
|---|
beanContext, beanContextChildPeer, pcSupport, rejectedSetBCOnce, vcSupport |
| Fields inherited from interface java.beans.beancontext.BeanContext |
|---|
globalHierarchyLock |
| Fields inherited from interface java.beans.DesignMode |
|---|
PROPERTYNAME |
| Constructor Summary | |
|---|---|
BeanContextServicesSupport()
Construct a BeanContextServicesSupport instance. |
|
BeanContextServicesSupport(BeanContextServices peer)
Construct a BeanContextServicesSupport instance. |
|
BeanContextServicesSupport(BeanContextServices peer,
Locale locale)
Construct a BeanContextServicesSupport instance. |
|
BeanContextServicesSupport(BeanContextServices peer,
Locale locale,
boolean dtime)
Construct a BeanContextServicesSupport instance. |
|
BeanContextServicesSupport(BeanContextServices peer,
Locale locale,
boolean dtime,
boolean visible)
Construct a BeanContextServicesSupport instance. |
|
| Method Summary | |
|---|---|
void |
addBeanContextServicesListener(BeanContextServicesListener listener)
Adds a new listener for service availability and revocation events. |
boolean |
addService(Class serviceClass,
BeanContextServiceProvider bcsp)
Registers a new service from the specified service provider. |
protected boolean |
addService(Class serviceClass,
BeanContextServiceProvider bcsp,
boolean fireEvent)
Registers a new service from the specified service provider. |
protected void |
bcsPreDeserializationHook(ObjectInputStream ois)
Deserializes any service providers which are serializable. |
protected void |
bcsPreSerializationHook(ObjectOutputStream oos)
Serializes any service providers which are serializable. |
protected void |
childJustRemovedHook(Object child,
BeanContextSupport.BCSChild bcsc)
Revokes any services used by a child that has just been removed. |
protected BeanContextSupport.BCSChild |
createBCSChild(Object targetChild,
Object peer)
Overrides the BeanContextSupport.createBCSChild(java.lang.Object, java.lang.Object) method
so as to use a BeanContextServicesSupport.BCSSChild instead. |
protected BeanContextServicesSupport.BCSSServiceProvider |
createBCSSServiceProvider(Class sc,
BeanContextServiceProvider bcsp)
Provides a hook so that subclasses can replace the BeanContextServicesSupport.BCSSServiceProvider class, used to store registered
service providers, with a subclass without replacing the
addService(Class, BeanContextServiceProvider) method. |
protected void |
fireServiceAdded(BeanContextServiceAvailableEvent bcssae)
Sends a BeanContextServiceAvailableEvent to all
registered listeners. |
protected void |
fireServiceAdded(Class serviceClass)
Sends a BeanContextServiceAvailableEvent to all
registered listeners. |
protected void |
fireServiceRevoked(BeanContextServiceRevokedEvent event)
Sends a BeanContextServiceRevokedEvent to all
registered listeners. |
protected void |
fireServiceRevoked(Class serviceClass,
boolean revokeNow)
Sends a BeanContextServiceRevokedEvent to all
registered listeners. |
BeanContextServices |
getBeanContextServicesPeer()
Returns the services peer given at construction time, or null if no peer was given. |
protected static BeanContextServicesListener |
getChildBeanContextServicesListener(Object child)
Returns child as an instance of
BeanContextServicesListener, or null if
child does not implement that interface. |
Iterator |
getCurrentServiceClasses()
Returns an iterator over the currently available services. |
Iterator |
getCurrentServiceSelectors(Class serviceClass)
Returns an iterator over the service selectors of the service provider for the given service. |
Object |
getService(BeanContextChild child,
Object requestor,
Class serviceClass,
Object serviceSelector,
BeanContextServiceRevokedListener bcsrl)
Retrieves the specified service. |
boolean |
hasService(Class serviceClass)
Returns true if the specified service is available. |
void |
initialize()
|
protected void |
initializeBeanContextResources()
Subclasses may override this method to allocate resources from the nesting bean context. |
protected void |
releaseBeanContextResources()
Relinquishes any resources obtained from the parent context. |
void |
releaseService(BeanContextChild child,
Object requestor,
Object service)
Releases the reference to a service held by a BeanContextChild (or an arbitrary object associated
with it). |
void |
removeBeanContextServicesListener(BeanContextServicesListener listener)
Remove a listener on all adds and removes of services. |
void |
revokeService(Class serviceClass,
BeanContextServiceProvider bcsp,
boolean revokeCurrentServicesNow)
Revokes the given service. |
void |
serviceAvailable(BeanContextServiceAvailableEvent bcssae)
Called by BeanContextServices whenever a service is made available. |
void |
serviceRevoked(BeanContextServiceRevokedEvent bcssre)
Called by BeanContextServices.revokeService() to indicate that a service has been revoked. |
| Methods inherited from class java.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 java.beans.beancontext.BeanContext |
|---|
addBeanContextMembershipListener, getResource, getResourceAsStream, instantiateChild, removeBeanContextMembershipListener |
| Methods inherited from interface java.util.Collection |
|---|
add, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray |
| Methods inherited from interface java.beans.beancontext.BeanContextChild |
|---|
addPropertyChangeListener, addVetoableChangeListener, getBeanContext, removePropertyChangeListener, removeVetoableChangeListener, setBeanContext |
| Methods inherited from interface java.beans.Visibility |
|---|
avoidingGui, dontUseGui, needsGui, okToUseGui |
| Methods inherited from interface java.beans.DesignMode |
|---|
isDesignTime, setDesignTime |
| Field Detail |
|---|
protected transient ArrayList bcsListeners
protected transient BeanContextServicesSupport.BCSSProxyServiceProvider proxy
protected transient int serializable
protected transient HashMap services
BeanContextServicesSupport.BCSSServiceProvider.
| Constructor Detail |
|---|
public BeanContextServicesSupport()
BeanContextServicesSupport instance.
public BeanContextServicesSupport(BeanContextServices peer)
BeanContextServicesSupport instance.
peer - the bean context services peer (null permitted).
public BeanContextServicesSupport(BeanContextServices peer,
Locale locale)
BeanContextServicesSupport instance.
peer - the bean context peer (null permitted).locale - the locale (null permitted, equivalent to
the default locale).
public BeanContextServicesSupport(BeanContextServices peer,
Locale locale,
boolean dtime)
BeanContextServicesSupport instance.
peer - the bean context peer (null permitted).locale - the locale (null permitted, equivalent to
the default locale).dtime - a flag indicating whether or not the bean context is in
design time mode.
public BeanContextServicesSupport(BeanContextServices peer,
Locale locale,
boolean dtime,
boolean visible)
BeanContextServicesSupport instance.
peer - the bean context peer (null permitted).locale - the locale (null permitted, equivalent to
the default locale).dtime - a flag indicating whether or not the bean context is in
design time mode.visible - initial value of the okToUseGui flag.| Method Detail |
|---|
public void addBeanContextServicesListener(BeanContextServicesListener listener)
addBeanContextServicesListener in interface BeanContextServiceslistener - the listener to add.
public boolean addService(Class serviceClass,
BeanContextServiceProvider bcsp)
BeanContextServiceAvailableEvent is fired. If
the service is already registered, then this method instead
returns false. This is equivalent to calling
addService(serviceClass, bcsp, true).
addService in interface BeanContextServicesserviceClass - the class of the service to be registered.bcsp - the provider of the given service.
addService(Class, BeanContextServiceProvider, boolean)
protected boolean addService(Class serviceClass,
BeanContextServiceProvider bcsp,
boolean fireEvent)
fireEvent is true) a
BeanContextServiceAvailableEvent is fired. If
the service is already registered, then this method instead
returns false.
serviceClass - the class of the service to be registered.bcsp - the provider of the given service.fireEvent - true if a service availability event should
be fired.
protected void bcsPreDeserializationHook(ObjectInputStream ois)
throws ClassNotFoundException,
IOException
readObject method of
BeanContextSupport prior to deserialization of the children.
Subclasses may envelope its behaviour in order to read further
serialized data to the stream.
bcsPreDeserializationHook in class BeanContextSupportois - the stream from which data is being deserialized.
IOException - if an I/O error occurs.
ClassNotFoundException - if the class of a deserialized object
can not be found.
protected void bcsPreSerializationHook(ObjectOutputStream oos)
throws IOException
writeObject method of
BeanContextSupport prior to serialization of the children.
Subclasses may envelope its behaviour in order to add further
serialized data to the stream.
bcsPreSerializationHook in class BeanContextSupportoos - the stream to which data is being serialized.
IOException - if an I/O error occurs.
protected void childJustRemovedHook(Object child,
BeanContextSupport.BCSChild bcsc)
BeanContextSupport) calls this method
when a child has just been successfully removed. Subclasses can
extend this method in order to perform additional operations
on child removal.
childJustRemovedHook in class BeanContextSupportchild - the child being removed.bcsc - the support object for the child.
protected BeanContextSupport.BCSChild createBCSChild(Object targetChild,
Object peer)
BeanContextSupport.createBCSChild(java.lang.Object, java.lang.Object) method
so as to use a BeanContextServicesSupport.BCSSChild instead.
createBCSChild in class BeanContextSupporttargetChild - the child to create the child for.peer - the peer which relates to the child if a proxy is used.
BeanContextServicesSupport.BCSSChild.
protected BeanContextServicesSupport.BCSSServiceProvider createBCSSServiceProvider(Class sc,
BeanContextServiceProvider bcsp)
BeanContextServicesSupport.BCSSServiceProvider class, used to store registered
service providers, with a subclass without replacing the
addService(Class, BeanContextServiceProvider) method.
sc - the class of service being registered.bcsp - the provider of the service.
BeanContextServicesSupport.BCSSServiceProvider wrapping the provider.protected final void fireServiceAdded(BeanContextServiceAvailableEvent bcssae)
BeanContextServiceAvailableEvent to all
registered listeners.
bcssae - the event to send.protected final void fireServiceAdded(Class serviceClass)
BeanContextServiceAvailableEvent to all
registered listeners.
serviceClass - the service that is now available.fireServiceAdded(BeanContextServiceAvailableEvent)protected final void fireServiceRevoked(BeanContextServiceRevokedEvent event)
BeanContextServiceRevokedEvent to all
registered listeners.
event - the event to send.
protected final void fireServiceRevoked(Class serviceClass,
boolean revokeNow)
BeanContextServiceRevokedEvent to all
registered listeners.
serviceClass - the service that has been revoked.fireServiceRevoked(BeanContextServiceRevokedEvent)public BeanContextServices getBeanContextServicesPeer()
null if no peer was given.
BeanContextServices peer.protected static final BeanContextServicesListener getChildBeanContextServicesListener(Object child)
child as an instance of
BeanContextServicesListener, or null if
child does not implement that interface.
child - the child (null permitted).
BeanContextServicesListener.public Iterator getCurrentServiceClasses()
getCurrentServiceClasses in interface BeanContextServicesBeanContext.globalHierarchyLockpublic Iterator getCurrentServiceSelectors(Class serviceClass)
BeanContextServiceProvider.getCurrentServiceSelectors(java.beans.beancontext.BeanContextServices, java.lang.Class)
of the provider itself. If the specified service is not available,
null is returned.
getCurrentServiceSelectors in interface BeanContextServicesserviceClass - the service whose provider's selectors should
be iterated over.
Iterator over the service selectors of the
provider of the given service.
public Object getService(BeanContextChild child,
Object requestor,
Class serviceClass,
Object serviceSelector,
BeanContextServiceRevokedListener bcsrl)
throws TooManyListenersException
BeanContextServices, if possible.
If the service can not be found at all, then null
is returned.
getService in interface BeanContextServiceschild - the child obtaining the reference.requestor - the requestor of the service, which may be the
child itself.serviceClass - the service being requested.serviceSelector - an additional service-dependent parameter
(may be null if not appropriate).bcsrl - a listener used to notify the requestor that the service
has since been revoked.
null.
TooManyListenersException - according to Sun's documentation.public boolean hasService(Class serviceClass)
hasService in interface BeanContextServicesserviceClass - the service to check for.
public void initialize()
initialize in class BeanContextSupportprotected void initializeBeanContextResources()
initializeBeanContextResources in class BeanContextChildSupportprotected void releaseBeanContextResources()
releaseBeanContextResources in class BeanContextChildSupport
public void releaseService(BeanContextChild child,
Object requestor,
Object service)
BeanContextChild (or an arbitrary object associated
with it). It simply calls the appropriate method on the
underlying provider.
releaseService in interface BeanContextServiceschild - the child who holds the reference.requestor - the object that requested the reference.service - the service being released.BeanContextServices.getService(java.beans.beancontext.BeanContextChild,java.lang.Object,java.lang.Class,java.lang.Object,java.beans.beancontext.BeanContextServiceRevokedListener)public void removeBeanContextServicesListener(BeanContextServicesListener listener)
BeanContextServices
removeBeanContextServicesListener in interface BeanContextServiceslistener - the listener to add.
public void revokeService(Class serviceClass,
BeanContextServiceProvider bcsp,
boolean revokeCurrentServicesNow)
BeanContextServiceRevokedEvent is
emitted to all registered BeanContextServiceRevokedListeners
and BeanContextServiceListeners. If revokeCurrentServicesNow
is true, termination of the service is immediate. Otherwise, prior
acquisitions of the service by requestors remain valid.
revokeService in interface BeanContextServicesserviceClass - the service to revoke.bcsp - the provider of the revoked service.revokeCurrentServicesNow - true if this is an exceptional circumstance
where service should be immediately revoked.public void serviceAvailable(BeanContextServiceAvailableEvent bcssae)
BeanContextChildSupportBeanContextServices whenever a service is made available.
This method is meant to be overriden.
BeanContextChildSupport's implementation does
nothing.
serviceAvailable in interface BeanContextServicesListenerserviceAvailable in class BeanContextChildSupportbcssae - the service revoked event, with useful information
about the new service.public void serviceRevoked(BeanContextServiceRevokedEvent bcssre)
BeanContextChildSupportBeanContextServices.revokeService() to indicate that a service has been revoked.
If you have a reference to such a service, it should be
discarded and may no longer function properly.
getService() will no longer work on the specified
service class after this event has been fired.
This method is meant to be overriden.
BeanContextChildSupport's implementation does
nothing.
serviceRevoked in interface BeanContextServiceRevokedListenerserviceRevoked in class BeanContextChildSupportbcssre - the service revoked event.BeanContextServices.revokeService(java.lang.Class,java.beans.beancontext.BeanContextServiceProvider,boolean)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||