You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by jw...@apache.org on 2013/02/05 16:54:25 UTC

svn commit: r1442635 - in /aries/trunk/subsystem/subsystem-obr: ./ src/main/java/org/apache/aries/subsystem/obr/internal/

Author: jwross
Date: Tue Feb  5 15:54:24 2013
New Revision: 1442635

URL: http://svn.apache.org/viewvc?rev=1442635&view=rev
Log:
Remove dependencies on subsystem-core internal packages.

Added:
    aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/AbstractCapability.java
    aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/AbstractRequirement.java
    aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/OsgiContentCapability.java
      - copied, changed from r1442572, aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/FelixCapabilityAdapter.java
    aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/OsgiIdentityCapability.java
    aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/ResourceHelper.java
Modified:
    aries/trunk/subsystem/subsystem-obr/pom.xml
    aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/FelixCapabilityAdapter.java
    aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/FelixRepositoryAdapter.java
    aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/FelixRequirementAdapter.java
    aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/FelixResourceAdapter.java
    aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/OsgiRequirementAdapter.java
    aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/OsgiResourceAdapter.java

Modified: aries/trunk/subsystem/subsystem-obr/pom.xml
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-obr/pom.xml?rev=1442635&r1=1442634&r2=1442635&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-obr/pom.xml (original)
+++ aries/trunk/subsystem/subsystem-obr/pom.xml Tue Feb  5 15:54:24 2013
@@ -60,11 +60,6 @@
             <version>1.0.0</version>
         </dependency>
         <dependency>
-            <groupId>org.apache.aries.subsystem</groupId>
-            <artifactId>org.apache.aries.subsystem.core</artifactId>
-            <version>1.0.0-SNAPSHOT</version>
-        </dependency>
-        <dependency>
             <groupId>org.apache.felix</groupId>
             <artifactId>org.apache.felix.bundlerepository</artifactId>
             <version>1.6.4</version>

Added: aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/AbstractCapability.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/AbstractCapability.java?rev=1442635&view=auto
==============================================================================
--- aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/AbstractCapability.java (added)
+++ aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/AbstractCapability.java Tue Feb  5 15:54:24 2013
@@ -0,0 +1,51 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.aries.subsystem.obr.internal;
+
+import org.osgi.resource.Capability;
+
+public abstract class AbstractCapability implements Capability {
+	@Override
+	public boolean equals(Object o) {
+		if (o == this)
+			return true;
+		if (!(o instanceof Capability))
+			return false;
+		Capability c = (Capability)o;
+		return c.getNamespace().equals(getNamespace())
+				&& c.getAttributes().equals(getAttributes())
+				&& c.getDirectives().equals(getDirectives())
+				&& c.getResource().equals(getResource());
+	}
+	
+	@Override
+	public int hashCode() {
+		int result = 17;
+		result = 31 * result + getNamespace().hashCode();
+		result = 31 * result + getAttributes().hashCode();
+		result = 31 * result + getDirectives().hashCode();
+		result = 31 * result + getResource().hashCode();
+		return result;
+	}
+	
+	@Override
+	public String toString() {
+		return new StringBuilder().append("[Capability: ")
+				.append("namespace=").append(getNamespace())
+				.append(", attributes=").append(getAttributes())
+				.append(", directives=").append(getDirectives())
+				.append(", resource=").append(getResource()).append(']')
+				.toString();
+	}
+}

Added: aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/AbstractRequirement.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/AbstractRequirement.java?rev=1442635&view=auto
==============================================================================
--- aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/AbstractRequirement.java (added)
+++ aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/AbstractRequirement.java Tue Feb  5 15:54:24 2013
@@ -0,0 +1,52 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.aries.subsystem.obr.internal;
+
+import org.osgi.resource.Requirement;
+
+public abstract class AbstractRequirement implements Requirement {
+	@Override
+	public boolean equals(Object o) {
+		if (o == this)
+			return true;
+		if (!(o instanceof Requirement))
+			return false;
+		Requirement c = (Requirement)o;
+		return c.getNamespace().equals(getNamespace())
+				&& c.getAttributes().equals(getAttributes())
+				&& c.getDirectives().equals(getDirectives())
+				&& c.getResource() != null ? c.getResource().equals(
+				getResource()) : getResource() == null;
+	}
+	
+	@Override
+	public int hashCode() {
+		int result = 17;
+		result = 31 * result + getNamespace().hashCode();
+		result = 31 * result + getAttributes().hashCode();
+		result = 31 * result + getDirectives().hashCode();
+		result = 31 * result
+				+ (getResource() == null ? 0 : getResource().hashCode());
+		return result;
+	}
+	
+	@Override
+	public String toString() {
+		return new StringBuffer().append(getClass().getName()).append(": ")
+				.append("namespace=").append(getNamespace())
+				.append(", attributes=").append(getAttributes())
+				.append(", directives=").append(getDirectives())
+				.append(", resource=").append(getResource()).toString();
+	}
+}

Modified: aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/FelixCapabilityAdapter.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/FelixCapabilityAdapter.java?rev=1442635&r1=1442634&r2=1442635&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/FelixCapabilityAdapter.java (original)
+++ aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/FelixCapabilityAdapter.java Tue Feb  5 15:54:24 2013
@@ -16,7 +16,6 @@ package org.apache.aries.subsystem.obr.i
 import java.util.Collections;
 import java.util.Map;
 
-import org.apache.aries.subsystem.core.internal.AbstractCapability;
 import org.osgi.namespace.service.ServiceNamespace;
 import org.osgi.resource.Resource;
 

Modified: aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/FelixRepositoryAdapter.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/FelixRepositoryAdapter.java?rev=1442635&r1=1442634&r2=1442635&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/FelixRepositoryAdapter.java (original)
+++ aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/FelixRepositoryAdapter.java Tue Feb  5 15:54:24 2013
@@ -23,8 +23,6 @@ import java.util.Map;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
-import org.apache.aries.subsystem.core.internal.OsgiIdentityCapability;
-import org.apache.aries.subsystem.core.internal.ResourceHelper;
 import org.osgi.framework.Constants;
 import org.osgi.framework.namespace.IdentityNamespace;
 import org.osgi.resource.Capability;

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=1442635&r1=1442634&r2=1442635&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 Tue Feb  5 15:54:24 2013
@@ -17,7 +17,6 @@ import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 
-import org.apache.aries.subsystem.core.internal.AbstractRequirement;
 import org.osgi.framework.Constants;
 import org.osgi.resource.Capability;
 import org.osgi.resource.Resource;

Modified: aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/FelixResourceAdapter.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/FelixResourceAdapter.java?rev=1442635&r1=1442634&r2=1442635&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/FelixResourceAdapter.java (original)
+++ aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/FelixResourceAdapter.java Tue Feb  5 15:54:24 2013
@@ -20,9 +20,6 @@ import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 
-import org.apache.aries.subsystem.core.internal.OsgiContentCapability;
-import org.apache.aries.subsystem.core.internal.OsgiIdentityCapability;
-import org.apache.aries.subsystem.core.internal.ResourceHelper;
 import org.osgi.framework.namespace.IdentityNamespace;
 import org.osgi.resource.Capability;
 import org.osgi.resource.Requirement;

Copied: aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/OsgiContentCapability.java (from r1442572, aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/FelixCapabilityAdapter.java)
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/OsgiContentCapability.java?p2=aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/OsgiContentCapability.java&p1=aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/FelixCapabilityAdapter.java&r1=1442572&r2=1442635&rev=1442635&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/FelixCapabilityAdapter.java (original)
+++ aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/OsgiContentCapability.java Tue Feb  5 15:54:24 2013
@@ -13,32 +13,30 @@
  */
 package org.apache.aries.subsystem.obr.internal;
 
+import java.net.URL;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.Map;
 
-import org.apache.aries.subsystem.core.internal.AbstractCapability;
-import org.osgi.namespace.service.ServiceNamespace;
 import org.osgi.resource.Resource;
 
-public class FelixCapabilityAdapter extends AbstractCapability {
-	private final org.apache.felix.bundlerepository.Capability capability;
+public class OsgiContentCapability extends AbstractCapability {
+	private final Map<String, Object> attributes = new HashMap<String, Object>();
 	private final Resource resource;
 	
-	public FelixCapabilityAdapter(org.apache.felix.bundlerepository.Capability capability, Resource resource) {
-		if (capability == null)
-			throw new NullPointerException("Missing required parameter: capability");
-		this.capability = capability;
+	public OsgiContentCapability(Resource resource, String url) {
+		// TOOD Add to constants.
+		attributes.put("osgi.content", url);
+		// TODO Any directives?
 		this.resource = resource;
 	}
+	
+	public OsgiContentCapability(Resource resource, URL url) {
+		this(resource, url.toExternalForm());
+	}
 
 	public Map<String, Object> getAttributes() {
-		Map<String, Object> result = capability.getPropertiesAsMap();
-		String namespace = getNamespace();
-		if (ServiceNamespace.SERVICE_NAMESPACE.equals(namespace))
-			result.put(ServiceNamespace.CAPABILITY_OBJECTCLASS_ATTRIBUTE, result.get("objectclass"));
-		else
-			result.put(namespace, result.get(capability.getName()));
-		return result;
+		return Collections.unmodifiableMap(attributes);
 	}
 
 	public Map<String, String> getDirectives() {
@@ -46,7 +44,8 @@ public class FelixCapabilityAdapter exte
 	}
 
 	public String getNamespace() {
-		return NamespaceTranslator.translate(capability.getName());
+		// TODO Add to constants.
+		return "osgi.content";
 	}
 
 	public Resource getResource() {

Added: aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/OsgiIdentityCapability.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/OsgiIdentityCapability.java?rev=1442635&view=auto
==============================================================================
--- aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/OsgiIdentityCapability.java (added)
+++ aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/OsgiIdentityCapability.java Tue Feb  5 15:54:24 2013
@@ -0,0 +1,61 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.aries.subsystem.obr.internal;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.osgi.framework.Version;
+import org.osgi.framework.namespace.IdentityNamespace;
+import org.osgi.resource.Resource;
+
+public class OsgiIdentityCapability extends AbstractCapability {
+	private final Map<String, Object> attributes = new HashMap<String, Object>();
+	private final Resource resource;
+	
+	public OsgiIdentityCapability(Resource resource, String symbolicName, Version version) {
+		this(resource, symbolicName, version, IdentityNamespace.TYPE_BUNDLE);
+	}
+	
+	public OsgiIdentityCapability(Resource resource, String symbolicName, Version version, String identityType) {
+		this.resource = resource;
+		attributes.put(
+				IdentityNamespace.IDENTITY_NAMESPACE, 
+				symbolicName);
+		attributes.put(
+				IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE, 
+				version);
+		attributes.put(
+				IdentityNamespace.CAPABILITY_TYPE_ATTRIBUTE, 
+				identityType);
+		// TODO Add directives, particularly "effective" and "singleton".
+	}
+
+	public Map<String, Object> getAttributes() {
+		return Collections.unmodifiableMap(attributes);
+	}
+
+	public Map<String, String> getDirectives() {
+		return Collections.emptyMap();
+	}
+
+	public String getNamespace() {
+		return IdentityNamespace.IDENTITY_NAMESPACE;
+	}
+
+	public Resource getResource() {
+		return resource;
+	}
+}

Modified: aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/OsgiRequirementAdapter.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/OsgiRequirementAdapter.java?rev=1442635&r1=1442634&r2=1442635&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/OsgiRequirementAdapter.java (original)
+++ aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/OsgiRequirementAdapter.java Tue Feb  5 15:54:24 2013
@@ -16,7 +16,6 @@ package org.apache.aries.subsystem.obr.i
 import static org.apache.aries.application.utils.AppConstants.LOG_ENTRY;
 import static org.apache.aries.application.utils.AppConstants.LOG_EXIT;
 
-import org.apache.aries.subsystem.core.internal.ResourceHelper;
 import org.apache.felix.bundlerepository.Capability;
 import org.apache.felix.bundlerepository.Requirement;
 import org.osgi.framework.Constants;

Modified: aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/OsgiResourceAdapter.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/OsgiResourceAdapter.java?rev=1442635&r1=1442634&r2=1442635&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/OsgiResourceAdapter.java (original)
+++ aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/OsgiResourceAdapter.java Tue Feb  5 15:54:24 2013
@@ -18,7 +18,6 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.Map;
 
-import org.apache.aries.subsystem.core.internal.ResourceHelper;
 import org.apache.felix.bundlerepository.Capability;
 import org.apache.felix.bundlerepository.Requirement;
 import org.apache.felix.bundlerepository.Resource;

Added: aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/ResourceHelper.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/ResourceHelper.java?rev=1442635&view=auto
==============================================================================
--- aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/ResourceHelper.java (added)
+++ aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/ResourceHelper.java Tue Feb  5 15:54:24 2013
@@ -0,0 +1,107 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.aries.subsystem.obr.internal;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+import org.osgi.framework.Constants;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.Version;
+import org.osgi.framework.namespace.IdentityNamespace;
+import org.osgi.resource.Capability;
+import org.osgi.resource.Requirement;
+import org.osgi.resource.Resource;
+import org.osgi.service.repository.Repository;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ResourceHelper {
+	private static final Logger logger = LoggerFactory.getLogger(ResourceHelper.class);
+	
+	public static String getContentAttribute(Resource resource) {
+		// TODO Add to constants.
+		return (String)getContentAttribute(resource, "osgi.content");
+	}
+	
+	public static Object getContentAttribute(Resource resource, String name) {
+		// TODO Add to constants.
+		List<Capability> capabilities = resource.getCapabilities("osgi.content");
+		Capability capability = capabilities.get(0);
+		return capability.getAttributes().get(name);
+	}
+	
+	public static Object getIdentityAttribute(Resource resource, String name) {
+		List<Capability> capabilities = resource.getCapabilities(IdentityNamespace.IDENTITY_NAMESPACE);
+		Capability capability = capabilities.get(0);
+		return capability.getAttributes().get(name);
+	}
+	
+	public static Resource getResource(Requirement requirement, Repository repository) {
+		Map<Requirement, Collection<Capability>> map = repository.findProviders(Arrays.asList(requirement));
+		Collection<Capability> capabilities = map.get(requirement);
+		return capabilities == null ? null : capabilities.size() == 0 ? null : capabilities.iterator().next().getResource();
+	}
+	
+	public static String getSymbolicNameAttribute(Resource resource) {
+		return (String)getIdentityAttribute(resource, IdentityNamespace.IDENTITY_NAMESPACE);
+	}
+	
+	public static String getTypeAttribute(Resource resource) {
+		String result = (String)getIdentityAttribute(resource, IdentityNamespace.CAPABILITY_TYPE_ATTRIBUTE);
+		if (result == null)
+			result = IdentityNamespace.TYPE_BUNDLE;
+		return result;
+	}
+	
+	public static Version getVersionAttribute(Resource resource) {
+		Version result = (Version)getIdentityAttribute(resource, IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE);
+		if (result == null)
+			result = Version.emptyVersion;
+		return result;
+	}
+	
+	public static boolean matches(Requirement requirement, Capability capability) {
+//		if (logger.isDebugEnabled())
+//			logger.debug(LOG_ENTRY, "matches", new Object[]{requirement, capability});
+		boolean result = false;
+		if (requirement == null && capability == null)
+			result = true;
+		else if (requirement == null || capability == null) 
+			result = false;
+		else if (!capability.getNamespace().equals(requirement.getNamespace())) 
+			result = false;
+		else {
+			String filterStr = requirement.getDirectives().get(Constants.FILTER_DIRECTIVE);
+			if (filterStr == null)
+				result = true;
+			else {
+				try {
+					if (FrameworkUtil.createFilter(filterStr).matches(capability.getAttributes()))
+						result = true;
+				}
+				catch (InvalidSyntaxException e) {
+					logger.debug("Requirement had invalid filter string: " + requirement, e);
+					result = false;
+				}
+			}
+		}
+		// TODO Check directives.
+//		logger.debug(LOG_EXIT, "matches", result);
+		return result;
+	}
+}