Search in sources :

Example 16 with Attribute

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

the class DependencyHandlerDescription method getHandlerInfo.

/**
 * Builds the Dependency Handler description.
 * @return the handler description.
 * @see org.apache.felix.ipojo.architecture.HandlerDescription#getHandlerInfo()
 */
public Element getHandlerInfo() {
    Element deps = super.getHandlerInfo();
    for (DependencyDescription dependency : m_dependencies) {
        String state = "resolved";
        if (dependency.getState() == DependencyModel.UNRESOLVED) {
            state = "unresolved";
        }
        if (dependency.getState() == DependencyModel.BROKEN) {
            state = "broken";
        }
        Element dep = new Element("Requires", "");
        dep.addAttribute(new Attribute("Specification", dependency.getInterface()));
        dep.addAttribute(new Attribute("Id", dependency.getId()));
        if (dependency.getFilter() != null) {
            dep.addAttribute(new Attribute("Filter", dependency.getFilter()));
        }
        if (dependency.isOptional()) {
            dep.addAttribute(new Attribute("Optional", "true"));
            if (dependency.supportsNullable()) {
                dep.addAttribute(new Attribute("Nullable", "true"));
            }
            if (dependency.getDefaultImplementation() != null) {
                dep.addAttribute(new Attribute("Default-Implementation", dependency.getDefaultImplementation()));
            }
        } else {
            dep.addAttribute(new Attribute("Optional", "false"));
        }
        if (dependency.isMultiple()) {
            dep.addAttribute(new Attribute("Aggregate", "true"));
        } else {
            dep.addAttribute(new Attribute("Aggregate", "false"));
        }
        if (dependency.isProxy()) {
            dep.addAttribute(new Attribute("Proxy", "true"));
        } else {
            dep.addAttribute(new Attribute("Proxy", "false"));
        }
        String policy = "dynamic";
        if (dependency.getPolicy() == DependencyModel.STATIC_BINDING_POLICY) {
            policy = "static";
        } else if (dependency.getPolicy() == DependencyModel.DYNAMIC_PRIORITY_BINDING_POLICY) {
            policy = "dynamic-priority";
        }
        dep.addAttribute(new Attribute("Binding-Policy", policy));
        if (dependency.getComparator() != null) {
            dep.addAttribute(new Attribute("Comparator", dependency.getComparator()));
        }
        dep.addAttribute(new Attribute("State", state));
        List<ServiceReference> set = dependency.getUsedServices();
        if (set != null) {
            for (ServiceReference ref : set) {
                Element use = new Element("Uses", "");
                computeServiceReferenceDescription(ref, use);
                dep.addElement(use);
            }
        }
        set = dependency.getServiceReferences();
        if (set != null) {
            for (ServiceReference ref : set) {
                Element use = new Element("Selected", "");
                computeServiceReferenceDescription(ref, use);
                dep.addElement(use);
            }
        }
        final ServiceReferenceManager serviceReferenceManager = dependency.getDependency().getServiceReferenceManager();
        if (serviceReferenceManager == null) {
            // Exit here, cannot compute anything else.
            deps.addElement(dep);
            continue;
        }
        set = serviceReferenceManager.getMatchingServices();
        if (set != null) {
            for (ServiceReference ref : set) {
                Element use = new Element("Matches", "");
                computeServiceReferenceDescription(ref, use);
                dep.addElement(use);
            }
        }
        // Add interceptors to the description
        List<ServiceReference> interceptors = serviceReferenceManager.getTrackingInterceptorReferences();
        for (ServiceReference ref : interceptors) {
            Element itcp = new Element("ServiceTrackingInterceptor", "");
            computeInterceptorDescription(ref, itcp);
            dep.addElement(itcp);
        }
        ServiceReference ref = serviceReferenceManager.getRankingInterceptorReference();
        if (ref != null) {
            Element itcp = new Element("ServiceRankingInterceptor", "");
            computeInterceptorDescription(ref, itcp);
            dep.addElement(itcp);
        }
        interceptors = serviceReferenceManager.getBindingInterceptorReferences();
        for (ServiceReference rf : interceptors) {
            Element itcp = new Element("ServiceBindingInterceptor", "");
            computeInterceptorDescription(rf, itcp);
            dep.addElement(itcp);
        }
        deps.addElement(dep);
    }
    return deps;
}
Also used : Attribute(org.apache.felix.ipojo.metadata.Attribute) Element(org.apache.felix.ipojo.metadata.Element) ServiceReferenceManager(org.apache.felix.ipojo.dependency.impl.ServiceReferenceManager) ServiceReference(org.osgi.framework.ServiceReference)

Example 17 with Attribute

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

the class ManifestMetadataParser method parseElements.

/**
 * Parses the given string.
 * This methods populates the {@link ManifestMetadataParser#m_elements}
 * list.
 * @param elems the string to parse
 */
private void parseElements(String elems) {
    char[] string = elems.toCharArray();
    for (int i = 0; i < string.length; i++) {
        char current = string[i];
        switch(// NOPMD
        current) {
            // Beginning of an attribute.
            case '$':
                StringBuffer attName = new StringBuffer();
                StringBuffer attValue = new StringBuffer();
                StringBuffer attNs = null;
                i++;
                // Increment and get the new current char.
                current = string[i];
                while (current != '=') {
                    if (current == ':') {
                        attNs = attName;
                        attName = new StringBuffer();
                    } else {
                        attName.append(current);
                    }
                    i++;
                    current = string[i];
                }
                // skip ="
                i = i + 2;
                current = string[i];
                while (current != '"') {
                    attValue.append(current);
                    i++;
                    // Increment and get the new current char.
                    current = string[i];
                }
                // skip "
                i++;
                current = string[i];
                Attribute att = null;
                if (attNs == null) {
                    att = new Attribute(attName.toString(), attValue.toString());
                } else {
                    att = new Attribute(attName.toString(), attNs.toString(), attValue.toString());
                }
                m_elements[m_elements.length - 1].addAttribute(att);
                break;
            // End of an element
            case '}':
                Element lastElement = removeLastElement();
                if (m_elements.length == 0) {
                    addElement(lastElement);
                } else {
                    Element newQueue = m_elements[m_elements.length - 1];
                    newQueue.addElement(lastElement);
                }
                break;
            // Space
            case ' ':
                // do nothing;
                break;
            // Default case
            default:
                StringBuffer qname = new StringBuffer();
                current = string[i];
                while (current != ' ') {
                    qname.append(current);
                    i++;
                    // Increment and get the new current char.
                    current = string[i];
                }
                // Skip spaces
                while (string[i] == ' ') {
                    i = i + 1;
                }
                // skip {
                i = i + 1;
                Element elem = null;
                // Parse the qname
                String n = qname.toString();
                if (n.indexOf(':') == -1) {
                    // No namespace
                    elem = new Element(n, null);
                } else {
                    // The namespace ends on the first ':'
                    int last = n.lastIndexOf(':');
                    String ns = n.substring(0, last);
                    String name = n.substring(last + 1);
                    elem = new Element(name.toString(), ns.toString());
                }
                addElement(elem);
                break;
        }
    }
}
Also used : Attribute(org.apache.felix.ipojo.metadata.Attribute) Element(org.apache.felix.ipojo.metadata.Element)

Example 18 with Attribute

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

the class ComponentVisitor method visitEnd.

/**
 * End of the visit.
 * Append to the "component" element computed attribute.
 * @see org.objectweb.asm.AnnotationVisitor#visitEnd()
 */
public void visitEnd() {
    String classname = workbench.getType().getClassName();
    if (component.getAttribute("name") == null) {
        component.addAttribute(new Attribute("name", classname));
    }
    component.addAttribute(new Attribute("classname", classname));
    if (workbench.getRoot() == null) {
        workbench.setRoot(component);
    } else {
        // Error case: 2 component type's annotations (@Component and @Handler for example) on the same class
        reporter.error("Multiple 'component type' annotations on the class '{%s}'.", classname);
        reporter.warn("@Component will be ignored.");
    }
}
Also used : Attribute(org.apache.felix.ipojo.metadata.Attribute)

Example 19 with Attribute

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

the class ControllerVisitor method visitEnd.

/**
 * Visit @Handler annotation attributes.
 * @see org.objectweb.asm.AnnotationVisitor#visit(String, Object)
 */
public void visitEnd() {
    Element controller = new Element("controller", "");
    controller.addAttribute(new Attribute("field", field));
    workbench.getElements().put(controller, null);
}
Also used : Attribute(org.apache.felix.ipojo.metadata.Attribute) Element(org.apache.felix.ipojo.metadata.Element)

Example 20 with Attribute

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

the class InstantiateVisitor method visitEnd.

/**
 * End of the visit. Creates the instance element.
 *
 * @see org.objectweb.asm.AnnotationVisitor#visitEnd()
 */
public void visitEnd() {
    // We set the instance's component attribute to the class name, if the component type has a custom name,
    // we will update it.
    instance.addAttribute(new Attribute("component", workbench.getType().getClassName()));
    workbench.setInstance(instance);
}
Also used : 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