Mercurial > projects > dwt2
comparison org.eclipse.osgi/osgi/src/org/osgi/framework/BundleContext.d @ 86:12b890a6392a
Work on databinding
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 18 Apr 2009 13:58:35 +0200 |
parents | |
children | bbe49769ec18 |
comparison
equal
deleted
inserted
replaced
85:6be48cf9f95c | 86:12b890a6392a |
---|---|
1 /* | |
2 * $Header: /cvshome/build/org.osgi.framework/src/org/osgi/framework/BundleContext.java,v 1.22 2007/02/21 16:49:05 hargrave Exp $ | |
3 * | |
4 * Copyright (c) OSGi Alliance (2000, 2007). All Rights Reserved. | |
5 * | |
6 * Licensed under the Apache License, Version 2.0 (the "License"); | |
7 * you may not use this file except in compliance with the License. | |
8 * You may obtain a copy of the License at | |
9 * | |
10 * http://www.apache.org/licenses/LICENSE-2.0 | |
11 * | |
12 * Unless required by applicable law or agreed to in writing, software | |
13 * distributed under the License is distributed on an "AS IS" BASIS, | |
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
15 * See the License for the specific language governing permissions and | |
16 * limitations under the License. | |
17 */ | |
18 | |
19 module org.osgi.framework.BundleContext; | |
20 import org.osgi.framework.Bundle; | |
21 import org.osgi.framework.BundleListener; | |
22 import org.osgi.framework.ServiceListener; | |
23 import org.osgi.framework.FrameworkListener; | |
24 import org.osgi.framework.ServiceReference; | |
25 import org.osgi.framework.ServiceRegistration; | |
26 import org.osgi.framework.Filter; | |
27 | |
28 import java.lang.all; | |
29 import java.io.File; | |
30 import java.io.InputStream; | |
31 import java.util.Dictionary; | |
32 | |
33 /** | |
34 * A bundle's execution context within the Framework. The context is used to | |
35 * grant access to other methods so that this bundle can interact with the | |
36 * Framework. | |
37 * | |
38 * <p> | |
39 * <code>BundleContext</code> methods allow a bundle to: | |
40 * <ul> | |
41 * <li>Subscribe to events published by the Framework. | |
42 * <li>Register service objects with the Framework service registry. | |
43 * <li>Retrieve <code>ServiceReferences</code> from the Framework service | |
44 * registry. | |
45 * <li>Get and release service objects for a referenced service. | |
46 * <li>Install new bundles in the Framework. | |
47 * <li>Get the list of bundles installed in the Framework. | |
48 * <li>Get the {@link Bundle} object for a bundle. | |
49 * <li>Create <code>File</code> objects for files in a persistent storage | |
50 * area provided for the bundle by the Framework. | |
51 * </ul> | |
52 * | |
53 * <p> | |
54 * A <code>BundleContext</code> object will be created and provided to the | |
55 * bundle associated with this context when it is started using the | |
56 * {@link BundleActivator#start} method. The same <code>BundleContext</code> | |
57 * object will be passed to the bundle associated with this context when it is | |
58 * stopped using the {@link BundleActivator#stop} method. A | |
59 * <code>BundleContext</code> object is generally for the private use of its | |
60 * associated bundle and is not meant to be shared with other bundles in the | |
61 * OSGi environment. | |
62 * | |
63 * <p> | |
64 * The <code>Bundle</code> object associated with a <code>BundleContext</code> | |
65 * object is called the <em>context bundle</em>. | |
66 * | |
67 * <p> | |
68 * The <code>BundleContext</code> object is only valid during the execution of | |
69 * its context bundle; that is, during the period from when the context bundle | |
70 * is in the <code>STARTING</code>, <code>STOPPING</code>, and | |
71 * <code>ACTIVE</code> bundle states. If the <code>BundleContext</code> | |
72 * object is used subsequently, an <code>IllegalStateException</code> must be | |
73 * thrown. The <code>BundleContext</code> object must never be reused after | |
74 * its context bundle is stopped. | |
75 * | |
76 * <p> | |
77 * The Framework is the only entity that can create <code>BundleContext</code> | |
78 * objects and they are only valid within the Framework that created them. | |
79 * | |
80 * @ThreadSafe | |
81 * @version $Revision: 1.22 $ | |
82 */ | |
83 | |
84 public interface BundleContext { | |
85 /** | |
86 * Returns the value of the specified property. If the key is not found in | |
87 * the Framework properties, the system properties are then searched. The | |
88 * method returns <code>null</code> if the property is not found. | |
89 * | |
90 * <p> | |
91 * The Framework defines the following standard property keys: | |
92 * </p> | |
93 * <ul> | |
94 * <li>{@link Constants#FRAMEWORK_VERSION} - The OSGi Framework version. | |
95 * </li> | |
96 * <li>{@link Constants#FRAMEWORK_VENDOR} - The Framework implementation | |
97 * vendor.</li> | |
98 * <li>{@link Constants#FRAMEWORK_LANGUAGE} - The language being used. See | |
99 * ISO 639 for possible values.</li> | |
100 * <li>{@link Constants#FRAMEWORK_OS_NAME} - The host computer operating | |
101 * system.</li> | |
102 * <li>{@link Constants#FRAMEWORK_OS_VERSION} - The host computer | |
103 * operating system version number.</li> | |
104 * <li>{@link Constants#FRAMEWORK_PROCESSOR} - The host computer processor | |
105 * name.</li> | |
106 * </ul> | |
107 * <p> | |
108 * All bundles must have permission to read these properties. | |
109 * | |
110 * <p> | |
111 * Note: The last four standard properties are used by the | |
112 * {@link Constants#BUNDLE_NATIVECODE} <code>Manifest</code> header's | |
113 * matching algorithm for selecting native language code. | |
114 * | |
115 * @param key The name of the requested property. | |
116 * @return The value of the requested property, or <code>null</code> if | |
117 * the property is undefined. | |
118 * @throws java.lang.SecurityException If the caller does not have the | |
119 * appropriate <code>PropertyPermission</code> to read the | |
120 * property, and the Java Runtime Environment supports permissions. | |
121 */ | |
122 public String getProperty(String key); | |
123 | |
124 /** | |
125 * Returns the <code>Bundle</code> object associated with this | |
126 * <code>BundleContext</code>. This bundle is called the context bundle. | |
127 * | |
128 * @return The <code>Bundle</code> object associated with this | |
129 * <code>BundleContext</code>. | |
130 * @throws java.lang.IllegalStateException If this BundleContext is no | |
131 * longer valid. | |
132 */ | |
133 public Bundle getBundle(); | |
134 | |
135 /** | |
136 * Installs a bundle from the specified location string. A bundle is | |
137 * obtained from <code>location</code> as interpreted by the Framework in | |
138 * an implementation dependent manner. | |
139 * <p> | |
140 * Every installed bundle is uniquely identified by its location string, | |
141 * typically in the form of a URL. | |
142 * | |
143 * <p> | |
144 * The following steps are required to install a bundle: | |
145 * <ol> | |
146 * <li>If a bundle containing the same location string is already | |
147 * installed, the <code>Bundle</code> object for that bundle is returned. | |
148 * | |
149 * <li>The bundle's content is read from the location string. If this | |
150 * fails, a {@link BundleException} is thrown. | |
151 * | |
152 * <li>The bundle's <code>Bundle-NativeCode</code> dependencies are | |
153 * resolved. If this fails, a <code>BundleException</code> is thrown. | |
154 * | |
155 * <li>The bundle's associated resources are allocated. The associated | |
156 * resources minimally consist of a unique identifier and a persistent | |
157 * storage area if the platform has file system support. If this step fails, | |
158 * a <code>BundleException</code> is thrown. | |
159 * | |
160 * <li>If the bundle has declared an Bundle-RequiredExecutionEnvironment | |
161 * header, then the listed execution environments must be verified against | |
162 * the installed execution environments. If none of the listed execution | |
163 * environments match an installed execution environment, a | |
164 * <code>BundleException</code> must be thrown. | |
165 * | |
166 * <li>The bundle's state is set to <code>INSTALLED</code>. | |
167 * | |
168 * <li>A bundle event of type {@link BundleEvent#INSTALLED} is fired. | |
169 * | |
170 * <li>The <code>Bundle</code> object for the newly or previously | |
171 * installed bundle is returned. | |
172 * </ol> | |
173 * | |
174 * <b>Postconditions, no exceptions thrown </b> | |
175 * <ul> | |
176 * <li><code>getState()</code> in {<code>INSTALLED</code>,<code>RESOLVED</code>}. | |
177 * <li>Bundle has a unique ID. | |
178 * </ul> | |
179 * <b>Postconditions, when an exception is thrown </b> | |
180 * <ul> | |
181 * <li>Bundle is not installed and no trace of the bundle exists. | |
182 * </ul> | |
183 * | |
184 * @param location The location identifier of the bundle to install. | |
185 * @return The <code>Bundle</code> object of the installed bundle. | |
186 * @throws BundleException If the installation failed. | |
187 * @throws java.lang.SecurityException If the caller does not have the | |
188 * appropriate <code>AdminPermission[installed bundle,LIFECYCLE]</code>, and the | |
189 * Java Runtime Environment supports permissions. | |
190 * @throws java.lang.IllegalStateException If this BundleContext is no | |
191 * longer valid. | |
192 */ | |
193 public Bundle installBundle(String location); | |
194 | |
195 /** | |
196 * Installs a bundle from the specified <code>InputStream</code> object. | |
197 * | |
198 * <p> | |
199 * This method performs all of the steps listed in | |
200 * <code>BundleContext.installBundle(String location)</code>, except that | |
201 * the bundle's content will be read from the <code>InputStream</code> | |
202 * object. The location identifier string specified will be used as the | |
203 * identity of the bundle. | |
204 * | |
205 * <p> | |
206 * This method must always close the <code>InputStream</code> object, even | |
207 * if an exception is thrown. | |
208 * | |
209 * @param location The location identifier of the bundle to install. | |
210 * @param input The <code>InputStream</code> object from which this bundle | |
211 * will be read. | |
212 * @return The <code>Bundle</code> object of the installed bundle. | |
213 * @throws BundleException If the provided stream cannot be read or the | |
214 * installation failed. | |
215 * @throws java.lang.SecurityException If the caller does not have the | |
216 * appropriate <code>AdminPermission[installed bundle,LIFECYCLE]</code>, and the | |
217 * Java Runtime Environment supports permissions. | |
218 * @throws java.lang.IllegalStateException If this BundleContext is no | |
219 * longer valid. | |
220 * @see #installBundle(java.lang.String) | |
221 */ | |
222 public Bundle installBundle(String location, InputStream input); | |
223 | |
224 /** | |
225 * Returns the bundle with the specified identifier. | |
226 * | |
227 * @param id The identifier of the bundle to retrieve. | |
228 * @return A <code>Bundle</code> object or <code>null</code> if the | |
229 * identifier does not match any installed bundle. | |
230 */ | |
231 public Bundle getBundle(long id); | |
232 | |
233 /** | |
234 * Returns a list of all installed bundles. | |
235 * <p> | |
236 * This method returns a list of all bundles installed in the OSGi | |
237 * environment at the time of the call to this method. However, since the | |
238 * Framework is a very dynamic environment, bundles can be installed or | |
239 * uninstalled at anytime. | |
240 * | |
241 * @return An array of <code>Bundle</code> objects, one object per | |
242 * installed bundle. | |
243 */ | |
244 public Bundle[] getBundles(); | |
245 | |
246 /** | |
247 * Adds the specified <code>ServiceListener</code> object with the | |
248 * specified <code>filter</code> to the context bundle's list of | |
249 * listeners. See {@link Filter} for a description of the filter syntax. | |
250 * <code>ServiceListener</code> objects are notified when a service has a | |
251 * lifecycle state change. | |
252 * | |
253 * <p> | |
254 * If the context bundle's list of listeners already contains a listener | |
255 * <code>l</code> such that <code>(l==listener)</code>, then this | |
256 * method replaces that listener's filter (which may be <code>null</code>) | |
257 * with the specified one (which may be <code>null</code>). | |
258 * | |
259 * <p> | |
260 * The listener is called if the filter criteria is met. To filter based | |
261 * upon the class of the service, the filter should reference the | |
262 * {@link Constants#OBJECTCLASS} property. If <code>filter</code> is | |
263 * <code>null</code>, all services are considered to match the filter. | |
264 * | |
265 * <p> | |
266 * When using a <code>filter</code>, it is possible that the | |
267 * <code>ServiceEvent</code>s for the complete lifecycle of a service | |
268 * will not be delivered to the listener. For example, if the | |
269 * <code>filter</code> only matches when the property <code>x</code> has | |
270 * the value <code>1</code>, the listener will not be called if the | |
271 * service is registered with the property <code>x</code> not set to the | |
272 * value <code>1</code>. Subsequently, when the service is modified | |
273 * setting property <code>x</code> to the value <code>1</code>, the | |
274 * filter will match and the listener will be called with a | |
275 * <code>ServiceEvent</code> of type <code>MODIFIED</code>. Thus, the | |
276 * listener will not be called with a <code>ServiceEvent</code> of type | |
277 * <code>REGISTERED</code>. | |
278 * | |
279 * <p> | |
280 * If the Java Runtime Environment supports permissions, the | |
281 * <code>ServiceListener</code> object will be notified of a service event | |
282 * only if the bundle that is registering it has the | |
283 * <code>ServicePermission</code> to get the service using at least one of | |
284 * the named classes the service was registered under. | |
285 * | |
286 * @param listener The <code>ServiceListener</code> object to be added. | |
287 * @param filter The filter criteria. | |
288 * | |
289 * @throws InvalidSyntaxException If <code>filter</code> contains an | |
290 * invalid filter string that cannot be parsed. | |
291 * @throws java.lang.IllegalStateException If this BundleContext is no | |
292 * longer valid. | |
293 * | |
294 * @see ServiceEvent | |
295 * @see ServiceListener | |
296 * @see ServicePermission | |
297 */ | |
298 public void addServiceListener(ServiceListener listener, | |
299 String filter); | |
300 | |
301 /** | |
302 * Adds the specified <code>ServiceListener</code> object to the context | |
303 * bundle's list of listeners. | |
304 * | |
305 * <p> | |
306 * This method is the same as calling | |
307 * <code>BundleContext.addServiceListener(ServiceListener listener, | |
308 * String filter)</code> | |
309 * with <code>filter</code> set to <code>null</code>. | |
310 * | |
311 * @param listener The <code>ServiceListener</code> object to be added. | |
312 * @throws java.lang.IllegalStateException If this BundleContext is no | |
313 * longer valid. | |
314 * | |
315 * @see #addServiceListener(ServiceListener, String) | |
316 */ | |
317 public void addServiceListener(ServiceListener listener); | |
318 | |
319 /** | |
320 * Removes the specified <code>ServiceListener</code> object from the | |
321 * context bundle's list of listeners. | |
322 * | |
323 * <p> | |
324 * If <code>listener</code> is not contained in this context bundle's list | |
325 * of listeners, this method does nothing. | |
326 * | |
327 * @param listener The <code>ServiceListener</code> to be removed. | |
328 * @throws java.lang.IllegalStateException If this BundleContext is no | |
329 * longer valid. | |
330 */ | |
331 public void removeServiceListener(ServiceListener listener); | |
332 | |
333 /** | |
334 * Adds the specified <code>BundleListener</code> object to the context | |
335 * bundle's list of listeners if not already present. BundleListener objects | |
336 * are notified when a bundle has a lifecycle state change. | |
337 * | |
338 * <p> | |
339 * If the context bundle's list of listeners already contains a listener | |
340 * <code>l</code> such that <code>(l==listener)</code>, this method | |
341 * does nothing. | |
342 * | |
343 * @param listener The <code>BundleListener</code> to be added. | |
344 * @throws java.lang.IllegalStateException If this BundleContext is no | |
345 * longer valid. | |
346 * @throws java.lang.SecurityException If listener is a | |
347 * <code>SynchronousBundleListener</code> and the caller does not | |
348 * have the appropriate <code>AdminPermission[context bundle,LISTENER]</code>, | |
349 * and the Java Runtime Environment supports permissions. | |
350 * | |
351 * @see BundleEvent | |
352 * @see BundleListener | |
353 */ | |
354 public void addBundleListener(BundleListener listener); | |
355 | |
356 /** | |
357 * Removes the specified <code>BundleListener</code> object from the | |
358 * context bundle's list of listeners. | |
359 * | |
360 * <p> | |
361 * If <code>listener</code> is not contained in the context bundle's list | |
362 * of listeners, this method does nothing. | |
363 * | |
364 * @param listener The <code>BundleListener</code> object to be removed. | |
365 * @throws java.lang.IllegalStateException If this BundleContext is no | |
366 * longer valid. | |
367 * @throws java.lang.SecurityException If listener is a | |
368 * <code>SynchronousBundleListener</code> and the caller does not | |
369 * have the appropriate <code>AdminPermission[context bundle,LISTENER]</code>, | |
370 * and the Java Runtime Environment supports permissions. | |
371 */ | |
372 public void removeBundleListener(BundleListener listener); | |
373 | |
374 /** | |
375 * Adds the specified <code>FrameworkListener</code> object to the context | |
376 * bundle's list of listeners if not already present. FrameworkListeners are | |
377 * notified of general Framework events. | |
378 * | |
379 * <p> | |
380 * If the context bundle's list of listeners already contains a listener | |
381 * <code>l</code> such that <code>(l==listener)</code>, this method | |
382 * does nothing. | |
383 * | |
384 * @param listener The <code>FrameworkListener</code> object to be added. | |
385 * @throws java.lang.IllegalStateException If this BundleContext is no | |
386 * longer valid. | |
387 * | |
388 * @see FrameworkEvent | |
389 * @see FrameworkListener | |
390 */ | |
391 public void addFrameworkListener(FrameworkListener listener); | |
392 | |
393 /** | |
394 * Removes the specified <code>FrameworkListener</code> object from the | |
395 * context bundle's list of listeners. | |
396 * | |
397 * <p> | |
398 * If <code>listener</code> is not contained in the context bundle's list | |
399 * of listeners, this method does nothing. | |
400 * | |
401 * @param listener The <code>FrameworkListener</code> object to be | |
402 * removed. | |
403 * @throws java.lang.IllegalStateException If this BundleContext is no | |
404 * longer valid. | |
405 */ | |
406 public void removeFrameworkListener(FrameworkListener listener); | |
407 | |
408 /** | |
409 * Registers the specified service object with the specified properties | |
410 * under the specified class names into the Framework. A | |
411 * <code>ServiceRegistration</code> object is returned. The | |
412 * <code>ServiceRegistration</code> object is for the private use of the | |
413 * bundle registering the service and should not be shared with other | |
414 * bundles. The registering bundle is defined to be the context bundle. | |
415 * Other bundles can locate the service by using either the | |
416 * {@link #getServiceReferences} or {@link #getServiceReference} method. | |
417 * | |
418 * <p> | |
419 * A bundle can register a service object that implements the | |
420 * {@link ServiceFactory} interface to have more flexibility in providing | |
421 * service objects to other bundles. | |
422 * | |
423 * <p> | |
424 * The following steps are required to register a service: | |
425 * <ol> | |
426 * <li>If <code>service</code> is not a <code>ServiceFactory</code>, | |
427 * an <code>IllegalArgumentException</code> is thrown if | |
428 * <code>service</code> is not an <code>instanceof</code> all the | |
429 * classes named. | |
430 * <li>The Framework adds these service properties to the specified | |
431 * <code>Dictionary</code> (which may be <code>null</code>): a property | |
432 * named {@link Constants#SERVICE_ID} identifying the registration number of | |
433 * the service and a property named {@link Constants#OBJECTCLASS} containing | |
434 * all the specified classes. If any of these properties have already been | |
435 * specified by the registering bundle, their values will be overwritten by | |
436 * the Framework. | |
437 * <li>The service is added to the Framework service registry and may now | |
438 * be used by other bundles. | |
439 * <li>A service event of type {@link ServiceEvent#REGISTERED} is | |
440 * fired. | |
441 * <li>A <code>ServiceRegistration</code> object for this registration is | |
442 * returned. | |
443 * </ol> | |
444 * | |
445 * @param clazzes The class names under which the service can be located. | |
446 * The class names in this array will be stored in the service's | |
447 * properties under the key {@link Constants#OBJECTCLASS}. | |
448 * @param service The service object or a <code>ServiceFactory</code> | |
449 * object. | |
450 * @param properties The properties for this service. The keys in the | |
451 * properties object must all be <code>String</code> objects. See | |
452 * {@link Constants} for a list of standard service property keys. | |
453 * Changes should not be made to this object after calling this | |
454 * method. To update the service's properties the | |
455 * {@link ServiceRegistration#setProperties} method must be called. | |
456 * The set of properties may be <code>null</code> if the service | |
457 * has no properties. | |
458 * | |
459 * @return A <code>ServiceRegistration</code> object for use by the bundle | |
460 * registering the service to update the service's properties or to | |
461 * unregister the service. | |
462 * | |
463 * @throws java.lang.IllegalArgumentException If one of the following is | |
464 * true: | |
465 * <ul> | |
466 * <li><code>service</code> is <code>null</code>. | |
467 * <li><code>service</code> is not a <code>ServiceFactory</code> | |
468 * object and is not an instance of all the named classes in | |
469 * <code>clazzes</code>. | |
470 * <li><code>properties</code> contains case variants of the same | |
471 * key name. | |
472 * </ul> | |
473 * | |
474 * @throws java.lang.SecurityException If the caller does not have the | |
475 * <code>ServicePermission</code> to register the service for all | |
476 * the named classes and the Java Runtime Environment supports | |
477 * permissions. | |
478 * | |
479 * @throws java.lang.IllegalStateException If this BundleContext is no | |
480 * longer valid. | |
481 * | |
482 * @see ServiceRegistration | |
483 * @see ServiceFactory | |
484 */ | |
485 public ServiceRegistration registerService(String[] clazzes, | |
486 Object service, Dictionary properties); | |
487 | |
488 /** | |
489 * Registers the specified service object with the specified properties | |
490 * under the specified class name with the Framework. | |
491 * | |
492 * <p> | |
493 * This method is otherwise identical to | |
494 * {@link #registerService(java.lang.String[], java.lang.Object, | |
495 * java.util.Dictionary)} and is provided as a convenience when | |
496 * <code>service</code> will only be registered under a single class name. | |
497 * Note that even in this case the value of the service's | |
498 * {@link Constants#OBJECTCLASS} property will be an array of strings, | |
499 * rather than just a single string. | |
500 * | |
501 * @param clazz The class name under which the service can be located. | |
502 * @param service The service object or a <code>ServiceFactory</code> | |
503 * object. | |
504 * @param properties The properties for this service. | |
505 * | |
506 * @return A <code>ServiceRegistration</code> object for use by the bundle | |
507 * registering the service to update the service's properties or to | |
508 * unregister the service. | |
509 * | |
510 * @throws java.lang.IllegalStateException If this BundleContext is no | |
511 * longer valid. | |
512 * @see #registerService(java.lang.String[], java.lang.Object, | |
513 * java.util.Dictionary) | |
514 */ | |
515 public ServiceRegistration registerService(String clazz, | |
516 Object service, Dictionary properties); | |
517 | |
518 /** | |
519 * Returns an array of <code>ServiceReference</code> objects. The returned | |
520 * array of <code>ServiceReference</code> objects contains services that | |
521 * were registered under the specified class, match the specified filter | |
522 * criteria, and the packages for the class names under which the services | |
523 * were registered match the context bundle's packages as defined in | |
524 * {@link ServiceReference#isAssignableTo(Bundle, String)}. | |
525 * | |
526 * <p> | |
527 * The list is valid at the time of the call to this method, however since | |
528 * the Framework is a very dynamic environment, services can be modified or | |
529 * unregistered at anytime. | |
530 * | |
531 * <p> | |
532 * <code>filter</code> is used to select the registered service whose | |
533 * properties objects contain keys and values which satisfy the filter. See | |
534 * {@link Filter} for a description of the filter string syntax. | |
535 * | |
536 * <p> | |
537 * If <code>filter</code> is <code>null</code>, all registered services | |
538 * are considered to match the filter. If <code>filter</code> cannot be | |
539 * parsed, an {@link InvalidSyntaxException} will be thrown with a human | |
540 * readable message where the filter became unparsable. | |
541 * | |
542 * <p> | |
543 * The following steps are required to select a set of | |
544 * <code>ServiceReference</code> objects: | |
545 * <ol> | |
546 * <li>If the filter string is not <code>null</code>, the filter string | |
547 * is parsed and the set <code>ServiceReference</code> objects of | |
548 * registered services that satisfy the filter is produced. If the filter | |
549 * string is <code>null</code>, then all registered services are | |
550 * considered to satisfy the filter. | |
551 * <li>If the Java Runtime Environment supports permissions, the set of | |
552 * <code>ServiceReference</code> objects produced by the previous step is | |
553 * reduced by checking that the caller has the | |
554 * <code>ServicePermission</code> to get at least one of the class names | |
555 * under which the service was registered. If the caller does not have the | |
556 * correct permission for a particular <code>ServiceReference</code> | |
557 * object, then it is removed from the set. | |
558 * <li>If <code>clazz</code> is not <code>null</code>, the set is | |
559 * further reduced to those services that are an <code>instanceof</code> | |
560 * and were registered under the specified class. The complete list of | |
561 * classes of which a service is an instance and which were specified when | |
562 * the service was registered is available from the service's | |
563 * {@link Constants#OBJECTCLASS} property. | |
564 * <li>The set is reduced one final time by cycling through each | |
565 * <code>ServiceReference</code> object and calling | |
566 * {@link ServiceReference#isAssignableTo(Bundle, String)} with the context | |
567 * bundle and each class name under which the <code>ServiceReference</code> | |
568 * object was registered. For any given <code>ServiceReference</code> | |
569 * object, if any call to | |
570 * {@link ServiceReference#isAssignableTo(Bundle, String)} returns | |
571 * <code>false</code>, then it is removed from the set of | |
572 * <code>ServiceReference</code> objects. | |
573 * <li>An array of the remaining <code>ServiceReference</code> objects is | |
574 * returned. | |
575 * </ol> | |
576 * | |
577 * @param clazz The class name with which the service was registered or | |
578 * <code>null</code> for all services. | |
579 * @param filter The filter criteria. | |
580 * @return An array of <code>ServiceReference</code> objects or | |
581 * <code>null</code> if no services are registered which satisfy | |
582 * the search. | |
583 * @throws InvalidSyntaxException If <code>filter</code> contains an | |
584 * invalid filter string that cannot be parsed. | |
585 * @throws java.lang.IllegalStateException If this BundleContext is no | |
586 * longer valid. | |
587 */ | |
588 public ServiceReference[] getServiceReferences(String clazz, | |
589 String filter); | |
590 | |
591 /** | |
592 * Returns an array of <code>ServiceReference</code> objects. The returned | |
593 * array of <code>ServiceReference</code> objects contains services that | |
594 * were registered under the specified class and match the specified filter | |
595 * criteria. | |
596 * | |
597 * <p> | |
598 * The list is valid at the time of the call to this method, however since | |
599 * the Framework is a very dynamic environment, services can be modified or | |
600 * unregistered at anytime. | |
601 * | |
602 * <p> | |
603 * <code>filter</code> is used to select the registered service whose | |
604 * properties objects contain keys and values which satisfy the filter. See | |
605 * {@link Filter} for a description of the filter string syntax. | |
606 * | |
607 * <p> | |
608 * If <code>filter</code> is <code>null</code>, all registered services | |
609 * are considered to match the filter. If <code>filter</code> cannot be | |
610 * parsed, an {@link InvalidSyntaxException} will be thrown with a human | |
611 * readable message where the filter became unparsable. | |
612 * | |
613 * <p> | |
614 * The following steps are required to select a set of | |
615 * <code>ServiceReference</code> objects: | |
616 * <ol> | |
617 * <li>If the filter string is not <code>null</code>, the filter string | |
618 * is parsed and the set <code>ServiceReference</code> objects of | |
619 * registered services that satisfy the filter is produced. If the filter | |
620 * string is <code>null</code>, then all registered services are | |
621 * considered to satisfy the filter. | |
622 * <li>If the Java Runtime Environment supports permissions, the set of | |
623 * <code>ServiceReference</code> objects produced by the previous step is | |
624 * reduced by checking that the caller has the | |
625 * <code>ServicePermission</code> to get at least one of the class names | |
626 * under which the service was registered. If the caller does not have the | |
627 * correct permission for a particular <code>ServiceReference</code> | |
628 * object, then it is removed from the set. | |
629 * <li>If <code>clazz</code> is not <code>null</code>, the set is | |
630 * further reduced to those services that are an <code>instanceof</code> | |
631 * and were registered under the specified class. The complete list of | |
632 * classes of which a service is an instance and which were specified when | |
633 * the service was registered is available from the service's | |
634 * {@link Constants#OBJECTCLASS} property. | |
635 * <li>An array of the remaining <code>ServiceReference</code> objects is | |
636 * returned. | |
637 * </ol> | |
638 * | |
639 * @param clazz The class name with which the service was registered or | |
640 * <code>null</code> for all services. | |
641 * @param filter The filter criteria. | |
642 * @return An array of <code>ServiceReference</code> objects or | |
643 * <code>null</code> if no services are registered which satisfy | |
644 * the search. | |
645 * @throws InvalidSyntaxException If <code>filter</code> contains an | |
646 * invalid filter string that cannot be parsed. | |
647 * @throws java.lang.IllegalStateException If this BundleContext is no | |
648 * longer valid. | |
649 * @since 1.3 | |
650 */ | |
651 public ServiceReference[] getAllServiceReferences(String clazz, | |
652 String filter); | |
653 | |
654 /** | |
655 * Returns a <code>ServiceReference</code> object for a service that | |
656 * implements and was registered under the specified class. | |
657 * | |
658 * <p> | |
659 * This <code>ServiceReference</code> object is valid at the time of the | |
660 * call to this method, however as the Framework is a very dynamic | |
661 * environment, services can be modified or unregistered at anytime. | |
662 * | |
663 * <p> | |
664 * This method is the same as calling | |
665 * {@link BundleContext#getServiceReferences(String, String)} with a | |
666 * <code>null</code> filter string. It is provided as a convenience for | |
667 * when the caller is interested in any service that implements the | |
668 * specified class. | |
669 * <p> | |
670 * If multiple such services exist, the service with the highest ranking (as | |
671 * specified in its {@link Constants#SERVICE_RANKING} property) is returned. | |
672 * <p> | |
673 * If there is a tie in ranking, the service with the lowest service ID (as | |
674 * specified in its {@link Constants#SERVICE_ID} property); that is, the | |
675 * service that was registered first is returned. | |
676 * | |
677 * @param clazz The class name with which the service was registered. | |
678 * @return A <code>ServiceReference</code> object, or <code>null</code> | |
679 * if no services are registered which implement the named class. | |
680 * @throws java.lang.IllegalStateException If this BundleContext is no | |
681 * longer valid. | |
682 * @see #getServiceReferences(String, String) | |
683 */ | |
684 public ServiceReference getServiceReference(String clazz); | |
685 | |
686 /** | |
687 * Returns the specified service object for a service. | |
688 * <p> | |
689 * A bundle's use of a service is tracked by the bundle's use count of that | |
690 * service. Each time a service's service object is returned by | |
691 * {@link #getService(ServiceReference)} the context bundle's use count for | |
692 * that service is incremented by one. Each time the service is released by | |
693 * {@link #ungetService(ServiceReference)} the context bundle's use count | |
694 * for that service is decremented by one. | |
695 * <p> | |
696 * When a bundle's use count for a service drops to zero, the bundle should | |
697 * no longer use that service. | |
698 * | |
699 * <p> | |
700 * This method will always return <code>null</code> when the service | |
701 * associated with this <code>reference</code> has been unregistered. | |
702 * | |
703 * <p> | |
704 * The following steps are required to get the service object: | |
705 * <ol> | |
706 * <li>If the service has been unregistered, <code>null</code> is | |
707 * returned. | |
708 * <li>The context bundle's use count for this service is incremented by | |
709 * one. | |
710 * <li>If the context bundle's use count for the service is currently one | |
711 * and the service was registered with an object implementing the | |
712 * <code>ServiceFactory</code> interface, the | |
713 * {@link ServiceFactory#getService(Bundle, ServiceRegistration)} method is | |
714 * called to create a service object for the context bundle. This service | |
715 * object is cached by the Framework. While the context bundle's use count | |
716 * for the service is greater than zero, subsequent calls to get the | |
717 * services's service object for the context bundle will return the cached | |
718 * service object. <br> | |
719 * If the service object returned by the <code>ServiceFactory</code> | |
720 * object is not an <code>instanceof</code> all the classes named when the | |
721 * service was registered or the <code>ServiceFactory</code> object throws | |
722 * an exception, <code>null</code> is returned and a Framework event of | |
723 * type {@link FrameworkEvent#ERROR} is fired. | |
724 * <li>The service object for the service is returned. | |
725 * </ol> | |
726 * | |
727 * @param reference A reference to the service. | |
728 * @return A service object for the service associated with | |
729 * <code>reference</code> or <code>null</code> if the service is | |
730 * not registered or does not implement the classes under which it | |
731 * was registered in the case of a <code>ServiceFactory</code>. | |
732 * @throws java.lang.SecurityException If the caller does not have the | |
733 * <code>ServicePermission</code> to get the service using at | |
734 * least one of the named classes the service was registered under | |
735 * and the Java Runtime Environment supports permissions. | |
736 * @throws java.lang.IllegalStateException If this BundleContext is no | |
737 * longer valid. | |
738 * @see #ungetService(ServiceReference) | |
739 * @see ServiceFactory | |
740 */ | |
741 public Object getService(ServiceReference reference); | |
742 | |
743 /** | |
744 * Releases the service object referenced by the specified | |
745 * <code>ServiceReference</code> object. If the context bundle's use count | |
746 * for the service is zero, this method returns <code>false</code>. | |
747 * Otherwise, the context bundle's use count for the service is decremented | |
748 * by one. | |
749 * | |
750 * <p> | |
751 * The service's service object should no longer be used and all references | |
752 * to it should be destroyed when a bundle's use count for the service drops | |
753 * to zero. | |
754 * | |
755 * <p> | |
756 * The following steps are required to unget the service object: | |
757 * <ol> | |
758 * <li>If the context bundle's use count for the service is zero or the | |
759 * service has been unregistered, <code>false</code> is returned. | |
760 * <li>The context bundle's use count for this service is decremented by | |
761 * one. | |
762 * <li>If the context bundle's use count for the service is currently zero | |
763 * and the service was registered with a <code>ServiceFactory</code> | |
764 * object, the | |
765 * {@link ServiceFactory#ungetService(Bundle, ServiceRegistration, Object)} | |
766 * method is called to release the service object for the context bundle. | |
767 * <li><code>true</code> is returned. | |
768 * </ol> | |
769 * | |
770 * @param reference A reference to the service to be released. | |
771 * @return <code>false</code> if the context bundle's use count for the | |
772 * service is zero or if the service has been unregistered; | |
773 * <code>true</code> otherwise. | |
774 * @throws java.lang.IllegalStateException If this BundleContext is no | |
775 * longer valid. | |
776 * @see #getService | |
777 * @see ServiceFactory | |
778 */ | |
779 public bool ungetService(ServiceReference reference); | |
780 | |
781 /** | |
782 * Creates a <code>File</code> object for a file in the persistent storage | |
783 * area provided for the bundle by the Framework. This method will return | |
784 * <code>null</code> if the platform does not have file system support. | |
785 * | |
786 * <p> | |
787 * A <code>File</code> object for the base directory of the persistent | |
788 * storage area provided for the context bundle by the Framework can be | |
789 * obtained by calling this method with an empty string as | |
790 * <code>filename</code>. | |
791 * | |
792 * <p> | |
793 * If the Java Runtime Environment supports permissions, the Framework will | |
794 * ensure that the bundle has the <code>java.io.FilePermission</code> with | |
795 * actions <code>read</code>,<code>write</code>,<code>delete</code> | |
796 * for all files (recursively) in the persistent storage area provided for | |
797 * the context bundle. | |
798 * | |
799 * @param filename A relative name to the file to be accessed. | |
800 * @return A <code>File</code> object that represents the requested file | |
801 * or <code>null</code> if the platform does not have file system | |
802 * support. | |
803 * @throws java.lang.IllegalStateException If this BundleContext is no | |
804 * longer valid. | |
805 */ | |
806 public File getDataFile(String filename); | |
807 | |
808 /** | |
809 * Creates a <code>Filter</code> object. This <code>Filter</code> object | |
810 * may be used to match a <code>ServiceReference</code> object or a | |
811 * <code>Dictionary</code> object. | |
812 * | |
813 * <p> | |
814 * If the filter cannot be parsed, an {@link InvalidSyntaxException} will be | |
815 * thrown with a human readable message where the filter became unparsable. | |
816 * | |
817 * @param filter The filter string. | |
818 * @return A <code>Filter</code> object encapsulating the filter string. | |
819 * @throws InvalidSyntaxException If <code>filter</code> contains an | |
820 * invalid filter string that cannot be parsed. | |
821 * @throws NullPointerException If <code>filter</code> is null. | |
822 * @throws java.lang.IllegalStateException If this BundleContext is no | |
823 * longer valid. | |
824 * | |
825 * @since 1.1 | |
826 * @see "Framework specification for a description of the filter string syntax." | |
827 * @see FrameworkUtil#createFilter(String) | |
828 */ | |
829 public Filter createFilter(String filter); | |
830 } |