use of io.fabric8.agent.model.Capability in project fabric8 by jboss-fuse.
the class BaseRepository method addResource.
protected void addResource(Resource resource) {
for (Capability cap : resource.getCapabilities(null)) {
String ns = cap.getNamespace();
CapabilitySet set = capSets.get(ns);
if (set == null) {
if ("service-reference".equals(ns) || "osgi.service".equals(ns)) {
set = new CapabilitySet(Collections.singletonList("objectClass"));
} else {
set = new CapabilitySet(Collections.singletonList(ns));
}
capSets.put(ns, set);
}
set.addCapability(cap);
}
resources.add(resource);
}
use of io.fabric8.agent.model.Capability in project fabric8 by jboss-fuse.
the class BaseRepository method findProviders.
@Override
public Map<Requirement, Collection<Capability>> findProviders(Collection<? extends Requirement> requirements) {
Map<Requirement, Collection<Capability>> result = new HashMap<Requirement, Collection<Capability>>();
for (Requirement requirement : requirements) {
CapabilitySet set = capSets.get(requirement.getNamespace());
if (set != null) {
SimpleFilter sf;
if (requirement instanceof RequirementImpl) {
sf = ((RequirementImpl) requirement).getFilter();
} else {
String filter = requirement.getDirectives().get(Constants.FILTER_DIRECTIVE);
sf = (filter != null) ? SimpleFilter.parse(filter) : new SimpleFilter(null, null, SimpleFilter.MATCH_ALL);
}
result.put(requirement, set.match(sf, true));
} else {
result.put(requirement, Collections.<Capability>emptyList());
}
}
return result;
}
use of io.fabric8.agent.model.Capability in project fabric8 by jboss-fuse.
the class RequirementSort method sort.
/**
* Sorts {@link org.osgi.resource.Resource} based on their {@link org.osgi.resource.Requirement}s and {@link org.osgi.resource.Capability}s.
*/
public static <T extends Resource> Collection<T> sort(Collection<T> resources) {
Set<String> namespaces = new HashSet<>();
for (Resource r : resources) {
for (Capability cap : r.getCapabilities(null)) {
namespaces.add(cap.getNamespace());
}
}
CapabilitySet capSet = new CapabilitySet(new ArrayList<>(namespaces));
for (Resource r : resources) {
for (Capability cap : r.getCapabilities(null)) {
capSet.addCapability(cap);
}
}
Set<T> sorted = new LinkedHashSet<>();
Set<T> visited = new LinkedHashSet<>();
for (T r : resources) {
visit(r, visited, sorted, capSet);
}
return sorted;
}
Aggregations