Search in sources :

Example 1 with ComponentInfo

use of org.apache.aries.samples.goat.api.ComponentInfo in project aries by apache.

the class BundleContextInfoProvider method getComponentForId.

public ComponentInfo getComponentForId(String id) {
    if (biCache.containsKey(id)) {
        return biCache.get(id);
    }
    Bundle b = getBundleForIDKey(ctx, id);
    ComponentInfoImpl bii = new ComponentInfoImpl();
    bii.setId(getKeyForBundle(b));
    HashSet<Long> allDepSet = new HashSet<Long>();
    bii.setComponentProperties(new HashMap<String, String>());
    bii.getComponentProperties().put("BundleID", "" + b.getBundleId());
    bii.getComponentProperties().put("State", bundleStateToString(b.getState()));
    bii.getComponentProperties().put("SymbolicName", b.getSymbolicName());
    bii.getComponentProperties().put("Version", "" + b.getVersion());
    Enumeration<String> e = b.getHeaders().keys();
    while (e.hasMoreElements()) {
        String key = e.nextElement();
        if (!(key.equals("Import-Package") || key.equals("Export-Package"))) {
        //bii.getComponentProperties().put(key, String.valueOf(b.getHeaders().get(key)));
        }
    }
    bii.setChildren(new ArrayList<ComponentInfo>());
    biCache.put(id, bii);
    return bii;
}
Also used : ComponentInfoImpl(org.apache.aries.samples.goat.info.ComponentInfoImpl) Bundle(org.osgi.framework.Bundle) ComponentInfo(org.apache.aries.samples.goat.api.ComponentInfo) HashSet(java.util.HashSet)

Example 2 with ComponentInfo

use of org.apache.aries.samples.goat.api.ComponentInfo in project aries by apache.

the class DummyRelationshipProvider method getRelationships.

@Override
public List<RelationshipInfo> getRelationships() {
    ArrayList<RelationshipInfo> ris = new ArrayList<RelationshipInfo>();
    ComponentInfo ci1 = cip.getComponentForId("/root/1");
    ComponentInfo ci2 = cip.getComponentForId("/root/2");
    ComponentInfo ci3 = cip.getComponentForId("/root/3");
    RelationshipInfoImpl ri1 = new RelationshipInfoImpl();
    RelationshipInfoImpl ri2 = new RelationshipInfoImpl();
    RelationshipInfoImpl ri3 = new RelationshipInfoImpl();
    RelationshipInfoImpl ri4 = new RelationshipInfoImpl();
    RelationshipInfoImpl ri5 = new RelationshipInfoImpl();
    RelationshipInfoImpl ri6 = new RelationshipInfoImpl();
    ris.add(ri1);
    ris.add(ri2);
    ris.add(ri3);
    ris.add(ri4);
    ris.add(ri5);
    ris.add(ri6);
    ri1.setName("i.am.exported.by.1.and.used.by.2.and.3");
    ri1.setProvidedBy(ci1);
    ArrayList<ComponentInfo> c = new ArrayList<ComponentInfo>();
    c.add(ci2);
    c.add(ci3);
    ri1.setConsumedBy(c);
    ri1.setType("Package");
    ri2.setName("i.am.exported.by.1.and.used.by.3");
    ri2.setProvidedBy(ci1);
    c = new ArrayList<ComponentInfo>();
    c.add(ci3);
    ri2.setConsumedBy(c);
    ri2.setType("Package");
    ri3.setName("i.am.exported.by.2.and.used.by.3");
    ri3.setProvidedBy(ci2);
    c = new ArrayList<ComponentInfo>();
    c.add(ci3);
    ri3.setConsumedBy(c);
    ri3.setType("Package");
    ri4.setName("i.am.exported.by.3.and.used.by.2");
    ri4.setProvidedBy(ci3);
    c = new ArrayList<ComponentInfo>();
    c.add(ci2);
    ri4.setConsumedBy(c);
    ri4.setType("Package");
    ri5.setName("i.am.a.funky.service.from.3.used.by.2");
    ri5.setProvidedBy(ci3);
    c = new ArrayList<ComponentInfo>();
    c.add(ci2);
    ri5.setConsumedBy(c);
    ri5.setType("Service");
    ri6.setName("i.am.a.funky.service.from.1.used.by.2");
    ri6.setProvidedBy(ci1);
    c = new ArrayList<ComponentInfo>();
    c.add(ci2);
    ri6.setConsumedBy(c);
    ri6.setType("Service");
    return ris;
}
Also used : RelationshipInfo(org.apache.aries.samples.goat.api.RelationshipInfo) ArrayList(java.util.ArrayList) RelationshipInfoImpl(org.apache.aries.samples.goat.info.RelationshipInfoImpl) ComponentInfo(org.apache.aries.samples.goat.api.ComponentInfo)

Example 3 with ComponentInfo

use of org.apache.aries.samples.goat.api.ComponentInfo 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 4 with ComponentInfo

use of org.apache.aries.samples.goat.api.ComponentInfo in project aries by apache.

the class BundleContextInfoProvider method bundleChanged.

public void bundleChanged(BundleEvent arg0) {
    String id = getKeyForBundle(arg0.getBundle());
    if (biCache.containsKey(id)) {
        biCache.remove(id);
    }
    ComponentInfo bi = getComponentForId(getKeyForBundle(arg0.getBundle()));
    for (ComponentInfoListener bil : clisteners) {
        bil.updateComponent(bi);
    }
}
Also used : ComponentInfo(org.apache.aries.samples.goat.api.ComponentInfo)

Example 5 with ComponentInfo

use of org.apache.aries.samples.goat.api.ComponentInfo 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)10 RelationshipInfoImpl (org.apache.aries.samples.goat.info.RelationshipInfoImpl)6 RelationshipInfo (org.apache.aries.samples.goat.api.RelationshipInfo)5 ArrayList (java.util.ArrayList)3 Bundle (org.osgi.framework.Bundle)3 ServiceReference (org.osgi.framework.ServiceReference)3 RelationshipAspect (org.apache.aries.samples.goat.api.RelationshipAspect)2 HashSet (java.util.HashSet)1 ServletContext (javax.servlet.ServletContext)1 ComponentInfoProvider (org.apache.aries.samples.goat.api.ComponentInfoProvider)1 ModelInfoService (org.apache.aries.samples.goat.api.ModelInfoService)1 RelationshipInfoProvider (org.apache.aries.samples.goat.api.RelationshipInfoProvider)1 ComponentInfoImpl (org.apache.aries.samples.goat.info.ComponentInfoImpl)1 BundleContext (org.osgi.framework.BundleContext)1 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)1 ExportedPackage (org.osgi.service.packageadmin.ExportedPackage)1 PackageAdmin (org.osgi.service.packageadmin.PackageAdmin)1