Examples of ServiceDependencyHandler


Examples of org.apache.felix.ipojo.composite.service.instantiator.ServiceDependencyHandler

    /**
     * Build the list of available specifications.
     */
    private void computeAvailableServices() {
        // Get instantiated services :
        ServiceDependencyHandler handler = (ServiceDependencyHandler) getHandler(HandlerFactory.IPOJO_NAMESPACE + ":subservice");

        for (int i = 0; handler != null && i < handler.getInstances().size(); i++) {
            SvcInstance svc = (SvcInstance) handler.getInstances().get(i);
            String itf = svc.getServiceSpecification();
            boolean agg = svc.isAggregate();
            boolean opt = svc.isOptional();

            SpecificationMetadata specMeta = new SpecificationMetadata(itf, m_context, agg, opt, this);
            m_services.add(specMeta);
        }

        for (int i = 0; handler != null && i < handler.getRequirements().size(); i++) {
            ServiceImporter imp = (ServiceImporter) handler.getRequirements().get(i);
            String itf = imp.getSpecification().getName();
            boolean agg = imp.isAggregate();
            boolean opt = imp.isOptional();

            SpecificationMetadata specMeta = new SpecificationMetadata(itf, m_context, agg, opt, this);
View Full Code Here

Examples of org.apache.felix.ipojo.composite.service.instantiator.ServiceDependencyHandler

     * Look for the implementation (i.e. composite) requirement for the given service-level requirement metadata.
     * @param element : the service-level requirement metadata
     * @return the ServiceImporter object, null if not found or if the DependencyHandler is not plugged to the instance
     */
    private ServiceImporter getAttachedRequirement(Element element) {
        ServiceDependencyHandler handler = (ServiceDependencyHandler) getHandler(HandlerFactory.IPOJO_NAMESPACE + ":subservice");
        if (handler == null) { return null; }

        String identity = element.getAttribute("id");
        if (identity != null) {
            // Look for dependency Id
            for (int i = 0; i < handler.getRequirements().size(); i++) {
                ServiceImporter imp = (ServiceImporter) handler.getRequirements().get(i);
                if (imp.getId().equals(identity)) { return imp; }
            }
        }

        // If not found or no id, look for a dependency with the same specification
        String requirement = element.getAttribute("specification");
        for (int i = 0; i < handler.getRequirements().size(); i++) {
            ServiceImporter imp = (ServiceImporter) handler.getRequirements().get(i);
            if (imp.getId().equals(requirement) || imp.getSpecification().getName().equals(requirement)) { return imp; }
        }
        return null;
    }
View Full Code Here

Examples of org.apache.felix.ipojo.composite.service.instantiator.ServiceDependencyHandler

        String aggregate = elem.getAttribute("aggregate");
        boolean agg = aggregate != null && aggregate.equalsIgnoreCase("true");

        if (imp == null) {
            // Add the missing requirement
            ServiceDependencyHandler handler = (ServiceDependencyHandler) getHandler(HandlerFactory.IPOJO_NAMESPACE + ":subservice");
            if (handler == null) {
                // Look for the ServiceDependencyHandler factory
                HandlerManager handlerManager = null;
                try {
                    ServiceReference[] refs = m_context.getServiceReferences(Factory.class.getName(), "(&(handler.name=subservice)(handler.namespace=" + HandlerFactory.IPOJO_NAMESPACE + ")(handler.type=composite))");
                    Factory factory = (Factory) m_context.getService(refs[0]);
                    handlerManager = (HandlerManager) factory.createComponentInstance(null, getCompositeManager().getServiceContext());
                } catch (InvalidSyntaxException e) {
                    // Should not happen
                } catch (UnacceptableConfiguration e) {
                    // Should not happen
                } catch (MissingHandlerException e) {
                    // Should not happen
                } catch (ConfigurationException e) {
                    // Should not happen
                }
               
                // Add the required handler
                try {
                    handlerManager.init(getCompositeManager(), new Element("composite", ""), new Properties());
                } catch (ConfigurationException e) {
                    error("Internal error : cannot configure the Import Handler : " + e.getMessage());
                    throw new CompositionException("Internal error : cannot configure the Import Handler", e);
                }
                handler = (ServiceDependencyHandler) handlerManager.getHandler();
                getCompositeManager().addCompositeHandler(handlerManager);
            }

            String spec = elem.getAttribute("specification");
            String filter = "(&(objectClass=" + spec + ")(!(instance.name=" + getCompositeManager().getInstanceName() + ")))"; // Cannot import yourself
            String givenFilter = elem.getAttribute("filter");
            if (givenFilter != null) {
                filter = "(&" + filter + givenFilter + ")"; //NOPMD
            }

            BundleContext context = new PolicyServiceContext(getCompositeManager().getGlobalContext(), getCompositeManager().getParentServiceContext(), PolicyServiceContext.GLOBAL);

            Filter fil = null;
            try {
                fil = getCompositeManager().getGlobalContext().createFilter(filter);
            } catch (InvalidSyntaxException e) {
                throw new CompositionException("A required filter " + filter + " is malformed", e);
            }

            Class specToImport = null;
            try {
                specToImport = getCompositeManager().getGlobalContext().getBundle().loadClass(spec);
            } catch (ClassNotFoundException e) {
                throw new CompositionException("A required specification cannot be loaded : " + spec, e);
            }

            ServiceImporter importer = new ServiceImporter(specToImport, fil, agg, opt, null, DependencyModel.DYNAMIC_BINDING_POLICY, context, null, handler);

            handler.getRequirements().add(importer);
            SpecificationMetadata specMeta = new SpecificationMetadata(spec, m_context, agg, opt, this);
            m_services.add(specMeta); // Update the available types
            return;
        }
View Full Code Here

Examples of org.apache.felix.ipojo.composite.service.instantiator.ServiceDependencyHandler

    /**
     * Build the list of available specifications.
     */
    private void computeAvailableServices() {
        // Get instantiated services :
        ServiceDependencyHandler handler = (ServiceDependencyHandler) getHandler(HandlerFactory.IPOJO_NAMESPACE + ":subservice");

        for (int i = 0; handler != null && i < handler.getInstances().size(); i++) {
            SvcInstance svc = (SvcInstance) handler.getInstances().get(i);
            String itf = svc.getServiceSpecification();
            boolean agg = svc.isAggregate();
            boolean opt = svc.isOptional();

            SpecificationMetadata specMeta = new SpecificationMetadata(itf, m_context, agg, opt, this);
            m_services.add(specMeta);
        }

        for (int i = 0; handler != null && i < handler.getRequirements().size(); i++) {
            ServiceImporter imp = (ServiceImporter) handler.getRequirements().get(i);
            String itf = imp.getSpecification().getName();
            boolean agg = imp.isAggregate();
            boolean opt = imp.isOptional();

            SpecificationMetadata specMeta = new SpecificationMetadata(itf, m_context, agg, opt, this);
View Full Code Here

Examples of org.apache.felix.ipojo.composite.service.instantiator.ServiceDependencyHandler

     * Look for the implementation (i.e. composite) requirement for the given service-level requirement metadata.
     * @param element : the service-level requirement metadata
     * @return the ServiceImporter object, null if not found or if the DependencyHandler is not plugged to the instance
     */
    private ServiceImporter getAttachedRequirement(Element element) {
        ServiceDependencyHandler handler = (ServiceDependencyHandler) getHandler(HandlerFactory.IPOJO_NAMESPACE + ":subservice");
        if (handler == null) { return null; }

        String identity = element.getAttribute("id");
        if (identity != null) {
            // Look for dependency Id
            for (int i = 0; i < handler.getRequirements().size(); i++) {
                ServiceImporter imp = (ServiceImporter) handler.getRequirements().get(i);
                if (imp.getId().equals(identity)) { return imp; }
            }
        }

        // If not found or no id, look for a dependency with the same specification
        String requirement = element.getAttribute("specification");
        for (int i = 0; i < handler.getRequirements().size(); i++) {
            ServiceImporter imp = (ServiceImporter) handler.getRequirements().get(i);
            if (imp.getId().equals(requirement) || imp.getSpecification().getName().equals(requirement)) { return imp; }
        }
        return null;
    }
View Full Code Here

Examples of org.apache.felix.ipojo.composite.service.instantiator.ServiceDependencyHandler

        String aggregate = elem.getAttribute("aggregate");
        boolean agg = aggregate != null && aggregate.equalsIgnoreCase("true");

        if (imp == null) {
            // Add the missing requirement
            ServiceDependencyHandler handler = (ServiceDependencyHandler) getHandler(HandlerFactory.IPOJO_NAMESPACE + ":subservice");
            if (handler == null) {
                // Look for the ServiceDependencyHandler factory
                HandlerManager handlerManager = null;
                try {
                    ServiceReference[] refs = m_context.getServiceReferences(Factory.class.getName(), "(&(handler.name=subservice)(handler.namespace=" + HandlerFactory.IPOJO_NAMESPACE + ")(handler.type=composite))");
                    Factory factory = (Factory) m_context.getService(refs[0]);
                    handlerManager = (HandlerManager) factory.createComponentInstance(null, getCompositeManager().getServiceContext());
                } catch (InvalidSyntaxException e) {
                    // Should not happen
                } catch (UnacceptableConfiguration e) {
                    // Should not happen
                } catch (MissingHandlerException e) {
                    // Should not happen
                } catch (ConfigurationException e) {
                    // Should not happen
                }
               
                // Add the required handler
                try {
                    handlerManager.init(getCompositeManager(), new Element("composite", ""), new Properties());
                } catch (ConfigurationException e) {
                    error("Internal error : cannot configure the Import Handler : " + e.getMessage());
                    throw new CompositionException("Internal error : cannot configure the Import Handler : " + e.getMessage());
                }
                handler = (ServiceDependencyHandler) handlerManager.getHandler();
                getCompositeManager().addCompositeHandler(handlerManager);
            }

            String spec = elem.getAttribute("specification");
            String filter = "(&(objectClass=" + spec + ")(!(instance.name=" + getCompositeManager().getInstanceName() + ")))"; // Cannot import yourself
            String givenFilter = elem.getAttribute("filter");
            if (givenFilter != null) {
                filter = "(&" + filter + givenFilter + ")"; //NOPMD
            }

            BundleContext context = new PolicyServiceContext(getCompositeManager().getGlobalContext(), getCompositeManager().getParentServiceContext(), PolicyServiceContext.GLOBAL);

            Filter fil = null;
            try {
                fil = getCompositeManager().getGlobalContext().createFilter(filter);
            } catch (InvalidSyntaxException e) {
                throw new CompositionException("A required filter " + filter + " is malformed : " + e.getMessage());
            }

            Class specToImport = null;
            try {
                specToImport = getCompositeManager().getGlobalContext().getBundle().loadClass(spec);
            } catch (ClassNotFoundException e) {
                throw new CompositionException("A required specification cannot be loaded : " + spec);
            }

            ServiceImporter importer = new ServiceImporter(specToImport, fil, agg, opt, null, DependencyModel.DYNAMIC_BINDING_POLICY, context, null, handler);

            handler.getRequirements().add(importer);
            SpecificationMetadata specMeta = new SpecificationMetadata(spec, m_context, agg, opt, this);
            m_services.add(specMeta); // Update the available types
            return;
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.