use of org.apache.felix.bundlerepository.Capability in project aries by apache.
the class FelixCapabilityAdapterTest method testOsgiWiringBundleNamespace.
@Test
public void testOsgiWiringBundleNamespace() {
Capability cap = EasyMock.createNiceMock(Capability.class);
EasyMock.expect(cap.getName()).andReturn(Capability.BUNDLE);
EasyMock.replay(cap);
FelixCapabilityAdapter adapter = new FelixCapabilityAdapter(cap, EasyMock.createNiceMock(org.osgi.resource.Resource.class));
assertEquals("Wrong namespace", BundleNamespace.BUNDLE_NAMESPACE, adapter.getNamespace());
}
use of org.apache.felix.bundlerepository.Capability in project aries by apache.
the class FelixCapabilityAdapterTest method testOsgiWiringPackageAttribute.
@Test
public void testOsgiWiringPackageAttribute() {
String pkg = "com.foo.Bar";
Capability cap = EasyMock.createNiceMock(Capability.class);
EasyMock.expect(cap.getName()).andReturn(Capability.PACKAGE).anyTimes();
Map<String, Object> props = new HashMap<String, Object>();
props.put(Capability.PACKAGE, pkg);
EasyMock.expect(cap.getPropertiesAsMap()).andReturn(props);
EasyMock.replay(cap);
FelixCapabilityAdapter adapter = new FelixCapabilityAdapter(cap, EasyMock.createNiceMock(org.osgi.resource.Resource.class));
assertEquals("Wrong value for attribute " + PackageNamespace.PACKAGE_NAMESPACE, pkg, adapter.getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE));
}
use of org.apache.felix.bundlerepository.Capability in project aries by apache.
the class FelixCapabilityAdapterTest method testObjectClassAttribute.
@Test
public void testObjectClassAttribute() {
String objectClass = "com.foo.Bar";
Capability cap = EasyMock.createNiceMock(Capability.class);
EasyMock.expect(cap.getName()).andReturn(Capability.SERVICE);
Map<String, Object> props = new HashMap<String, Object>();
props.put(ServiceNamespace.CAPABILITY_OBJECTCLASS_ATTRIBUTE.toLowerCase(), objectClass);
EasyMock.expect(cap.getPropertiesAsMap()).andReturn(props);
EasyMock.replay(cap);
FelixCapabilityAdapter adapter = new FelixCapabilityAdapter(cap, EasyMock.createNiceMock(org.osgi.resource.Resource.class));
assertEquals("Wrong value for attribute " + ServiceNamespace.CAPABILITY_OBJECTCLASS_ATTRIBUTE, objectClass, adapter.getAttributes().get(ServiceNamespace.CAPABILITY_OBJECTCLASS_ATTRIBUTE));
}
use of org.apache.felix.bundlerepository.Capability in project karaf by apache.
the class FindCommand method printResource.
private void printResource(PrintStream out, Resource resource) {
String name = resource.getPresentationName();
if (name == null) {
name = resource.getSymbolicName();
}
printUnderline(out, name.length());
out.println(name);
printUnderline(out, name.length());
Map map = resource.getProperties();
for (Object o : map.entrySet()) {
Map.Entry entry = (Map.Entry) o;
if (entry.getValue().getClass().isArray()) {
out.println(entry.getKey() + ":");
for (int j = 0; j < Array.getLength(entry.getValue()); j++) {
out.println(" " + Array.get(entry.getValue(), j));
}
} else {
out.println(entry.getKey() + ": " + entry.getValue());
}
}
Requirement[] reqs = resource.getRequirements();
if ((reqs != null) && (reqs.length > 0)) {
boolean hdr = false;
for (Requirement req : reqs) {
if (!req.isOptional()) {
if (!hdr) {
hdr = true;
out.println("Requirements:");
}
out.println(" " + req.getName() + ":" + req.getFilter());
}
}
hdr = false;
for (Requirement req : reqs) {
if (req.isOptional()) {
if (!hdr) {
hdr = true;
out.println("Optional Requirements:");
}
out.println(" " + req.getName() + ":" + req.getFilter());
}
}
}
Capability[] caps = resource.getCapabilities();
if ((caps != null) && (caps.length > 0)) {
out.println("Capabilities:");
for (Capability cap : caps) {
out.println(" " + cap.getName() + ":" + cap.getPropertiesAsMap());
}
}
}
use of org.apache.felix.bundlerepository.Capability in project karaf by apache.
the class InfoCommand method printResource.
private void printResource(PrintStream out, Resource resource) {
// OBR R5 per Spec has no presentation name
String resourceId = getResourceId(resource);
printUnderline(out, resourceId.length());
out.println(resourceId);
printUnderline(out, resourceId.length());
Map map = resource.getProperties();
for (Object o : map.entrySet()) {
Map.Entry entry = (Map.Entry) o;
if (entry.getValue().getClass().isArray()) {
out.println(entry.getKey() + ":");
for (int j = 0; j < Array.getLength(entry.getValue()); j++) {
out.println(" " + Array.get(entry.getValue(), j));
}
} else {
out.println(entry.getKey() + ": " + entry.getValue());
}
}
Requirement[] reqs = resource.getRequirements();
if ((reqs != null) && (reqs.length > 0)) {
out.println("Requires:");
for (Requirement req : reqs) {
out.println(" " + req.getName() + ":" + req.getFilter());
}
}
Capability[] caps = resource.getCapabilities();
if ((caps != null) && (caps.length > 0)) {
out.println("Capabilities:");
for (Capability cap : caps) {
out.println(" " + cap.getName() + ":" + cap.getPropertiesAsMap());
}
}
}
Aggregations