use of org.apache.felix.framework.capabilityset.CapabilitySet 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;
}
use of org.apache.felix.framework.capabilityset.CapabilitySet in project felix by apache.
the class StatefulResolver method indexCapabilities.
private synchronized void indexCapabilities(BundleRevision br) {
List<BundleCapability> caps = (Util.isFragment(br) || (br.getWiring() == null)) ? br.getDeclaredCapabilities(null) : br.getWiring().getCapabilities(null);
if (caps != null) {
for (BundleCapability cap : caps) {
// attached hosts for fragments.
if (cap.getRevision() == br) {
CapabilitySet capSet = m_capSets.get(cap.getNamespace());
if (capSet == null) {
capSet = new CapabilitySet(null, true);
m_capSets.put(cap.getNamespace(), capSet);
}
capSet.addCapability(cap);
}
}
}
}
Aggregations