Search in sources :

Example 16 with Element

use of org.apache.felix.ipojo.metadata.Element in project felix by apache.

the class ComponentTypeDescription method getDescription.

/**
 * Gets the component type description.
 *
 * @return : the description
 */
public Element getDescription() {
    Element desc = new Element("Factory", "");
    desc.addAttribute(new Attribute("name", m_factory.getName()));
    desc.addAttribute(new Attribute("bundle", Long.toString(m_factory.getBundleContext().getBundle().getBundleId())));
    String state = "valid";
    if (m_factory.getState() == Factory.INVALID) {
        state = "invalid";
    }
    desc.addAttribute(new Attribute("state", state));
    // Display required & missing handlers
    Element req = new Element("RequiredHandlers", "");
    req.addAttribute(new Attribute("list", m_factory.getRequiredHandlers().toString()));
    Element missing = new Element("MissingHandlers", "");
    missing.addAttribute(new Attribute("list", m_factory.getMissingHandlers().toString()));
    desc.addElement(req);
    desc.addElement(missing);
    for (int i = 0; i < m_providedServiceSpecification.length; i++) {
        Element prov = new Element("provides", "");
        prov.addAttribute(new Attribute("specification", m_providedServiceSpecification[i]));
        desc.addElement(prov);
    }
    for (int i = 0; i < m_properties.length; i++) {
        Element prop = new Element("property", "");
        prop.addAttribute(new Attribute("name", m_properties[i].getName()));
        prop.addAttribute(new Attribute("type", m_properties[i].getType()));
        if (m_properties[i].isMandatory() && m_properties[i].getValue() == null) {
            prop.addAttribute(new Attribute("value", "REQUIRED"));
        } else {
            prop.addAttribute(new Attribute("value", m_properties[i].getValue()));
        }
        desc.addElement(prop);
    }
    if (m_handlerInfoSlot.size() > 0) {
        Enumeration keys = m_handlerInfoSlot.keys();
        while (keys.hasMoreElements()) {
            String fullHandlerName = (String) keys.nextElement();
            CustomHandlerInfo handlerInfo = (CustomHandlerInfo) m_handlerInfoSlot.get(fullHandlerName);
            desc.addElement(handlerInfo.getDescription());
        }
    }
    return desc;
}
Also used : Enumeration(java.util.Enumeration) Attribute(org.apache.felix.ipojo.metadata.Attribute) Element(org.apache.felix.ipojo.metadata.Element)

Example 17 with Element

use of org.apache.felix.ipojo.metadata.Element in project felix by apache.

the class InstanceDescription method getDescription.

/**
 * Gets the instance description.
 * @return the instance description
 */
public Element getDescription() {
    Element instance = new Element("Instance", "");
    // Name
    instance.addAttribute(new Attribute("name", getName()));
    int state = getState();
    if (state == ComponentInstance.STOPPED) {
        instance.addAttribute(new Attribute("state", "stopped"));
    }
    if (state == ComponentInstance.VALID) {
        instance.addAttribute(new Attribute("state", "valid"));
    }
    if (state == ComponentInstance.INVALID) {
        instance.addAttribute(new Attribute("state", "invalid"));
    }
    if (state == ComponentInstance.DISPOSED) {
        instance.addAttribute(new Attribute("state", "disposed"));
    }
    // Bundle
    instance.addAttribute(new Attribute("bundle", Long.toString(getBundleId())));
    // Component Type
    instance.addAttribute(new Attribute("component.type", m_type.getName()));
    // Handlers
    for (HandlerDescription description : m_handlers) {
        instance.addElement(description.getHandlerInfo());
    }
    return instance;
}
Also used : Attribute(org.apache.felix.ipojo.metadata.Attribute) Element(org.apache.felix.ipojo.metadata.Element)

Example 18 with Element

use of org.apache.felix.ipojo.metadata.Element in project felix by apache.

the class TestDeclarationBuilderService method germanComponent.

/*
    @Test
    public void testTypeCreationFromAPI() throws Exception {
        PrimitiveComponentType type = new PrimitiveComponentType()
                .setClassName("org.apache.felix.ipojo.runtime.core.test.components.GermanHelloService")
                .setComponentTypeName("german-service")
                .addService(new Service());

        Element description = type.getFactory().getComponentMetadata();
        handle = builder.newType(description);
        handle.publish();

        DeclarationHandle instance = builder.newInstance("german-service")
                .name("german-hello")
                .build();
        instance.publish();

        String filter = format("(instance.name=%s)", "german-hello");
        osgiHelper.waitForService(HelloService.class, filter, 1000);
        HelloService service = osgiHelper.getServiceObject(HelloService.class, filter);
        assertEquals(service.hello("Guillaume"), "Hallo Guillaume");

        instance.retract();

    }
    */
private Element germanComponent() {
    Element component = new Element("component", null);
    component.addAttribute(new Attribute("name", "german-service"));
    component.addAttribute(new Attribute("classname", "org.apache.felix.ipojo.runtime.core.test.components.GermanHelloService"));
    component.addElement(new Element("provides", null));
    component.addElement(manipulation());
    return component;
}
Also used : Attribute(org.apache.felix.ipojo.metadata.Attribute) Element(org.apache.felix.ipojo.metadata.Element)

Example 19 with Element

use of org.apache.felix.ipojo.metadata.Element in project felix by apache.

the class DefaultDeclarationBuilderServiceTestCase method testNewType.

public void testNewType() throws Exception {
    DefaultDeclarationBuilderService service = new DefaultDeclarationBuilderService(m_bundleContext);
    DeclarationHandle type = service.newType(new Element("component", null));
    assertNotNull(type);
    type.publish();
    verify(m_bundleContext).registerService(eq(TypeDeclaration.class.getName()), anyObject(), isNull(Dictionary.class));
}
Also used : Dictionary(java.util.Dictionary) Element(org.apache.felix.ipojo.metadata.Element) DeclarationHandle(org.apache.felix.ipojo.extender.DeclarationHandle)

Example 20 with Element

use of org.apache.felix.ipojo.metadata.Element in project felix by apache.

the class ManagedTypeTestCase method element.

private Element element(String type, String classname) {
    Element root = new Element(type, null);
    root.addAttribute(new Attribute("classname", classname));
    return root;
}
Also used : Attribute(org.apache.felix.ipojo.metadata.Attribute) Element(org.apache.felix.ipojo.metadata.Element)

Aggregations

Element (org.apache.felix.ipojo.metadata.Element)400 Test (org.junit.Test)126 Attribute (org.apache.felix.ipojo.metadata.Attribute)109 ConfigurationException (org.apache.felix.ipojo.ConfigurationException)22 ParseException (org.apache.felix.ipojo.parser.ParseException)14 PojoMetadata (org.apache.felix.ipojo.parser.PojoMetadata)14 ArrayList (java.util.ArrayList)13 Reporter (org.apache.felix.ipojo.manipulator.Reporter)12 FieldMetadata (org.apache.felix.ipojo.parser.FieldMetadata)12 Dictionary (java.util.Dictionary)10 Properties (java.util.Properties)10 MethodMetadata (org.apache.felix.ipojo.parser.MethodMetadata)10 BaseTest (org.ow2.chameleon.testing.helpers.BaseTest)10 PropertyDescription (org.apache.felix.ipojo.architecture.PropertyDescription)9 IOException (java.io.IOException)8 List (java.util.List)8 Before (org.junit.Before)7 Enumeration (java.util.Enumeration)6 ComponentWorkbench (org.apache.felix.ipojo.manipulator.metadata.annotation.ComponentWorkbench)6 FooService (org.apache.felix.ipojo.runtime.core.services.FooService)6