in repository/service/src/main/java/org/apache/karaf/cave/repository/service/bundlerepository/ResourceBuilder.java [352:388]
private static List<Requirement> convertImportService(List<ParsedHeaderClause> clauses, Resource resource) throws BundleException {
try {
List<Requirement> reqList = new ArrayList<>();
for (ParsedHeaderClause clause : clauses) {
for (String path : clause.paths) {
String multiple = clause.dirs.get("multiple");
String avail = clause.dirs.get("availability");
String filter = (String) clause.attrs.get("filter");
Map<String, String> dirs = new LinkedHashMap<>();
dirs.put(ServiceNamespace.REQUIREMENT_EFFECTIVE_DIRECTIVE, ServiceNamespace.EFFECTIVE_ACTIVE);
if ("optional".equals(avail)) {
dirs.put(ServiceNamespace.REQUIREMENT_RESOLUTION_DIRECTIVE, ServiceNamespace.RESOLUTION_OPTIONAL);
}
if ("true".equals(multiple)) {
dirs.put(ServiceNamespace.REQUIREMENT_CARDINALITY_DIRECTIVE, ServiceNamespace.CARDINALITY_MULTIPLE);
}
if (filter == null) {
filter = "(" + Constants.OBJECTCLASS + "=" + path + ")";
} else if (!filter.startsWith("(") && !filter.endsWith(")")) {
filter = "(&(" + Constants.OBJECTCLASS + "=" + path + ")(" + filter + "))";
} else {
filter = "(&(" + Constants.OBJECTCLASS + "=" + path + ")" + filter + ")";
}
dirs.put(ServiceNamespace.REQUIREMENT_FILTER_DIRECTIVE, filter);
reqList.add(new RequirementImpl(
resource,
ServiceNamespace.SERVICE_NAMESPACE,
dirs,
Collections.<String, Object>emptyMap(),
SimpleFilter.parse(filter)));
}
}
return reqList;
} catch (Exception ex) {
throw new BundleException("Error creating requirement: " + ex, ex);
}
}