private static Map<BundleRevision, List<ResolverWire>> populateWireMap(
BundleRevision revision, Map<BundleRevision, Packages> revisionPkgMap,
Map<BundleRevision, List<ResolverWire>> wireMap,
Candidates allCandidates)
{
BundleRevision unwrappedRevision = getActualBundleRevision(revision);
if ((unwrappedRevision.getWiring() == null)
&& !wireMap.containsKey(unwrappedRevision))
{
wireMap.put(unwrappedRevision, (List<ResolverWire>) Collections.EMPTY_LIST);
List<ResolverWire> packageWires = new ArrayList<ResolverWire>();
List<ResolverWire> bundleWires = new ArrayList<ResolverWire>();
List<ResolverWire> capabilityWires = new ArrayList<ResolverWire>();
for (BundleRequirement req : revision.getDeclaredRequirements(null))
{
SortedSet<BundleCapability> cands = allCandidates.getCandidates(req);
if ((cands != null) && (cands.size() > 0))
{
BundleCapability cand = cands.iterator().next();
// Ignore revisions that import themselves.
if (!revision.equals(cand.getRevision()))
{
if (cand.getRevision().getWiring() == null)
{
populateWireMap(cand.getRevision(),
revisionPkgMap, wireMap, allCandidates);
}
Packages candPkgs = revisionPkgMap.get(cand.getRevision());
ResolverWire wire = new ResolverWireImpl(
unwrappedRevision,
getActualRequirement(req),
getActualBundleRevision(cand.getRevision()),
getActualCapability(cand));
if (req.getNamespace().equals(BundleRevision.PACKAGE_NAMESPACE))
{
packageWires.add(wire);
}
else if (req.getNamespace().equals(BundleRevision.BUNDLE_NAMESPACE))
{
bundleWires.add(wire);
}
else
{
capabilityWires.add(wire);
}
}
}
}
// Combine package wires with require wires last.
packageWires.addAll(bundleWires);
packageWires.addAll(capabilityWires);
wireMap.put(unwrappedRevision, packageWires);
// Add host wire for any fragments.
if (revision instanceof HostBundleRevision)
{
List<BundleRevision> fragments = ((HostBundleRevision) revision).getFragments();
for (BundleRevision fragment : fragments)
{
List<ResolverWire> hostWires = wireMap.get(fragment);
if (hostWires == null)
{
hostWires = new ArrayList<ResolverWire>();
wireMap.put(fragment, hostWires);
}
hostWires.add(
new ResolverWireImpl(
getActualBundleRevision(fragment),
fragment.getDeclaredRequirements(
BundleRevision.HOST_NAMESPACE).get(0),
unwrappedRevision,
unwrappedRevision.getDeclaredCapabilities(
BundleRevision.HOST_NAMESPACE).get(0)));
}
}
}