use of org.apache.aries.samples.goat.api.RelationshipAspect in project aries by apache.
the class BundleContextInfoProvider method getRelationships.
@Override
public List<RelationshipInfo> getRelationships() {
ArrayList<RelationshipInfo> r = new ArrayList<RelationshipInfo>();
Bundle[] bundles = ctx.getBundles();
PackageAdmin pa = (PackageAdmin) ctx.getService(ctx.getServiceReference(PackageAdmin.class.getName().toString()));
if (bundles != null && bundles.length != 0) {
for (Bundle b : bundles) {
String bkey = getKeyForBundle(b);
ComponentInfo ci = getComponentForId(bkey);
// add all the packages..
// we only add exports, as imports are implied in the reverse
ExportedPackage[] eps = pa.getExportedPackages(b);
if (eps != null && eps.length != 0) {
for (ExportedPackage ep : eps) {
RelationshipInfoImpl ri = new RelationshipInfoImpl();
ri.setProvidedBy(ci);
ri.setType("Package");
ri.setName(ep.getName());
ri.setRelationshipAspects(new ArrayList<RelationshipAspect>());
ri.setConsumedBy(new ArrayList<ComponentInfo>());
// TODO: add versioning aspect.
Bundle[] imps = ep.getImportingBundles();
if (imps != null && imps.length != 0) {
for (Bundle imp : imps) {
ri.getConsumedBy().add(getComponentForId(getKeyForBundle(imp)));
}
}
r.add(ri);
}
}
// add all the services..
// we only add registered services, as ones in use are handled in the reverse
ServiceReference[] srs = b.getRegisteredServices();
if (srs != null && srs.length != 0) {
for (ServiceReference sr : srs) {
RelationshipInfoImpl ri = getRIforSR(sr);
ri.setProvidedBy(ci);
r.add(ri);
}
}
}
}
return r;
}
use of org.apache.aries.samples.goat.api.RelationshipAspect in project aries by apache.
the class BundleContextInfoProvider method getRIforSR.
private RelationshipInfoImpl getRIforSR(ServiceReference sr) {
RelationshipInfoImpl ri = new RelationshipInfoImpl();
ri.setType("Service");
String serviceNames = "";
String[] objectClasses = (String[]) sr.getProperty("objectClass");
if (objectClasses != null) {
for (String objectClass : objectClasses) {
serviceNames += "," + objectClass;
}
}
if (serviceNames.length() > 1) {
serviceNames = serviceNames.substring(1);
}
ri.setName(serviceNames);
ri.setRelationshipAspects(new ArrayList<RelationshipAspect>());
// TODO: add service parameters
ri.setConsumedBy(new ArrayList<ComponentInfo>());
Bundle[] using = sr.getUsingBundles();
if (using != null && using.length != 0) {
for (Bundle u : using) {
ri.getConsumedBy().add(getComponentForId(getKeyForBundle(u)));
}
}
return ri;
}
Aggregations