1 11 package org.eclipse.osgi.framework.internal.core; 12 13 import java.util.ArrayList ; 14 import org.eclipse.osgi.service.resolver.BundleDescription; 15 import org.eclipse.osgi.service.resolver.ExportPackageDescription; 16 import org.osgi.framework.*; 17 import org.osgi.framework.Constants; 18 import org.osgi.service.packageadmin.ExportedPackage; 19 20 public class ExportedPackageImpl implements ExportedPackage { 21 22 String specVersion; 23 ExportPackageDescription exportedPackage; 24 BundleLoaderProxy supplier; 25 26 public ExportedPackageImpl(ExportPackageDescription exportedPackage, BundleLoaderProxy supplier) { 27 this.exportedPackage = exportedPackage; 28 this.supplier = supplier; 29 Version version = exportedPackage.getVersion(); 30 if (version != null) 31 this.specVersion = version.toString(); 32 } 33 34 public String getName() { 35 return exportedPackage.getName(); 36 } 37 38 public org.osgi.framework.Bundle getExportingBundle() { 39 if (supplier.isStale()) 40 return null; 41 return supplier.getBundleHost(); 42 } 43 44 public Bundle[] getImportingBundles() { 45 if (supplier.isStale()) 46 return null; 47 AbstractBundle bundle = (AbstractBundle) getExportingBundle(); 48 if (bundle == null) 49 return null; 50 AbstractBundle[] bundles = bundle.framework.getAllBundles(); 51 ArrayList importers = new ArrayList (10); 52 PackageSource supplierSource = supplier.createPackageSource(exportedPackage, false); 53 for (int i = 0; i < bundles.length; i++) { 54 if (!(bundles[i] instanceof BundleHost)) 55 continue; 56 BundleLoader loader = ((BundleHost) bundles[i]).getBundleLoader(); 57 if (loader == null) 58 continue; 59 PackageSource importerSource = loader.getPackageSource(getName()); 60 if (supplierSource != null && supplierSource.hasCommonSource(importerSource)) 61 importers.add(bundles[i]); 62 } 63 return (Bundle[]) importers.toArray(new Bundle[importers.size()]); 64 } 65 66 public String getSpecificationVersion() { 67 return specVersion; 68 } 69 70 public Version getVersion() { 71 return exportedPackage.getVersion(); 72 } 73 74 public boolean isRemovalPending() { 75 BundleDescription exporter = exportedPackage.getExporter(); 76 if (exporter != null) 77 return exporter.isRemovalPending(); 78 return true; 79 } 80 81 public String toString() { 82 StringBuffer result = new StringBuffer (getName()); 83 if (specVersion != null) { 84 result.append("; ").append(Constants.VERSION_ATTRIBUTE); result.append("=\"").append(specVersion).append("\""); } 87 return result.toString(); 88 } 89 } 90 | Popular Tags |