[FELIX-5166] WrappedResource does not handle namespace correctly
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1731695 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/resolver/src/main/java/org/apache/felix/resolver/WrappedResource.java b/resolver/src/main/java/org/apache/felix/resolver/WrappedResource.java
index 3f80ae3..f338cac 100644
--- a/resolver/src/main/java/org/apache/felix/resolver/WrappedResource.java
+++ b/resolver/src/main/java/org/apache/felix/resolver/WrappedResource.java
@@ -18,9 +18,7 @@
*/
package org.apache.felix.resolver;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
+import java.util.*;
import org.osgi.framework.namespace.ExecutionEnvironmentNamespace;
import org.osgi.framework.namespace.HostNamespace;
import org.osgi.framework.namespace.IdentityNamespace;
@@ -32,13 +30,60 @@
{
private final Resource m_host;
private final List<Resource> m_fragments;
- private List<Capability> m_cachedCapabilities = null;
- private List<Requirement> m_cachedRequirements = null;
+ private final List<Capability> m_cachedCapabilities;
+ private final List<Requirement> m_cachedRequirements;
public WrappedResource(Resource host, List<Resource> fragments)
{
m_host = host;
m_fragments = fragments;
+
+ // Wrap host capabilities.
+ List<Capability> caps = new ArrayList<Capability>();
+ for (Capability cap : m_host.getCapabilities(null))
+ {
+ caps.add(new WrappedCapability(this, cap));
+ }
+
+ // Wrap fragment capabilities.
+ if (m_fragments != null)
+ {
+ for (Resource fragment : m_fragments)
+ {
+ for (Capability cap : fragment.getCapabilities(null))
+ {
+ caps.add(new WrappedCapability(this, cap));
+ }
+ }
+ }
+ m_cachedCapabilities = Collections.unmodifiableList(caps);
+
+ // Wrap host requirements.
+ List<Requirement> reqs = new ArrayList<Requirement>();
+ for (Requirement req : m_host.getRequirements(null))
+ {
+ reqs.add(new WrappedRequirement(this, req));
+ }
+
+ // Wrap fragment requirements.
+ if (m_fragments != null)
+ {
+ for (Resource fragment : m_fragments)
+ {
+ for (Requirement req : fragment.getRequirements(null))
+ {
+ // Filter out host and execution environment requirements,
+ // since they are not part of the fragment payload.
+ if (!req.getNamespace().equals(HostNamespace.HOST_NAMESPACE)
+ && !req.getNamespace().equals(
+ ExecutionEnvironmentNamespace.EXECUTION_ENVIRONMENT_NAMESPACE))
+ {
+ reqs.add(new WrappedRequirement(this, req));
+ }
+ }
+ }
+ }
+ m_cachedRequirements = Collections.unmodifiableList(reqs);
}
public Resource getDeclaredResource()
@@ -53,63 +98,28 @@
public List<Capability> getCapabilities(String namespace)
{
- if (m_cachedCapabilities == null)
- {
- List<Capability> caps = new ArrayList<Capability>();
-
- // Wrap host capabilities.
- for (Capability cap : m_host.getCapabilities(namespace))
- {
- caps.add(new WrappedCapability(this, cap));
- }
-
- // Wrap fragment capabilities.
- if (m_fragments != null)
- {
- for (Resource fragment : m_fragments)
- {
- for (Capability cap : fragment.getCapabilities(namespace))
- {
- caps.add(new WrappedCapability(this, cap));
- }
+ if (namespace != null) {
+ List<Capability> filtered = new ArrayList<Capability>();
+ for (Capability capability : m_cachedCapabilities) {
+ if (namespace.equals(capability.getNamespace())) {
+ filtered.add(capability);
}
}
- m_cachedCapabilities = Collections.unmodifiableList(caps);
+ return Collections.unmodifiableList(filtered);
}
return m_cachedCapabilities;
}
public List<Requirement> getRequirements(String namespace)
{
- if (m_cachedRequirements == null)
- {
- List<Requirement> reqs = new ArrayList<Requirement>();
-
- // Wrap host requirements.
- for (Requirement req : m_host.getRequirements(null))
- {
- reqs.add(new WrappedRequirement(this, req));
- }
-
- // Wrap fragment requirements.
- if (m_fragments != null)
- {
- for (Resource fragment : m_fragments)
- {
- for (Requirement req : fragment.getRequirements(null))
- {
- // Filter out host and execution environment requirements,
- // since they are not part of the fragment payload.
- if (!req.getNamespace().equals(HostNamespace.HOST_NAMESPACE)
- && !req.getNamespace().equals(
- ExecutionEnvironmentNamespace.EXECUTION_ENVIRONMENT_NAMESPACE))
- {
- reqs.add(new WrappedRequirement(this, req));
- }
- }
+ if (namespace != null) {
+ List<Requirement> filtered = new ArrayList<Requirement>();
+ for (Requirement requirement : m_cachedRequirements) {
+ if (namespace.equals(requirement.getNamespace())) {
+ filtered.add(requirement);
}
}
- m_cachedRequirements = Collections.unmodifiableList(reqs);
+ return Collections.unmodifiableList(filtered);
}
return m_cachedRequirements;
}