@Override public int compare(Capability cap1, Capability cap2) { // Prefer already wired if (wirings != null) { Wiring w1 = wirings.get(cap1.getResource()); Wiring w2 = wirings.get(cap2.getResource()); if (w1 != null && w2 == null) return -1; if (w1 == null && w2 != null) return +1; } // Prefer higher version Version v1 = AbstractCapability.getVersion(cap1, IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE); Version v2 = AbstractCapability.getVersion(cap2, IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE); return v2.compareTo(v1); } }; }
public AbstractCapability(AbstractResource resource, String namespace, Map<String, Object> atts, Map<String, String> dirs) { if (resource == null) throw new IllegalArgumentException("Null resource"); if (namespace == null) throw new IllegalArgumentException("Null namespace"); this.resource = resource; this.namespace = namespace; if (atts != null) { getAttributes().putAll(atts); } if (dirs != null) { getDirectives().putAll(dirs); } }
protected void validate() { for (Entry<String, Object> entry : attributes.entrySet()) { String key = entry.getKey(); Object val = entry.getValue(); if (CAPABILITY_MAVEN_IDENTITY_ATTRIBUTE.equals(key)) { IllegalStateAssertion.assertTrue(val instanceof MavenCoordinates, "Illegal attribute type: " + val); } } canonicalName = toString(); }
String type; String nsval = null; if (IdentityNamespace.IDENTITY_NAMESPACE.equals(getNamespace())) { type = "IdentityCapability"; } else { addcomma = true; if (!getAttributes().isEmpty()) { buffer.append(addcomma ? "," : ""); buffer.append("atts=" + attributes); addcomma = true; if (!getDirectives().isEmpty()) { buffer.append(addcomma ? "," : ""); buffer.append("dirs=" + directives);
void validate() { // Make sure we have an identity getIdentity(); // Validate the capabilities for (Capability cap : getCapabilities(null)) { ((AbstractCapability) cap).validate(); } // Validate the requirements for (Requirement req : getRequirements(null)) { ((AbstractRequirement) req).validate(); } }
@Override public void validate() { super.validate(); if (ContentNamespace.CONTENT_NAMESPACE.equals(getNamespace())) { digest = (String) getAttribute(ContentNamespace.CONTENT_NAMESPACE); if (digest == null) throw illegalStateCannotObtainAttribute(ContentNamespace.CONTENT_NAMESPACE); mimeType = (String) getAttribute(ContentNamespace.CAPABILITY_MIME_ATTRIBUTE); if (mimeType == null) throw illegalStateCannotObtainAttribute(ContentNamespace.CAPABILITY_MIME_ATTRIBUTE); contentURL = (URL) getAttribute(ContentNamespace.CAPABILITY_URL_ATTRIBUTE); contentStream = (InputStream) getAttribute(ContentNamespace.CAPABILITY_STREAM_ATTRIBUTE); if (contentURL == null && contentStream == null) throw illegalStateCannotObtainAttribute(ContentNamespace.CAPABILITY_URL_ATTRIBUTE); size = (Long) getAttribute(ContentNamespace.CAPABILITY_SIZE_ATTRIBUTE); if (size == null) throw illegalStateCannotObtainAttribute(ContentNamespace.CAPABILITY_SIZE_ATTRIBUTE); } }
Version version = AbstractCapability.getVersion(cap, IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE); matches = range.includes(version); reqatts = new HashMap<String, Object>(req.getAttributes());