Search in sources :

Example 21 with Attribute

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

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

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

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

Example 25 with Attribute

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

the class GenericVisitor method visit.

/**
 * Visit a 'simple' annotation attribute.
 * This method is used for primitive arrays too.
 *
 * @param name  : attribute name
 * @param value : attribute value
 * @see org.objectweb.asm.AnnotationVisitor#visit(String, Object)
 */
public void visit(String name, Object value) {
    if (value.getClass().isArray()) {
        // Primitive arrays case
        String v = null;
        int index = Array.getLength(value);
        for (int i = 0; i < index; i++) {
            if (v == null) {
                v = "{" + Array.get(value, i);
            } else {
                v += "," + Array.get(value, i);
            }
        }
        v += "}";
        element.addAttribute(new Attribute(name, v));
        return;
    }
    // Attributes are added as normal attributes
    if (!(value instanceof Type)) {
        element.addAttribute(new Attribute(name, value.toString()));
    } else {
        // Attributes of type class need a special handling
        element.addAttribute(new Attribute(name, ((Type) value).getClassName()));
    }
}
Also used : Type(org.objectweb.asm.Type) Attribute(org.apache.felix.ipojo.metadata.Attribute)

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