| 1 |
771 |
jeremybenn |
/* java.beans.beancontext.BeanContextServices
|
| 2 |
|
|
Copyright (C) 1999 Free Software Foundation, Inc.
|
| 3 |
|
|
|
| 4 |
|
|
This file is part of GNU Classpath.
|
| 5 |
|
|
|
| 6 |
|
|
GNU Classpath is free software; you can redistribute it and/or modify
|
| 7 |
|
|
it under the terms of the GNU General Public License as published by
|
| 8 |
|
|
the Free Software Foundation; either version 2, or (at your option)
|
| 9 |
|
|
any later version.
|
| 10 |
|
|
|
| 11 |
|
|
GNU Classpath is distributed in the hope that it will be useful, but
|
| 12 |
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 14 |
|
|
General Public License for more details.
|
| 15 |
|
|
|
| 16 |
|
|
You should have received a copy of the GNU General Public License
|
| 17 |
|
|
along with GNU Classpath; see the file COPYING. If not, write to the
|
| 18 |
|
|
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
| 19 |
|
|
02110-1301 USA.
|
| 20 |
|
|
|
| 21 |
|
|
Linking this library statically or dynamically with other modules is
|
| 22 |
|
|
making a combined work based on this library. Thus, the terms and
|
| 23 |
|
|
conditions of the GNU General Public License cover the whole
|
| 24 |
|
|
combination.
|
| 25 |
|
|
|
| 26 |
|
|
As a special exception, the copyright holders of this library give you
|
| 27 |
|
|
permission to link this library with independent modules to produce an
|
| 28 |
|
|
executable, regardless of the license terms of these independent
|
| 29 |
|
|
modules, and to copy and distribute the resulting executable under
|
| 30 |
|
|
terms of your choice, provided that you also meet, for each linked
|
| 31 |
|
|
independent module, the terms and conditions of the license of that
|
| 32 |
|
|
module. An independent module is a module which is not derived from
|
| 33 |
|
|
or based on this library. If you modify this library, you may extend
|
| 34 |
|
|
this exception to your version of the library, but you are not
|
| 35 |
|
|
obligated to do so. If you do not wish to do so, delete this
|
| 36 |
|
|
exception statement from your version. */
|
| 37 |
|
|
|
| 38 |
|
|
|
| 39 |
|
|
package java.beans.beancontext;
|
| 40 |
|
|
|
| 41 |
|
|
import java.util.Iterator;
|
| 42 |
|
|
import java.util.TooManyListenersException;
|
| 43 |
|
|
|
| 44 |
|
|
/**
|
| 45 |
|
|
* Allows a <code>BeanContext</code> to provide services to its children.
|
| 46 |
|
|
*
|
| 47 |
|
|
* @specnote it is unclear whether a <code>BeanContextServices</code>
|
| 48 |
|
|
* should delegate unhandled requests to parents. I assume so.
|
| 49 |
|
|
* @author John Keiser
|
| 50 |
|
|
* @since 1.2
|
| 51 |
|
|
*/
|
| 52 |
|
|
|
| 53 |
|
|
public interface BeanContextServices
|
| 54 |
|
|
extends BeanContext, BeanContextServicesListener
|
| 55 |
|
|
{
|
| 56 |
|
|
/**
|
| 57 |
|
|
* Register a service to make it available to others.
|
| 58 |
|
|
* This class may refuse to add the service based on whatever
|
| 59 |
|
|
* information it can gather, including whether the service
|
| 60 |
|
|
* provider is trusted.
|
| 61 |
|
|
*
|
| 62 |
|
|
* @param serviceClass the service class.
|
| 63 |
|
|
* @param provider the factory that will actually provide the service.
|
| 64 |
|
|
* @return whether the service was added or not.
|
| 65 |
|
|
*/
|
| 66 |
|
|
boolean addService (Class serviceClass,
|
| 67 |
|
|
BeanContextServiceProvider provider);
|
| 68 |
|
|
|
| 69 |
|
|
/**
|
| 70 |
|
|
* Make it so that no one else can use this service.
|
| 71 |
|
|
* <P>
|
| 72 |
|
|
*
|
| 73 |
|
|
* If <code>revokeNow</code> is <code>false</code>, the only
|
| 74 |
|
|
* effect of this method is to make all subsequent calls to
|
| 75 |
|
|
* <code>getService()</code> on this service class fail.
|
| 76 |
|
|
* <P>
|
| 77 |
|
|
*
|
| 78 |
|
|
* If it is <code>true</code>, a message is also sent out to all
|
| 79 |
|
|
* listeners on the service and all references to it are released.
|
| 80 |
|
|
*
|
| 81 |
|
|
* @param serviceClass the service class to revoke.
|
| 82 |
|
|
* @param provider the service provider providing the service class.
|
| 83 |
|
|
* @param revokeNow whether to release all current references to
|
| 84 |
|
|
* the service.
|
| 85 |
|
|
*/
|
| 86 |
|
|
void revokeService (Class serviceClass,
|
| 87 |
|
|
BeanContextServiceProvider provider,
|
| 88 |
|
|
boolean revokeNow);
|
| 89 |
|
|
|
| 90 |
|
|
/**
|
| 91 |
|
|
* Release your copy of this service.
|
| 92 |
|
|
* <P>
|
| 93 |
|
|
*
|
| 94 |
|
|
* If all copies of the service's class have been relinquished by
|
| 95 |
|
|
* the requestor, the <code>BeanContextServiceRevokedListener</code>
|
| 96 |
|
|
* previously registered by <code>getService()</code> will be
|
| 97 |
|
|
* unregistered.
|
| 98 |
|
|
*
|
| 99 |
|
|
* @param requestorChild the original <code>BeanContextChild</code>
|
| 100 |
|
|
* requesting the service.
|
| 101 |
|
|
* @param requestor the original requestor of the service.
|
| 102 |
|
|
* @param service the service to relinquish
|
| 103 |
|
|
* @see #getService(java.beans.beancontext.BeanContextChild,java.lang.Object,java.lang.Class,java.lang.Object,java.beans.beancontext.BeanContextServiceRevokedListener)
|
| 104 |
|
|
*/
|
| 105 |
|
|
void releaseService (BeanContextChild requestorChild, Object requestor,
|
| 106 |
|
|
Object service);
|
| 107 |
|
|
|
| 108 |
|
|
/**
|
| 109 |
|
|
* Get a service from this <code>BeanContextServices</code>.
|
| 110 |
|
|
* <P>
|
| 111 |
|
|
*
|
| 112 |
|
|
* The specified listener will be registered to receive a
|
| 113 |
|
|
* revocation notice for the specified serviceClass. One
|
| 114 |
|
|
* notification per service class per requestor object will be
|
| 115 |
|
|
* sent.
|
| 116 |
|
|
* <P>
|
| 117 |
|
|
*
|
| 118 |
|
|
* The listener will be unregistered when all services that were
|
| 119 |
|
|
* obtained by that requestor for that service class are released.
|
| 120 |
|
|
* <P>
|
| 121 |
|
|
*
|
| 122 |
|
|
* If the requested service class is not available, or if this
|
| 123 |
|
|
* <code>BeanContextServices</code> object chooses not honor the
|
| 124 |
|
|
* request because the service class has been revoked or for some
|
| 125 |
|
|
* other reason, then this method will return <code>null</code>.
|
| 126 |
|
|
* <P>
|
| 127 |
|
|
*
|
| 128 |
|
|
* This method may throw unchecked exceptions, so watch out.
|
| 129 |
|
|
*
|
| 130 |
|
|
* @specnote it is not specified what happens when two subsequent
|
| 131 |
|
|
* calls are made to <code>getService()</code> with the
|
| 132 |
|
|
* same requestor object and service class but different
|
| 133 |
|
|
* listeners. Which listener is to be notified?
|
| 134 |
|
|
*
|
| 135 |
|
|
* @param requestorChild the <code>BeanContextChild</code>
|
| 136 |
|
|
* associated with the requestor. Typically this will be
|
| 137 |
|
|
* the same as the requestor itself, but since any
|
| 138 |
|
|
* <code>Object</code>, even one outside the hierarchy, may
|
| 139 |
|
|
* make a request, this parameter is necessary. Only weak
|
| 140 |
|
|
* references to this will be retained, and it will never
|
| 141 |
|
|
* be changed, only queried in a read-only manner.
|
| 142 |
|
|
* @param requestor the actual requestor of the service. Only
|
| 143 |
|
|
* weak references to this will be retained, and it will
|
| 144 |
|
|
* never be changed, only queried in a read-only manner.
|
| 145 |
|
|
* @param serviceClass the <code>Class</code> of the service being
|
| 146 |
|
|
* requested.
|
| 147 |
|
|
* @param serviceSelector a parameter to customize the service
|
| 148 |
|
|
* returned with.
|
| 149 |
|
|
* @param listener a listener that will be notified if the service
|
| 150 |
|
|
* being requested is revoked.
|
| 151 |
|
|
* @return an instance of <code>serviceClass</code> (such that
|
| 152 |
|
|
* <code>instanceof</code> serviceClass is true), or
|
| 153 |
|
|
* <code>null</code>.
|
| 154 |
|
|
*/
|
| 155 |
|
|
Object getService (BeanContextChild requestorChild, Object requestor,
|
| 156 |
|
|
Class serviceClass, Object serviceSelector,
|
| 157 |
|
|
BeanContextServiceRevokedListener listener)
|
| 158 |
|
|
throws TooManyListenersException;
|
| 159 |
|
|
|
| 160 |
|
|
/**
|
| 161 |
|
|
* Get a list of all service classes supported.
|
| 162 |
|
|
* <P>
|
| 163 |
|
|
*
|
| 164 |
|
|
* This method must synchronize on
|
| 165 |
|
|
* <code>BeanContext.globalHierarchyLock</code>.
|
| 166 |
|
|
*
|
| 167 |
|
|
* @return a list of all service classes supported.
|
| 168 |
|
|
* @see java.beans.beancontext.BeanContext#globalHierarchyLock
|
| 169 |
|
|
*/
|
| 170 |
|
|
Iterator getCurrentServiceClasses ();
|
| 171 |
|
|
|
| 172 |
|
|
/**
|
| 173 |
|
|
* Get a list of valid service selectors for the specified service class.
|
| 174 |
|
|
* <P>
|
| 175 |
|
|
*
|
| 176 |
|
|
* If the specified service class does not have a finite number of
|
| 177 |
|
|
* valid service selectors, it should return <code>null</code>.
|
| 178 |
|
|
* If it takes a general <code>Integer</code> parameter, for
|
| 179 |
|
|
* example, you may as well return <code>null</code> or the poor
|
| 180 |
|
|
* soul who called this method will be iterating all day.
|
| 181 |
|
|
* <P>
|
| 182 |
|
|
*
|
| 183 |
|
|
* If it has no valid service selectors, it should still return an empty
|
| 184 |
|
|
* <code>Iterator</code>.
|
| 185 |
|
|
*
|
| 186 |
|
|
* @param serviceClass the service class to get selectors for.
|
| 187 |
|
|
* @return a list of valid service selectors for the service
|
| 188 |
|
|
* class, or <code>null</code>.
|
| 189 |
|
|
*/
|
| 190 |
|
|
Iterator getCurrentServiceSelectors (Class serviceClass);
|
| 191 |
|
|
|
| 192 |
|
|
/**
|
| 193 |
|
|
* Tell whether the specified service class is available.
|
| 194 |
|
|
* Iff getService() could return a non-null value for the
|
| 195 |
|
|
* specified service, this method will return <code>true</code>.
|
| 196 |
|
|
*
|
| 197 |
|
|
* @param serviceClass the service class to check on.
|
| 198 |
|
|
* @return whether the specified service class is available.
|
| 199 |
|
|
*/
|
| 200 |
|
|
boolean hasService (Class serviceClass);
|
| 201 |
|
|
|
| 202 |
|
|
/**
|
| 203 |
|
|
* Add a listener on all adds and removes of services.
|
| 204 |
|
|
* @param listener the listener to add.
|
| 205 |
|
|
*/
|
| 206 |
|
|
void addBeanContextServicesListener (BeanContextServicesListener listener);
|
| 207 |
|
|
|
| 208 |
|
|
/**
|
| 209 |
|
|
* Remove a listener on all adds and removes of services.
|
| 210 |
|
|
* @specnote it is not certain whether this should remove this
|
| 211 |
|
|
* listener if it was specified in
|
| 212 |
|
|
* <code>getService()</code>.
|
| 213 |
|
|
* @param listener the listener to add.
|
| 214 |
|
|
*/
|
| 215 |
|
|
void removeBeanContextServicesListener (BeanContextServicesListener listener);
|
| 216 |
|
|
}
|