Search in sources :

Example 1 with ManifestMetadataParser

use of org.apache.felix.ipojo.parser.ManifestMetadataParser 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 2 with ManifestMetadataParser

use of org.apache.felix.ipojo.parser.ManifestMetadataParser in project felix by apache.

the class ManifestMetadataParserTest method testHandlerHeader.

/**
 * Check the parsing of handler element using {@link ManifestMetadataParser#parseHeader(String)}
 * @throws ParseException
 */
public void testHandlerHeader() 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\" }}}";
    ManifestMetadataParser parser = new ManifestMetadataParser();
    parser.parseHeader(header);
    Element[] elems = parser.getComponentsMetadata();
    Assert.assertEquals(1, elems.length);
    Element element = elems[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) ManifestMetadataParser(org.apache.felix.ipojo.parser.ManifestMetadataParser)

Aggregations

Element (org.apache.felix.ipojo.metadata.Element)2 ManifestMetadataParser (org.apache.felix.ipojo.parser.ManifestMetadataParser)2