Search in sources :

Example 6 with OsgiRequirementAdapter

use of org.apache.aries.subsystem.util.felix.OsgiRequirementAdapter in project aries by apache.

the class RepositoryAdminRepository method findProviders.

public Collection<Capability> findProviders(Requirement requirement) {
    logger.debug(LOG_ENTRY, "findProviders", requirement);
    Collection<Capability> result = Collections.emptyList();
    if (IdentityNamespace.IDENTITY_NAMESPACE.equals(requirement.getNamespace())) {
        result = new ArrayList<Capability>();
        for (org.apache.felix.bundlerepository.Repository r : repositoryAdmin.listRepositories()) {
            FelixRepositoryAdapter repository = new FelixRepositoryAdapter(r);
            Map<Requirement, Collection<Capability>> map = repository.findProviders(Arrays.asList(requirement));
            Collection<Capability> capabilities = map.get(requirement);
            if (capabilities != null)
                result.addAll(capabilities);
        }
        return result;
    } else {
        Resource[] resources = repositoryAdmin.discoverResources(new org.apache.felix.bundlerepository.Requirement[] { new OsgiRequirementAdapter(requirement) });
        logger.debug("Found {} resources with capabilities satisfying {}", resources == null ? 0 : resources.length, requirement);
        if (resources != null && resources.length != 0) {
            result = new ArrayList<Capability>(result.size());
            OsgiRequirementAdapter adapter = new OsgiRequirementAdapter(requirement);
            for (Resource resource : resources) {
                logger.debug("Evaluating resource {}", resource);
                for (org.apache.felix.bundlerepository.Capability capability : resource.getCapabilities()) {
                    logger.debug("Evaluating capability {}", capability);
                    if (adapter.isSatisfied(capability)) {
                        logger.debug("Adding capability {}", capability);
                        result.add(new FelixCapabilityAdapter(capability, new FelixResourceAdapter(resource)));
                    }
                }
            }
        }
    }
    logger.debug(LOG_EXIT, "findProviders", result);
    return result;
}
Also used : Capability(org.osgi.resource.Capability) Resource(org.apache.felix.bundlerepository.Resource) OsgiRequirementAdapter(org.apache.aries.subsystem.util.felix.OsgiRequirementAdapter) FelixResourceAdapter(org.apache.aries.subsystem.util.felix.FelixResourceAdapter) Requirement(org.osgi.resource.Requirement) FelixCapabilityAdapter(org.apache.aries.subsystem.util.felix.FelixCapabilityAdapter) FelixRepositoryAdapter(org.apache.aries.subsystem.util.felix.FelixRepositoryAdapter) Collection(java.util.Collection)

Aggregations

OsgiRequirementAdapter (org.apache.aries.subsystem.util.felix.OsgiRequirementAdapter)6 Requirement (org.osgi.resource.Requirement)6 Test (org.junit.Test)5 HashMap (java.util.HashMap)2 Collection (java.util.Collection)1 FelixCapabilityAdapter (org.apache.aries.subsystem.util.felix.FelixCapabilityAdapter)1 FelixRepositoryAdapter (org.apache.aries.subsystem.util.felix.FelixRepositoryAdapter)1 FelixResourceAdapter (org.apache.aries.subsystem.util.felix.FelixResourceAdapter)1 Resource (org.apache.felix.bundlerepository.Resource)1 Capability (org.osgi.resource.Capability)1