java.beans.beancontext

Class BeanContextServicesSupport

Implemented Interfaces:
BeanContext, BeanContextChild, BeanContextServiceRevokedListener, BeanContextServices, BeanContextServicesListener, Collection, DesignMode, EventListener, Iterable, PropertyChangeListener, Serializable, VetoableChangeListener, Visibility

public class BeanContextServicesSupport
extends BeanContextSupport
implements BeanContextServices

Since:
1.2
See Also:
Serialized Form

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
protected BeanContextServicesSupport.BCSSProxyServiceProvider
proxy
protected int
serializable
protected HashMap
services

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()
The basic constructor.
BeanContextServicesSupport(BeanContextServices peer)
BeanContextServicesSupport(BeanContextServices peer, Locale locale)
BeanContextServicesSupport(BeanContextServices peer, Locale locale, boolean dtime)
BeanContextServicesSupport(BeanContextServices peer, Locale locale, boolean dtime, boolean visible)

Method Summary

void
addBeanContextServicesListener(BeanContextServicesListener listener)
Add a listener on all adds and removes of services.
boolean
addService(Class serviceClass, BeanContextServiceProvider bcsp)
Register a service to make it available to others.
protected boolean
addService(Class serviceClass, BeanContextServiceProvider bcsp, boolean fireEvent)
protected void
bcsPreDeserializationHook(ObjectInputStream ois)
protected void
bcsPreSerializationHook(ObjectOutputStream oos)
protected void
childJustRemovedHook(Object child, BeanContextSupport.BCSChild bcsc)
protected BeanContextSupport.BCSChild
createBCSChild(Object targetChild, Object peer)
protected BeanContextServicesSupport.BCSSServiceProvider
createBCSSServiceProvider(Class sc, BeanContextServiceProvider bcsp)
protected void
fireServiceAdded(BeanContextServiceAvailableEvent bcssae)
protected void
fireServiceAdded(Class serviceClass)
protected void
fireServiceRevoked(BeanContextServiceRevokedEvent event)
protected void
fireServiceRevoked(Class serviceClass, boolean revokeNow)
BeanContextServices
getBeanContextServicesPeer()
protected static BeanContextServicesListener
getChildBeanContextServicesListener(Object child)
Iterator
getCurrentServiceClasses()
Get a list of all service classes supported.
Iterator
getCurrentServiceSelectors(Class serviceClass)
Get a list of valid service selectors for the specified service class.
Object
getService(BeanContextChild child, Object requestor, Class serviceClass, Object serviceSelector, BeanContextServiceRevokedListener bcsrl)
Get a service from this BeanContextServices.
boolean
hasService(Class serviceClass)
Tell whether the specified service class is available.
void
initialize()
protected void
initializeBeanContextResources()
protected void
releaseBeanContextResources()
void
releaseService(BeanContextChild child, Object requestor, Object service)
Release your copy of this service.
void
removeBeanContextServicesListener(BeanContextServicesListener listener)
Remove a listener on all adds and removes of services.
void
revokeService(Class serviceClass, BeanContextServiceProvider bcsp, boolean revokeCurrentServicesNow)
Make it so that no one else can use this service.
void
serviceAvailable(BeanContextServiceAvailableEvent bcssae)
Called by BeanContextServices whenever a service is made available.
void
serviceRevoked(BeanContextServiceRevokedEvent bcssre)

Methods inherited from class java.beans.beancontext.BeanContextSupport

add, addAll, addBeanContextMembershipListener, avoidingGui, bcsChildren, bcsPreDeserializationHook, bcsPreSerializationHook, childDeserializedHook, childJustAddedHook, childJustRemovedHook, classEquals, clear, contains, containsAll, containsKey, copyChildren, createBCSChild, deserialize, dontUseGui, fireChildrenAdded, fireChildrenRemoved, getBeanContextPeer, getChildBeanContextChild, getChildBeanContextMembershipListener, getChildPropertyChangeListener, getChildSerializable, getChildVetoableChangeListener, getChildVisibility, getLocale, getResource, getResourceAsStream, initialize, 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 java.beans.beancontext.BeanContextChildSupport

addPropertyChangeListener, addVetoableChangeListener, firePropertyChange, fireVetoableChange, getBeanContext, getBeanContextChildPeer, initializeBeanContextResources, isDelegated, releaseBeanContextResources, removePropertyChangeListener, removeVetoableChangeListener, serviceAvailable, serviceRevoked, setBeanContext, validatePendingSetBeanContext

Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Details

bcsListeners

protected ArrayList bcsListeners

proxy

protected BeanContextServicesSupport.BCSSProxyServiceProvider proxy

serializable

protected int serializable

services

protected HashMap services

Constructor Details

BeanContextServicesSupport

public BeanContextServicesSupport()
The basic constructor. Object is special, because it has no superclass, so there is no call to super().

BeanContextServicesSupport

public BeanContextServicesSupport(BeanContextServices peer)

BeanContextServicesSupport

public BeanContextServicesSupport(BeanContextServices peer,
                                  Locale locale)

BeanContextServicesSupport

public BeanContextServicesSupport(BeanContextServices peer,
                                  Locale locale,
                                  boolean dtime)

BeanContextServicesSupport

public BeanContextServicesSupport(BeanContextServices peer,
                                  Locale locale,
                                  boolean dtime,
                                  boolean visible)

Method Details

addBeanContextServicesListener

public void addBeanContextServicesListener(BeanContextServicesListener listener)
Add a listener on all adds and removes of services.
Specified by:
addBeanContextServicesListener in interface BeanContextServices
Parameters:
listener - the listener to add.

addService

public boolean addService(Class serviceClass,
                          BeanContextServiceProvider bcsp)
Register a service to make it available to others. This class may refuse to add the service based on whatever information it can gather, including whether the service provider is trusted.
Specified by:
addService in interface BeanContextServices
Parameters:
serviceClass - the service class.
Returns:
whether the service was added or not.

addService

protected boolean addService(Class serviceClass,
                             BeanContextServiceProvider bcsp,
                             boolean fireEvent)

bcsPreDeserializationHook

protected void bcsPreDeserializationHook(ObjectInputStream ois)
            throws ClassNotFoundException,
                   IOException,
                   NotImplementedException
Overrides:
bcsPreDeserializationHook in interface BeanContextSupport

bcsPreSerializationHook

protected void bcsPreSerializationHook(ObjectOutputStream oos)
            throws IOException,
                   NotImplementedException
Overrides:
bcsPreSerializationHook in interface BeanContextSupport

childJustRemovedHook

protected void childJustRemovedHook(Object child,
                                    BeanContextSupport.BCSChild bcsc)
            throws NotImplementedException
Overrides:
childJustRemovedHook in interface BeanContextSupport

createBCSChild

protected BeanContextSupport.BCSChild createBCSChild(Object targetChild,
                                                     Object peer)
Overrides:
createBCSChild in interface BeanContextSupport

createBCSSServiceProvider

protected BeanContextServicesSupport.BCSSServiceProvider createBCSSServiceProvider(Class sc,
                                                                                   BeanContextServiceProvider bcsp)
            throws NotImplementedException

fireServiceAdded

protected final void fireServiceAdded(BeanContextServiceAvailableEvent bcssae)

fireServiceAdded

protected final void fireServiceAdded(Class serviceClass)

fireServiceRevoked

protected final void fireServiceRevoked(BeanContextServiceRevokedEvent event)

fireServiceRevoked

protected final void fireServiceRevoked(Class serviceClass,
                                        boolean revokeNow)

getBeanContextServicesPeer

public BeanContextServices getBeanContextServicesPeer()
            throws NotImplementedException

getChildBeanContextServicesListener

protected static final BeanContextServicesListener getChildBeanContextServicesListener(Object child)
            throws NotImplementedException

getCurrentServiceClasses

public Iterator getCurrentServiceClasses()
Get a list of all service classes supported.

This method must synchronize on BeanContext.globalHierarchyLock.

Specified by:
getCurrentServiceClasses in interface BeanContextServices
Returns:
a list of all service classes supported.

getCurrentServiceSelectors

public Iterator getCurrentServiceSelectors(Class serviceClass)
Get a list of valid service selectors for the specified service class.

If the specified service class does not have a finite number of valid service selectors, it should return null. If it takes a general Integer parameter, for example, you may as well return null or the poor soul who called this method will be iterating all day.

If it has no valid service selectors, it should still return an empty Iterator.

Specified by:
getCurrentServiceSelectors in interface BeanContextServices
Parameters:
serviceClass - the service class to get selectors for.
Returns:
a list of valid service selectors for the service class, or null.

getService

public Object getService(BeanContextChild child,
                         Object requestor,
                         Class serviceClass,
                         Object serviceSelector,
                         BeanContextServiceRevokedListener bcsrl)
            throws TooManyListenersException,
                   NotImplementedException
Get a service from this BeanContextServices.

The specified listener will be registered to receive a revocation notice for the specified serviceClass. One notification per service class per requestor object will be sent.

The listener will be unregistered when all services that were obtained by that requestor for that service class are released.

If the requested service class is not available, or if this BeanContextServices object chooses not honor the request because the service class has been revoked or for some other reason, then this method will return null.

This method may throw unchecked exceptions, so watch out.

Specified by:
getService in interface BeanContextServices
Parameters:
requestor - the actual requestor of the service. Only weak references to this will be retained, and it will never be changed, only queried in a read-only manner.
serviceClass - the Class of the service being requested.
serviceSelector - a parameter to customize the service returned with.
Returns:
an instance of serviceClass (such that instanceof serviceClass is true), or null.

hasService

public boolean hasService(Class serviceClass)
Tell whether the specified service class is available. Iff getService() could return a non-null value for the specified service, this method will return true.
Specified by:
hasService in interface BeanContextServices
Parameters:
serviceClass - the service class to check on.
Returns:
whether the specified service class is available.

initialize

public void initialize()
Overrides:
initialize in interface BeanContextSupport

initializeBeanContextResources

protected void initializeBeanContextResources()
            throws NotImplementedException
Overrides:
initializeBeanContextResources in interface BeanContextChildSupport

releaseBeanContextResources

protected void releaseBeanContextResources()
            throws NotImplementedException
Overrides:
releaseBeanContextResources in interface BeanContextChildSupport

releaseService

public void releaseService(BeanContextChild child,
                           Object requestor,
                           Object service)
            throws NotImplementedException
Release your copy of this service.

If all copies of the service's class have been relinquished by the requestor, the BeanContextServiceRevokedListener previously registered by getService() will be unregistered.

Specified by:
releaseService in interface BeanContextServices
Parameters:
requestor - the original requestor of the service.
service - the service to relinquish

removeBeanContextServicesListener

public void removeBeanContextServicesListener(BeanContextServicesListener listener)
Remove a listener on all adds and removes of services.
Specified by:
removeBeanContextServicesListener in interface BeanContextServices
Parameters:
listener - the listener to add.

revokeService

public void revokeService(Class serviceClass,
                          BeanContextServiceProvider bcsp,
                          boolean revokeCurrentServicesNow)
            throws NotImplementedException
Make it so that no one else can use this service.

If revokeNow is false, the only effect of this method is to make all subsequent calls to getService() on this service class fail.

If it is true, a message is also sent out to all listeners on the service and all references to it are released.

Specified by:
revokeService in interface BeanContextServices
Parameters:
serviceClass - the service class to revoke.

serviceAvailable

public void serviceAvailable(BeanContextServiceAvailableEvent bcssae)
Called by BeanContextServices whenever a service is made available.
Specified by:
serviceAvailable in interface BeanContextServicesListener
Overrides:
serviceAvailable in interface BeanContextChildSupport
Parameters:

serviceRevoked

public void serviceRevoked(BeanContextServiceRevokedEvent bcssre)
Specified by:
serviceRevoked in interface BeanContextServiceRevokedListener
Overrides:
serviceRevoked in interface BeanContextChildSupport

BeanContextServicesSupport.java -- Copyright (C) 2003, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.