Exemple #1
0
  /**
   * Caches the package capabilities that are needed for a set of interface classes
   *
   * @param classes interfaces we want to track
   */
  private void cachePackageCapabilities(Class<?>... classes) {
    BundleWiring ourWiring = bundleContext.getBundle().adapt(BundleWiring.class);
    Set<String> packageNames = new HashSet<String>();
    for (Class<?> clazz : classes) {
      packageNames.add(clazz.getPackage().getName());
    }

    List<BundleCapability> ourExports = ourWiring.getCapabilities(PACKAGE_NAMESPACE);
    for (BundleCapability ourExport : ourExports) {
      String ourPkgName = (String) ourExport.getAttributes().get(PACKAGE_NAMESPACE);
      if (packageNames.contains(ourPkgName)) {
        packageCapabilities.add(ourExport);
      }
    }
  }
Exemple #2
0
 private boolean checkPackage(String packageName, String version) {
   VersionRange range = VersionRange.parseVersionRange(version);
   Bundle[] bundles = bundleContext.getBundles();
   for (int i = 0; (bundles != null) && (i < bundles.length); i++) {
     BundleWiring wiring = bundles[i].adapt(BundleWiring.class);
     List<BundleCapability> caps =
         wiring != null ? wiring.getCapabilities(BundleRevision.PACKAGE_NAMESPACE) : null;
     if (caps != null) {
       for (BundleCapability cap : caps) {
         String n = getAttribute(cap, BundleRevision.PACKAGE_NAMESPACE);
         String v = getAttribute(cap, Constants.VERSION_ATTRIBUTE);
         if (packageName.equals(n) && range.contains(VersionTable.getVersion(v))) {
           return true;
         }
       }
     }
   }
   return false;
 }
 private BundleWiringDTO.NodeDTO getBundleWiringNodeDTO(BundleWiring wiring) {
   if (wiring == null) {
     return null;
   }
   BundleWiringDTO.NodeDTO dto = wiringnodes.get(wiring);
   if (dto != null) {
     return dto;
   }
   dto = new BundleWiringDTO.NodeDTO();
   dto.id = identifier(wiring);
   wiringnodes.put(wiring, dto);
   dto.current = wiring.isCurrent();
   dto.inUse = wiring.isInUse();
   dto.resource = getResourceId(wiring.getRevision());
   dto.capabilities = getListCapabilityRefDTO(wiring.getCapabilities(null));
   dto.requirements = getListRequirementRefDTO(wiring.getRequirements(null));
   dto.providedWires = getListBundleWireDTO(wiring.getProvidedWires(null));
   dto.requiredWires = getListBundleWireDTO(wiring.getRequiredWires(null));
   return dto;
 }