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();
}
}
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();
}
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);
}
}
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
}
}
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
}
}
Aggregations