use of org.apache.felix.ipojo.Factory in project felix by apache.
the class Arch method factories.
/**
* Displays the list of public iPOJO factories.
*/
@Descriptor("Display iPOJO factories")
public void factories() {
StringBuilder buffer = new StringBuilder();
for (Factory m_factory : m_factories) {
if (m_factory.getMissingHandlers().size() == 0) {
buffer.append(format("Factory %s (VALID)%n", m_factory.getName()));
} else {
buffer.append(format("Factory %s (INVALID: %s)%n", m_factory.getName(), m_factory.getMissingHandlers()));
}
}
for (TypeDeclaration type : m_types) {
if (!type.isPublic()) {
// give access to the underlying Factory or description (if valid)
if (type.getStatus().isBound()) {
buffer.append(format("Factory %s (UNKNOWN) - Private%n", type.getComponentName()));
} else {
// Unbound type means that required extension is not available
// We'll say that the factory is INVALID even if in reality it's not even instantiated
buffer.append(format("Factory %s (INVALID) - Private%n", type.getComponentName()));
buffer.append(format(" -> %s", type.getStatus().getMessage()));
}
} else {
if (!type.getStatus().isBound()) {
buffer.append(format("Factory %s is not bound%n", type.getComponentName()));
buffer.append(format(" -> %s%n", type.getStatus().getMessage()));
}
}
}
if (buffer.length() == 0) {
buffer.append("No factories \n");
}
System.out.println(buffer.toString());
}
use of org.apache.felix.ipojo.Factory in project felix by apache.
the class TestCompositeAPI method testInstantiator.
@Test
public void testInstantiator() {
String type = "composite.instantiator";
Factory fact = ipojoHelper.getFactory(type);
ComponentInstance ci = null;
Properties p = new Properties();
p.put("instance.name", "mon_coeur");
try {
ci = fact.createComponentInstance(p);
} catch (Exception e) {
e.printStackTrace();
}
assertTrue("Check ci", ci.getState() == ComponentInstance.VALID);
ServiceReference ref = ipojoHelper.getServiceReferenceByName(BazService.class.getName(), "mon_coeur");
assertNotNull("Check ref", ref);
BazService bs = (BazService) getContext().getService(ref);
assertTrue("Check invocation", bs.foo());
getContext().ungetService(ref);
ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), "mon_coeur");
assertNotNull("Check ref 2 ", ref);
FooService fs = (FooService) getContext().getService(ref);
assertTrue("Check invocation", fs.foo());
getContext().ungetService(ref);
ci.dispose();
}
use of org.apache.felix.ipojo.Factory in project felix by apache.
the class TestCompositeAPI method testAPI2.
@Test
public void testAPI2() {
Factory fact1 = ipojoHelper.getFactory("composite.empty");
Properties p = new Properties();
p.put("instance.name", "empty-2");
ComponentInstance empty = null;
try {
empty = fact1.createComponentInstance(p);
} catch (Exception e) {
e.printStackTrace();
}
ServiceContext sc = getServiceContext(empty);
Factory fact2 = ipojoHelper.getFactory(sc, "composite.test.2");
Properties props2 = new Properties();
props2.put("instance.name", "4");
Factory fact3 = ipojoHelper.getFactory(sc, "composite.test.3");
Properties props3 = new Properties();
props3.put("instance.name", "5");
ComponentInstance comp2 = null;
ComponentInstance comp3 = null;
try {
comp2 = fact2.createComponentInstance(props2, sc);
comp3 = fact3.createComponentInstance(props3, sc);
} catch (Exception e) {
e.printStackTrace();
}
assertTrue("Test comp3", comp3.getState() == ComponentInstance.VALID);
assertTrue("Test comp2", comp2.getState() == ComponentInstance.VALID);
ServiceReference ref = null;
ref = ipojoHelper.getServiceReferenceByName(sc, CheckService.class.getName(), "4");
assertNotNull("Check ref", ref);
CheckService cs = (CheckService) sc.getService(ref);
assertTrue("Check invoke", cs.check());
comp3.dispose();
comp2.dispose();
empty.dispose();
}
use of org.apache.felix.ipojo.Factory in project felix by apache.
the class TestCompositeAPI method testAPI.
@Test
public void testAPI() {
Factory fact1 = ipojoHelper.getFactory("composite.empty");
Properties p = new Properties();
p.put("instance.name", "empty-1");
ComponentInstance empty = null;
try {
empty = fact1.createComponentInstance(p);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
ServiceContext sc = getServiceContext(empty);
Factory fact2 = ipojoHelper.getFactory("composite.test.2");
Properties props2 = new Properties();
// 2
props2.put("instance.name", "2");
Factory fact3 = ipojoHelper.getFactory("composite.test.3");
Properties props3 = new Properties();
props3.put("instance.name", "3");
ComponentInstance comp2 = null;
ComponentInstance comp3 = null;
try {
comp2 = fact2.createComponentInstance(props2, sc);
comp3 = fact3.createComponentInstance(props3, sc);
} catch (Throwable e) {
e.printStackTrace();
fail(e.getMessage());
}
assertTrue("Test comp3", comp3.getState() == ComponentInstance.VALID);
assertTrue("Test comp2", comp2.getState() == ComponentInstance.VALID);
ServiceReference ref = null;
// 2
ref = ipojoHelper.getServiceReferenceByName(sc, CheckService.class.getName(), "2");
assertNotNull("Check ref", ref);
CheckService cs = (CheckService) sc.getService(ref);
assertTrue("Check invoke", cs.check());
comp3.dispose();
comp2.dispose();
empty.dispose();
}
use of org.apache.felix.ipojo.Factory in project felix by apache.
the class TestComp2 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-2");
Properties props2 = new Properties();
props2.put("instance.name", "ff");
try {
under = factory.createComponentInstance(props2);
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations