Rename and slightly refactor some classes to make their purpose more
obvious. (FELIX-2858)
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1080256 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/framework/src/main/java/org/apache/felix/framework/ModuleImpl.java b/framework/src/main/java/org/apache/felix/framework/ModuleImpl.java
index 6b727f0..5829b79 100644
--- a/framework/src/main/java/org/apache/felix/framework/ModuleImpl.java
+++ b/framework/src/main/java/org/apache/felix/framework/ModuleImpl.java
@@ -49,6 +49,8 @@
import org.apache.felix.framework.capabilityset.Requirement;
import org.apache.felix.framework.capabilityset.SimpleFilter;
import org.apache.felix.framework.resolver.Content;
+import org.apache.felix.framework.resolver.HostedCapability;
+import org.apache.felix.framework.resolver.HostedRequirement;
import org.apache.felix.framework.resolver.Module;
import org.apache.felix.framework.resolver.ResolveException;
import org.apache.felix.framework.resolver.ResourceNotFoundException;
@@ -60,7 +62,6 @@
import org.apache.felix.framework.util.SecureAction;
import org.apache.felix.framework.util.SecurityManagerEx;
import org.apache.felix.framework.util.Util;
-import org.apache.felix.framework.util.manifestparser.CapabilityImpl;
import org.apache.felix.framework.util.manifestparser.ManifestParser;
import org.apache.felix.framework.util.manifestparser.R4Library;
import org.apache.felix.framework.util.manifestparser.RequirementImpl;
@@ -312,11 +313,7 @@
if (caps.get(capIdx).getNamespace().equals(Capability.PACKAGE_NAMESPACE))
{
capList.add(
- new CapabilityImpl(
- this,
- caps.get(capIdx).getNamespace(),
- caps.get(capIdx).getDirectives(),
- caps.get(capIdx).getAttributes()));
+ new HostedCapability(this, caps.get(capIdx)));
}
}
}
@@ -344,8 +341,7 @@
|| reqs.get(reqIdx).getNamespace().equals(Capability.MODULE_NAMESPACE))
{
reqList.add(
- new FragmentRequirement(
- this, reqs.get(reqIdx)));
+ new HostedRequirement(this, reqs.get(reqIdx)));
}
}
}
@@ -403,7 +399,7 @@
// We need to return null here if we don't have any libraries, since a
// zero-length array is used to indicate that matching native libraries
// could not be found when resolving the bundle.
- result = (nativeList.size() == 0)
+ result = (nativeList.isEmpty())
? null
: Collections.unmodifiableList(nativeList);
}
@@ -2438,56 +2434,4 @@
return sb.toString();
}
-
- static class FragmentRequirement implements Requirement
- {
- private final Module m_owner;
- private final Requirement m_fragmentReq;
-
- public FragmentRequirement(Module owner, Requirement fragmentReq)
- {
- m_owner = owner;
- m_fragmentReq = fragmentReq;
- }
-
- public Module getFragment()
- {
- return m_fragmentReq.getModule();
- }
-
- public Module getModule()
- {
- return m_owner;
- }
-
- public String getNamespace()
- {
- return m_fragmentReq.getNamespace();
- }
-
- public SimpleFilter getFilter()
- {
- return m_fragmentReq.getFilter();
- }
-
- public boolean isOptional()
- {
- return m_fragmentReq.isOptional();
- }
-
- public Directive getDirective(String name)
- {
- return m_fragmentReq.getDirective(name);
- }
-
- public List<Directive> getDirectives()
- {
- return m_fragmentReq.getDirectives();
- }
-
- public String toString()
- {
- return m_fragmentReq.toString();
- }
- }
}
\ No newline at end of file
diff --git a/framework/src/main/java/org/apache/felix/framework/resolver/Candidates.java b/framework/src/main/java/org/apache/felix/framework/resolver/Candidates.java
index efd7ff3..ac95e7d 100644
--- a/framework/src/main/java/org/apache/felix/framework/resolver/Candidates.java
+++ b/framework/src/main/java/org/apache/felix/framework/resolver/Candidates.java
@@ -55,7 +55,7 @@
private final Map<Capability, Map<String, Map<Version, List<Requirement>>>> m_hostFragments;
// Maps a module to its associated wrapped module; this only happens
// when a module being resolved has fragments to attach to it.
- private final Map<Module, WrappedModule> m_allWrappedHosts;
+ private final Map<Module, HostModule> m_allWrappedHosts;
// Map used when populating candidates to hold intermediate and final results.
Map<Module, Object> m_populateResultCache;
@@ -73,7 +73,7 @@
Map<Capability, Set<Requirement>> dependentMap,
Map<Requirement, SortedSet<Capability>> candidateMap,
Map<Capability, Map<String, Map<Version, List<Requirement>>>> hostFragments,
- Map<Module, WrappedModule> wrappedHosts, Map<Module, Object> populateResultCache)
+ Map<Module, HostModule> wrappedHosts, Map<Module, Object> populateResultCache)
{
m_root = root;
m_candidateModules = candidateModules;
@@ -97,7 +97,7 @@
m_candidateMap = new HashMap<Requirement, SortedSet<Capability>>();
m_hostFragments =
new HashMap<Capability, Map<String, Map<Version, List<Requirement>>>>();
- m_allWrappedHosts = new HashMap<Module, WrappedModule>();
+ m_allWrappedHosts = new HashMap<Module, HostModule>();
m_populateResultCache = new HashMap<Module, Object>();
populate(state, m_root);
@@ -122,7 +122,7 @@
m_candidateMap = new HashMap<Requirement, SortedSet<Capability>>();
m_hostFragments =
new HashMap<Capability, Map<String, Map<Version, List<Requirement>>>>();
- m_allWrappedHosts = new HashMap<Module, WrappedModule>();
+ m_allWrappedHosts = new HashMap<Module, HostModule>();
m_populateResultCache = new HashMap<Module, Object>();
add(req, candidates);
@@ -546,7 +546,7 @@
// with host's attached fragment capabilities.
// Steps 1 and 2
- List<WrappedModule> wrappedHosts = new ArrayList<WrappedModule>();
+ List<HostModule> wrappedHosts = new ArrayList<HostModule>();
List<Module> unselectedFragments = new ArrayList<Module>();
for (Entry<Capability, Map<String, Map<Version, List<Requirement>>>> hostEntry :
m_hostFragments.entrySet())
@@ -590,7 +590,7 @@
}
// Step 2
- WrappedModule wrappedHost = new WrappedModule(hostCap.getModule(), selectedFragments);
+ HostModule wrappedHost = new HostModule(hostCap.getModule(), selectedFragments);
wrappedHosts.add(wrappedHost);
m_allWrappedHosts.put(hostCap.getModule(), wrappedHost);
}
@@ -602,20 +602,20 @@
}
// Step 4
- for (WrappedModule wrappedHost : wrappedHosts)
+ for (HostModule wrappedHost : wrappedHosts)
{
// Replaces capabilities from fragments with the capabilities
// from the merged host.
for (Capability c : wrappedHost.getCapabilities())
{
Set<Requirement> dependents =
- m_dependentMap.get(((WrappedCapability) c).getWrappedCapability());
+ m_dependentMap.get(((HostedCapability) c).getDeclaredCapability());
if (dependents != null)
{
for (Requirement r : dependents)
{
Set<Capability> cands = m_candidateMap.get(r);
- cands.remove(((WrappedCapability) c).getWrappedCapability());
+ cands.remove(((HostedCapability) c).getDeclaredCapability());
cands.add(c);
}
}
@@ -627,7 +627,7 @@
for (Requirement r : wrappedHost.getRequirements())
{
SortedSet<Capability> cands =
- m_candidateMap.get(((WrappedRequirement) r).getWrappedRequirement());
+ m_candidateMap.get(((HostedRequirement) r).getDeclaredRequirement());
if (cands != null)
{
m_candidateMap.put(r, new TreeSet<Capability>(cands));
diff --git a/framework/src/main/java/org/apache/felix/framework/resolver/WrappedModule.java b/framework/src/main/java/org/apache/felix/framework/resolver/HostModule.java
similarity index 88%
rename from framework/src/main/java/org/apache/felix/framework/resolver/WrappedModule.java
rename to framework/src/main/java/org/apache/felix/framework/resolver/HostModule.java
index 5daacaa..819eeef 100644
--- a/framework/src/main/java/org/apache/felix/framework/resolver/WrappedModule.java
+++ b/framework/src/main/java/org/apache/felix/framework/resolver/HostModule.java
@@ -32,22 +32,22 @@
import org.osgi.framework.Bundle;
import org.osgi.framework.Version;
-class WrappedModule implements Module
+class HostModule implements Module
{
- private final Module m_module;
+ private final Module m_host;
private final List<Module> m_fragments;
private List<Capability> m_cachedCapabilities = null;
private List<Requirement> m_cachedRequirements = null;
- public WrappedModule(Module module, List<Module> fragments)
+ public HostModule(Module module, List<Module> fragments)
{
- m_module = module;
+ m_host = module;
m_fragments = fragments;
}
- public Module getWrappedModule()
+ public Module getHost()
{
- return m_module;
+ return m_host;
}
public List<Module> getFragments()
@@ -57,7 +57,7 @@
public String getId()
{
- return m_module.getId();
+ return m_host.getId();
}
public List<Capability> getCapabilities()
@@ -67,13 +67,13 @@
List<Capability> capList = new ArrayList<Capability>();
// Wrap host capabilities.
- List<Capability> caps = m_module.getCapabilities();
+ List<Capability> caps = m_host.getCapabilities();
for (int capIdx = 0;
(caps != null) && (capIdx < caps.size());
capIdx++)
{
capList.add(
- new WrappedCapability(this, caps.get(capIdx)));
+ new HostedCapability(this, caps.get(capIdx)));
}
// Wrap fragment capabilities.
@@ -89,7 +89,7 @@
if (caps.get(capIdx).getNamespace().equals(Capability.PACKAGE_NAMESPACE))
{
capList.add(
- new WrappedCapability(this, caps.get(capIdx)));
+ new HostedCapability(this, caps.get(capIdx)));
}
}
}
@@ -105,13 +105,13 @@
List<Requirement> reqList = new ArrayList<Requirement>();
// Wrap host requirements.
- List<Requirement> reqs = m_module.getRequirements();
+ List<Requirement> reqs = m_host.getRequirements();
for (int reqIdx = 0;
(reqs != null) && (reqIdx < reqs.size());
reqIdx++)
{
reqList.add(
- new WrappedRequirement(this, reqs.get(reqIdx)));
+ new HostedRequirement(this, reqs.get(reqIdx)));
}
// Wrap fragment requirements.
@@ -128,7 +128,7 @@
|| reqs.get(reqIdx).getNamespace().equals(Capability.MODULE_NAMESPACE))
{
reqList.add(
- new WrappedRequirement(this, reqs.get(reqIdx)));
+ new HostedRequirement(this, reqs.get(reqIdx)));
}
}
}
@@ -139,7 +139,7 @@
public String toString()
{
- return m_module.getId();
+ return m_host.getId();
}
public Map getHeaders()
@@ -154,7 +154,7 @@
public String getSymbolicName()
{
- return m_module.getSymbolicName();
+ return m_host.getSymbolicName();
}
public Version getVersion()
@@ -179,7 +179,7 @@
public Bundle getBundle()
{
- return m_module.getBundle();
+ return m_host.getBundle();
}
public List<Wire> getWires()
@@ -199,7 +199,7 @@
public boolean isRemovalPending()
{
- return m_module.isRemovalPending();
+ return m_host.isRemovalPending();
}
public Content getContent()
diff --git a/framework/src/main/java/org/apache/felix/framework/resolver/WrappedCapability.java b/framework/src/main/java/org/apache/felix/framework/resolver/HostedCapability.java
similarity index 63%
rename from framework/src/main/java/org/apache/felix/framework/resolver/WrappedCapability.java
rename to framework/src/main/java/org/apache/felix/framework/resolver/HostedCapability.java
index 29f5d00..04c68b7 100644
--- a/framework/src/main/java/org/apache/felix/framework/resolver/WrappedCapability.java
+++ b/framework/src/main/java/org/apache/felix/framework/resolver/HostedCapability.java
@@ -23,25 +23,57 @@
import org.apache.felix.framework.capabilityset.Capability;
import org.apache.felix.framework.capabilityset.Directive;
-class WrappedCapability implements Capability
+public class HostedCapability implements Capability
{
- private final Module m_module;
+ private final Module m_host;
private final Capability m_cap;
- public WrappedCapability(Module module, Capability cap)
+ public HostedCapability(Module module, Capability cap)
{
- m_module = module;
+ m_host = module;
m_cap = cap;
}
- public Capability getWrappedCapability()
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (obj == null)
+ {
+ return false;
+ }
+ if (getClass() != obj.getClass())
+ {
+ return false;
+ }
+ final HostedCapability other = (HostedCapability) obj;
+ if (m_host != other.m_host && (m_host == null || !m_host.equals(other.m_host)))
+ {
+ return false;
+ }
+ if (m_cap != other.m_cap && (m_cap == null || !m_cap.equals(other.m_cap)))
+ {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ int hash = 7;
+ hash = 37 * hash + (m_host != null ? m_host.hashCode() : 0);
+ hash = 37 * hash + (m_cap != null ? m_cap.hashCode() : 0);
+ return hash;
+ }
+
+ public Capability getDeclaredCapability()
{
return m_cap;
}
public Module getModule()
{
- return m_module;
+ return m_host;
}
public String getNamespace()
@@ -74,17 +106,18 @@
return m_cap.getUses();
}
+ @Override
public String toString()
{
- if (m_module == null)
+ if (m_host == null)
{
return getAttributes().toString();
}
if (getNamespace().equals(Capability.PACKAGE_NAMESPACE))
{
- return "[" + m_module + "] "
+ return "[" + m_host + "] "
+ getNamespace() + "; " + getAttribute(Capability.PACKAGE_ATTR);
}
- return "[" + m_module + "] " + getNamespace() + "; " + getAttributes();
+ return "[" + m_host + "] " + getNamespace() + "; " + getAttributes();
}
}
\ No newline at end of file
diff --git a/framework/src/main/java/org/apache/felix/framework/resolver/WrappedRequirement.java b/framework/src/main/java/org/apache/felix/framework/resolver/HostedRequirement.java
similarity index 60%
rename from framework/src/main/java/org/apache/felix/framework/resolver/WrappedRequirement.java
rename to framework/src/main/java/org/apache/felix/framework/resolver/HostedRequirement.java
index a188ce1..10f6f53 100644
--- a/framework/src/main/java/org/apache/felix/framework/resolver/WrappedRequirement.java
+++ b/framework/src/main/java/org/apache/felix/framework/resolver/HostedRequirement.java
@@ -23,25 +23,57 @@
import org.apache.felix.framework.capabilityset.Requirement;
import org.apache.felix.framework.capabilityset.SimpleFilter;
-class WrappedRequirement implements Requirement
+public class HostedRequirement implements Requirement
{
- private final Module m_module;
+ private final Module m_host;
private final Requirement m_req;
- public WrappedRequirement(Module module, Requirement req)
+ public HostedRequirement(Module module, Requirement req)
{
- m_module = module;
+ m_host = module;
m_req = req;
}
- public Requirement getWrappedRequirement()
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (obj == null)
+ {
+ return false;
+ }
+ if (getClass() != obj.getClass())
+ {
+ return false;
+ }
+ final HostedRequirement other = (HostedRequirement) obj;
+ if (m_host != other.m_host && (m_host == null || !m_host.equals(other.m_host)))
+ {
+ return false;
+ }
+ if (m_req != other.m_req && (m_req == null || !m_req.equals(other.m_req)))
+ {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ int hash = 7;
+ hash = 37 * hash + (m_host != null ? m_host.hashCode() : 0);
+ hash = 37 * hash + (m_req != null ? m_req.hashCode() : 0);
+ return hash;
+ }
+
+ public Requirement getDeclaredRequirement()
{
return m_req;
}
public Module getModule()
{
- return m_module;
+ return m_host;
}
public String getNamespace()
@@ -71,6 +103,6 @@
public String toString()
{
- return "[" + m_module + "] " + getNamespace() + "; " + getFilter().toString();
+ return "[" + m_host + "] " + getNamespace() + "; " + getFilter().toString();
}
}
\ No newline at end of file
diff --git a/framework/src/main/java/org/apache/felix/framework/resolver/ResolverImpl.java b/framework/src/main/java/org/apache/felix/framework/resolver/ResolverImpl.java
index e061ad9..e750bad 100644
--- a/framework/src/main/java/org/apache/felix/framework/resolver/ResolverImpl.java
+++ b/framework/src/main/java/org/apache/felix/framework/resolver/ResolverImpl.java
@@ -146,11 +146,11 @@
if (rethrow != null)
{
Module faultyModule = getActualModule(rethrow.getModule());
- if (rethrow.getRequirement() instanceof WrappedRequirement)
+ if (rethrow.getRequirement() instanceof HostedRequirement)
{
faultyModule =
- ((WrappedRequirement) rethrow.getRequirement())
- .getWrappedRequirement().getModule();
+ ((HostedRequirement) rethrow.getRequirement())
+ .getDeclaredRequirement().getModule();
}
if (fragments.remove(faultyModule))
{
@@ -281,11 +281,11 @@
if (rethrow != null)
{
Module faultyModule = getActualModule(rethrow.getModule());
- if (rethrow.getRequirement() instanceof WrappedRequirement)
+ if (rethrow.getRequirement() instanceof HostedRequirement)
{
faultyModule =
- ((WrappedRequirement) rethrow.getRequirement())
- .getWrappedRequirement().getModule();
+ ((HostedRequirement) rethrow.getRequirement())
+ .getDeclaredRequirement().getModule();
}
if (fragments.remove(faultyModule))
{
@@ -485,7 +485,7 @@
Requirement r = wire.getRequirement();
if (!r.getModule().equals(wire.getImporter()))
{
- r = new WrappedRequirement(wire.getImporter(), r);
+ r = new HostedRequirement(wire.getImporter(), r);
}
// Wrap the capability as a hosted capability
// if it comes from a fragment, since we will need
@@ -493,7 +493,7 @@
Capability c = wire.getCapability();
if (!c.getModule().equals(wire.getExporter()))
{
- c = new WrappedCapability(wire.getExporter(), c);
+ c = new HostedCapability(wire.getExporter(), c);
}
reqs.add(r);
caps.add(c);
@@ -1291,27 +1291,27 @@
private static Module getActualModule(Module m)
{
- if (m instanceof WrappedModule)
+ if (m instanceof HostModule)
{
- return ((WrappedModule) m).getWrappedModule();
+ return ((HostModule) m).getHost();
}
return m;
}
private static Capability getActualCapability(Capability c)
{
- if (c instanceof WrappedCapability)
+ if (c instanceof HostedCapability)
{
- return ((WrappedCapability) c).getWrappedCapability();
+ return ((HostedCapability) c).getDeclaredCapability();
}
return c;
}
private static Requirement getActualRequirement(Requirement r)
{
- if (r instanceof WrappedRequirement)
+ if (r instanceof HostedRequirement)
{
- return ((WrappedRequirement) r).getWrappedRequirement();
+ return ((HostedRequirement) r).getDeclaredRequirement();
}
return r;
}
@@ -1370,9 +1370,9 @@
wireMap.put(unwrappedModule, packageWires);
// Add host wire for any fragments.
- if (module instanceof WrappedModule)
+ if (module instanceof HostModule)
{
- List<Module> fragments = ((WrappedModule) module).getFragments();
+ List<Module> fragments = ((HostModule) module).getFragments();
for (Module fragment : fragments)
{
List<Wire> hostWires = wireMap.get(fragment);