Search in sources :

Example 1 with CapabilitySet

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;
}
Also used : BundleCapability(org.osgi.framework.wiring.BundleCapability) Capability(org.osgi.resource.Capability) ResolverHook(org.osgi.framework.hooks.resolver.ResolverHook) ArrayList(java.util.ArrayList) BundleRequirementImpl(org.apache.felix.framework.wiring.BundleRequirementImpl) BundleRequirement(org.osgi.framework.wiring.BundleRequirement) CandidateComparator(org.apache.felix.framework.resolver.CandidateComparator) SimpleFilter(org.apache.felix.framework.capabilityset.SimpleFilter) CapabilitySet(org.apache.felix.framework.capabilityset.CapabilitySet) ShrinkableCollection(org.apache.felix.framework.util.ShrinkableCollection) BundleCapability(org.osgi.framework.wiring.BundleCapability)

Example 2 with CapabilitySet

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);
            }
        }
    }
}
Also used : CapabilitySet(org.apache.felix.framework.capabilityset.CapabilitySet) BundleCapability(org.osgi.framework.wiring.BundleCapability)

Aggregations

CapabilitySet (org.apache.felix.framework.capabilityset.CapabilitySet)2 BundleCapability (org.osgi.framework.wiring.BundleCapability)2 ArrayList (java.util.ArrayList)1 SimpleFilter (org.apache.felix.framework.capabilityset.SimpleFilter)1 CandidateComparator (org.apache.felix.framework.resolver.CandidateComparator)1 ShrinkableCollection (org.apache.felix.framework.util.ShrinkableCollection)1 BundleRequirementImpl (org.apache.felix.framework.wiring.BundleRequirementImpl)1 ResolverHook (org.osgi.framework.hooks.resolver.ResolverHook)1 BundleRequirement (org.osgi.framework.wiring.BundleRequirement)1 Capability (org.osgi.resource.Capability)1