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; }
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; }
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; }
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(); }