Search in sources :

Example 6 with ComponentTypeDescription

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);
}
Also used : FooService(org.apache.felix.ipojo.runtime.core.services.FooService) PropertyDescription(org.apache.felix.ipojo.architecture.PropertyDescription) ComponentTypeDescription(org.apache.felix.ipojo.architecture.ComponentTypeDescription) Element(org.apache.felix.ipojo.metadata.Element) Test(org.junit.Test)

Example 7 with ComponentTypeDescription

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;
}
Also used : PropertyDescription(org.apache.felix.ipojo.architecture.PropertyDescription) ComponentTypeDescription(org.apache.felix.ipojo.architecture.ComponentTypeDescription) Enumeration(java.util.Enumeration) Factory(org.apache.felix.ipojo.Factory) Properties(java.util.Properties)

Aggregations

ComponentTypeDescription (org.apache.felix.ipojo.architecture.ComponentTypeDescription)7 PropertyDescription (org.apache.felix.ipojo.architecture.PropertyDescription)6 Test (org.junit.Test)6 Element (org.apache.felix.ipojo.metadata.Element)5 FooService (org.apache.felix.ipojo.runtime.core.services.FooService)5 Properties (java.util.Properties)2 Factory (org.apache.felix.ipojo.Factory)2 Enumeration (java.util.Enumeration)1 ComponentInstance (org.apache.felix.ipojo.ComponentInstance)1 ServiceContext (org.apache.felix.ipojo.ServiceContext)1 CompositeInstanceDescription (org.apache.felix.ipojo.composite.CompositeInstanceDescription)1 CompositeManager (org.apache.felix.ipojo.composite.CompositeManager)1 BarService (org.apache.felix.ipojo.runtime.core.services.BarService)1 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)1