private Set<PackageBundlePair> getDynamicImportingPairs(PackageAdmin packageAdmin, Bundle bundle, Set<String> wiredPackages) { BundleDescription description = new BundleDescription(bundle.getHeaders()); Set<PackageBundlePair> dynamicImportingPairs = new HashSet<PackageBundlePair>(); if (!description.getDynamicImportPackage().isEmpty()) { for (Bundle b : bundle.getBundleContext().getBundles()) { // find the packages that importing from the bundle ExportedPackage[] exportedPackages = packageAdmin.getExportedPackages(b); if (exportedPackages != null) { for (ExportedPackage exportedPackage : exportedPackages) { if (wiredPackages.contains(toString(exportedPackage))) { continue; } Bundle[] importingBundles = exportedPackage.getImportingBundles(); if (containsBundle(importingBundles, bundle)) { dynamicImportingPairs.add(new PackageBundlePair(exportedPackage, b)); } } } } } return dynamicImportingPairs; }
public static LinkedHashSet<Bundle> getWiredBundles(PackageAdmin packageAdmin, Bundle bundle) { BundleDescription description = new BundleDescription(bundle.getHeaders()); // handle static wire via Import-Package List<BundleDescription.ImportPackage> imports = description.getExternalImports(); LinkedHashSet<Bundle> wiredBundles = new LinkedHashSet<Bundle>(); for (BundleDescription.ImportPackage packageImport : imports) { ExportedPackage[] exports = packageAdmin.getExportedPackages(packageImport.getName()); Bundle wiredBundle = getWiredBundle(bundle, exports); if (wiredBundle != null) { wiredBundles.add(wiredBundle); } } // handle dynamic wire via DynamicImport-Package if (!description.getDynamicImportPackage().isEmpty()) { for (Bundle b : bundle.getBundleContext().getBundles()) { if (!wiredBundles.contains(b)) { ExportedPackage[] exports = packageAdmin.getExportedPackages(b); Bundle wiredBundle = getWiredBundle(bundle, exports); if (wiredBundle != null) { wiredBundles.add(wiredBundle); } } } } return wiredBundles; }
private boolean needsProviderImports(Bundle persistenceBundle, BundleDescription providerDescription) { BundleDescription description = new BundleDescription(persistenceBundle.getHeaders()); for (HeaderEntry importPackage : description.getDynamicImportPackage()) { if ("*".equals(importPackage.getName())) { LOG.debug("Persistence bundle {} can load any class.", persistenceBundle.getSymbolicName()); return false; } } for (ImportPackage importPackage : description.getImportPackage()) { for (ExportPackage exportPackage : providerDescription.getExportPackage()) { if (importPackage.getName().equals(exportPackage.getName()) && importPackage.getVersionRange().isInRange(exportPackage.getVersion())) { LOG.debug("Persistence bundle {} already imports at least one package from JPA provider bundle.", persistenceBundle.getSymbolicName()); return false; } } } return true; }