use of org.apache.felix.utils.collections.StringArrayMap in project karaf by apache.
the class ResourceUtils method toFeatureRequirement.
/**
* Changes feature identifier (<code>name[/version]</code>) into a requirement specification.
* The OSGi manifest header for a feature will be: <code>osgi.identity;osgi.identity=feature-name;type=karaf.feature[;version=feature-version];filter:=filter-from-attrs</code>.
*
* @param feature The feature name.
* @return The feature requirement.
*/
public static String toFeatureRequirement(String feature) {
String[] parts = feature.split("/");
Map<String, Object> attrs = new StringArrayMap<>(parts.length > 1 ? 3 : 2);
attrs.put(IDENTITY_NAMESPACE, parts[0]);
attrs.put(CAPABILITY_TYPE_ATTRIBUTE, TYPE_FEATURE);
if (parts.length > 1) {
attrs.put(CAPABILITY_VERSION_ATTRIBUTE, new VersionRange(parts[1]));
}
Map<String, String> dirs = Collections.singletonMap(Constants.FILTER_DIRECTIVE, SimpleFilter.convert(attrs).toString());
return new RequirementImpl(null, IDENTITY_NAMESPACE, dirs, attrs).toString();
}
use of org.apache.felix.utils.collections.StringArrayMap in project karaf by apache.
the class ResourceUtils method toFeatureCapability.
public static String toFeatureCapability(String feature) {
String[] parts = feature.split("/");
Map<String, String> dirs = Collections.emptyMap();
Map<String, Object> attrs = new StringArrayMap<>(parts.length > 1 ? 3 : 2);
attrs.put(IDENTITY_NAMESPACE, parts[0]);
attrs.put(CAPABILITY_TYPE_ATTRIBUTE, TYPE_FEATURE);
if (parts.length > 1) {
attrs.put(CAPABILITY_VERSION_ATTRIBUTE, VersionTable.getVersion(parts[1]));
}
return new CapabilityImpl(null, IDENTITY_NAMESPACE, dirs, attrs).toString();
}
use of org.apache.felix.utils.collections.StringArrayMap in project karaf by apache.
the class ResourceUtils method addIdentityRequirement.
public static RequirementImpl addIdentityRequirement(ResourceImpl resource, String name, String type, VersionRange range, boolean mandatory, boolean conditional) {
Map<String, String> dirs = new StringArrayMap<>((mandatory ? 0 : 1) + (conditional ? 1 : 0));
Map<String, Object> attrs = new StringArrayMap<>((name != null ? 1 : 0) + (type != null ? 1 : 0) + (range != null ? 1 : 0));
if (!mandatory) {
dirs.put(REQUIREMENT_RESOLUTION_DIRECTIVE, RESOLUTION_OPTIONAL);
}
if (conditional) {
dirs.put(REQUIREMENT_CONDITIONAL_DIRECTIVE, CONDITIONAL_TRUE);
}
if (name != null) {
attrs.put(IDENTITY_NAMESPACE, name);
}
if (type != null) {
attrs.put(CAPABILITY_TYPE_ATTRIBUTE, type);
}
if (range != null) {
attrs.put(CAPABILITY_VERSION_ATTRIBUTE, range);
}
RequirementImpl requirement = new RequirementImpl(resource, IDENTITY_NAMESPACE, dirs, attrs);
resource.addRequirement(requirement);
return requirement;
}
use of org.apache.felix.utils.collections.StringArrayMap in project karaf by apache.
the class ResourceUtils method addIdentityRequirement.
public static void addIdentityRequirement(ResourceImpl resource, Resource required, boolean mandatory) {
for (Capability cap : required.getCapabilities(null)) {
if (cap.getNamespace().equals(IDENTITY_NAMESPACE)) {
Map<String, Object> attributes = cap.getAttributes();
Map<String, String> dirs = new StringArrayMap<>(1);
dirs.put(REQUIREMENT_RESOLUTION_DIRECTIVE, mandatory ? RESOLUTION_MANDATORY : RESOLUTION_OPTIONAL);
Version version = (Version) attributes.get(CAPABILITY_VERSION_ATTRIBUTE);
Map<String, Object> attrs = new StringArrayMap<>(version != null ? 3 : 2);
attrs.put(IDENTITY_NAMESPACE, attributes.get(IDENTITY_NAMESPACE));
attrs.put(CAPABILITY_TYPE_ATTRIBUTE, attributes.get(CAPABILITY_TYPE_ATTRIBUTE));
if (version != null) {
attrs.put(CAPABILITY_VERSION_ATTRIBUTE, new VersionRange(version, true));
}
resource.addRequirement(new RequirementImpl(resource, IDENTITY_NAMESPACE, dirs, attrs));
}
}
}
use of org.apache.felix.utils.collections.StringArrayMap 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 StringArrayMap<>(cap.getDirectives()), new StringArrayMap<>(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 StringArrayMap<>(req.getDirectives()), new StringArrayMap<>(req.getAttributes()), sf));
}
return res;
}
Aggregations