/** * Return a {@code Bundle} for the specified bundle class. The returned * {@code Bundle} is the bundle associated with the bundle class loader * which defined the specified class. * * @param classFromBundle A class defined by a bundle class loader. * @return A {@code Bundle} for the specified bundle class or {@code null} * if the specified class was not defined by a bundle class loader. * @since 1.5 */ public static Bundle getBundle(final Class<?> classFromBundle) { // We use doPriv since the caller may not have permission // to call getClassLoader. Object cl = AccessController.doPrivileged(new PrivilegedAction<Object>() { @Override public Object run() { return classFromBundle.getClassLoader(); } }); if (cl instanceof BundleReference) { return ((BundleReference) cl).getBundle(); } for (FrameworkUtilHelper helper : helpers) { Bundle b = helper.getBundle(classFromBundle); if (b != null) { return b; } } return null; }