in repository/service/src/main/java/org/apache/karaf/cave/repository/service/bundlerepository/XmlRepository.java [79:98]
protected void addResource(Resource resource) {
List<Capability> identities = resource.getCapabilities(IDENTITY_NAMESPACE);
if (identities.isEmpty()) {
throw new IllegalStateException("Invalid resource: a capability with 'osgi.identity' namespace is required");
} else if (identities.size() > 1) {
throw new IllegalStateException("Invalid resource: multiple 'osgi.identity' capabilities found");
}
Capability identity = identities.get(0);
Object name = identity.getAttributes().get(IDENTITY_NAMESPACE);
Object type = identity.getAttributes().get(CAPABILITY_TYPE_ATTRIBUTE);
Object vers = identity.getAttributes().get(CAPABILITY_VERSION_ATTRIBUTE);
if (!String.class.isInstance(name)
|| !String.class.isInstance(type)
|| !Version.class.isInstance(vers)) {
throw new IllegalStateException("Invalid osgi.identity capability: " + identity);
}
if (!hasResource((String) type, (String) name, (Version) vers)) {
super.addResource(resource);
}
}