Search in sources :

Example 6 with Attribute

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

the class EventAdminPublisherHandlerDescription method getHandlerInfo.

/**
 * Gets the handler description.
 * @see org.apache.felix.ipojo.architecture.HandlerDescription#getHandlerInfo()
 */
public Element getHandlerInfo() {
    Element root = super.getHandlerInfo();
    for (int i = 0; i < m_publishersDescriptions.size(); i++) {
        PublisherDescription p = (PublisherDescription) m_publishersDescriptions.get(i);
        Element publisher = new Element("Publisher", "");
        publisher.addAttribute(new Attribute("name", p.getName()));
        publisher.addAttribute(new Attribute("synchronous", String.valueOf(p.isSynchronous())));
        publisher.addAttribute(new Attribute("data_key", p.getDataKey()));
        Element topics = new Element("Topics", "");
        if (p.getTopics() != null) {
            for (int j = 0; j < p.getTopics().length; j++) {
                String topic = p.getTopics()[j];
                Element e_topic = new Element("topic", "");
                topics.addElement(e_topic);
                e_topic.addAttribute(new Attribute("name", topic));
            }
        }
        publisher.addElement(topics);
        root.addElement(publisher);
    }
    return root;
}
Also used : Attribute(org.apache.felix.ipojo.metadata.Attribute) Element(org.apache.felix.ipojo.metadata.Element)

Example 7 with Attribute

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

the class PrimitiveInstanceDescription method getDescription.

/**
 * Gets the instance description.
 * Overridden to add created objects.
 * @return the instance description
 */
public Element getDescription() {
    Element elem = super.getDescription();
    // Created Object (empty is composite)
    String[] objs = getCreatedObjects();
    for (int i = 0; objs != null && i < objs.length; i++) {
        Element obj = new Element("Object", "");
        obj.addAttribute(new Attribute("name", ((Object) objs[i]).toString()));
        elem.addElement(obj);
    }
    return elem;
}
Also used : Attribute(org.apache.felix.ipojo.metadata.Attribute) Element(org.apache.felix.ipojo.metadata.Element)

Example 8 with Attribute

use of org.apache.felix.ipojo.metadata.Attribute 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 9 with Attribute

use of org.apache.felix.ipojo.metadata.Attribute 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 10 with Attribute

use of org.apache.felix.ipojo.metadata.Attribute 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)

Aggregations

Attribute (org.apache.felix.ipojo.metadata.Attribute)125 Element (org.apache.felix.ipojo.metadata.Element)109 Test (org.junit.Test)9 PojoMetadata (org.apache.felix.ipojo.parser.PojoMetadata)6 Iterator (java.util.Iterator)4 Enumeration (java.util.Enumeration)3 Map (java.util.Map)3 Set (java.util.Set)3 ServiceReference (org.osgi.framework.ServiceReference)3 List (java.util.List)2 Entry (java.util.Map.Entry)2 PropertyDescription (org.apache.felix.ipojo.architecture.PropertyDescription)2 FieldMetadata (org.apache.felix.ipojo.parser.FieldMetadata)2 MethodMetadata (org.apache.felix.ipojo.parser.MethodMetadata)2 Type (org.objectweb.asm.Type)2 Member (java.lang.reflect.Member)1 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutorService (java.util.concurrent.ExecutorService)1