}
// Process the candidates, removing any candidates that
// cannot resolve.
List<Capability> candidates = rc.findProviders(req);
ResolutionException rethrow = processCandidates(rc, resource, candidates);
// First, due to cycles, makes sure we haven't already failed in
// a deeper recursion.
Object result = m_populateResultCache.get(resource);
if (result instanceof ResolutionException)
{
throw (ResolutionException) result;
}
// Next, if are no candidates remaining and the requirement is not
// not optional, then record and throw a resolve exception.
else if (candidates.isEmpty() && !Util.isOptional(req))
{
if (Util.isFragment(resource) && rc.getWirings().containsKey(resource))
{
// This is a fragment that is already resolved and there is no unresolved hosts to attach it to.
m_populateResultCache.put(resource, Boolean.TRUE);
return;
}
String msg = "Unable to resolve " + resource
+ ": missing requirement " + req;
if (rethrow != null)
{
msg = msg + " [caused by: " + rethrow.getMessage() + "]";
}
rethrow = new ResolutionException(msg, null, Collections.singleton(req));
m_populateResultCache.put(resource, rethrow);
throw rethrow;
}
// Otherwise, if we actually have candidates for the requirement, then
// add them to the local candidate map.