1 | /* 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., 59 Temple Place, Suite 330, Boston, MA
|
---|
19 | 02111-1307 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 |
|
---|
43 | /**
|
---|
44 | * Allows a <code>BeanContext</code> to provide services to its children.
|
---|
45 | *
|
---|
46 | * @specnote it is unclear whether a <code>BeanContextServices</code>
|
---|
47 | * should delegate unhandled requests to parents. I assume so.
|
---|
48 | * @author John Keiser
|
---|
49 | * @since JDK1.2
|
---|
50 | */
|
---|
51 |
|
---|
52 | public interface BeanContextServices extends BeanContext, BeanContextServicesListener {
|
---|
53 | /**
|
---|
54 | * Register a service to make it available to others.
|
---|
55 | * This class may refuse to add the service based on whatever
|
---|
56 | * information it can gather, including whether the service
|
---|
57 | * provider is trusted.
|
---|
58 | *
|
---|
59 | * @param serviceClass the service class.
|
---|
60 | * @param provider the factory that will actually provide the service.
|
---|
61 | * @return whether the service was added or not.
|
---|
62 | */
|
---|
63 | public boolean addService(Class serviceClass, BeanContextServiceProvider provider);
|
---|
64 |
|
---|
65 | /**
|
---|
66 | * Make it so that no one else can use this service.
|
---|
67 | * <P>
|
---|
68 | *
|
---|
69 | * If <code>revokeNow</code> is <code>false</code>, the only
|
---|
70 | * effect of this method is to make all subsequent calls to
|
---|
71 | * <code>getService()</code> on this service class fail.
|
---|
72 | * <P>
|
---|
73 | *
|
---|
74 | * If it is <code>true</code>, a message is also sent out to all
|
---|
75 | * listeners on the service and all references to it are released.
|
---|
76 | *
|
---|
77 | * @param serviceClass the service class to revoke.
|
---|
78 | * @param provider the service provider providing the service class.
|
---|
79 | * @param revokeNow whether to release all current references to
|
---|
80 | * the service.
|
---|
81 | */
|
---|
82 | public void revokeService(Class serviceClass, BeanContextServiceProvider provider, boolean revokeNow);
|
---|
83 |
|
---|
84 | /**
|
---|
85 | * Release your copy of this service.
|
---|
86 | * <P>
|
---|
87 | *
|
---|
88 | * If all copies of the service's class have been relinquished by
|
---|
89 | * the requestor, the <code>BeanContextServiceRevokedListener</code>
|
---|
90 | * previously registered by <code>getService()</code> will be
|
---|
91 | * unregistered.
|
---|
92 | *
|
---|
93 | * @param requestorChild the original <code>BeanContextChild</code>
|
---|
94 | * requesting the service.
|
---|
95 | * @param requestor the original requestor of the service.
|
---|
96 | * @param service the service to relinquish
|
---|
97 | * @see #getService(java.beans.beancontext.BeanContextChild,java.lang.Object,java.lang.Class,java.lang.Object,java.beans.beancontext.BeanContextServiceRevokedListener)
|
---|
98 | */
|
---|
99 | public void releaseService(BeanContextChild requestorChild, Object requestor, Object service);
|
---|
100 |
|
---|
101 | /**
|
---|
102 | * Get a service from this <code>BeanContextServices</code>.
|
---|
103 | * <P>
|
---|
104 | *
|
---|
105 | * The specified listener will be registered to receive a
|
---|
106 | * revocation notice for the specified serviceClass. One
|
---|
107 | * notification per service class per requestor object will be
|
---|
108 | * sent.
|
---|
109 | * <P>
|
---|
110 | *
|
---|
111 | * The listener will be unregistered when all services that were
|
---|
112 | * obtained by that requestor for that service class are released.
|
---|
113 | * <P>
|
---|
114 | *
|
---|
115 | * If the requested service class is not available, or if this
|
---|
116 | * <code>BeanContextServices</code> object chooses not honor the
|
---|
117 | * request because the service class has been revoked or for some
|
---|
118 | * other reason, then this method will return <code>null</code>.
|
---|
119 | * <P>
|
---|
120 | *
|
---|
121 | * This method may throw unchecked exceptions, so watch out.
|
---|
122 | *
|
---|
123 | * @specnote it is not specified what happens when two subsequent
|
---|
124 | * calls are made to <code>getService()</code> with the
|
---|
125 | * same requestor object and service class but different
|
---|
126 | * listeners. Which listener is to be notified?
|
---|
127 | *
|
---|
128 | * @param requestorChild the <code>BeanContextChild</code>
|
---|
129 | * associated with the requestor. Typically this will be
|
---|
130 | * the same as the requestor itself, but since any
|
---|
131 | * <code>Object</code>, even one outside the hierarchy, may
|
---|
132 | * make a request, this parameter is necessary. Only weak
|
---|
133 | * references to this will be retained, and it will never
|
---|
134 | * be changed, only queried in a read-only manner.
|
---|
135 | * @param requestor the actual requestor of the service. Only
|
---|
136 | * weak references to this will be retained, and it will
|
---|
137 | * never be changed, only queried in a read-only manner.
|
---|
138 | * @param serviceClass the <code>Class</code> of the service being
|
---|
139 | * requested.
|
---|
140 | * @param serviceSelector a parameter to customize the service
|
---|
141 | * returned with.
|
---|
142 | * @param listener a listener that will be notified if the service
|
---|
143 | * being requested is revoked.
|
---|
144 | * @return an instance of <code>serviceClass</code> (such that
|
---|
145 | * <code>instanceof</code> serviceClass is true), or
|
---|
146 | * <code>null</code>.
|
---|
147 | */
|
---|
148 | public Object getService(BeanContextChild requestorChild, Object requestor, Class serviceClass, Object serviceSelector, BeanContextServiceRevokedListener listener);
|
---|
149 |
|
---|
150 | /**
|
---|
151 | * Get a list of all service classes supported.
|
---|
152 | * <P>
|
---|
153 | *
|
---|
154 | * This method must synchronize on
|
---|
155 | * <code>BeanContext.globalHierarchyLock</code>.
|
---|
156 | *
|
---|
157 | * @return a list of all service classes supported.
|
---|
158 | * @see java.beans.beancontext.BeanContext#globalHierarchyLock
|
---|
159 | */
|
---|
160 | public Iterator getCurrentServiceClasses();
|
---|
161 |
|
---|
162 | /**
|
---|
163 | * Get a list of valid service selectors for the specified service class.
|
---|
164 | * <P>
|
---|
165 | *
|
---|
166 | * If the specified service class does not have a finite number of
|
---|
167 | * valid service selectors, it should return <code>null</code>.
|
---|
168 | * If it takes a general <code>Integer</code> parameter, for
|
---|
169 | * example, you may as well return <code>null</code> or the poor
|
---|
170 | * soul who called this method will be iterating all day.
|
---|
171 | * <P>
|
---|
172 | *
|
---|
173 | * If it has no valid service selectors, it should still return an empty
|
---|
174 | * <code>Iterator</code>.
|
---|
175 | *
|
---|
176 | * @param serviceClass the service class to get selectors for.
|
---|
177 | * @return a list of valid service selectors for the service
|
---|
178 | * class, or <code>null</code>.
|
---|
179 | */
|
---|
180 | public Iterator getCurrentServiceSelectors(Class serviceClass);
|
---|
181 |
|
---|
182 | /**
|
---|
183 | * Tell whether the specified service class is available.
|
---|
184 | * Iff getService() could return a non-null value for the
|
---|
185 | * specified service, this method will return <code>true</code>.
|
---|
186 | *
|
---|
187 | * @param serviceClass the service class to check on.
|
---|
188 | * @return whether the specified service class is availabe.
|
---|
189 | */
|
---|
190 | public boolean hasService(Class serviceClass);
|
---|
191 |
|
---|
192 | /**
|
---|
193 | * Add a listener on all adds and removes of services.
|
---|
194 | * @param listener the listener to add.
|
---|
195 | */
|
---|
196 | public void addBeanContextServicesListener(BeanContextServicesListener listener);
|
---|
197 |
|
---|
198 | /**
|
---|
199 | * Remove a listener on all adds and removes of services.
|
---|
200 | * @specnote it is not certain whether this should remove this
|
---|
201 | * listener if it was specified in
|
---|
202 | * <code>getService()</code>.
|
---|
203 | * @param listener the listener to add.
|
---|
204 | */
|
---|
205 | public void removeBeanContextServicesListener(BeanContextServicesListener listener);
|
---|
206 | }
|
---|