aQute.bnd.osgi.resource.ResourceImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bnd Show documentation
Show all versions of bnd Show documentation
A command line utility and Ant plugin to wrap, build, or examine bundles.
package aQute.bnd.osgi.resource;
import java.util.*;
import org.osgi.framework.namespace.*;
import org.osgi.resource.*;
class ResourceImpl implements Resource {
private List allCapabilities;
private Map> capabilityMap;
private List allRequirements;
private Map> requirementMap;
void setCapabilities(List capabilities) {
allCapabilities = capabilities;
capabilityMap = new HashMap>();
for (Capability capability : capabilities) {
List list = capabilityMap.get(capability.getNamespace());
if (list == null) {
list = new LinkedList();
capabilityMap.put(capability.getNamespace(), list);
}
list.add(capability);
}
}
public List getCapabilities(String namespace) {
return namespace == null ? allCapabilities : capabilityMap.get(namespace);
}
void setRequirements(List requirements) {
allRequirements = requirements;
requirementMap = new HashMap>();
for (Requirement requirement : requirements) {
List list = requirementMap.get(requirement.getNamespace());
if (list == null) {
list = new LinkedList();
requirementMap.put(requirement.getNamespace(), list);
}
list.add(requirement);
}
}
public List getRequirements(String namespace) {
return namespace == null ? allRequirements : requirementMap.get(namespace);
}
@Override
public String toString() {
final StringBuilder builder = new StringBuilder();
List identities = getCapabilities(IdentityNamespace.IDENTITY_NAMESPACE);
if (identities != null && identities.size() == 1) {
Capability idCap = identities.get(0);
Object id = idCap.getAttributes().get(IdentityNamespace.IDENTITY_NAMESPACE);
Object version = idCap.getAttributes().get(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE);
builder.append(id).append(" ver=").append(version);
} else {
// Generic toString
builder.append("ResourceImpl [caps=");
builder.append(allCapabilities);
builder.append(", reqs=");
builder.append(allRequirements);
builder.append("]");
}
return builder.toString();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy