use of org.apache.felix.framework.resolver.CandidateComparator in project felix by apache.
the class ResolveContextImpl method insertHostedCapability.
@Override
public int insertHostedCapability(List<Capability> caps, HostedCapability hc) {
int idx = Collections.binarySearch(caps, hc, new CandidateComparator());
if (idx < 0) {
idx = Math.abs(idx + 1);
}
caps.add(idx, hc);
return idx;
}
use of org.apache.felix.framework.resolver.CandidateComparator in project felix by apache.
the class StatefulResolver method findProvidersInternal.
synchronized List<BundleCapability> findProvidersInternal(final ResolverHookRecord record, final Requirement req, final boolean obeyMandatory, final boolean invokeHooksAndSecurity) {
List<BundleCapability> result = new ArrayList<BundleCapability>();
CapabilitySet capSet = m_capSets.get(req.getNamespace());
if (capSet != null) {
// Get the requirement's filter; if this is our own impl we
// have a shortcut to get the already parsed filter, otherwise
// we must parse it from the directive.
SimpleFilter sf;
if (req instanceof BundleRequirementImpl) {
sf = ((BundleRequirementImpl) req).getFilter();
} else {
String filter = req.getDirectives().get(Constants.FILTER_DIRECTIVE);
if (filter == null) {
sf = new SimpleFilter(null, null, SimpleFilter.MATCH_ALL);
} else {
sf = SimpleFilter.parse(filter);
}
}
// Find the matching candidates.
Set<Capability> matches = capSet.match(sf, obeyMandatory);
// Filter matching candidates.
for (Capability cap : matches) {
if (!(cap instanceof BundleCapability))
continue;
BundleCapability bcap = (BundleCapability) cap;
// Filter according to security.
if (invokeHooksAndSecurity && filteredBySecurity((BundleRequirement) req, bcap)) {
continue;
}
// dynamic attachment of fragments.
if (req.getNamespace().equals(BundleRevision.HOST_NAMESPACE) && (bcap.getRevision().getWiring() != null)) {
continue;
}
result.add(bcap);
}
}
if (invokeHooksAndSecurity) {
// based on a whitelist and/or fine-grained candidate filtering.
if (!result.isEmpty() && !record.getResolverHookRefs().isEmpty()) {
// from disallowed revisions.
if (record.getBundleRevisionWhitelist() != null) {
for (Iterator<BundleCapability> it = result.iterator(); it.hasNext(); ) {
if (!record.getBundleRevisionWhitelist().contains(it.next().getRevision())) {
it.remove();
}
}
}
// Now give the hooks a chance to do fine-grained filtering.
ShrinkableCollection<BundleCapability> shrinkable = new ShrinkableCollection<BundleCapability>(result);
for (ResolverHook hook : record.getResolverHooks()) {
try {
Felix.m_secureAction.invokeResolverHookMatches(hook, (BundleRequirement) req, shrinkable);
} catch (Throwable th) {
m_logger.log(Logger.LOG_WARNING, "Resolver hook exception.", th);
}
}
}
}
Collections.sort(result, new CandidateComparator());
return result;
}
Aggregations