use of org.apache.karaf.features.internal.resolver.SimpleFilter in project karaf by apache.
the class StaxParser method parseRequirement.
private static RequirementImpl parseRequirement(XMLStreamReader reader, ResourceImpl resource) throws XMLStreamException {
String[] namespace = new String[1];
Map<String, String> directives = new HashMap<>();
Map<String, Object> attributes = new HashMap<>();
parseClause(reader, namespace, directives, attributes);
sanityCheckEndElement(reader, reader.getEventType(), REQUIREMENT);
String filterStr = directives.get(Constants.FILTER_DIRECTIVE);
SimpleFilter sf = (filterStr != null) ? SimpleFilter.parse(filterStr) : SimpleFilter.convert(attributes);
return new RequirementImpl(resource, namespace[0], directives, attributes, sf);
}
use of org.apache.karaf.features.internal.resolver.SimpleFilter in project karaf by apache.
the class BaseRepository method findProviders.
@Override
public Map<Requirement, Collection<Capability>> findProviders(Collection<? extends Requirement> requirements) {
Map<Requirement, Collection<Capability>> result = new HashMap<>();
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.emptyList());
}
}
return result;
}
use of org.apache.karaf.features.internal.resolver.SimpleFilter in project karaf by apache.
the class SubsystemResolver method toJson.
private Object toJson(Repository repository) {
Requirement req = new RequirementImpl(null, IDENTITY_NAMESPACE, Collections.emptyMap(), Collections.emptyMap(), new SimpleFilter(null, null, SimpleFilter.MATCH_ALL));
Collection<Capability> identities = repository.findProviders(Collections.singleton(req)).get(req);
List<Object> resources = new ArrayList<>();
for (Capability identity : identities) {
String id = BaseClause.toString(null, identity.getNamespace(), identity.getAttributes(), identity.getDirectives());
resources.add(toJson(identity.getResource()));
}
return resources;
}
use of org.apache.karaf.features.internal.resolver.SimpleFilter in project karaf by apache.
the class SubsystemResolver method getFeatures.
public Map<Resource, String> getFeatures() {
if (features == null) {
SimpleFilter sf = createFilter(IDENTITY_NAMESPACE, "*", CAPABILITY_TYPE_ATTRIBUTE, TYPE_FEATURE);
features = getResourceMapping(sf);
}
return features;
}
use of org.apache.karaf.features.internal.resolver.SimpleFilter in project karaf by apache.
the class Subsystem method cloneResource.
ResourceImpl cloneResource(Resource resource) {
ResourceImpl res = new ResourceImpl();
for (Capability cap : resource.getCapabilities(null)) {
res.addCapability(new CapabilityImpl(res, cap.getNamespace(), new HashMap<>(cap.getDirectives()), new HashMap<>(cap.getAttributes())));
}
for (Requirement req : resource.getRequirements(null)) {
SimpleFilter sf;
if (req instanceof RequirementImpl) {
sf = ((RequirementImpl) req).getFilter();
} else if (req.getDirectives().containsKey(REQUIREMENT_FILTER_DIRECTIVE)) {
sf = SimpleFilter.parse(req.getDirectives().get(REQUIREMENT_FILTER_DIRECTIVE));
} else {
sf = SimpleFilter.convert(req.getAttributes());
}
res.addRequirement(new RequirementImpl(res, req.getNamespace(), new HashMap<>(req.getDirectives()), new HashMap<>(req.getAttributes()), sf));
}
return res;
}
Aggregations