Search in sources :

Example 21 with ComponentFactory

use of org.apache.felix.ipojo.ComponentFactory in project felix by apache.

the class TestComp4 method setUp.

@Before
public void setUp() {
    tataFactory = (ComponentFactory) ipojoHelper.getFactory("tata");
    totoFactory = (ComponentFactory) ipojoHelper.getFactory("toto");
    tataFactory2 = (ComponentFactory) ipojoHelper.getFactory("comp-6");
    tataFactory2.stop();
    tataFactory.stop();
    Properties props = new Properties();
    props.put("instance.name", "toto provider");
    try {
        totoProv = totoFactory.createComponentInstance(props);
    } catch (Exception e) {
        e.printStackTrace();
    }
    Properties props3 = new Properties();
    props3.put("instance.name", "toto provider 2");
    try {
        totoProv2 = totoFactory.createComponentInstance(props3);
    } catch (Exception e) {
        e.printStackTrace();
    }
    totoProv.stop();
    totoProv2.stop();
    Factory factory = ipojoHelper.getFactory("comp-4");
    Properties props2 = new Properties();
    props2.put("instance.name", "ff");
    try {
        under = factory.createComponentInstance(props2);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Factory(org.apache.felix.ipojo.Factory) ComponentFactory(org.apache.felix.ipojo.ComponentFactory) Properties(java.util.Properties) Before(org.junit.Before)

Example 22 with ComponentFactory

use of org.apache.felix.ipojo.ComponentFactory in project felix by apache.

the class TestComp8 method setUp.

@Before
public void setUp() {
    tataFactory = (ComponentFactory) ipojoHelper.getFactory("tata");
    totoFactory = (ComponentFactory) ipojoHelper.getFactory("toto");
    tataFactory2 = (ComponentFactory) ipojoHelper.getFactory("comp-6");
    tataFactory2.stop();
    Properties props = new Properties();
    props.put("instance.name", "toto provider");
    try {
        totoProv = totoFactory.createComponentInstance(props);
    } catch (Exception e) {
        e.printStackTrace();
    }
    Properties props3 = new Properties();
    props3.put("instance.name", "toto provider 2");
    try {
        totoProv2 = totoFactory.createComponentInstance(props3);
    } catch (Exception e) {
        e.printStackTrace();
    }
    totoProv.stop();
    totoProv2.stop();
    Factory factory = ipojoHelper.getFactory("comp-8");
    Properties props2 = new Properties();
    props2.put("instance.name", "ff");
    try {
        under = factory.createComponentInstance(props2);
    } catch (Exception e) {
        e.printStackTrace();
    }
    tataFactory.stop();
}
Also used : Factory(org.apache.felix.ipojo.Factory) ComponentFactory(org.apache.felix.ipojo.ComponentFactory) Properties(java.util.Properties) Before(org.junit.Before)

Example 23 with ComponentFactory

use of org.apache.felix.ipojo.ComponentFactory in project felix by apache.

the class ProvidedService method start.

/**
 * Start method.
 * Build service implementation type, factory and instance.
 * @throws CompositionException if a consistent mapping cannot be discovered.
 */
public void start() throws CompositionException {
    m_composition.buildMapping();
    m_instanceName = m_composition.getSpecificationMetadata().getName() + "Provider-Gen";
    byte[] clazz = m_composition.buildPOJO();
    Element metadata = m_composition.buildMetadata(m_instanceName);
    // Create the factory
    try {
        m_factory = new ComponentFactory(m_context, clazz, metadata);
        m_factory.setUseFactoryClassloader(true);
        m_factory.start();
    } catch (ConfigurationException e) {
        // Should not happen.
        m_manager.getFactory().getLogger().log(Logger.ERROR, "A factory cannot be created", e);
    }
    try {
        Class spec = DependencyMetadataHelper.loadSpecification(m_composition.getSpecificationMetadata().getName(), m_context);
        Filter filter = m_context.createFilter("(instance.name=" + m_instanceName + ")");
        // Create the exports
        m_exports = new ServiceExporter(spec, filter, false, false, null, DependencyModel.DYNAMIC_BINDING_POLICY, m_scope, m_context, this, m_manager);
    } catch (InvalidSyntaxException e) {
        throw new CompositionException("A provided service filter is invalid", e);
    } catch (ConfigurationException e) {
        throw new CompositionException("The class " + m_composition.getSpecificationMetadata().getName() + " cannot be loaded", e);
    }
}
Also used : ConfigurationException(org.apache.felix.ipojo.ConfigurationException) Filter(org.osgi.framework.Filter) Element(org.apache.felix.ipojo.metadata.Element) ComponentFactory(org.apache.felix.ipojo.ComponentFactory) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException)

Example 24 with ComponentFactory

use of org.apache.felix.ipojo.ComponentFactory in project felix by apache.

the class TestBadLFCController method testNoField.

@Test
public void testNoField() {
    try {
        ComponentFactory cf = new ComponentFactory(osgiHelper.getContext(), getNoFieldController());
        cf.start();
        cf.stop();
        fail("A lifecycle controller with a missing field must be rejected " + cf);
    } catch (Exception e) {
    // OK
    }
}
Also used : ComponentFactory(org.apache.felix.ipojo.ComponentFactory) ParseException(org.apache.felix.ipojo.parser.ParseException) Test(org.junit.Test)

Example 25 with ComponentFactory

use of org.apache.felix.ipojo.ComponentFactory in project felix by apache.

the class TestBadLFCController method testBadField.

@Test
public void testBadField() {
    try {
        ComponentFactory cf = new ComponentFactory(osgiHelper.getContext(), getBadFieldController());
        cf.start();
        cf.stop();
        fail("A lifecycle controller with a bad field must be rejected " + cf);
    } catch (Exception e) {
    // OK
    }
}
Also used : ComponentFactory(org.apache.felix.ipojo.ComponentFactory) ParseException(org.apache.felix.ipojo.parser.ParseException) Test(org.junit.Test)

Aggregations

ComponentFactory (org.apache.felix.ipojo.ComponentFactory)35 Properties (java.util.Properties)27 Before (org.junit.Before)15 Test (org.junit.Test)15 ComponentInstance (org.apache.felix.ipojo.ComponentInstance)14 Factory (org.apache.felix.ipojo.Factory)14 ServiceContext (org.apache.felix.ipojo.ServiceContext)7 Architecture (org.apache.felix.ipojo.architecture.Architecture)5 ServiceReference (org.osgi.framework.ServiceReference)5 InstanceDescription (org.apache.felix.ipojo.architecture.InstanceDescription)4 CompositeInstanceDescription (org.apache.felix.ipojo.composite.CompositeInstanceDescription)4 BarService (org.apache.felix.ipojo.runtime.core.services.BarService)4 ConfigurationException (org.apache.felix.ipojo.ConfigurationException)2 InstanceManager (org.apache.felix.ipojo.InstanceManager)2 Element (org.apache.felix.ipojo.metadata.Element)2 ParseException (org.apache.felix.ipojo.parser.ParseException)2 MockBundle (org.apache.felix.ipojo.test.MockBundle)2 Logger (org.apache.felix.ipojo.util.Logger)2 Bundle (org.osgi.framework.Bundle)2 BundleContext (org.osgi.framework.BundleContext)2