// We use parallel lists so we can calculate the packages spaces for
// resolved and unresolved resources in an identical fashion.
List<Requirement> reqs = new ArrayList();
List<Capability> caps = new ArrayList();
boolean isDynamicImporting = false;
Wiring wiring = session.getContext().getWirings().get(resource);
if (wiring != null)
{
// Use wires to get actual requirements and satisfying capabilities.
for (Wire wire : wiring.getRequiredResourceWires(null))
{
// Wrap the requirement as a hosted requirement if it comes
// from a fragment, since we will need to know the host. We
// also need to wrap if the requirement is a dynamic import,
// since that requirement will be shared with any other
// matching dynamic imports.
Requirement r = wire.getRequirement();
if (!r.getResource().equals(wire.getRequirer())
|| ((r.getDirectives()
.get(PackageNamespace.REQUIREMENT_RESOLUTION_DIRECTIVE) != null)
&& r.getDirectives()
.get(PackageNamespace.REQUIREMENT_RESOLUTION_DIRECTIVE)
.equals(PackageNamespace.RESOLUTION_DYNAMIC)))
{
r = new WrappedRequirement(wire.getRequirer(), r);
}
// Wrap the capability as a hosted capability if it comes
// from a fragment, since we will need to know the host.
Capability c = wire.getCapability();
if (!c.getResource().equals(wire.getProvider()))
{
c = new WrappedCapability(wire.getProvider(), c);
}
reqs.add(r);
caps.add(c);
}
// Since the resource is resolved, it could be dynamically importing,
// so check to see if there are candidates for any of its dynamic
// imports.
//
// NOTE: If the resource is dynamically importing, the fact that
// the dynamic import is added here last to the parallel reqs/caps
// list is used later when checking to see if the package being
// dynamically imported shadows an existing provider.
for (Requirement req
: Util.getDynamicRequirements(wiring.getResourceRequirements(null)))
{
// Get the candidates for the current requirement.
List<Capability> candCaps = allCandidates.getCandidates(req);
// Optional requirements may not have any candidates.
if (candCaps == null)