Search in sources :

Example 41 with Element

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

the class HandlerDeclarationVisitor method visitEnd.

/**
 * End of the visit.
 * Builds the XML document.
 * @see org.objectweb.asm.AnnotationVisitor#visitEnd()
 */
public void visitEnd() {
    // The value is an XML document
    InputStream is = new ByteArrayInputStream(m_value.getBytes());
    Document document = null;
    try {
        document = builder.parse(is);
        Element e = convertDOMElements(document.getDocumentElement());
        workbench.getElements().put(e, null);
    } catch (Exception e) {
        reporter.warn("Cannot convert {} to iPOJO Elements.", m_value, e);
    } finally {
        try {
            is.close();
        } catch (IOException e) {
            reporter.trace("Cannot close correctly the value input stream ({}).", m_value, e);
        }
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Element(org.apache.felix.ipojo.metadata.Element) IOException(java.io.IOException) Document(org.w3c.dom.Document) IOException(java.io.IOException)

Example 42 with Element

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

the class PostRegistrationVisitor method visitEnd.

@Override
public void visitEnd() {
    Element provides;
    if (workbench.getIds().containsKey("provides")) {
        provides = workbench.getIds().get("provides");
        provides.addAttribute(new Attribute("post-registration", name));
    }
// Else ignore annotation ...
}
Also used : Attribute(org.apache.felix.ipojo.metadata.Attribute) Element(org.apache.felix.ipojo.metadata.Element)

Example 43 with Element

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

the class PostUnregistrationVisitor method visitEnd.

@Override
public void visitEnd() {
    Element provides;
    if (workbench.getIds().containsKey("provides")) {
        provides = workbench.getIds().get("provides");
        provides.addAttribute(new Attribute("post-unregistration", name));
    }
// Else ignore annotation ...
}
Also used : Attribute(org.apache.felix.ipojo.metadata.Attribute) Element(org.apache.felix.ipojo.metadata.Element)

Example 44 with Element

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

the class RequiresVisitor method visitEnd.

/**
 * End of the annotation.
 * Create a "requires" element
 * @see org.objectweb.asm.AnnotationVisitor#visitEnd()
 */
public void visitEnd() {
    Element requires;
    if (m_id == null) {
        requires = workbench.getIds().get(m_field);
    } else {
        requires = workbench.getIds().get(m_id);
    }
    if (requires == null) {
        requires = new Element("requires", "");
    }
    requires.addAttribute(new Attribute("field", m_field));
    if (m_specification != null) {
        requires.addAttribute(new Attribute("specification", m_specification));
    }
    if (m_filter != null) {
        requires.addAttribute(new Attribute("filter", m_filter));
    }
    if (m_optional != null) {
        requires.addAttribute(new Attribute("optional", m_optional));
    }
    if (m_nullable != null) {
        requires.addAttribute(new Attribute("nullable", m_nullable));
    }
    if (m_defaultImplementation != null) {
        requires.addAttribute(new Attribute("default-implementation", m_defaultImplementation));
    }
    if (m_exception != null) {
        requires.addAttribute(new Attribute("exception", m_exception));
    }
    if (m_policy != null) {
        requires.addAttribute(new Attribute("policy", m_policy));
    }
    if (m_id != null) {
        requires.addAttribute(new Attribute("id", m_id));
    }
    if (m_comparator != null) {
        requires.addAttribute(new Attribute("comparator", m_comparator));
    }
    if (m_from != null) {
        requires.addAttribute(new Attribute("from", m_from));
    }
    if (m_proxy != null) {
        requires.addAttribute(new Attribute("proxy", m_proxy));
    }
    if (m_timeout != null) {
        requires.addAttribute(new Attribute("timeout", m_timeout));
    }
    if (m_id != null) {
        workbench.getIds().put(m_id, requires);
    } else {
        workbench.getIds().put(m_field, requires);
    }
    workbench.getElements().put(requires, null);
}
Also used : Attribute(org.apache.felix.ipojo.metadata.Attribute) Element(org.apache.felix.ipojo.metadata.Element)

Example 45 with Element

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

the class MethodBindVisitor method visitEnd.

/**
 * End of the visit.
 * Create or append the requirement info to a created or already existing "requires" element.
 *
 * @see org.objectweb.asm.commons.EmptyVisitor#visitEnd()
 */
public void visitEnd() {
    if (m_id == null) {
        String identifier = Names.getMethodIdentifier(m_node);
        if (identifier != null) {
            m_id = identifier;
        } else {
            if (m_specification != null) {
                m_id = m_specification;
            } else {
                m_reporter.error("Cannot determine the requires identifier for the (%s) %s method: %s", computeEffectiveMethodName(m_node.name), action.name(), "Either 'id' attribute is missing or method name do not follow the bind/set/add/modified " + "naming pattern, or no specification (service interface) can be found in method signature " + "or specified in annotation. Dependency will be ignored (would cause an Exception at runtime)");
                return;
            }
        }
    }
    Element requires = getRequiresElement();
    Element callback = new Element("callback", "");
    callback.addAttribute(new Attribute("method", computeEffectiveMethodName(m_node.name)));
    callback.addAttribute(new Attribute("type", action.name().toLowerCase()));
    requires.addElement(callback);
    workbench.getIds().put(m_id, requires);
    workbench.getElements().put(requires, null);
}
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