Search in sources :

Example 1 with RelationshipInfo

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

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

the class ModelInfoEnhancerService method removeRelationship.

@Override
public void removeRelationship(RelationshipInfo r) {
    if (SERVICE.equals(r.getType())) {
        removeSyntheticServiceArtefactsAndNotifyListeners(r);
    } else {
        // We don't want to track this relationship anymore
        String id = constructId(r);
        RelationshipInfo relationship = relationships.get(id);
        relationships.remove(id);
        if (relationship != null) {
            // This shouldn't affect us, but pass it on to our listeners
            for (RelationshipInfoListener listener : rlisteners) {
                listener.removeRelationship(relationship);
            }
        }
    }
}
Also used : RelationshipInfo(org.apache.aries.samples.goat.api.RelationshipInfo)

Example 3 with RelationshipInfo

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

the class ServerSideClass method getInitialComponents.

/**
 * this is invoked by a page onload.. so until it's invoked.. we dont care
 * about components
 */
public void getInitialComponents(String dataProvider) {
    System.err.println("GET INITIAL BUNDLES ASKED TO USE DATAPROVIDER " + dataProvider);
    if (dataProvider == null)
        throw new IllegalArgumentException("Unable to accept 'null' as a dataProvider");
    // do we need to update?
    if (!this.modelInfoServiceHint.equals(dataProvider)) {
        this.modelInfoServiceHint = dataProvider;
        if (!(this.ModelInfoService == null)) {
            // we already had a provider.. we need to shut down the existing
            // components & relationships in the browsers..
            addFunctionCall("forgetAboutEverything");
        }
        ServletContext context = org.directwebremoting.ServerContextFactory.get().getServletContext();
        Object o = context.getAttribute("osgi-bundlecontext");
        if (o != null) {
            if (o instanceof BundleContext) {
                BundleContext b_ctx = (BundleContext) o;
                System.err.println("Looking up bcip");
                try {
                    ServiceReference[] sr = b_ctx.getServiceReferences(ModelInfoService.class.getName(), "(displayName=" + this.modelInfoServiceHint + ")");
                    if (sr != null) {
                        System.err.println("Getting bcip");
                        this.ModelInfoService = (ModelInfoService) b_ctx.getService(sr[0]);
                        System.err.println("Got bcip " + this.ModelInfoService);
                    } else {
                        System.err.println("UNABLE TO FIND BCIP!!");
                        System.err.println("UNABLE TO FIND BCIP!!");
                        System.err.println("UNABLE TO FIND BCIP!!");
                    }
                } catch (InvalidSyntaxException ise) {
                }
                if (this.ModelInfoService != null) {
                    if (!rlisteners.containsKey(this.ModelInfoService)) {
                        RelationshipInfoProvider.RelationshipInfoListener rl = new RelationshipInfoListenerImpl(this.modelInfoServiceHint);
                        rlisteners.put(this.ModelInfoService, rl);
                        this.ModelInfoService.getRelationshipInfoProvider().registerRelationshipInfoListener(rl);
                    }
                    if (!clisteners.containsKey(this.ModelInfoService)) {
                        ComponentInfoProvider.ComponentInfoListener cl = new ComponentInfoListenerImpl(this.modelInfoServiceHint);
                        clisteners.put(this.ModelInfoService, cl);
                        this.ModelInfoService.getComponentInfoProvider().registerComponentInfoListener(cl);
                    }
                }
            }
        }
    }
    Collection<ComponentInfo> bis = this.ModelInfoService.getComponentInfoProvider().getComponents();
    System.err.println("Got " + (bis == null ? "null" : bis.size()) + " components back from the provider ");
    if (bis != null) {
        for (ComponentInfo b : bis) {
            System.err.println("Adding Component .. " + b.getId());
            addFunctionCall("addComponent", b);
        }
    }
    Collection<RelationshipInfo> ris = this.ModelInfoService.getRelationshipInfoProvider().getRelationships();
    System.err.println("Got " + (ris == null ? "null" : ris.size()) + " relationships back from the provider ");
    if (ris != null) {
        for (RelationshipInfo r : ris) {
            System.err.println("Adding relationship type " + r.getType() + " called " + r.getName() + " from " + r.getProvidedBy().getId());
            addFunctionCall("addRelationship", r);
        }
    }
}
Also used : RelationshipInfoProvider(org.apache.aries.samples.goat.api.RelationshipInfoProvider) ComponentInfoProvider(org.apache.aries.samples.goat.api.ComponentInfoProvider) ServiceReference(org.osgi.framework.ServiceReference) ModelInfoService(org.apache.aries.samples.goat.api.ModelInfoService) RelationshipInfo(org.apache.aries.samples.goat.api.RelationshipInfo) ServletContext(javax.servlet.ServletContext) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) ComponentInfo(org.apache.aries.samples.goat.api.ComponentInfo) BundleContext(org.osgi.framework.BundleContext)

Example 4 with RelationshipInfo

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

use of org.apache.aries.samples.goat.api.RelationshipInfo 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)

Aggregations

RelationshipInfo (org.apache.aries.samples.goat.api.RelationshipInfo)6 ComponentInfo (org.apache.aries.samples.goat.api.ComponentInfo)5 ArrayList (java.util.ArrayList)3 RelationshipInfoImpl (org.apache.aries.samples.goat.info.RelationshipInfoImpl)3 ServiceReference (org.osgi.framework.ServiceReference)2 ServletContext (javax.servlet.ServletContext)1 ComponentInfoProvider (org.apache.aries.samples.goat.api.ComponentInfoProvider)1 ModelInfoService (org.apache.aries.samples.goat.api.ModelInfoService)1 RelationshipAspect (org.apache.aries.samples.goat.api.RelationshipAspect)1 RelationshipInfoProvider (org.apache.aries.samples.goat.api.RelationshipInfoProvider)1 Bundle (org.osgi.framework.Bundle)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