private static List<Capability> convertProvideCapabilities( List<ParsedHeaderClause> clauses, Resource resource) throws BundleException { List<Capability> capList = new ArrayList<>(); for (ParsedHeaderClause clause : clauses) { for (String path : clause.paths) { if (path.startsWith("osgi.wiring.")) { // throw new BundleException("Manifest cannot use Provide-Capability for '" + path + "' namespace."); } // Create package capability and add to capability list. capList.add(new CapabilityImpl(resource, path, clause.dirs, clause.attrs)); } } return capList; }
public static String toFeatureCapability(String feature) { String[] parts = feature.split("/"); Map<String, String> dirs = Collections.emptyMap(); Map<String, Object> attrs = new StringArrayMap<>(parts.length > 1 ? 3 : 2); attrs.put(IDENTITY_NAMESPACE, parts[0]); attrs.put(CAPABILITY_TYPE_ATTRIBUTE, TYPE_FEATURE); if (parts.length > 1) { attrs.put(CAPABILITY_VERSION_ATTRIBUTE, VersionTable.getVersion(parts[1])); } return new CapabilityImpl(null, IDENTITY_NAMESPACE, dirs, attrs).toString(); } }
CapabilityImpl cap = parseCapability(reader, resource); if (repositoryUrl != null && ContentNamespace.CONTENT_NAMESPACE.equals(cap.getNamespace())) { Object url = cap.getAttributes().get(ContentNamespace.CAPABILITY_URL_ATTRIBUTE); if (url instanceof String) { url = repositoryUrl.resolve(url.toString()).toString(); cap.getAttributes().put(ContentNamespace.CAPABILITY_URL_ATTRIBUTE, url);
private static boolean matchMandatory(Capability cap, SimpleFilter sf) { if (cap instanceof CapabilityImpl) { for (Entry<String, Object> entry : cap.getAttributes().entrySet()) { if (((CapabilityImpl) cap).isAttributeMandatory(entry.getKey()) && !matchMandatoryAttribute(entry.getKey(), sf)) { return false; } } } else { String value = cap.getDirectives().get(Constants.MANDATORY_DIRECTIVE); if (value != null) { List<String> names = ResourceBuilder.parseDelimitedString(value, ","); for (Entry<String, Object> entry : cap.getAttributes().entrySet()) { if (names.contains(entry.getKey()) && !matchMandatoryAttribute(entry.getKey(), sf)) { return false; } } } } return true; }
CapabilityImpl cap = parseCapability(reader, resource); if (repositoryUrl != null && ContentNamespace.CONTENT_NAMESPACE.equals(cap.getNamespace())) { Object url = cap.getAttributes().get(ContentNamespace.CAPABILITY_URL_ATTRIBUTE); if (url instanceof String) { url = repositoryUrl.resolve(url.toString()).toString(); cap.getAttributes().put(ContentNamespace.CAPABILITY_URL_ATTRIBUTE, url);
private static boolean matchMandatory(Capability cap, SimpleFilter sf) { if (cap instanceof CapabilityImpl) { for (Entry<String, Object> entry : cap.getAttributes().entrySet()) { if (((CapabilityImpl) cap).isAttributeMandatory(entry.getKey()) && !matchMandatoryAttribute(entry.getKey(), sf)) { return false; } } } else { String value = cap.getDirectives().get(Constants.MANDATORY_DIRECTIVE); if (value != null) { List<String> names = ResourceBuilder.parseDelimitedString(value, ","); for (Entry<String, Object> entry : cap.getAttributes().entrySet()) { if (names.contains(entry.getKey()) && !matchMandatoryAttribute(entry.getKey(), sf)) { return false; } } } } return true; }
private static List<Capability> convertProvideCapabilities( List<ParsedHeaderClause> clauses, Resource resource) throws BundleException { List<Capability> capList = new ArrayList<>(); for (ParsedHeaderClause clause : clauses) { for (String path : clause.paths) { if (path.startsWith("osgi.wiring.")) { // throw new BundleException("Manifest cannot use Provide-Capability for '" + path + "' namespace."); } // Create package capability and add to capability list. capList.add(new CapabilityImpl(resource, path, clause.dirs, clause.attrs)); } } return capList; }
private static List<Capability> convertExportService(List<ParsedHeaderClause> clauses, Resource resource) { List<Capability> capList = new ArrayList<>(); for (ParsedHeaderClause clause : clauses) { for (String path : clause.paths) { Map<String, Object> attrs = new LinkedHashMap<>(); attrs.put(Constants.OBJECTCLASS, path); attrs.putAll(clause.attrs); capList.add(new CapabilityImpl( resource, ServiceNamespace.SERVICE_NAMESPACE, DEFAULT_DIRECTIVES, attrs)); } } return capList; }
private static List<Capability> convertExportService(List<ParsedHeaderClause> clauses, Resource resource) { List<Capability> capList = new ArrayList<>(); for (ParsedHeaderClause clause : clauses) { for (String path : clause.paths) { Map<String, Object> attrs = new LinkedHashMap<>(); attrs.put(Constants.OBJECTCLASS, path); attrs.putAll(clause.attrs); capList.add(new CapabilityImpl( resource, ServiceNamespace.SERVICE_NAMESPACE, DEFAULT_DIRECTIVES, attrs)); } } return capList; }
private static List<Capability> convertExports(List<ParsedHeaderClause> clauses, Resource resource) { List<Capability> capList = new ArrayList<>(); for (ParsedHeaderClause clause : clauses) { for (String pkgName : clause.paths) { // Prepend the package name to the array of attributes. Map<String, Object> attrs = clause.attrs; Map<String, Object> newAttrs = new StringArrayMap<>(attrs.size() + 1); newAttrs.putAll(attrs); newAttrs.put(BundleRevision.PACKAGE_NAMESPACE, pkgName); // Create package capability and add to capability list. capList.add(new CapabilityImpl(resource, BundleRevision.PACKAGE_NAMESPACE, clause.dirs, newAttrs)); } } return capList; }
private static List<Capability> convertExports(List<ParsedHeaderClause> clauses, Resource resource) { List<Capability> capList = new ArrayList<>(); for (ParsedHeaderClause clause : clauses) { for (String pkgName : clause.paths) { // Prepend the package name to the array of attributes. Map<String, Object> attrs = clause.attrs; Map<String, Object> newAttrs = new StringArrayMap<>(attrs.size() + 1); newAttrs.putAll(attrs); newAttrs.put(BundleRevision.PACKAGE_NAMESPACE, pkgName); // Create package capability and add to capability list. capList.add(new CapabilityImpl(resource, BundleRevision.PACKAGE_NAMESPACE, clause.dirs, newAttrs)); } } return capList; }
public ResourceImpl(String name, String type, Version version) { caps = new ArrayList<>(1); Map<String, String> dirs = new StringArrayMap<>(0); Map<String, Object> attrs = new StringArrayMap<>(3); attrs.put(IdentityNamespace.IDENTITY_NAMESPACE, name); attrs.put(IdentityNamespace.CAPABILITY_TYPE_ATTRIBUTE, type); attrs.put(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE, version); CapabilityImpl identity = new CapabilityImpl(this, IdentityNamespace.IDENTITY_NAMESPACE, dirs, attrs); caps.add(identity); reqs = new ArrayList<>(0); }
public ResourceImpl(String name, String type, Version version) { caps = new ArrayList<>(1); Map<String, String> dirs = new StringArrayMap<>(0); Map<String, Object> attrs = new StringArrayMap<>(3); attrs.put(IdentityNamespace.IDENTITY_NAMESPACE, name); attrs.put(IdentityNamespace.CAPABILITY_TYPE_ATTRIBUTE, type); attrs.put(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE, version); CapabilityImpl identity = new CapabilityImpl(this, IdentityNamespace.IDENTITY_NAMESPACE, dirs, attrs); caps.add(identity); reqs = new ArrayList<>(0); }
private static CapabilityImpl parseCapability(XMLStreamReader reader, ResourceImpl resource) throws XMLStreamException { String[] namespace = new String[1]; Map<String, String> directives = new HashMap<>(); Map<String, Object> attributes = new HashMap<>(); parseClause(reader, namespace, directives, attributes); sanityCheckEndElement(reader, reader.getEventType(), CAPABILITY); return new CapabilityImpl(resource, namespace[0], directives, attributes); }
private static CapabilityImpl parseCapability(XMLStreamReader reader, ResourceImpl resource) throws XMLStreamException { String[] namespace = new String[1]; Map<String, String> directives = new HashMap<>(); Map<String, Object> attributes = new HashMap<>(); parseClause(reader, namespace, directives, attributes); sanityCheckEndElement(reader, reader.getEventType(), CAPABILITY); return new CapabilityImpl(resource, namespace[0], directives, attributes); }
attrs.put(IdentityNamespace.CAPABILITY_TYPE_ATTRIBUTE, type); attrs.put(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE, bundleVersion); CapabilityImpl identity = new CapabilityImpl(resource, IdentityNamespace.IDENTITY_NAMESPACE, Collections.<String, String>emptyMap(), attrs); resource.addCapability(identity); resource.addCapability(new CapabilityImpl(resource, ContentNamespace.CONTENT_NAMESPACE, Collections.<String, String>emptyMap(), Collections.<String, Object>singletonMap(ContentNamespace.CAPABILITY_URL_ATTRIBUTE, uri))); resource.addCapability(new CapabilityImpl(resource, BundleRevision.BUNDLE_NAMESPACE, bundleCap.dirs, bundleCap.attrs)); resource.addCapability(new CapabilityImpl( resource, BundleRevision.HOST_NAMESPACE, bundleCap.dirs,
attrs.put(IdentityNamespace.CAPABILITY_TYPE_ATTRIBUTE, type); attrs.put(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE, bundleVersion); CapabilityImpl identity = new CapabilityImpl(resource, IdentityNamespace.IDENTITY_NAMESPACE, Collections.<String, String>emptyMap(), attrs); resource.addCapability(identity); resource.addCapability(new CapabilityImpl(resource, ContentNamespace.CONTENT_NAMESPACE, Collections.<String, String>emptyMap(), Collections.<String, Object>singletonMap(ContentNamespace.CAPABILITY_URL_ATTRIBUTE, uri))); resource.addCapability(new CapabilityImpl(resource, BundleRevision.BUNDLE_NAMESPACE, bundleCap.dirs, bundleCap.attrs)); resource.addCapability(new CapabilityImpl( resource, BundleRevision.HOST_NAMESPACE, bundleCap.dirs,
Resource tmp = ResourceBuilder.build(res.getBundle().getLocation(), headers); for (Capability cap : tmp.getCapabilities(ServiceNamespace.SERVICE_NAMESPACE)) { dummy.addCapability(new CapabilityImpl(dummy, cap.getNamespace(), cap.getDirectives(), cap.getAttributes()));
private void wrap(Map<Capability, Capability> map, Subsystem subsystem, Resource resource) { ResourceImpl wrapped = new ResourceImpl(); for (Capability cap : resource.getCapabilities(null)) { CapabilityImpl wCap = new CapabilityImpl(wrapped, cap.getNamespace(), cap.getDirectives(), cap.getAttributes()); map.put(cap, wCap); wrapped.addCapability(wCap); } for (Requirement req : resource.getRequirements(null)) { RequirementImpl wReq = new RequirementImpl(wrapped, req.getNamespace(), req.getDirectives(), req.getAttributes()); wrapped.addRequirement(wReq); } addIdentityRequirement(wrapped, subsystem, false); resToSub.put(wrapped, subsystem); try { downloader.download(getUri(wrapped), null); } catch (MalformedURLException e) { throw new IllegalStateException("Unable to download resource: " + getUri(wrapped)); } } }
ResourceImpl cloneResource(Resource resource) { ResourceImpl res = new ResourceImpl(); for (Capability cap : resource.getCapabilities(null)) { res.addCapability(new CapabilityImpl(res, cap.getNamespace(), new StringArrayMap<>(cap.getDirectives()), new StringArrayMap<>(cap.getAttributes()))); } for (Requirement req : resource.getRequirements(null)) { SimpleFilter sf; if (req instanceof RequirementImpl) { sf = ((RequirementImpl) req).getFilter(); } else if (req.getDirectives().containsKey(REQUIREMENT_FILTER_DIRECTIVE)) { sf = SimpleFilter.parse(req.getDirectives().get(REQUIREMENT_FILTER_DIRECTIVE)); } else { sf = SimpleFilter.convert(req.getAttributes()); } res.addRequirement(new RequirementImpl(res, req.getNamespace(), new StringArrayMap<>(req.getDirectives()), new StringArrayMap<>(req.getAttributes()), sf)); } return res; }