private CapabilityDTO getCapabilityDTO(BundleCapability cap) {
   if (cap == null) {
     return null;
   }
   CapabilityDTO dto = new CapabilityDTO();
   dto.id = identifier(cap);
   dto.namespace = cap.getNamespace();
   dto.resource = getResourceId(cap.getRevision());
   dto.attributes = newAttributesMapDTO(cap.getAttributes());
   dto.directives = newDirectivesMapDTO(cap.getDirectives());
   return dto;
 }
Exemplo n.º 2
0
 private List<BundleCapability> getCapabilities(String namespace) {
   List<BundleCapability> caps = m_capabilities;
   List<BundleCapability> result = caps;
   if (namespace != null) {
     result = new ArrayList<BundleCapability>();
     for (BundleCapability cap : caps) {
       if (cap.getNamespace().equals(namespace)) {
         result.add(cap);
       }
     }
   }
   return result;
 }
Exemplo n.º 3
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);
      }
    }
  }
 private CapabilityRefDTO getCapabilityRefDTO(BundleCapability cap) {
   if (cap == null) {
     return null;
   }
   CapabilityRefDTO dto = new CapabilityRefDTO();
   dto.capability = identifier(cap);
   dto.resource = getResourceId(cap.getRevision());
   return dto;
 }
Exemplo n.º 5
0
  private String convertCapabilitiesToHeaders(Map headers) {
    StringBuffer exportSB = new StringBuffer("");
    Set<String> exportNames = new HashSet<String>();

    List<BundleCapability> caps = m_capabilities;
    for (BundleCapability cap : caps) {
      if (cap.getNamespace().equals(BundleRevision.PACKAGE_NAMESPACE)) {
        // Add a comma separate if there is an existing package.
        if (exportSB.length() > 0) {
          exportSB.append(", ");
        }

        // Append exported package information.
        exportSB.append(cap.getAttributes().get(BundleRevision.PACKAGE_NAMESPACE));
        for (Entry<String, String> entry : cap.getDirectives().entrySet()) {
          exportSB.append("; ");
          exportSB.append(entry.getKey());
          exportSB.append(":=\"");
          exportSB.append(entry.getValue());
          exportSB.append("\"");
        }
        for (Entry<String, Object> entry : cap.getAttributes().entrySet()) {
          if (!entry.getKey().equals(BundleRevision.PACKAGE_NAMESPACE)
              && !entry.getKey().equals(Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE)
              && !entry.getKey().equals(Constants.BUNDLE_VERSION_ATTRIBUTE)) {
            exportSB.append("; ");
            exportSB.append(entry.getKey());
            exportSB.append("=\"");
            exportSB.append(entry.getValue());
            exportSB.append("\"");
          }
        }

        // Remember exported packages.
        exportNames.add((String) cap.getAttributes().get(BundleRevision.PACKAGE_NAMESPACE));
      }
    }

    m_exportNames = exportNames;

    return exportSB.toString();
  }
Exemplo n.º 6
0
 private String getAttribute(BundleCapability cap, String name) {
   Object obj = cap.getAttributes().get(name);
   return obj != null ? obj.toString() : null;
 }
  private static List<BundleCapability> aliasSymbolicName(List<BundleCapability> caps) {
    if (caps == null) {
      return new ArrayList<BundleCapability>(0);
    }

    List<BundleCapability> aliasCaps = new ArrayList<BundleCapability>(caps);

    String[] aliases = {
      FelixConstants.SYSTEM_BUNDLE_SYMBOLICNAME, Constants.SYSTEM_BUNDLE_SYMBOLICNAME
    };

    for (int capIdx = 0; capIdx < aliasCaps.size(); capIdx++) {
      BundleCapability cap = aliasCaps.get(capIdx);

      // Need to alias bundle and host capabilities.
      if (cap.getNamespace().equals(BundleRevision.BUNDLE_NAMESPACE)
          || cap.getNamespace().equals(BundleRevision.HOST_NAMESPACE)) {
        // Make a copy of the attribute array.
        Map<String, Object> aliasAttrs = new HashMap<String, Object>(cap.getAttributes());
        // Add the aliased value.
        aliasAttrs.put(cap.getNamespace(), aliases);
        // Create the aliased capability to replace the old capability.
        cap =
            new BundleCapabilityImpl(
                cap.getRevision(), cap.getNamespace(), cap.getDirectives(), aliasAttrs);
        aliasCaps.set(capIdx, cap);
      }

      // Further, search attributes for bundle symbolic name and alias it too.
      for (Entry<String, Object> entry : cap.getAttributes().entrySet()) {
        // If there is a bundle symbolic name attribute, add the
        // standard alias as a value.
        if (entry.getKey().equalsIgnoreCase(Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE)) {
          // Make a copy of the attribute array.
          Map<String, Object> aliasAttrs = new HashMap<String, Object>(cap.getAttributes());
          // Add the aliased value.
          aliasAttrs.put(Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE, aliases);
          // Create the aliased capability to replace the old capability.
          aliasCaps.set(
              capIdx,
              new BundleCapabilityImpl(
                  cap.getRevision(), cap.getNamespace(), cap.getDirectives(), aliasAttrs));
          // Continue with the next capability.
          break;
        }
      }
    }

    return aliasCaps;
  }