public static RequirementImpl addIdentityRequirement(ResourceImpl resource, String name, String type, VersionRange range, boolean mandatory, boolean conditional) { Map<String, String> dirs = new StringArrayMap<>((mandatory ? 0 : 1) + (conditional ? 1 : 0)); Map<String, Object> attrs = new StringArrayMap<>((name != null ? 1 : 0) + (type != null ? 1 : 0) + (range != null ? 1 : 0)); if (!mandatory) { dirs.put(REQUIREMENT_RESOLUTION_DIRECTIVE, RESOLUTION_OPTIONAL); } if (conditional) { dirs.put(REQUIREMENT_CONDITIONAL_DIRECTIVE, CONDITIONAL_TRUE); } if (name != null) { attrs.put(IDENTITY_NAMESPACE, name); } if (type != null) { attrs.put(CAPABILITY_TYPE_ATTRIBUTE, type); } if (range != null) { attrs.put(CAPABILITY_VERSION_ATTRIBUTE, range); } RequirementImpl requirement = new RequirementImpl(resource, IDENTITY_NAMESPACE, dirs, attrs); resource.addRequirement(requirement); return requirement; }
public static void addIdentityRequirement(ResourceImpl resource, Resource required, boolean mandatory) { for (Capability cap : required.getCapabilities(null)) { if (cap.getNamespace().equals(IDENTITY_NAMESPACE)) { Map<String, Object> attributes = cap.getAttributes(); Map<String, String> dirs = new StringArrayMap<>(1); dirs.put(REQUIREMENT_RESOLUTION_DIRECTIVE, mandatory ? RESOLUTION_MANDATORY : RESOLUTION_OPTIONAL); Version version = (Version) attributes.get(CAPABILITY_VERSION_ATTRIBUTE); Map<String, Object> attrs = new StringArrayMap<>(version != null ? 3 : 2); attrs.put(IDENTITY_NAMESPACE, attributes.get(IDENTITY_NAMESPACE)); attrs.put(CAPABILITY_TYPE_ATTRIBUTE, attributes.get(CAPABILITY_TYPE_ATTRIBUTE)); if (version != null) { attrs.put(CAPABILITY_VERSION_ATTRIBUTE, new VersionRange(version, true)); } resource.addRequirement(new RequirementImpl(resource, IDENTITY_NAMESPACE, dirs, attrs)); } } }
break; case REQUIREMENT: resource.addRequirement(parseRequirement(reader, resource)); break; default:
break; case REQUIREMENT: resource.addRequirement(parseRequirement(reader, resource)); break; default:
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; }