Richard S. Hall | 930fecc | 2005-08-16 18:33:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | * $Header: /cvshome/build/org.osgi.framework/src/org/osgi/framework/Bundle.java,v 1.27 2005/06/21 16:37:35 hargrave Exp $ |
| 3 | * |
| 4 | * Copyright (c) OSGi Alliance (2000, 2005). All Rights Reserved. |
| 5 | * |
| 6 | * This program and the accompanying materials are made available under the |
| 7 | * terms of the Eclipse Public License v1.0 which accompanies this |
| 8 | * distribution, and is available at http://www.eclipse.org/legal/epl-v10.html. |
| 9 | */ |
| 10 | |
| 11 | package org.osgi.framework; |
| 12 | |
| 13 | import java.io.IOException; |
| 14 | import java.io.InputStream; |
| 15 | import java.net.URL; |
| 16 | import java.util.Dictionary; |
| 17 | import java.util.Enumeration; |
| 18 | |
| 19 | /** |
| 20 | * An installed bundle in the Framework. |
| 21 | * |
| 22 | * <p> |
| 23 | * A <code>Bundle</code> object is the access point to define the lifecycle of |
| 24 | * an installed bundle. Each bundle installed in the OSGi environment must have |
| 25 | * an associated <code>Bundle</code> object. |
| 26 | * |
| 27 | * <p> |
| 28 | * A bundle must have a unique identity, a <code>long</code>, chosen by the |
| 29 | * Framework. This identity must not change during the lifecycle of a bundle, |
| 30 | * even when the bundle is updated. Uninstalling and then reinstalling the |
| 31 | * bundle must create a new unique identity. |
| 32 | * |
| 33 | * <p> |
| 34 | * A bundle can be in one of six states: |
| 35 | * <ul> |
| 36 | * <li>{@link #UNINSTALLED} |
| 37 | * <li>{@link #INSTALLED} |
| 38 | * <li>{@link #RESOLVED} |
| 39 | * <li>{@link #STARTING} |
| 40 | * <li>{@link #STOPPING} |
| 41 | * <li>{@link #ACTIVE} |
| 42 | * </ul> |
| 43 | * <p> |
| 44 | * Values assigned to these states have no specified ordering; they represent |
| 45 | * bit values that may be ORed together to determine if a bundle is in one of |
| 46 | * the valid states. |
| 47 | * |
| 48 | * <p> |
| 49 | * A bundle should only execute code when its state is one of |
| 50 | * <code>STARTING</code>,<code>ACTIVE</code>, or <code>STOPPING</code>. |
| 51 | * An <code>UNINSTALLED</code> bundle can not be set to another state; it is a |
| 52 | * zombie and can only be reached because references are kept somewhere. |
| 53 | * |
| 54 | * <p> |
| 55 | * The Framework is the only entity that is allowed to create |
| 56 | * <code>Bundle</code> objects, and these objects are only valid within the |
| 57 | * Framework that created them. |
| 58 | * |
| 59 | * @version $Revision: 1.27 $ |
| 60 | */ |
| 61 | public abstract interface Bundle { |
| 62 | /** |
| 63 | * This bundle is uninstalled and may not be used. |
| 64 | * |
| 65 | * <p> |
| 66 | * The <code>UNINSTALLED</code> state is only visible after a bundle is |
| 67 | * uninstalled; the bundle is in an unusable state but references to the |
| 68 | * <code>Bundle</code> object may still be available and used for |
| 69 | * introspection. |
| 70 | * <p> |
| 71 | * The value of <code>UNINSTALLED</code> is 0x00000001. |
| 72 | */ |
| 73 | public static final int UNINSTALLED = 0x00000001; |
| 74 | |
| 75 | /** |
| 76 | * This bundle is installed but not yet resolved. |
| 77 | * |
| 78 | * <p> |
| 79 | * A bundle is in the <code>INSTALLED</code> state when it has been |
| 80 | * installed in the Framework but cannot run. |
| 81 | * <p> |
| 82 | * This state is visible if the bundle's code dependencies are not resolved. |
| 83 | * The Framework may attempt to resolve an <code>INSTALLED</code> bundle's |
| 84 | * code dependencies and move the bundle to the <code>RESOLVED</code> |
| 85 | * state. |
| 86 | * <p> |
| 87 | * The value of <code>INSTALLED</code> is 0x00000002. |
| 88 | */ |
| 89 | public static final int INSTALLED = 0x00000002; |
| 90 | |
| 91 | /** |
| 92 | * This bundle is resolved and is able to be started. |
| 93 | * |
| 94 | * <p> |
| 95 | * A bundle is in the <code>RESOLVED</code> state when the Framework has |
| 96 | * successfully resolved the bundle's dependencies. These dependencies |
| 97 | * include: |
| 98 | * <ul> |
| 99 | * <li>The bundle's class path from its {@link Constants#BUNDLE_CLASSPATH} |
| 100 | * Manifest header. |
| 101 | * <li>The bundle's package dependencies from its |
| 102 | * {@link Constants#EXPORT_PACKAGE}and {@link Constants#IMPORT_PACKAGE} |
| 103 | * Manifest headers. |
| 104 | * <li>The bundle's required bundle dependencies from its |
| 105 | * {@link Constants#REQUIRE_BUNDLE}Manifest header. |
| 106 | * <li>A fragment bundle's host dependency from its |
| 107 | * {@link Constants#FRAGMENT_HOST}Manifest header. |
| 108 | * </ul> |
| 109 | * <p> |
| 110 | * Note that the bundle is not active yet. A bundle must be put in the |
| 111 | * <code>RESOLVED</code> state before it can be started. The Framework may |
| 112 | * attempt to resolve a bundle at any time. |
| 113 | * <p> |
| 114 | * The value of <code>RESOLVED</code> is 0x00000004. |
| 115 | */ |
| 116 | public static final int RESOLVED = 0x00000004; |
| 117 | |
| 118 | /** |
| 119 | * This bundle is in the process of starting. |
| 120 | * |
| 121 | * <p> |
| 122 | * A bundle is in the <code>STARTING</code> state when the {@link #start} |
| 123 | * method is active. A bundle must be in this state when the bundle's |
| 124 | * {@link BundleActivator#start}is called. If this method completes without |
| 125 | * exception, then the bundle has successfully started and must move to the |
| 126 | * <code>ACTIVE</code> state. |
| 127 | * <p> |
| 128 | * The value of <code>STARTING</code> is 0x00000008. |
| 129 | */ |
| 130 | public static final int STARTING = 0x00000008; |
| 131 | |
| 132 | /** |
| 133 | * This bundle is in the process of stopping. |
| 134 | * |
| 135 | * <p> |
| 136 | * A bundle is in the <code>STOPPING</code> state when the {@link #stop} |
| 137 | * method is active. A bundle must be in this state when the bundle's |
| 138 | * {@link BundleActivator#stop}method is called. When this method completes |
| 139 | * the bundle is stopped and must move to the <code>RESOLVED</code> state. |
| 140 | * <p> |
| 141 | * The value of <code>STOPPING</code> is 0x00000010. |
| 142 | */ |
| 143 | public static final int STOPPING = 0x00000010; |
| 144 | |
| 145 | /** |
| 146 | * This bundle is now running. |
| 147 | * |
| 148 | * <p> |
| 149 | * A bundle is in the <code>ACTIVE</code> state when it has been |
| 150 | * successfully started. |
| 151 | * <p> |
| 152 | * The value of <code>ACTIVE</code> is 0x00000020. |
| 153 | */ |
| 154 | public static final int ACTIVE = 0x00000020; |
| 155 | |
| 156 | /** |
| 157 | * Returns this bundle's current state. |
| 158 | * |
| 159 | * <p> |
| 160 | * A bundle can be in only one state at any time. |
| 161 | * |
| 162 | * @return An element of <code>UNINSTALLED</code>,<code>INSTALLED</code>, |
| 163 | * <code>RESOLVED</code>,<code>STARTING</code>, |
| 164 | * <code>STOPPING</code>,<code>ACTIVE</code>. |
| 165 | */ |
| 166 | public abstract int getState(); |
| 167 | |
| 168 | /** |
| 169 | * Starts this bundle. |
| 170 | * |
| 171 | * <p> |
| 172 | * If the Framework implements the optional Start Level service and the |
| 173 | * current start level is less than this bundle's start level, then the |
| 174 | * Framework must persistently mark this bundle as started and delay the |
| 175 | * starting of this bundle until the Framework's current start level becomes |
| 176 | * equal or more than the bundle's start level. |
| 177 | * <p> |
| 178 | * Otherwise, the following steps are required to start a bundle: |
| 179 | * <ol> |
| 180 | * <li>If this bundle's state is <code>UNINSTALLED</code> then an |
| 181 | * <code>IllegalStateException</code> is thrown. |
| 182 | * |
| 183 | * <li>If this bundle's state is <code>STARTING</code> or |
| 184 | * <code>STOPPING</code> then this method must wait for this bundle to |
| 185 | * change state before continuing. If this does not occur in a reasonable |
| 186 | * time, a <code>BundleException</code> is thrown to indicate this bundle |
| 187 | * was unable to be started. |
| 188 | * |
| 189 | * <li>If this bundle's state is <code>ACTIVE</code> then this method |
| 190 | * returns immediately. |
| 191 | * |
| 192 | * <li>Persistently record that this bundle has been started. When the |
| 193 | * Framework is restarted, this bundle must be automatically started. |
| 194 | * |
| 195 | * <li>If this bundle's state is not <code>RESOLVED</code>, an attempt |
| 196 | * is made to resolve this bundle's package dependencies. If the Framework |
| 197 | * cannot resolve this bundle, a <code>BundleException</code> is thrown. |
| 198 | * |
| 199 | * <li>This bundle's state is set to <code>STARTING</code>. |
| 200 | * |
| 201 | * <li>The {@link BundleActivator#start}method of this bundle's |
| 202 | * <code>BundleActivator</code>, if one is specified, is called. If the |
| 203 | * <code>BundleActivator</code> is invalid or throws an exception, this |
| 204 | * bundle's state is set back to <code>RESOLVED</code>.<br> |
| 205 | * Any services registered by the bundle must be unregistered. <br> |
| 206 | * Any services used by the bundle must be released. <br> |
| 207 | * Any listeners registered by the bundle must be removed. <br> |
| 208 | * A <code>BundleException</code> is then thrown. |
| 209 | * |
| 210 | * <li>If this bundle's state is <code>UNINSTALLED</code>, because the |
| 211 | * bundle was uninstalled while the <code>BundleActivator.start</code> |
| 212 | * method was running, a <code>BundleException</code> is thrown. |
| 213 | * |
| 214 | * <li>This bundle's state is set to <code>ACTIVE</code>. |
| 215 | * |
| 216 | * <li>A bundle event of type {@link BundleEvent#STARTED}is broadcast. |
| 217 | * </ol> |
| 218 | * |
| 219 | * <b>Preconditions </b> |
| 220 | * <ul> |
| 221 | * <li><code>getState()</code> in {<code>INSTALLED</code>}, { |
| 222 | * <code>RESOLVED</code>}. |
| 223 | * </ul> |
| 224 | * <b>Postconditions, no exceptions thrown </b> |
| 225 | * <ul> |
| 226 | * <li>Bundle persistent state is marked as active. |
| 227 | * <li><code>getState()</code> in {<code>ACTIVE</code>}. |
| 228 | * <li><code>BundleActivator.start()</code> has been called and did not |
| 229 | * throw an exception. |
| 230 | * </ul> |
| 231 | * <b>Postconditions, when an exception is thrown </b> |
| 232 | * <ul> |
| 233 | * <li>Depending on when the exception occurred, bundle persistent state is |
| 234 | * marked as active. |
| 235 | * <li><code>getState()</code> not in {<code>STARTING</code>}, { |
| 236 | * <code>ACTIVE</code>}. |
| 237 | * </ul> |
| 238 | * |
| 239 | * @exception BundleException If this bundle could not be started. This |
| 240 | * could be because a code dependency could not be resolved or |
| 241 | * the specified <code>BundleActivator</code> could not be |
| 242 | * loaded or threw an exception. |
| 243 | * @exception java.lang.IllegalStateException If this bundle has been |
| 244 | * uninstalled or this bundle tries to change its own state. |
| 245 | * @exception java.lang.SecurityException If the caller does not have the |
| 246 | * appropriate <code>AdminPermission[bundle, EXECUTE]</code>, |
| 247 | * and the Java Runtime Environment supports permissions. |
| 248 | */ |
| 249 | public abstract void start() throws BundleException; |
| 250 | |
| 251 | /** |
| 252 | * Stops this bundle. |
| 253 | * |
| 254 | * <p> |
| 255 | * The following steps are required to stop a bundle: |
| 256 | * <ol> |
| 257 | * <li>If this bundle's state is <code>UNINSTALLED</code> then an |
| 258 | * <code>IllegalStateException</code> is thrown. |
| 259 | * |
| 260 | * <li>If this bundle's state is <code>STARTING</code> or |
| 261 | * <code>STOPPING</code> then this method must wait for this bundle to |
| 262 | * change state before continuing. If this does not occur in a reasonable |
| 263 | * time, a <code>BundleException</code> is thrown to indicate this bundle |
| 264 | * was unable to be stopped. |
| 265 | * |
| 266 | * <li>Persistently record that this bundle has been stopped. When the |
| 267 | * Framework is restarted, this bundle must not be automatically started. |
| 268 | * |
| 269 | * <li>If this bundle's state is not <code>ACTIVE</code> then this method |
| 270 | * returns immediately. |
| 271 | * |
| 272 | * <li>This bundle's state is set to <code>STOPPING</code>. |
| 273 | * |
| 274 | * <li>The {@link BundleActivator#stop}method of this bundle's |
| 275 | * <code>BundleActivator</code>, if one is specified, is called. If that |
| 276 | * method throws an exception, this method must continue to stop this |
| 277 | * bundle. A <code>BundleException</code> must be thrown after completion |
| 278 | * of the remaining steps. |
| 279 | * |
| 280 | * <li>Any services registered by this bundle must be unregistered. |
| 281 | * <li>Any services used by this bundle must be released. |
| 282 | * <li>Any listeners registered by this bundle must be removed. |
| 283 | * |
| 284 | * <li>If this bundle's state is <code>UNINSTALLED</code>, because the |
| 285 | * bundle was uninstalled while the <code>BundleActivator.stop</code> |
| 286 | * method was running, a <code>BundleException</code> must be thrown. |
| 287 | * |
| 288 | * <li>This bundle's state is set to <code>RESOLVED</code>. |
| 289 | * |
| 290 | * <li>A bundle event of type {@link BundleEvent#STOPPED}is broadcast. |
| 291 | * </ol> |
| 292 | * |
| 293 | * <b>Preconditions </b> |
| 294 | * <ul> |
| 295 | * <li><code>getState()</code> in {<code>ACTIVE</code>}. |
| 296 | * </ul> |
| 297 | * <b>Postconditions, no exceptions thrown </b> |
| 298 | * <ul> |
| 299 | * <li>Bundle persistent state is marked as stopped. |
| 300 | * <li><code>getState()</code> not in {<code>ACTIVE</code>, |
| 301 | * <code>STOPPING</code>}. |
| 302 | * <li><code>BundleActivator.stop</code> has been called and did not |
| 303 | * throw an exception. |
| 304 | * </ul> |
| 305 | * <b>Postconditions, when an exception is thrown </b> |
| 306 | * <ul> |
| 307 | * <li>Bundle persistent state is marked as stopped. |
| 308 | * </ul> |
| 309 | * |
| 310 | * @exception BundleException If this bundle's <code>BundleActivator</code> |
| 311 | * could not be loaded or threw an exception. |
| 312 | * @exception java.lang.IllegalStateException If this bundle has been |
| 313 | * uninstalled or this bundle tries to change its own state. |
| 314 | * @exception java.lang.SecurityException If the caller does not have the |
| 315 | * appropriate <code>AdminPermission[bundle, EXECUTE]</code>, |
| 316 | * and the Java Runtime Environment supports permissions. |
| 317 | */ |
| 318 | public abstract void stop() throws BundleException; |
| 319 | |
| 320 | /** |
| 321 | * Updates this bundle. |
| 322 | * |
| 323 | * <p> |
| 324 | * If this bundle's state is <code>ACTIVE</code>, it must be stopped |
| 325 | * before the update and started after the update successfully completes. |
| 326 | * |
| 327 | * <p> |
| 328 | * If the bundle being updated has exported any packages, these packages |
| 329 | * must not be updated. Instead, the previous package version must remain |
| 330 | * exported until the <code>PackageAdmin.refreshPackages</code> method has |
| 331 | * been has been called or the Framework is relaunched. |
| 332 | * |
| 333 | * <p> |
| 334 | * The following steps are required to update a bundle: |
| 335 | * <ol> |
| 336 | * <li>If this bundle's state is <code>UNINSTALLED</code> then an |
| 337 | * <code>IllegalStateException</code> is thrown. |
| 338 | * |
| 339 | * <li>If this bundle's state is <code>ACTIVE</code>, |
| 340 | * <code>STARTING</code> or <code>STOPPING</code>, the bundle is |
| 341 | * stopped as described in the <code>Bundle.stop</code> method. If |
| 342 | * <code>Bundle.stop</code> throws an exception, the exception is rethrown |
| 343 | * terminating the update. |
| 344 | * |
| 345 | * <li>The download location of the new version of this bundle is |
| 346 | * determined from either the bundle's |
| 347 | * {@link Constants#BUNDLE_UPDATELOCATION}Manifest header (if available) or |
| 348 | * the bundle's original location. |
| 349 | * |
| 350 | * <li>The location is interpreted in an implementation dependent manner, |
| 351 | * typically as a URL, and the new version of this bundle is obtained from |
| 352 | * this location. |
| 353 | * |
| 354 | * <li>The new version of this bundle is installed. If the Framework is |
| 355 | * unable to install the new version of this bundle, the original version of |
| 356 | * this bundle must be restored and a <code>BundleException</code> must be |
| 357 | * thrown after completion of the remaining steps. |
| 358 | * |
| 359 | * <li>If the bundle has declared an Bundle-RequiredExecutionEnvironment |
| 360 | * header, then the listed execution environments must be verified against |
| 361 | * the installed execution environments. If they do not all match, the |
| 362 | * original version of this bundle must be restored and a |
| 363 | * <code>BundleException</code> must be thrown after completion of the |
| 364 | * remaining steps. |
| 365 | * |
| 366 | * <li>This bundle's state is set to <code>INSTALLED</code>. |
| 367 | * |
| 368 | * <li>If the new version of this bundle was successfully installed, a |
| 369 | * bundle event of type {@link BundleEvent#UPDATED}is broadcast. |
| 370 | * |
| 371 | * <li>If this bundle's state was originally <code>ACTIVE</code>, the |
| 372 | * updated bundle is started as described in the <code>Bundle.start</code> |
| 373 | * method. If <code>Bundle.start</code> throws an exception, a Framework |
| 374 | * event of type {@link FrameworkEvent#ERROR}is broadcast containing the |
| 375 | * exception. |
| 376 | * </ol> |
| 377 | * |
| 378 | * <b>Preconditions </b> |
| 379 | * <ul> |
| 380 | * <li><code>getState()</code> not in {<code>UNINSTALLED</code>}. |
| 381 | * </ul> |
| 382 | * <b>Postconditions, no exceptions thrown </b> |
| 383 | * <ul> |
| 384 | * <li><code>getState()</code> in {<code>INSTALLED</code>, |
| 385 | * <code>RESOLVED</code>,<code>ACTIVE</code>}. |
| 386 | * <li>This bundle has been updated. |
| 387 | * </ul> |
| 388 | * <b>Postconditions, when an exception is thrown </b> |
| 389 | * <ul> |
| 390 | * <li><code>getState()</code> in {<code>INSTALLED</code>, |
| 391 | * <code>RESOLVED</code>,<code>ACTIVE</code>}. |
| 392 | * <li>Original bundle is still used; no update occurred. |
| 393 | * </ul> |
| 394 | * |
| 395 | * @exception BundleException If the update fails. |
| 396 | * @exception java.lang.IllegalStateException If this bundle has been |
| 397 | * uninstalled or this bundle tries to change its own state. |
| 398 | * @exception java.lang.SecurityException If the caller does not have the |
| 399 | * appropriate <code>AdminPermission[bundle, LIFECYCLE]</code> for both |
| 400 | * the current bundle and the updated bundle, |
| 401 | * and the Java Runtime Environment supports permissions. |
| 402 | * @see #stop() |
| 403 | * @see #start() |
| 404 | */ |
| 405 | public abstract void update() throws BundleException; |
| 406 | |
| 407 | /** |
| 408 | * Updates this bundle from an <code>InputStream</code>. |
| 409 | * |
| 410 | * <p> |
| 411 | * This method performs all the steps listed in <code>Bundle.update()</code>, |
| 412 | * except the bundle must be read from the supplied <code>InputStream</code>, |
| 413 | * rather than a <code>URL</code>. |
| 414 | * <p> |
| 415 | * This method must always close the <code>InputStream</code> when it is |
| 416 | * done, even if an exception is thrown. |
| 417 | * |
| 418 | * @param in The <code>InputStream</code> from which to read the new |
| 419 | * bundle. |
| 420 | * @exception BundleException If the provided stream cannot be read or the |
| 421 | * update fails. |
| 422 | * @exception java.lang.IllegalStateException If this bundle has been |
| 423 | * uninstalled or this bundle tries to change its own state. |
| 424 | * @exception java.lang.SecurityException If the caller does not have the |
| 425 | * appropriate <code>AdminPermission[bundle, LIFECYCLE]</code> for both |
| 426 | * the current bundle and the updated bundle, |
| 427 | * and the Java Runtime Environment supports permissions. |
| 428 | * @see #update() |
| 429 | */ |
| 430 | public abstract void update(InputStream in) throws BundleException; |
| 431 | |
| 432 | /** |
| 433 | * Uninstalls this bundle. |
| 434 | * |
| 435 | * <p> |
| 436 | * This method causes the Framework to notify other bundles that this bundle |
| 437 | * is being uninstalled, and then puts this bundle into the |
| 438 | * <code>UNINSTALLED</code> state. The Framework must remove any resources |
| 439 | * related to this bundle that it is able to remove. |
| 440 | * |
| 441 | * <p> |
| 442 | * If this bundle has exported any packages, the Framework must continue to |
| 443 | * make these packages available to their importing bundles until the |
| 444 | * <code>PackageAdmin.refreshPackages</code> method has been called or the |
| 445 | * Framework is relaunched. |
| 446 | * |
| 447 | * <p> |
| 448 | * The following steps are required to uninstall a bundle: |
| 449 | * <ol> |
| 450 | * <li>If this bundle's state is <code>UNINSTALLED</code> then an |
| 451 | * <code>IllegalStateException</code> is thrown. |
| 452 | * |
| 453 | * <li>If this bundle's state is <code>ACTIVE</code>, |
| 454 | * <code>STARTING</code> or <code>STOPPING</code>, this bundle is |
| 455 | * stopped as described in the <code>Bundle.stop</code> method. If |
| 456 | * <code>Bundle.stop</code> throws an exception, a Framework event of type |
| 457 | * {@link FrameworkEvent#ERROR}is broadcast containing the exception. |
| 458 | * |
| 459 | * <li>This bundle's state is set to <code>UNINSTALLED</code>. |
| 460 | * |
| 461 | * <li>A bundle event of type {@link BundleEvent#UNINSTALLED}is broadcast. |
| 462 | * |
| 463 | * <li>This bundle and any persistent storage area provided for this bundle |
| 464 | * by the Framework are removed. |
| 465 | * </ol> |
| 466 | * |
| 467 | * <b>Preconditions </b> |
| 468 | * <ul> |
| 469 | * <li><code>getState()</code> not in {<code>UNINSTALLED</code>}. |
| 470 | * </ul> |
| 471 | * <b>Postconditions, no exceptions thrown </b> |
| 472 | * <ul> |
| 473 | * <li><code>getState()</code> in {<code>UNINSTALLED</code>}. |
| 474 | * <li>This bundle has been uninstalled. |
| 475 | * </ul> |
| 476 | * <b>Postconditions, when an exception is thrown </b> |
| 477 | * <ul> |
| 478 | * <li><code>getState()</code> not in {<code>UNINSTALLED</code>}. |
| 479 | * <li>This Bundle has not been uninstalled. |
| 480 | * </ul> |
| 481 | * |
| 482 | * @exception BundleException If the uninstall failed. This can occur if |
| 483 | * another thread is attempting to change the bundle's state and |
| 484 | * does not complete in a timely manner. |
| 485 | * @exception java.lang.IllegalStateException If this bundle has been |
| 486 | * uninstalled or this bundle tries to change its own state. |
| 487 | * @exception java.lang.SecurityException If the caller does not have the |
| 488 | * appropriate <code>AdminPermission[bundle, LIFECYCLE]</code>, |
| 489 | * and the Java Runtime Environment supports permissions. |
| 490 | * @see #stop() |
| 491 | */ |
| 492 | public abstract void uninstall() throws BundleException; |
| 493 | |
| 494 | /** |
| 495 | * Returns this bundle's Manifest headers and values. This method returns |
| 496 | * all the Manifest headers and values from the main section of the bundle's |
| 497 | * Manifest file; that is, all lines prior to the first blank line. |
| 498 | * |
| 499 | * <p> |
| 500 | * Manifest header names are case-insensitive. The methods of the returned |
| 501 | * <code>Dictionary</code> object must operate on header names in a |
| 502 | * case-insensitive manner. |
| 503 | * |
| 504 | * If a Manifest header value starts with "%", it must be |
| 505 | * localized according to the default locale. |
| 506 | * |
| 507 | * <p> |
| 508 | * For example, the following Manifest headers and values are included if |
| 509 | * they are present in the Manifest file: |
| 510 | * |
| 511 | * <pre> |
| 512 | * Bundle-Name |
| 513 | * Bundle-Vendor |
| 514 | * Bundle-Version |
| 515 | * Bundle-Description |
| 516 | * Bundle-DocURL |
| 517 | * Bundle-ContactAddress |
| 518 | * </pre> |
| 519 | * |
| 520 | * <p> |
| 521 | * This method must continue to return Manifest header information while |
| 522 | * this bundle is in the <code>UNINSTALLED</code> state. |
| 523 | * |
| 524 | * @return A <code>Dictionary</code> object containing this bundle's |
| 525 | * Manifest headers and values. |
| 526 | * |
| 527 | * @exception java.lang.SecurityException If the caller does not have the appropriate |
| 528 | * <code>AdminPermission[bundle, METADATA]</code>, and the |
| 529 | * Java Runtime Environment supports permissions. |
| 530 | * |
| 531 | * @see Constants#BUNDLE_LOCALIZATION |
| 532 | */ |
| 533 | public abstract Dictionary getHeaders(); |
| 534 | |
| 535 | /** |
| 536 | * Returns this bundle's identifier. The bundle is assigned a unique |
| 537 | * identifier by the Framework when it is installed in the OSGi environment. |
| 538 | * |
| 539 | * <p> |
| 540 | * A bundle's unique identifier has the following attributes: |
| 541 | * <ul> |
| 542 | * <li>Is unique and persistent. |
| 543 | * <li>Is a <code>long</code>. |
| 544 | * <li>Its value is not reused for another bundle, even after the bundle is |
| 545 | * uninstalled. |
| 546 | * <li>Does not change while the bundle remains installed. |
| 547 | * <li>Does not change when the bundle is updated. |
| 548 | * </ul> |
| 549 | * |
| 550 | * <p> |
| 551 | * This method must continue to return this bundle's unique identifier while |
| 552 | * this bundle is in the <code>UNINSTALLED</code> state. |
| 553 | * |
| 554 | * @return The unique identifier of this bundle. |
| 555 | */ |
| 556 | public abstract long getBundleId(); |
| 557 | |
| 558 | /** |
| 559 | * Returns this bundle's location identifier. |
| 560 | * |
| 561 | * <p> |
| 562 | * The bundle location identifier is the location passed to |
| 563 | * <code>BundleContext.installBundle</code> when a bundle is installed. |
| 564 | * The bundle location identifier does not change while the bundle remains |
| 565 | * installed, even if the bundle is updated. |
| 566 | * |
| 567 | * <p> |
| 568 | * This method must continue to return this bundle's location identifier |
| 569 | * while this bundle is in the <code>UNINSTALLED</code> state. |
| 570 | * |
| 571 | * @return The string representation of this bundle's location identifier. |
| 572 | * @exception java.lang.SecurityException If the caller does not have the |
| 573 | * appropriate <code>AdminPermission[bundle, METADATA]</code>, |
| 574 | * and the Java Runtime Environment supports permissions. |
| 575 | */ |
| 576 | public abstract String getLocation(); |
| 577 | |
| 578 | /** |
| 579 | * Returns this bundle's <code>ServiceReference</code> list for all |
| 580 | * services it has registered or <code>null</code> if this bundle has no |
| 581 | * registered services. |
| 582 | * |
| 583 | * <p> |
| 584 | * If the Java runtime supports permissions, a <code>ServiceReference</code> |
| 585 | * object to a service is included in the returned list only if the caller |
| 586 | * has the <code>ServicePermission</code> to get the service using at |
| 587 | * least one of the named classes the service was registered under. |
| 588 | * |
| 589 | * <p> |
| 590 | * The list is valid at the time of the call to this method, however, as the |
| 591 | * Framework is a very dynamic environment, services can be modified or |
| 592 | * unregistered at anytime. |
| 593 | * |
| 594 | * @return An array of <code>ServiceReference</code> objects or |
| 595 | * <code>null</code>. |
| 596 | * @exception java.lang.IllegalStateException If this bundle has been |
| 597 | * uninstalled. |
| 598 | * @see ServiceRegistration |
| 599 | * @see ServiceReference |
| 600 | * @see ServicePermission |
| 601 | */ |
| 602 | public abstract ServiceReference[] getRegisteredServices(); |
| 603 | |
| 604 | /** |
| 605 | * Returns this bundle's <code>ServiceReference</code> list for all |
| 606 | * services it is using or returns <code>null</code> if this bundle is not |
| 607 | * using any services. A bundle is considered to be using a service if its |
| 608 | * use count for that service is greater than zero. |
| 609 | * |
| 610 | * <p> |
| 611 | * If the Java Runtime Environment supports permissions, a |
| 612 | * <code>ServiceReference</code> object to a service is included in the |
| 613 | * returned list only if the caller has the <code>ServicePermission</code> |
| 614 | * to get the service using at least one of the named classes the service |
| 615 | * was registered under. |
| 616 | * <p> |
| 617 | * The list is valid at the time of the call to this method, however, as the |
| 618 | * Framework is a very dynamic environment, services can be modified or |
| 619 | * unregistered at anytime. |
| 620 | * |
| 621 | * @return An array of <code>ServiceReference</code> objects or |
| 622 | * <code>null</code>. |
| 623 | * @exception java.lang.IllegalStateException If this bundle has been |
| 624 | * uninstalled. |
| 625 | * @see ServiceReference |
| 626 | * @see ServicePermission |
| 627 | */ |
| 628 | public abstract ServiceReference[] getServicesInUse(); |
| 629 | |
| 630 | /** |
| 631 | * Determines if this bundle has the specified permissions. |
| 632 | * |
| 633 | * <p> |
| 634 | * If the Java Runtime Environment does not support permissions, this method |
| 635 | * always returns <code>true</code>. |
| 636 | * <p> |
| 637 | * <code>permission</code> is of type <code>Object</code> to avoid |
| 638 | * referencing the <code>java.security.Permission</code> class directly. |
| 639 | * This is to allow the Framework to be implemented in Java environments |
| 640 | * which do not support permissions. |
| 641 | * |
| 642 | * <p> |
| 643 | * If the Java Runtime Environment does support permissions, this bundle and |
| 644 | * all its resources including embedded JAR files, belong to the same |
| 645 | * <code>java.security.ProtectionDomain</code>; that is, they must share |
| 646 | * the same set of permissions. |
| 647 | * |
| 648 | * @param permission The permission to verify. |
| 649 | * |
| 650 | * @return <code>true</code> if this bundle has the specified permission |
| 651 | * or the permissions possessed by this bundle imply the specified |
| 652 | * permission; <code>false</code> if this bundle does not have the |
| 653 | * specified permission or <code>permission</code> is not an |
| 654 | * <code>instanceof</code> <code>java.security.Permission</code>. |
| 655 | * |
| 656 | * @exception java.lang.IllegalStateException If this bundle has been |
| 657 | * uninstalled. |
| 658 | */ |
| 659 | public abstract boolean hasPermission(Object permission); |
| 660 | |
| 661 | /** |
| 662 | * Find the specified resource from this bundle. |
| 663 | * |
| 664 | * This bundle's class loader is called to search for the named resource. If |
| 665 | * this bundle's state is <code>INSTALLED</code>, then only this bundle |
| 666 | * must be searched for the specified resource. Imported packages cannot be |
| 667 | * searched when a bundle has not been resolved. If this bundle is a |
| 668 | * fragment bundle then <code>null</code> is returned. |
| 669 | * |
| 670 | * @param name The name of the resource. See |
| 671 | * <code>java.lang.ClassLoader.getResource</code> for a description |
| 672 | * of the format of a resource name. |
| 673 | * @return a URL to the named resource, or <code>null</code> if the |
| 674 | * resource could not be found or if this bundle is a fragment |
| 675 | * bundle or if the caller does not have the appropriate |
| 676 | * <code>AdminPermission[bundle, RESOURCE]</code>, and the Java |
| 677 | * Runtime Environment supports permissions. |
| 678 | * |
| 679 | * @since 1.1 |
| 680 | * @exception java.lang.IllegalStateException If this bundle has been |
| 681 | * uninstalled. |
| 682 | */ |
| 683 | public abstract URL getResource(String name); |
| 684 | |
| 685 | /** |
| 686 | * Returns this bundle's Manifest headers and values localized to the |
| 687 | * specifed locale. |
| 688 | * |
| 689 | * <p> |
| 690 | * This method performs the same function as |
| 691 | * <code>Bundle.getHeaders()</code> except the manifest header values are |
| 692 | * localized to the specified locale. |
| 693 | * |
| 694 | * If a Manifest header value starts with "%", it must be |
| 695 | * localized according to the specified locale. If the specified locale |
| 696 | * cannot be found, then the header values must be returned using the |
| 697 | * default locale. |
| 698 | * |
| 699 | * If <code>null</code> is specified as the locale string, the header |
| 700 | * values must be localized using the default locale. If the empty string |
| 701 | * ("") is specified as the locale string, the header values must |
| 702 | * not be localized and the raw (unlocalized) header values, including any |
| 703 | * leading "%", must be returned. |
| 704 | * |
| 705 | * <p> |
| 706 | * This method must continue to return Manifest header information while |
| 707 | * this bundle is in the <code>UNINSTALLED</code> state, however the |
| 708 | * header values must only be available in the raw and default locale |
| 709 | * values. |
| 710 | * |
| 711 | * @param locale The locale name into which the header values are to be |
| 712 | * localized. If the specified locale is <code>null</code> then the |
| 713 | * locale returned by <code>java.util.Locale.getDefault</code> is |
| 714 | * used. If the specified locale is the empty string, this method |
| 715 | * will return the raw (unlocalized) manifest headers including any |
| 716 | * leading "%". |
| 717 | * @return A <code>Dictionary</code> object containing this bundle's |
| 718 | * Manifest headers and values. |
| 719 | * |
| 720 | * @exception java.lang.SecurityException If the caller does not have the appropriate |
| 721 | * <code>AdminPermission[bundle, METADATA]</code>, and the |
| 722 | * Java Runtime Environment supports permissions. |
| 723 | * |
| 724 | * @see #getHeaders() |
| 725 | * @see Constants#BUNDLE_LOCALIZATION |
| 726 | * @since 1.3 |
| 727 | */ |
| 728 | public Dictionary getHeaders(String locale); |
| 729 | |
| 730 | /** |
| 731 | * Returns the symbolic name of this bundle as specified by its |
| 732 | * <code>Bundle-SymbolicName</code> manifest header. The name must be |
| 733 | * unique, it is recommended to use a reverse domain name naming convention |
| 734 | * like that used for java packages. If the bundle does not have a specified |
| 735 | * symbolic name then <code>null</code> is returned. |
| 736 | * |
| 737 | * <p> |
| 738 | * This method must continue to return this bundle's symbolic name while |
| 739 | * this bundle is in the <code>UNINSTALLED</code> state. |
| 740 | * |
| 741 | * @return The symbolic name of this bundle. |
| 742 | * @since 1.3 |
| 743 | */ |
| 744 | public String getSymbolicName(); |
| 745 | |
| 746 | /** |
| 747 | * |
| 748 | * Loads the specified class using this bundle's classloader. |
| 749 | * |
| 750 | * <p> |
| 751 | * If the bundle is a fragment bundle then this method must throw a |
| 752 | * <code>ClassNotFoundException</code>. |
| 753 | * |
| 754 | * <p> |
| 755 | * If this bundle's state is <code>INSTALLED</code>, this method must |
| 756 | * attempt to resolve the bundle before attempting to load the class. |
| 757 | * |
| 758 | * <p> |
| 759 | * If the bundle cannot be resolved, a Framework event of type |
| 760 | * {@link FrameworkEvent#ERROR}is broadcast containing a |
| 761 | * <code>BundleException</code> with details of the reason the bundle |
| 762 | * could not be resolved. This method must then throw a |
| 763 | * <code>ClassNotFoundException</code>. |
| 764 | * |
| 765 | * <p> |
| 766 | * If this bundle's state is <code>UNINSTALLED</code>, then an |
| 767 | * <code>IllegalStateException</code> is thrown. |
| 768 | * |
| 769 | * @param name The name of the class to load. |
| 770 | * @return The Class object for the requested class. |
| 771 | * @exception java.lang.ClassNotFoundException If no such class can be found |
| 772 | * or if this bundle is a fragment bundle or if the caller does |
| 773 | * not have the appropriate <code>AdminPermission[bundle, CLASS]</code>, |
| 774 | * and the Java Runtime Environment supports permissions. |
| 775 | * @exception java.lang.IllegalStateException If this bundle has been |
| 776 | * uninstalled. |
| 777 | * @since 1.3 |
| 778 | */ |
| 779 | public Class loadClass(String name) throws ClassNotFoundException; |
| 780 | |
| 781 | /** |
| 782 | * Find the specified resources from this bundle. |
| 783 | * |
| 784 | * This bundle's class loader is called to search for the named resource. If |
| 785 | * this bundle's state is <code>INSTALLED</code>, then only this bundle |
| 786 | * must be searched for the specified resource. Imported packages cannot be |
| 787 | * searched when a bundle has not been resolved. If this bundle is a |
| 788 | * fragment bundle then <code>null</code> is returned. |
| 789 | * |
| 790 | * @param name The name of the resource. See |
| 791 | * <code>java.lang.ClassLoader.getResources</code> for a |
| 792 | * description of the format of a resource name. |
| 793 | * @return an Enumeration of URLs to the named resources, or |
| 794 | * <code>null</code> if the resource could not be found or if this |
| 795 | * bundle is a fragment bundle or if the caller does not have the appropriate |
| 796 | * <code>AdminPermission[bundle, RESOURCE]</code>, and the Java |
| 797 | * Runtime Environment supports permissions. |
| 798 | * |
| 799 | * @since 1.3 |
| 800 | * @exception java.lang.IllegalStateException If this bundle has been |
| 801 | * uninstalled. |
| 802 | * @throws java.io.IOException If there is an I/O error. |
| 803 | */ |
| 804 | public Enumeration getResources(String name) throws IOException; |
| 805 | |
| 806 | /** |
| 807 | * Returns an Enumeration of all the paths (<code>String</code>) objects) to |
| 808 | * entries within the bundle whose longest sub-path matches the supplied path |
| 809 | * argument. The bundle's classloader is not used to search for entries. Only |
| 810 | * the contents of the bundle is searched. A specified path of "/" |
| 811 | * indicates the root of the bundle. |
| 812 | * |
| 813 | * <p> |
| 814 | * Returned paths indicating subdirectory paths end with a "/". |
| 815 | * The returned paths are all relative to the root of the bundle. |
| 816 | * |
| 817 | * <p> |
| 818 | * This method returns <code>null</code> if no entries could be found that |
| 819 | * match the specified path or if the caller does not have the appropriate |
| 820 | * <code>AdminPermission[bundle, RESOURCE]</code> and the Java |
| 821 | * Runtime Environment supports permissions. |
| 822 | * |
| 823 | * @param path the path name to get the entry path for. |
| 824 | * @return An Enumeration of the entry paths (<code>String</code> objects) |
| 825 | * or <code>null</code> if an entry could not be found or if the |
| 826 | * caller does not have the appropriate <code>AdminPermission[bundle, RESOURCE]</code> |
| 827 | * and the Java Runtime Environment supports permissions. |
| 828 | * @exception java.lang.IllegalStateException If this bundle has been |
| 829 | * uninstalled. |
| 830 | * @since 1.3 |
| 831 | */ |
| 832 | public Enumeration getEntryPaths(String path); |
| 833 | |
| 834 | /** |
| 835 | * Returns a URL to the specified entry in this bundle. The bundle's |
| 836 | * classloader is not used to search for the specified entry. Only the |
| 837 | * contents of the bundle is searched for the specified entry. A specified |
| 838 | * path of "/" indicates the root of the bundle. |
| 839 | * |
| 840 | * <p> |
| 841 | * This method returns a URL to the specified entry, or <code>null</code> |
| 842 | * if the entry could not be found or if the caller does not have the appropriate |
| 843 | * <code>AdminPermission[bundle, RESOURCE]</code> and the Java Runtime |
| 844 | * Environment supports permissions. |
| 845 | * |
| 846 | * @param name The name of the entry. See |
| 847 | * <code>java.lang.ClassLoader.getResource</code> for a description |
| 848 | * of the format of a resource name. |
| 849 | * @return A URL to the specified entry, or <code>null</code> if the entry |
| 850 | * could not be found or if the caller does not have the appropriate |
| 851 | * <code>AdminPermission[bundle, RESOURCE]</code> and the Java |
| 852 | * Runtime Environment supports permissions. |
| 853 | * |
| 854 | * @exception java.lang.IllegalStateException If this bundle has been |
| 855 | * uninstalled. |
| 856 | * @since 1.3 |
| 857 | */ |
| 858 | public URL getEntry(String name); |
| 859 | |
| 860 | /** |
| 861 | * Returns the time when this bundle was last modified. A bundle is |
| 862 | * considered to be modified when it is installed, updated or uninstalled. |
| 863 | * |
| 864 | * <p> |
| 865 | * The time value is the number of milliseconds since January 1, 1970, |
| 866 | * 00:00:00 GMT. |
| 867 | * |
| 868 | * @return The time when this bundle was last modified. |
| 869 | * @since 1.3 |
| 870 | */ |
| 871 | public long getLastModified(); |
| 872 | |
| 873 | /** |
| 874 | * Returns entries in this bundle and its attached fragments. The bundle's |
| 875 | * classloader is not used to search for entries. Only the contents of the |
| 876 | * bundle and its attached fragments are searched for the specified |
| 877 | * entries. |
| 878 | * |
| 879 | * If this bundle's state is <code>INSTALLED</code>, this method must |
| 880 | * attempt to resolve the bundle before attempting to find entries.<p> |
| 881 | * |
| 882 | * This method is intended to be used to obtain configuration, setup, |
| 883 | * localization and other information from this bundle. This method takes |
| 884 | * into account that the "contents" of this bundle can be extended |
| 885 | * with fragments. This "bundle space" is not a namespace with |
| 886 | * unique members; the same entry name can be present multiple times. This |
| 887 | * method therefore returns an enumeration of URL objects. These URLs can |
| 888 | * come from different JARs but have the same path name. This method can |
| 889 | * either return only entries in the specified path or recurse into |
| 890 | * subdirectories returning entries in the directory tree beginning at the |
| 891 | * specified path. Fragments can be attached after this bundle is resolved, |
| 892 | * possibly changing the set of URLs returned by this method. If this bundle |
| 893 | * is not resolved, only the entries in the JAR file of this bundle are |
| 894 | * returned. |
| 895 | * <p> |
| 896 | * Examples: |
| 897 | * <pre> |
| 898 | * // List all XML files in the OSGI-INF directory and below |
| 899 | * Enumeration e = b.findEntries("OSGI-INF", "*.xml", true); |
| 900 | * |
| 901 | * // Find a specific localization file |
| 902 | * Enumeration e = b.findEntries("OSGI-INF/l10n", |
| 903 | * "bundle_nl_DU.properties", false); |
| 904 | * if (e.hasMoreElements()) |
| 905 | * return (URL) e.nextElement(); |
| 906 | * </pre> |
| 907 | * |
| 908 | * @param path The path name in which to look. A specified path of |
| 909 | * "/" indicates the root of the bundle. Path is relative |
| 910 | * to the root of the bundle and must not be null. |
| 911 | * @param filePattern The file name pattern for selecting entries in the |
| 912 | * specified path. The pattern is only matched against the last |
| 913 | * element of the entry path and it supports substring matching, as |
| 914 | * specified in the Filter specification, using the wildcard |
| 915 | * character ("*"). If null is specified, this is |
| 916 | * equivalent to "*" and matches all files. |
| 917 | * @param recurse If <code>true</code>, recurse into subdirectories. |
| 918 | * Otherwise only return entries from the given directory. |
| 919 | * @return An enumeration of URL objects for each matching entry, or |
| 920 | * <code>null</code> if an entry could not be found or if the |
| 921 | * caller does not have the appropriate |
| 922 | * <code>AdminPermission[bundle, RESOURCE]</code>, and the Java |
| 923 | * Runtime Environment supports permissions. The URLs are sorted |
| 924 | * such that entries from this bundle are returned first followed by |
| 925 | * the entries from attached fragments in ascending bundle id order. |
| 926 | * If this bundle is a fragment, then only matching entries in this |
| 927 | * fragment are returned. |
| 928 | * @since 1.3 |
| 929 | */ |
| 930 | public Enumeration findEntries(String path, String filePattern, |
| 931 | boolean recurse); |
| 932 | } |