aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jwr...@apache.org
Subject svn commit: r1449267 - /aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/FelixRequirementAdapter.java
Date Sat, 23 Feb 2013 04:58:59 GMT
Author: jwross
Date: Sat Feb 23 04:58:59 2013
New Revision: 1449267

URL: http://svn.apache.org/r1449267
Log:
Don't treat optional requirements as mandatory.

Fixes issue where optional requirements from a Felix OBR repository were treated as mandatory.

Modified:
    aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/FelixRequirementAdapter.java

Modified: aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/FelixRequirementAdapter.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/FelixRequirementAdapter.java?rev=1449267&r1=1449266&r2=1449267&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/FelixRequirementAdapter.java
(original)
+++ aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/FelixRequirementAdapter.java
Sat Feb 23 04:58:59 2013
@@ -17,11 +17,12 @@ import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 
-import org.osgi.framework.Constants;
 import org.osgi.resource.Capability;
+import org.osgi.resource.Namespace;
 import org.osgi.resource.Resource;
 
 public class FelixRequirementAdapter extends AbstractRequirement {
+	private final Map<String, String> directives;
 	private final org.apache.felix.bundlerepository.Requirement requirement;
 	private final Resource resource;
 	
@@ -32,6 +33,7 @@ public class FelixRequirementAdapter ext
 			throw new NullPointerException("Missing required parameter: resource");
 		this.requirement = requirement;
 		this.resource = resource;
+		directives = computeDirectives();
 	}
 
 	public Map<String, Object> getAttributes() {
@@ -39,16 +41,7 @@ public class FelixRequirementAdapter ext
 	}
 
 	public Map<String, String> getDirectives() {
-		Map<String, String> result = new HashMap<String, String>(1);
-		/* (1) The Felix OBR specific "mandatory:<*" syntax must be stripped out of the filter.
-		 * (2) The namespace must be translated.
-		 */
-		result.put(Constants.FILTER_DIRECTIVE, requirement.getFilter()
-				.replaceAll("\\(mandatory\\:\\<\\*[^\\)]*\\)", "")
-				.replaceAll("\\(service\\=[^\\)]*\\)", "")
-				.replaceAll("objectclass", "objectClass")
-				.replaceAll(requirement.getName() + '=', getNamespace() + '='));
-		return result;
+		return directives;
 	}
 
 	public String getNamespace() {
@@ -62,4 +55,19 @@ public class FelixRequirementAdapter ext
 	public boolean matches(Capability capability) {
 		return requirement.isSatisfied(new OsgiCapabilityAdapter(capability));
 	}
+	
+	private Map<String, String> computeDirectives() {
+		Map<String, String> result = new HashMap<String, String>(3);
+		/* (1) The Felix OBR specific "mandatory:<*" syntax must be stripped out of the filter.
+		 * (2) The namespace must be translated.
+		 */
+		result.put(Namespace.REQUIREMENT_FILTER_DIRECTIVE, requirement.getFilter()
+				.replaceAll("\\(mandatory\\:\\<\\*[^\\)]*\\)", "")
+				.replaceAll("\\(service\\=[^\\)]*\\)", "")
+				.replaceAll("objectclass", "objectClass")
+				.replaceAll(requirement.getName() + '=', getNamespace() + '='));
+		result.put(Namespace.REQUIREMENT_RESOLUTION_DIRECTIVE, requirement.isOptional() ? Namespace.RESOLUTION_OPTIONAL
: Namespace.RESOLUTION_MANDATORY);
+		result.put(Namespace.REQUIREMENT_CARDINALITY_DIRECTIVE, requirement.isMultiple() ? Namespace.CARDINALITY_MULTIPLE
: Namespace.CARDINALITY_SINGLE);
+		return Collections.unmodifiableMap(result);
+	}
 }



Mime
View raw message