blob: 03ca2e5a80e7e843e9f3bd886cb7e7d0460eff2c [file] [log] [blame]
Richard S. Hall2532cf82010-03-24 09:51:11 +00001/*
Carsten Ziegeler3314f912014-07-30 07:22:32 +00002 * Copyright (c) OSGi Alliance (2001, 2013). All Rights Reserved.
Richard S. Hall2532cf82010-03-24 09:51:11 +00003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package org.osgi.service.packageadmin;
18
19import org.osgi.framework.Bundle;
20
21/**
22 * Framework service which allows bundle programmers to inspect the package
23 * wiring state of bundles in the Framework as well as other functions related
24 * to the class loader network among bundles.
25 *
26 * <p>
27 * If present, there will only be a single instance of this service registered
28 * with the Framework.
29 *
30 * @ThreadSafe
Richard S. Halld0dca9b2011-05-18 14:52:16 +000031 * @noimplement
Carsten Ziegeler3314f912014-07-30 07:22:32 +000032 * @author $Id: 4aad25d2f145d9a2d24825bc481dcc254b74ed51 $
Richard S. Halld0dca9b2011-05-18 14:52:16 +000033 * @deprecated This service has been replaced by the
34 * <code>org.osgi.framework.wiring</code> package.
Richard S. Hall2532cf82010-03-24 09:51:11 +000035 * @see org.osgi.service.packageadmin.ExportedPackage
36 * @see org.osgi.service.packageadmin.RequiredBundle
37 */
38public interface PackageAdmin {
39 /**
40 * Gets the exported packages for the specified bundle.
41 *
42 * @param bundle The bundle whose exported packages are to be returned, or
Richard S. Halld0dca9b2011-05-18 14:52:16 +000043 * {@code null} if all exported packages are to be returned. If
Richard S. Hall2532cf82010-03-24 09:51:11 +000044 * the specified bundle is the system bundle (that is, the bundle
45 * with id zero), this method returns all the packages known to be
46 * exported by the system bundle. This will include the package
Richard S. Halld0dca9b2011-05-18 14:52:16 +000047 * specified by the {@code org.osgi.framework.system.packages}
Richard S. Hall2532cf82010-03-24 09:51:11 +000048 * system property as well as any other package exported by the
49 * framework implementation.
50 *
Richard S. Halld0dca9b2011-05-18 14:52:16 +000051 * @return An array of exported packages, or {@code null} if the
Richard S. Hall2532cf82010-03-24 09:51:11 +000052 * specified bundle has no exported packages.
Richard S. Halld0dca9b2011-05-18 14:52:16 +000053 * @throws IllegalArgumentException If the specified {@code Bundle} was
Richard S. Hall2532cf82010-03-24 09:51:11 +000054 * not created by the same framework instance that registered this
Richard S. Halld0dca9b2011-05-18 14:52:16 +000055 * {@code PackageAdmin} service.
Richard S. Hall2532cf82010-03-24 09:51:11 +000056 */
57 public ExportedPackage[] getExportedPackages(Bundle bundle);
58
59 /**
60 * Gets the exported packages for the specified package name.
61 *
62 * @param name The name of the exported packages to be returned.
63 *
Richard S. Halld0dca9b2011-05-18 14:52:16 +000064 * @return An array of the exported packages, or {@code null} if no
Richard S. Hall2532cf82010-03-24 09:51:11 +000065 * exported packages with the specified name exists.
66 * @since 1.2
67 */
68 public ExportedPackage[] getExportedPackages(String name);
69
70 /**
71 * Gets the exported package for the specified package name.
72 *
73 * <p>
74 * If there are multiple exported packages with specified name, the exported
75 * package with the highest version will be returned.
76 *
77 * @param name The name of the exported package to be returned.
78 *
Richard S. Halld0dca9b2011-05-18 14:52:16 +000079 * @return The exported package, or {@code null} if no exported
Richard S. Hall2532cf82010-03-24 09:51:11 +000080 * package with the specified name exists.
81 * @see #getExportedPackages(String)
82 */
83 public ExportedPackage getExportedPackage(String name);
84
85 /**
86 * Forces the update (replacement) or removal of packages exported by the
87 * specified bundles.
88 *
89 * <p>
90 * If no bundles are specified, this method will update or remove any
91 * packages exported by any bundles that were previously updated or
92 * uninstalled since the last call to this method. The technique by which
93 * this is accomplished may vary among different Framework implementations.
94 * One permissible implementation is to stop and restart the Framework.
95 *
96 * <p>
97 * This method returns to the caller immediately and then performs the
98 * following steps on a separate thread:
99 *
100 * <ol>
101 * <li>Compute a graph of bundles starting with the specified bundles. If no
102 * bundles are specified, compute a graph of bundles starting with bundle
103 * updated or uninstalled since the last call to this method. Add to the
104 * graph any bundle that is wired to a package that is currently exported by
105 * a bundle in the graph. The graph is fully constructed when there is no
106 * bundle outside the graph that is wired to a bundle in the graph. The
Carsten Ziegeler3314f912014-07-30 07:22:32 +0000107 * graph may contain {@code UNINSTALLED} bundles that are currently still
108 * exporting packages.</li>
Richard S. Hall2532cf82010-03-24 09:51:11 +0000109 *
Carsten Ziegeler3314f912014-07-30 07:22:32 +0000110 * <li>Each bundle in the graph that is in the {@code ACTIVE} state will be
111 * stopped as described in the {@code Bundle.stop} method.</li>
Richard S. Hall2532cf82010-03-24 09:51:11 +0000112 *
Carsten Ziegeler3314f912014-07-30 07:22:32 +0000113 * <li>Each bundle in the graph that is in the {@code RESOLVED} state is
114 * unresolved and thus moved to the {@code INSTALLED} state. The effect of
115 * this step is that bundles in the graph are no longer {@code RESOLVED}.</li>
Richard S. Hall2532cf82010-03-24 09:51:11 +0000116 *
Carsten Ziegeler3314f912014-07-30 07:22:32 +0000117 * <li>Each bundle in the graph that is in the {@code UNINSTALLED} state is
118 * removed from the graph and is now completely removed from the Framework.</li>
Richard S. Hall2532cf82010-03-24 09:51:11 +0000119 *
Carsten Ziegeler3314f912014-07-30 07:22:32 +0000120 * <li>Each bundle in the graph that was in the {@code ACTIVE} state prior
121 * to Step 2 is started as described in the {@code Bundle.start} method,
122 * causing all bundles required for the restart to be resolved. It is
123 * possible that, as a result of the previous steps, packages that were
Richard S. Hall2532cf82010-03-24 09:51:11 +0000124 * previously exported no longer are. Therefore, some bundles may be
125 * unresolvable until another bundle offering a compatible package for
Carsten Ziegeler3314f912014-07-30 07:22:32 +0000126 * export has been installed in the Framework.</li>
127 * <li>A framework event of type {@code FrameworkEvent.PACKAGES_REFRESHED}
128 * is fired.</li>
Richard S. Hall2532cf82010-03-24 09:51:11 +0000129 * </ol>
130 *
131 * <p>
132 * For any exceptions that are thrown during any of these steps, a
Richard S. Halld0dca9b2011-05-18 14:52:16 +0000133 * {@code FrameworkEvent} of type {@code ERROR} is fired
Richard S. Hall2532cf82010-03-24 09:51:11 +0000134 * containing the exception. The source bundle for these events should be
135 * the specific bundle to which the exception is related. If no specific
136 * bundle can be associated with the exception then the System Bundle must
137 * be used as the source bundle for the event.
138 *
139 * @param bundles The bundles whose exported packages are to be updated or
Richard S. Halld0dca9b2011-05-18 14:52:16 +0000140 * removed, or {@code null} for all bundles updated or
Richard S. Hall2532cf82010-03-24 09:51:11 +0000141 * uninstalled since the last call to this method.
142 * @throws SecurityException If the caller does not have
Richard S. Halld0dca9b2011-05-18 14:52:16 +0000143 * {@code AdminPermission[System Bundle,RESOLVE]} and the Java
Richard S. Hall2532cf82010-03-24 09:51:11 +0000144 * runtime environment supports permissions.
Richard S. Halld0dca9b2011-05-18 14:52:16 +0000145 * @throws IllegalArgumentException If the specified {@code Bundle}s
Richard S. Hall2532cf82010-03-24 09:51:11 +0000146 * were not created by the same framework instance that registered
Richard S. Halld0dca9b2011-05-18 14:52:16 +0000147 * this {@code PackageAdmin} service.
Richard S. Hall2532cf82010-03-24 09:51:11 +0000148 */
149 public void refreshPackages(Bundle[] bundles);
150
151 /**
152 * Resolve the specified bundles. The Framework must attempt to resolve the
153 * specified bundles that are unresolved. Additional bundles that are not
154 * included in the specified bundles may be resolved as a result of calling
155 * this method. A permissible implementation of this method is to attempt to
156 * resolve all unresolved bundles installed in the framework.
157 *
158 * <p>
Richard S. Halld0dca9b2011-05-18 14:52:16 +0000159 * If {@code null} is specified then the Framework will attempt to
Richard S. Hall2532cf82010-03-24 09:51:11 +0000160 * resolve all unresolved bundles. This method must not cause any bundle to
161 * be refreshed, stopped, or started. This method will not return until the
162 * operation has completed.
163 *
Richard S. Halld0dca9b2011-05-18 14:52:16 +0000164 * @param bundles The bundles to resolve or {@code null} to resolve all
Richard S. Hall2532cf82010-03-24 09:51:11 +0000165 * unresolved bundles installed in the Framework.
Richard S. Halld0dca9b2011-05-18 14:52:16 +0000166 * @return {@code true} if all specified bundles are resolved;
Richard S. Hall2532cf82010-03-24 09:51:11 +0000167 * @throws SecurityException If the caller does not have
Richard S. Halld0dca9b2011-05-18 14:52:16 +0000168 * {@code AdminPermission[System Bundle,RESOLVE]} and the Java
Richard S. Hall2532cf82010-03-24 09:51:11 +0000169 * runtime environment supports permissions.
Richard S. Halld0dca9b2011-05-18 14:52:16 +0000170 * @throws IllegalArgumentException If the specified {@code Bundle}s
Richard S. Hall2532cf82010-03-24 09:51:11 +0000171 * were not created by the same framework instance that registered
Richard S. Halld0dca9b2011-05-18 14:52:16 +0000172 * this {@code PackageAdmin} service.
Richard S. Hall2532cf82010-03-24 09:51:11 +0000173 * @since 1.2
174 */
175 public boolean resolveBundles(Bundle[] bundles);
176
177 /**
178 * Returns an array of required bundles having the specified symbolic name.
179 *
180 * <p>
Richard S. Halld0dca9b2011-05-18 14:52:16 +0000181 * If {@code null} is specified, then all required bundles will be
Richard S. Hall2532cf82010-03-24 09:51:11 +0000182 * returned.
183 *
Richard S. Halld0dca9b2011-05-18 14:52:16 +0000184 * @param symbolicName The bundle symbolic name or {@code null} for
Richard S. Hall2532cf82010-03-24 09:51:11 +0000185 * all required bundles.
Richard S. Halld0dca9b2011-05-18 14:52:16 +0000186 * @return An array of required bundles or {@code null} if no
Richard S. Hall2532cf82010-03-24 09:51:11 +0000187 * required bundles exist for the specified symbolic name.
188 * @since 1.2
189 */
190 public RequiredBundle[] getRequiredBundles(String symbolicName);
191
192 /**
193 * Returns the bundles with the specified symbolic name whose bundle version
194 * is within the specified version range. If no bundles are installed that
Richard S. Halld0dca9b2011-05-18 14:52:16 +0000195 * have the specified symbolic name, then {@code null} is returned.
Richard S. Hall2532cf82010-03-24 09:51:11 +0000196 * If a version range is specified, then only the bundles that have the
197 * specified symbolic name and whose bundle versions belong to the specified
198 * version range are returned. The returned bundles are ordered by version
199 * in descending version order so that the first element of the array
200 * contains the bundle with the highest version.
201 *
202 * @see org.osgi.framework.Constants#BUNDLE_VERSION_ATTRIBUTE
203 * @param symbolicName The symbolic name of the desired bundles.
204 * @param versionRange The version range of the desired bundles, or
Richard S. Halld0dca9b2011-05-18 14:52:16 +0000205 * {@code null} if all versions are desired.
Richard S. Hall2532cf82010-03-24 09:51:11 +0000206 * @return An array of bundles with the specified name belonging to the
207 * specified version range ordered in descending version order, or
Richard S. Halld0dca9b2011-05-18 14:52:16 +0000208 * {@code null} if no bundles are found.
Richard S. Hall2532cf82010-03-24 09:51:11 +0000209 * @since 1.2
210 */
211 public Bundle[] getBundles(String symbolicName, String versionRange);
212
213 /**
214 * Returns an array of attached fragment bundles for the specified bundle.
Richard S. Halld0dca9b2011-05-18 14:52:16 +0000215 * If the specified bundle is a fragment then {@code null} is returned.
Richard S. Hall2532cf82010-03-24 09:51:11 +0000216 * If no fragments are attached to the specified bundle then
Richard S. Halld0dca9b2011-05-18 14:52:16 +0000217 * {@code null} is returned.
Richard S. Hall2532cf82010-03-24 09:51:11 +0000218 * <p>
219 * This method does not attempt to resolve the specified bundle. If the
Richard S. Halld0dca9b2011-05-18 14:52:16 +0000220 * specified bundle is not resolved then {@code null} is returned.
Richard S. Hall2532cf82010-03-24 09:51:11 +0000221 *
222 * @param bundle The bundle whose attached fragment bundles are to be
223 * returned.
Richard S. Halld0dca9b2011-05-18 14:52:16 +0000224 * @return An array of fragment bundles or {@code null} if the bundle
Richard S. Hall2532cf82010-03-24 09:51:11 +0000225 * does not have any attached fragment bundles or the bundle is not
226 * resolved.
Richard S. Halld0dca9b2011-05-18 14:52:16 +0000227 * @throws IllegalArgumentException If the specified {@code Bundle} was
Richard S. Hall2532cf82010-03-24 09:51:11 +0000228 * not created by the same framework instance that registered this
Richard S. Halld0dca9b2011-05-18 14:52:16 +0000229 * {@code PackageAdmin} service.
Richard S. Hall2532cf82010-03-24 09:51:11 +0000230 * @since 1.2
231 */
232 public Bundle[] getFragments(Bundle bundle);
233
234 /**
235 * Returns the host bundles to which the specified fragment bundle is
236 * attached.
237 *
238 * @param bundle The fragment bundle whose host bundles are to be returned.
239 * @return An array containing the host bundles to which the specified
Richard S. Halld0dca9b2011-05-18 14:52:16 +0000240 * fragment is attached or {@code null} if the specified bundle
Richard S. Hall2532cf82010-03-24 09:51:11 +0000241 * is not a fragment or is not attached to any host bundles.
Richard S. Halld0dca9b2011-05-18 14:52:16 +0000242 * @throws IllegalArgumentException If the specified {@code Bundle} was
Richard S. Hall2532cf82010-03-24 09:51:11 +0000243 * not created by the same framework instance that registered this
Richard S. Halld0dca9b2011-05-18 14:52:16 +0000244 * {@code PackageAdmin} service.
Richard S. Hall2532cf82010-03-24 09:51:11 +0000245 * @since 1.2
246 */
247 public Bundle[] getHosts(Bundle bundle);
248
249 /**
250 * Returns the bundle from which the specified class is loaded. The class
251 * loader of the returned bundle must have been used to load the specified
252 * class. If the class was not loaded by a bundle class loader then
Richard S. Halld0dca9b2011-05-18 14:52:16 +0000253 * {@code null} is returned.
Richard S. Hall2532cf82010-03-24 09:51:11 +0000254 *
255 * @param clazz The class object from which to locate the bundle.
256 * @return The bundle from which the specified class is loaded or
Richard S. Halld0dca9b2011-05-18 14:52:16 +0000257 * {@code null} if the class was not loaded by a bundle class
Richard S. Hall2532cf82010-03-24 09:51:11 +0000258 * loader created by the same framework instance that registered
Richard S. Halld0dca9b2011-05-18 14:52:16 +0000259 * this {@code PackageAdmin} service.
Richard S. Hall2532cf82010-03-24 09:51:11 +0000260 * @since 1.2
261 */
262 public Bundle getBundle(Class clazz);
263
264 /**
265 * Bundle type indicating the bundle is a fragment bundle.
266 *
267 * <p>
Richard S. Halld0dca9b2011-05-18 14:52:16 +0000268 * The value of {@code BUNDLE_TYPE_FRAGMENT} is 0x00000001.
Richard S. Hall2532cf82010-03-24 09:51:11 +0000269 *
270 * @since 1.2
271 */
272 public static final int BUNDLE_TYPE_FRAGMENT = 0x00000001;
273
274 /**
275 * Returns the special type of the specified bundle. The bundle type values
276 * are:
277 * <ul>
Carsten Ziegeler3314f912014-07-30 07:22:32 +0000278 * <li>{@link #BUNDLE_TYPE_FRAGMENT}</li>
Richard S. Hall2532cf82010-03-24 09:51:11 +0000279 * </ul>
280 *
281 * A bundle may be more than one type at a time. A type code is used to
282 * identify the bundle type for future extendability.
283 *
284 * <p>
285 * If a bundle is not one or more of the defined types then 0x00000000 is
286 * returned.
287 *
288 * @param bundle The bundle for which to return the special type.
289 * @return The special type of the bundle.
Richard S. Halld0dca9b2011-05-18 14:52:16 +0000290 * @throws IllegalArgumentException If the specified {@code Bundle} was
Richard S. Hall2532cf82010-03-24 09:51:11 +0000291 * not created by the same framework instance that registered this
Richard S. Halld0dca9b2011-05-18 14:52:16 +0000292 * {@code PackageAdmin} service.
Richard S. Hall2532cf82010-03-24 09:51:11 +0000293 * @since 1.2
294 */
295 public int getBundleType(Bundle bundle);
296}