Search in sources :

Example 1 with ModelInfoService

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

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

the class ServiceInterceptor method registerServiceEnhancer.

@SuppressWarnings({ "rawtypes", "unchecked" })
private void registerServiceEnhancer(ServiceReference reference) {
    Object actualService = ctx.getService(reference);
    if (actualService instanceof ModelInfoService) {
        ModelInfoService infoService = (ModelInfoService) actualService;
        Object serviceId = reference.getProperty(SERVICE_ID);
        Object enhancer = new ModelInfoEnhancerService(infoService);
        Dictionary properties = new Hashtable();
        Object originalDisplayName = reference.getProperty(DISPLAY_NAME);
        properties.put(DISPLAY_NAME, originalDisplayName + " [enhanced]");
        ServiceRegistration registration = ctx.registerService(ModelInfoService.class.getName(), enhancer, properties);
        registrations.put(serviceId + "", registration);
    } else {
        System.out.println("Oh dear - unexpected service " + actualService.getClass());
    }
}
Also used : Dictionary(java.util.Dictionary) Hashtable(java.util.Hashtable) ModelInfoService(org.apache.aries.samples.goat.api.ModelInfoService) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Aggregations

ModelInfoService (org.apache.aries.samples.goat.api.ModelInfoService)2 Dictionary (java.util.Dictionary)1 Hashtable (java.util.Hashtable)1 ServletContext (javax.servlet.ServletContext)1 ComponentInfo (org.apache.aries.samples.goat.api.ComponentInfo)1 ComponentInfoProvider (org.apache.aries.samples.goat.api.ComponentInfoProvider)1 RelationshipInfo (org.apache.aries.samples.goat.api.RelationshipInfo)1 RelationshipInfoProvider (org.apache.aries.samples.goat.api.RelationshipInfoProvider)1 BundleContext (org.osgi.framework.BundleContext)1 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)1 ServiceReference (org.osgi.framework.ServiceReference)1 ServiceRegistration (org.osgi.framework.ServiceRegistration)1