use of org.apache.felix.ipojo.architecture.ComponentTypeDescription in project felix by apache.
the class TestComponentDesc method testFooProvider3.
/**
* Check component properties.
*/
@Test
public void testFooProvider3() {
// Test SR properties
// String impl = (String) sr_fooProvider3.getProperty("component.class");
// assertEquals("Check component.class", impl, "org.apache.felix.ipojo.test.scenarios.component.FooProviderType1");
String[] specs = (String[]) sr_fooProvider3.getProperty("component.providedServiceSpecifications");
assertEquals("Check component.providedServiceSpecifications length", specs.length, 1);
assertEquals("Check component.providedServiceSpecifications", FooService.class.getName(), specs[0]);
PropertyDescription[] pd = (PropertyDescription[]) sr_fooProvider3.getProperty("component.properties");
assertEquals("Check component.properties length (" + pd.length + ")", pd.length, 3);
assertEquals("Check component.properties name [" + 0 + "]", "foo", pd[0].getName());
assertEquals("Check component.properties name [" + 1 + "]", "bar", pd[1].getName());
assertEquals("Check component.properties name [" + 2 + "]", "baz", pd[2].getName());
assertEquals("Check component.properties type [" + 2 + "]", "java.lang.String", pd[2].getType());
// Test factory
assertEquals("Check factory name", fooProvider3.getName(), "Factories-FooProviderType-3");
Element cd = fooProvider3.getDescription();
// assertEquals("Check implementation class ", cd.getAttribute("implementation-class"), impl);
Element[] specs2 = cd.getElements("provides");
assertEquals("Check specs length", specs2.length, 1);
assertEquals("Check specs", FooService.class.getName(), specs2[0].getAttribute("specification"));
Element[] pd2 = cd.getElements("property");
assertEquals("Check props length", pd2.length, 3);
assertEquals("Check component.properties name [" + 0 + "]", "foo", pd2[0].getAttribute("name"));
assertEquals("Check component.properties name [" + 1 + "]", "bar", pd2[1].getAttribute("name"));
assertEquals("Check component.properties name [" + 2 + "]", "baz", pd2[2].getAttribute("name"));
assertEquals("Check component.properties type [" + 2 + "]", "java.lang.String", pd2[2].getAttribute("type"));
// Check Description equality
ComponentTypeDescription desc = (ComponentTypeDescription) sr_fooProvider3.getProperty("component.description");
assertNotNull("check description equality", desc);
}
use of org.apache.felix.ipojo.architecture.ComponentTypeDescription in project felix by apache.
the class SvcInstance method match.
/**
* Does the service instance match with the given factory ?
* @param fact : the factory to test.
* @return true if the factory match, false otherwise.
*/
public boolean match(ServiceReference fact) {
// Check if the factory can provide the specification
ComponentTypeDescription desc = (ComponentTypeDescription) fact.getProperty("component.description");
if (desc == null) {
// No component type description.
return false;
}
String[] provides = desc.getprovidedServiceSpecification();
for (int i = 0; provides != null && i < provides.length; i++) {
if (provides[i].equals(m_specification)) {
// Check that the factory needs every properties contained in
// the configuration
PropertyDescription[] props = desc.getProperties();
Properties conf = new Properties();
Enumeration keys = m_configuration.keys();
while (keys.hasMoreElements()) {
String key = (String) keys.nextElement();
if (!containsProperty(key, props)) {
return false;
}
conf.put(key, m_configuration.get(key));
}
Factory factory = (Factory) getService(fact);
return factory.isAcceptable(conf);
}
}
return false;
}
Aggregations