Search in sources :

Example 1 with RelationshipAspect

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;
}
Also used : Bundle(org.osgi.framework.Bundle) ArrayList(java.util.ArrayList) ServiceReference(org.osgi.framework.ServiceReference) RelationshipInfo(org.apache.aries.samples.goat.api.RelationshipInfo) PackageAdmin(org.osgi.service.packageadmin.PackageAdmin) ExportedPackage(org.osgi.service.packageadmin.ExportedPackage) RelationshipAspect(org.apache.aries.samples.goat.api.RelationshipAspect) RelationshipInfoImpl(org.apache.aries.samples.goat.info.RelationshipInfoImpl) ComponentInfo(org.apache.aries.samples.goat.api.ComponentInfo)

Example 2 with RelationshipAspect

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;
}
Also used : Bundle(org.osgi.framework.Bundle) RelationshipAspect(org.apache.aries.samples.goat.api.RelationshipAspect) RelationshipInfoImpl(org.apache.aries.samples.goat.info.RelationshipInfoImpl) ComponentInfo(org.apache.aries.samples.goat.api.ComponentInfo)

Aggregations

ComponentInfo (org.apache.aries.samples.goat.api.ComponentInfo)2 RelationshipAspect (org.apache.aries.samples.goat.api.RelationshipAspect)2 RelationshipInfoImpl (org.apache.aries.samples.goat.info.RelationshipInfoImpl)2 Bundle (org.osgi.framework.Bundle)2 ArrayList (java.util.ArrayList)1 RelationshipInfo (org.apache.aries.samples.goat.api.RelationshipInfo)1 ServiceReference (org.osgi.framework.ServiceReference)1 ExportedPackage (org.osgi.service.packageadmin.ExportedPackage)1 PackageAdmin (org.osgi.service.packageadmin.PackageAdmin)1