use of org.apache.felix.ipojo.PrimitiveInstanceDescription in project felix by apache.
the class TestImmediateCallbackSeveralFactories method testCallback.
@Test
public void testCallback() {
// Check instance is invalid
ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance.getInstanceName());
assertNotNull("Check architecture availability", arch_ref);
PrimitiveInstanceDescription id_dep = (PrimitiveInstanceDescription) ((Architecture) osgiHelper.getRawServiceObject(arch_ref)).getInstanceDescription();
assertTrue("Check instance invalidity - 1", id_dep.getState() == ComponentInstance.INVALID);
assertEquals("Check pojo count - 1", id_dep.getCreatedObjects().length, 0);
// Start fooprovider
fooProvider.start();
// Check instance validity
// id_dep = ((Architecture) getContext().getService(arch_ref)).getInstanceDescription();
assertTrue("Check instance validity - 1", id_dep.getState() == ComponentInstance.VALID);
// Check service providing
ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance.getInstanceName());
assertNotNull("Check CheckService availability", cs_ref);
CheckService cs = (CheckService) osgiHelper.getRawServiceObject(cs_ref);
assertTrue("check CheckService invocation", cs.check());
assertEquals("Check pojo count - 2", id_dep.getCreatedObjects().length, 1);
// Check int property
Integer index = (Integer) (cs.getProps().get("int"));
Integer count = (Integer) (cs.getProps().get("count"));
assertEquals("Check int property - 1 (" + index + ")", index.intValue(), 1);
assertEquals("Check count property - 1 (" + count + ")", count.intValue(), 1);
fooProvider.stop();
// id_dep = ((Architecture) getContext().getService(arch_ref)).getInstanceDescription();
assertTrue("Check instance invalidity - 2", id_dep.getState() == ComponentInstance.INVALID);
assertEquals("Check pojo count - 3", id_dep.getCreatedObjects().length, 1);
fooProvider.start();
// Check instance validity
// id_dep = ((Architecture) getContext().getService(arch_ref)).getInstanceDescription();
assertTrue("Check instance validity - 2", id_dep.getState() == ComponentInstance.VALID);
// Check service providing
cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance.getInstanceName());
assertNotNull("Check CheckService availability", cs_ref);
cs = (CheckService) osgiHelper.getRawServiceObject(cs_ref);
assertTrue("check CheckService invocation", cs.check());
// Check int property
index = (Integer) (cs.getProps().get("int"));
count = (Integer) (cs.getProps().get("count"));
assertEquals("Check int property - 2 (" + index + ")", index.intValue(), 3);
assertEquals("Check count property - 2 (" + count + ")", count.intValue(), 1);
assertEquals("Check pojo count - 4 ", id_dep.getCreatedObjects().length, 1);
}
use of org.apache.felix.ipojo.PrimitiveInstanceDescription in project felix by apache.
the class TestParentCallback method testCallback.
@Test
public void testCallback() {
// Check instance is invalid
ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance.getInstanceName());
assertNotNull("Check architecture availability", arch_ref);
PrimitiveInstanceDescription id_dep = (PrimitiveInstanceDescription) ((Architecture) osgiHelper.getRawServiceObject(arch_ref)).getInstanceDescription();
assertTrue("Check instance invalidity - 1", id_dep.getState() == ComponentInstance.INVALID);
// Start fooprovider
fooProvider.start();
// Check instance validity
// id_dep = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
assertTrue("Check instance validity - 1", id_dep.getState() == ComponentInstance.VALID);
// Check service providing
ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance.getInstanceName());
assertNotNull("Check CheckService availability", cs_ref);
// Check int property
assertEquals("Check pojo count - 2", id_dep.getCreatedObjects().length, 1);
fooProvider.stop();
// id_dep = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
assertTrue("Check instance invalidity - 2", id_dep.getState() == ComponentInstance.INVALID);
fooProvider.start();
// Check instance validity
// id_dep = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
assertTrue("Check instance validity - 2", id_dep.getState() == ComponentInstance.VALID);
// Check service providing
cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance.getInstanceName());
assertNotNull("Check CheckService availability", cs_ref);
CheckService cs = (CheckService) osgiHelper.getRawServiceObject(cs_ref);
assertTrue("check CheckService invocation", cs.check());
// Clean up
bc.ungetService(arch_ref);
bc.ungetService(cs_ref);
}
use of org.apache.felix.ipojo.PrimitiveInstanceDescription in project felix by apache.
the class TestDependencyArchitecture method testProxiedSimpleDependency.
@Test
public void testProxiedSimpleDependency() {
ServiceReference arch_dep = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance5.getInstanceName());
assertNotNull("Check architecture availability", arch_dep);
PrimitiveInstanceDescription id_dep = (PrimitiveInstanceDescription) ((Architecture) osgiHelper.getRawServiceObject(arch_dep)).getInstanceDescription();
assertTrue("Check instance invalidity - 1", id_dep.getState() == ComponentInstance.INVALID);
// Check dependency handler invalidity
DependencyHandlerDescription dhd = getDependencyDesc(id_dep);
assertFalse("Check dependency handler invalidity", dhd.isValid());
// Check dependency metadata
assertEquals("Check dependency interface", dhd.getDependencies()[0].getInterface(), FooService.class.getName());
assertEquals("Check dependency id", dhd.getDependencies()[0].getId(), FooService.class.getName());
assertFalse("Check dependency cardinality", dhd.getDependencies()[0].isMultiple());
assertFalse("Check dependency optionality", dhd.getDependencies()[0].isOptional());
assertNull("Check dependency ref -1", dhd.getDependencies()[0].getServiceReferences());
assertTrue("Check dependency proxy", dhd.getDependencies()[0].isProxy());
fooProvider1.start();
ServiceReference arch_ps = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), fooProvider1.getInstanceName());
assertNotNull("Check architecture availability", arch_ps);
PrimitiveInstanceDescription id_ps = (PrimitiveInstanceDescription) ((Architecture) osgiHelper.getRawServiceObject(arch_ps)).getInstanceDescription();
assertTrue("Check instance invalidity - 1", id_ps.getState() == ComponentInstance.VALID);
// id_dep = ((Architecture) osgiHelper.getRawServiceObject(arch_dep)).getInstanceDescription();
assertTrue("Check instance validity", id_dep.getState() == ComponentInstance.VALID);
dhd = getDependencyDesc(id_dep);
assertTrue("Check dependency handler validity", dhd.isValid());
assertEquals("Check dependency ref - 2 ", dhd.getDependencies()[0].getServiceReferences().size(), 1);
ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance5.getInstanceName());
assertNotNull("Check CheckService availability", cs_ref);
CheckService cs = (CheckService) osgiHelper.getRawServiceObject(cs_ref);
assertTrue("check CheckService invocation", cs.check());
// Check object graph
// id_dep = ((Architecture) osgiHelper.getRawServiceObject(arch_dep)).getInstanceDescription();
dhd = getDependencyDesc(id_dep);
// id_ps = ((Architecture) osgiHelper.getRawServiceObject(arch_ps)).getInstanceDescription();
ProvidedServiceHandlerDescription psh = getPSDesc(id_ps);
assertEquals("Check POJO creation", id_ps.getCreatedObjects().length, 1);
fooProvider1.stop();
// id_dep = ((Architecture) osgiHelper.getRawServiceObject(arch_dep)).getInstanceDescription();
assertTrue("Check instance invalidity - 2", id_dep.getState() == ComponentInstance.INVALID);
dhd = getDependencyDesc(id_dep);
assertFalse("Check dependency handler invalidity", dhd.isValid());
fooProvider1.start();
// id_dep = ((Architecture) osgiHelper.getRawServiceObject(arch_dep)).getInstanceDescription();
dhd = getDependencyDesc(id_dep);
arch_ps = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), fooProvider1.getInstanceName());
assertNotNull("Check architecture availability", arch_ps);
// id_ps = ((Architecture) osgiHelper.getRawServiceObject(arch_ps)).getInstanceDescription();
assertTrue("Check instance invalidity - 1", id_ps.getState() == ComponentInstance.VALID);
psh = getPSDesc(id_ps);
assertTrue("Check instance validity", id_dep.getState() == ComponentInstance.VALID);
assertTrue("Check dependency handler validity", dhd.isValid());
assertEquals("Check dependency ref -3", dhd.getDependencies()[0].getServiceReferences().size(), 1);
cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance5.getInstanceName());
assertNotNull("Check CheckService availability", cs_ref);
cs = (CheckService) osgiHelper.getRawServiceObject(cs_ref);
assertTrue("check CheckService invocation", cs.check());
// Check object graph
// id_dep = ((Architecture) osgiHelper.getRawServiceObject(arch_dep)).getInstanceDescription();
dhd = getDependencyDesc(id_dep);
// id_ps = ((Architecture) osgiHelper.getRawServiceObject(arch_ps)).getInstanceDescription();
psh = getPSDesc(id_ps);
fooProvider1.stop();
// id_dep = ((Architecture) osgiHelper.getRawServiceObject(arch_dep)).getInstanceDescription();
assertTrue("Check instance invalidity - 2", id_dep.getState() == ComponentInstance.INVALID);
dhd = getDependencyDesc(id_dep);
assertFalse("Check dependency handler invalidity", dhd.isValid());
id_dep = null;
cs = null;
getContext().ungetService(arch_dep);
getContext().ungetService(cs_ref);
}
use of org.apache.felix.ipojo.PrimitiveInstanceDescription in project felix by apache.
the class Service method getProvidedServiceDescription.
/**
* Gets the provided service description associated with the current service.
* @param instance the instance on which looking for the provided service description
* @return the provided service description or <code>null</code> if not found.
*/
public ProvidedServiceDescription getProvidedServiceDescription(ComponentInstance instance) {
PrimitiveInstanceDescription desc = (PrimitiveInstanceDescription) instance.getInstanceDescription();
ProvidedServiceDescription[] pss = desc.getProvidedServices();
if (pss.length == 0) {
return null;
}
if (pss.length == 1) {
return pss[0];
}
if (m_specifications == null) {
return null;
} else {
for (int j = 0; j < pss.length; j++) {
ProvidedServiceDescription psd = pss[j];
List specs = Arrays.asList(psd.getServiceSpecifications());
if (specs.containsAll(m_specifications)) {
return psd;
}
}
}
return null;
}
use of org.apache.felix.ipojo.PrimitiveInstanceDescription in project felix by apache.
the class ServiceProperty method getPropertyValue.
/**
* Gets the property value of the current property
* on the given instance.
* @param instance the instance on which looking for
* the property value
* @return the property value or <code>null</code>
* if not found.
*/
public Object getPropertyValue(ComponentInstance instance) {
PrimitiveInstanceDescription desc = (PrimitiveInstanceDescription) instance.getInstanceDescription();
ProvidedServiceDescription[] pss = desc.getProvidedServices();
for (int i = 0; i < pss.length; i++) {
// Check with the name
if (m_name != null && pss[i].getProperties().containsKey(m_name)) {
return pss[i].getProperties().get(m_name);
}
// Check with the field
if (m_field != null && pss[i].getProperties().containsKey(m_field)) {
return pss[i].getProperties().get(m_field);
}
}
// Not found.
return null;
}
Aggregations