@Override
public Collection<Capability> findProviders(Requirement req) {
IllegalArgumentAssertion.assertNotNull(req, "req");
// Try to find the providers in the storage
RepositoryStorage repositoryStorage = getRequiredRepositoryStorage();
Collection<Capability> providers = repositoryStorage.findProviders(req);
// Try to find the providers in the fallback
if (providers.isEmpty() && getFallbackRepository() != null) {
providers = new HashSet<Capability>();
for (Capability cap : getFallbackRepository().findProviders(req)) {
Resource res = cap.getResource();
ResourceIdentity resid = res.getIdentity();
Resource storageResource = repositoryStorage.getResource(resid);
if (storageResource == null) {
storageResource = repositoryStorage.addResource(res);
for (Capability aux : storageResource.getCapabilities(req.getNamespace())) {
if (cap.getAttributes().equals(aux.getAttributes())) {
cap = aux;
break;
}