Search in sources :

Example 26 with Element

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

the class MethodMetadataTest method testComputationForArraysUsingObjectsFromElement.

public void testComputationForArraysUsingObjectsFromElement() {
    Element metadata1 = new Element("method", null);
    metadata1.addAttribute(new Attribute("name", "withOneArray"));
    metadata1.addAttribute(new Attribute("arguments", "{java.lang.String[]}"));
    Element metadata2 = new Element("method", null);
    metadata2.addAttribute(new Attribute("name", "withOneArray"));
    metadata2.addAttribute(new Attribute("arguments", "{java.lang.String[][]}"));
    Element metadata3 = new Element("method", null);
    metadata3.addAttribute(new Attribute("name", "withOneArray"));
    metadata3.addAttribute(new Attribute("arguments", "{java.lang.String[][][]}"));
    MethodMetadata methodMetadata1 = new MethodMetadata(metadata1);
    Assert.assertEquals("withOneArray$java_lang_String__", methodMetadata1.getMethodIdentifier());
    MethodMetadata methodMetadata2 = new MethodMetadata(metadata2);
    Assert.assertEquals("withOneArray$java_lang_String____", methodMetadata2.getMethodIdentifier());
    MethodMetadata methodMetadata3 = new MethodMetadata(metadata3);
    Assert.assertEquals("withOneArray$java_lang_String______", methodMetadata3.getMethodIdentifier());
}
Also used : Attribute(org.apache.felix.ipojo.metadata.Attribute) Element(org.apache.felix.ipojo.metadata.Element)

Example 27 with Element

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

the class PojoMetadataTest method testGetMetadata.

public void testGetMetadata() {
    Element elem = null;
    try {
        elem = ManifestMetadataParser.parseHeaderMetadata(header);
    } catch (ParseException e) {
        fail("Parse Exception when parsing iPOJO-Component");
    }
    assertNotNull("Check elem not null", elem);
    Element manip = getMetadataForComponent(elem, "ManipulationMetadata-FooProviderType-1");
    assertNotNull("Check manipulation metadata not null for " + "Manipulation-FooProviderType-1", manip);
    PojoMetadata mm;
    try {
        mm = new PojoMetadata(manip);
        assertNotNull("Check mm not null", mm);
    } catch (ConfigurationException e) {
        fail("The creation of pojo metadata has failed");
    }
}
Also used : ConfigurationException(org.apache.felix.ipojo.ConfigurationException) Element(org.apache.felix.ipojo.metadata.Element)

Example 28 with Element

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

the class ManifestMetadataParserTest method testHandlerHeader2.

/**
 * Check the parsing of handler element using {@link ManifestMetadataParser#parseHeaderMetadata(String)}
 * @throws ParseException
 */
public void testHandlerHeader2() throws ParseException {
    String header = "handler { $name=\"wbp\" $classname=\"org.apache.felix.ipojo.handler.wbp.WhiteBoardPatternHandler\"" + " $namespace=\"org.apache.felix.ipojo.whiteboard\" manipulation { $super=\"org.apache.felix.ipojo.PrimitiveHandler\"" + " field { $name=\"m_managers\" $type=\"java.util.List\" }method { $name=\"$init\" }method { $arguments=" + "\"{org.apache.felix.ipojo.metadata.Element,java.util.Dictionary}\" $name=\"configure\" }method { $name=\"start\"" + " }method { $arguments=\"{int}\" $name=\"stateChanged\" }method { $name=\"stop\" }}}";
    // This method returns an iPOJO root element
    Element elem = ManifestMetadataParser.parseHeaderMetadata(header);
    Element element = elem.getElements("handler")[0];
    Assert.assertEquals("handler", element.getName());
    Assert.assertNull(element.getNameSpace());
    Assert.assertEquals("wbp", element.getAttribute("name"));
    Assert.assertEquals("org.apache.felix.ipojo.handler.wbp.WhiteBoardPatternHandler", element.getAttribute("classname"));
    Assert.assertEquals("org.apache.felix.ipojo.whiteboard", element.getAttribute("namespace"));
    // Check the manipulation element
    Element[] manip = element.getElements("manipulation");
    Assert.assertNotNull(manip[0]);
    Element[] methods = manip[0].getElements("method");
    Assert.assertEquals(5, methods.length);
}
Also used : Element(org.apache.felix.ipojo.metadata.Element)

Example 29 with Element

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

the class ComponentsBundleProcessor method parse.

/**
 * Parses the internal metadata (from the manifest
 * (in the iPOJO-Components property)). This methods
 * creates factories and add instances to the instance creator.
 *
 * @param bundle     the owner bundle.
 * @param components The iPOJO Header String.
 * @throws IOException    if the manifest can not be found
 * @throws ParseException if the parsing process failed
 */
private void parse(Bundle bundle, String components) throws IOException, ParseException {
    ManifestMetadataParser parser = new ManifestMetadataParser();
    parser.parseHeader(components);
    // Get the component type declaration
    Element[] metadata = parser.getComponentsMetadata();
    for (int i = 0; i < metadata.length; i++) {
        handleTypeDeclaration(bundle, metadata[i]);
    }
    Dictionary[] instances = parser.getInstances();
    for (int i = 0; instances != null && i < instances.length; i++) {
        handleInstanceDeclaration(bundle, instances[i]);
    }
}
Also used : Element(org.apache.felix.ipojo.metadata.Element) ManifestMetadataParser(org.apache.felix.ipojo.parser.ManifestMetadataParser)

Example 30 with Element

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

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