Package org.apache.felix.ipojo

Examples of org.apache.felix.ipojo.Factory


     * @param name the factory name
     * @throws IOException if the json object cannot be written.
     */
    private void getFactoryDetail(PrintWriter pw, String name) throws IOException{
        // Find the factory
        Factory factory = null;
        for (Factory fact : m_factories) {
            if (fact.getName().equals(name)) {
                factory = fact;
            }
        }
       
        if (factory == null) {
            // This will be used a error message (cannot be interpreted as json)
            pw.println("The factory " + name + " does not exist or is private");
            return;
        }
       
        try {
            JSONObject resp = new JSONObject();
           
            // Statline.
            resp.put("count", m_factories.size());
            resp.put("valid_count", StateUtils.getValidFactoriesCount(m_factories));
            resp.put("invalid_count", StateUtils.getInvalidFactoriesCount(m_factories));
            // End of the statline
           
            // Factory object
            JSONObject data = new JSONObject();
            data.put("name", factory.getName());
            data.put("state", StateUtils.getFactoryState(factory.getState()));
           
            String bundle = factory.getBundleContext().getBundle().getSymbolicName()
            + " (" + factory.getBundleContext().getBundle().getBundleId() + ")";
            data.put("bundle", bundle);
           
            // Provided service specifications
            if (factory.getComponentDescription().getprovidedServiceSpecification().length != 0) {
                JSONArray services = new JSONArray
                    (Arrays.asList(factory.getComponentDescription().getprovidedServiceSpecification()));
                data.put("services", services);
            }
           
            // Properties
            PropertyDescription[] props = factory.getComponentDescription().getProperties();
            if (props != null  && props.length != 0) {
                JSONArray properties = new JSONArray();
                for (int i = 0; i < props.length; i++) {
                    JSONObject prop = new JSONObject();
                    prop.put("name", props[i].getName());
                    prop.put("type", props[i].getType());
                    prop.put("mandatory", props[i].isMandatory());
                    prop.put("immutable", props[i].isImmutable());
                    if (props[i].getValue() != null) {
                        prop.put("value", props[i].getValue());
                    }
                    properties.put(prop);
                }
                data.put("properties", properties);
            }
           
            if (! factory.getRequiredHandlers().isEmpty()) {
                JSONArray req = new JSONArray
                    (factory.getRequiredHandlers());
                data.put("requiredHandlers", req);
            }
           
            if (! factory.getMissingHandlers().isEmpty()) {
                JSONArray req = new JSONArray
                    (factory.getMissingHandlers());
                data.put("missingHandlers", req);
            }
           
            List<?> instances = StateUtils.getInstanceList(m_archs, name);
            if (! instances.isEmpty()) {
                JSONArray req = new JSONArray(instances);
                data.put("instances", req);
            }
           
            data.put("architecture", factory.getDescription().toString());
            resp.put("data", data);
           
            pw.print(resp.toString());
        } catch (JSONException e) {
            // Propagate the exception.
View Full Code Here


        String factName = "Manipulation-FooProviderType-1";
        String compName = "FooProvider-1";
        ServiceReference ref = null;

        // Get the factory to create a component instance
        Factory fact = ipojoHelper.getFactory(factName);
        assertNotNull("Cannot find the factory FooProvider-1", fact);

        Properties props = new Properties();
        props.put("instance.name", compName);
        ComponentInstance ci = null;
        try {
            ci = fact.createComponentInstance(props);
        } catch (Exception e1) {
            fail(e1.getMessage());
        }

        assertEquals("Check instance name", compName, ci.getInstanceName());
View Full Code Here

       * Get the registered factories and bind all factories matching the specification
       */
      ServiceReference[] factoryReferences = searchFactories(null);
      for (ServiceReference factoryReference : factoryReferences != null ? factoryReferences : new ServiceReference[0]) {
       
        Factory factory = (Factory) context.getService(factoryReference);
       
        if (factory != null && isEligible(factory) && matchingScore((IPojoFactory)factory, specification) > 0) {
          factoryBound((IPojoFactory)factory,specification);
        }
       
View Full Code Here

        // verify component's factory is here
        // verify BazService has been published
        // --> verify instance has been created

        Factory factory = ipojoHelper.getFactory(FACTORY_NAME);
        assertNotNull(factory);
        assertEquals(Factory.VALID, factory.getState());


        List<HandlerBindingTestService> services = osgiHelper.getServiceObjects(HandlerBindingTestService.class);
        assertEquals(1, services.size());
View Full Code Here

        // verify component's factory is here
        // verify BazService has been published
        // --> verify instance has been created

        Factory factory = ipojoHelper.getFactory(BAZ_FACTORY_NAME);
        Assert.assertNotNull(factory);
        assertEquals(Factory.VALID, factory.getState());


        List<BazService> services = osgiHelper.getServiceObjects(BazService.class);
        assertEquals(1, services.size());
View Full Code Here

        // verify component's factory is here
        // verify that the requires handler has been activated
        // verify that a created instance works

        Factory factory = ipojoHelper.getFactory(MB_FACTORY_NAME);
        Assert.assertNotNull(factory);
        assertEquals(Factory.VALID, factory.getState());

        assertTrue(factory.getRequiredHandlers().contains("org.apache.felix.ipojo:requires"));

        ComponentInstance instance = ipojoHelper.createComponentInstance(MB_FACTORY_NAME, "stereotype-multibind-instance");
        assertTrue(ipojoHelper.isInstanceValid(instance));

        ipojoHelper.dispose();
View Full Code Here

     * @param name the factory name
     * @throws IOException if the json object cannot be written.
     */
    private void getFactoryDetail(PrintWriter pw, String name) throws IOException{
        // Find the factory
        Factory factory = null;
        for (Factory fact : m_factories) {
            if (fact.getName().equals(name)) {
                factory = fact;
            }
        }
       
        if (factory == null) {
            // This will be used a error message (cannot be interpreted as json)
            pw.println("The factory " + name + " does not exist or is private");
            return;
        }
       
        try {
            JSONObject resp = new JSONObject();
           
            // Statline.
            resp.put("count", m_factories.size());
            resp.put("valid_count", StateUtils.getValidFactoriesCount(m_factories));
            resp.put("invalid_count", StateUtils.getInvalidFactoriesCount(m_factories));
            // End of the statline
           
            // Factory object
            JSONObject data = new JSONObject();
            data.put("name", factory.getName());
            data.put("state", StateUtils.getFactoryState(factory.getState()));
           
            String bundle = factory.getBundleContext().getBundle().getSymbolicName()
            + " (" + factory.getBundleContext().getBundle().getBundleId() + ")";
            data.put("bundle", bundle);
           
            // Provided service specifications
            if (factory.getComponentDescription().getprovidedServiceSpecification().length != 0) {
                JSONArray services = new JSONArray
                    (Arrays.asList(factory.getComponentDescription().getprovidedServiceSpecification()));
                data.put("services", services);
            }
           
            // Properties
            PropertyDescription[] props = factory.getComponentDescription().getProperties();
            if (props != null  && props.length != 0) {
                JSONArray properties = new JSONArray();
                for (int i = 0; i < props.length; i++) {
                    JSONObject prop = new JSONObject();
                    prop.put("name", props[i].getName());
                    prop.put("type", props[i].getType());
                    prop.put("mandatory", props[i].isMandatory());
                    prop.put("immutable", props[i].isImmutable());
                    if (props[i].getValue() != null) {
                        prop.put("value", props[i].getValue());
                    }
                    properties.put(prop);
                }
                data.put("properties", properties);
            }
           
            if (! factory.getRequiredHandlers().isEmpty()) {
                JSONArray req = new JSONArray
                    (factory.getRequiredHandlers());
                data.put("requiredHandlers", req);
            }
           
            if (! factory.getMissingHandlers().isEmpty()) {
                JSONArray req = new JSONArray
                    (factory.getMissingHandlers());
                data.put("missingHandlers", req);
            }
           
            List<?> instances = StateUtils.getInstanceList(m_archs, name);
            if (! instances.isEmpty()) {
                JSONArray req = new JSONArray(instances);
                data.put("instances", req);
            }
           
            data.put("architecture", factory.getDescription().toString());
            resp.put("data", data);
           
            pw.print(resp.toString());
        } catch (JSONException e) {
            // Propagate the exception.
View Full Code Here

*/
public class IPojoTestUtils {

    public static ComponentInstance getComponentInstance(BundleContext bc,
            String factoryName, Dictionary configuration) {
        Factory fact = getFactoryByName(bc, factoryName);

        if (fact == null) {
            System.err.println("Factory " + factoryName + " not found");
            return null;
        }

        try {
            return fact.createComponentInstance(configuration);
        } catch (Exception e) {
            System.err.println("Cannot create the instance from " + factoryName
                    + " : " + e.getMessage());
            e.printStackTrace();
            return null;
View Full Code Here

        }
    }

    public static ComponentInstance getComponentInstance(ServiceContext bc,
            String factoryName, Dictionary configuration) {
        Factory fact = getFactoryByName(bc, factoryName);

        if (fact == null) {
            return null;
        }

        if (fact.isAcceptable(configuration)) {
            try {
                return fact.createComponentInstance(configuration);
            } catch (Exception e) {
                System.err.println(e.getMessage());
                e.printStackTrace();
                return null;
            }
View Full Code Here

        }
    }

    public static ComponentInstance getComponentInstanceByName(
            BundleContext bc, String factoryName, String name) {
        Factory fact = getFactoryByName(bc, factoryName);

        if (fact == null) {
            System.err.println("Factory " + factoryName + " not found");
            return null;
        }

        try {
            Properties props = new Properties();
            props.put("instance.name",name);
            return fact.createComponentInstance(props);
        } catch (Exception e) {
            System.err.println("Cannot create the instance from " + factoryName
                    + " : " + e.getMessage());
            e.printStackTrace();
            return null;
View Full Code Here

TOP

Related Classes of org.apache.felix.ipojo.Factory

Copyright © 2018 www.massapicom. 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.