Search in sources :

Example 1 with ParseException

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

the class TestManipulationMetadata method testGetMetadata.

@Test
public void testGetMetadata() {
    String header = (String) getTestBundle().getHeaders().get("iPOJO-Components");
    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 = getManipulationForComponent(elem, "ManipulationMetadata-FooProviderType-1");
    assertNotNull("Check manipulation metadata not null for " + "FooProviderType-1", manip);
}
Also used : Element(org.apache.felix.ipojo.metadata.Element) ParseException(org.apache.felix.ipojo.parser.ParseException) Test(org.junit.Test) BaseTest(org.ow2.chameleon.testing.helpers.BaseTest)

Example 2 with ParseException

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

the class TestBadLFCController method getManipulationForComponent.

private Element getManipulationForComponent(String comp_name) {
    // On KF we must cast the result
    String header = (String) getTestBundle().getHeaders().get("iPOJO-Components");
    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 = getManipulationForComponent(elem, comp_name);
    assertNotNull("Check manipulation metadata not null for " + comp_name, manip);
    return manip;
}
Also used : Element(org.apache.felix.ipojo.metadata.Element) ParseException(org.apache.felix.ipojo.parser.ParseException)

Example 3 with ParseException

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

the class TestBadServiceDependencies method getManipulationForComponent.

private Element getManipulationForComponent() {
    // On KF we must cast the result.
    String header = (String) getTestBundle().getHeaders().get("iPOJO-Components");
    Element elem = null;
    try {
        elem = ManifestMetadataParser.parse(header);
    } catch (ParseException e) {
        fail("Parse Exception when parsing iPOJO-Component");
    }
    assertNotNull("Check elem not null", elem);
    Element manip = getManipulationForComponent(elem, type);
    assertNotNull("Check manipulation metadata not null for " + type, manip);
    return manip;
}
Also used : Element(org.apache.felix.ipojo.metadata.Element) ParseException(org.apache.felix.ipojo.parser.ParseException)

Example 4 with ParseException

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

the class InstanceHandler method parseProperty.

/**
 * Parse a property.
 * @param prop : the current element to parse
 * @param dict : the dictionary to populate
 * @throws ParseException : occurs if the property cannot be parsed correctly
 */
public static void parseProperty(Element prop, Dictionary dict) throws ParseException {
    // Check that the property has a name
    String name = prop.getAttribute("name");
    String value = prop.getAttribute("value");
    if (name == null) {
        throw new ParseException("A property does not have the 'name' attribute");
    }
    // Final case : the property element has a 'value' attribute
    if (value == null) {
        // Recursive case
        // Check if there is 'property' element
        Element[] subProps = prop.getElements("property");
        if (subProps == null) {
            throw new ParseException("A complex property must have at least one 'property' sub-element");
        }
        Dictionary dict2 = new Properties();
        for (int i = 0; i < subProps.length; i++) {
            parseProperty(subProps[i], dict2);
            dict.put(prop.getAttribute("name"), dict2);
        }
    } else {
        dict.put(name, value);
    }
}
Also used : Dictionary(java.util.Dictionary) Element(org.apache.felix.ipojo.metadata.Element) ParseException(org.apache.felix.ipojo.parser.ParseException) Properties(java.util.Properties)

Example 5 with ParseException

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

the class InstanceHandler method parseInstance.

/**
 * Parse an Element to get a dictionary.
 * @param instance : the Element describing an instance.
 * @return : the resulting dictionary
 * @throws ParseException : occurs when a configuration cannot be parse correctly.
 */
public static Properties parseInstance(Element instance) throws ParseException {
    Properties dict = new Properties();
    String name = instance.getAttribute("name");
    if (name != null) {
        dict.put("instance.name", name);
    }
    String comp = instance.getAttribute("component");
    if (comp == null) {
        throw new ParseException("An instance does not have the 'component' attribute");
    } else {
        dict.put("component", comp);
    }
    Element[] props = instance.getElements("property");
    for (int i = 0; props != null && i < props.length; i++) {
        parseProperty(props[i], dict);
    }
    return dict;
}
Also used : Element(org.apache.felix.ipojo.metadata.Element) ParseException(org.apache.felix.ipojo.parser.ParseException) Properties(java.util.Properties)

Aggregations

Element (org.apache.felix.ipojo.metadata.Element)14 ParseException (org.apache.felix.ipojo.parser.ParseException)14 Properties (java.util.Properties)4 ConfigurationException (org.apache.felix.ipojo.ConfigurationException)3 Field (java.lang.reflect.Field)2 ArrayList (java.util.ArrayList)2 Enumeration (java.util.Enumeration)2 Comparator (java.util.Comparator)1 Dictionary (java.util.Dictionary)1 ServiceImporter (org.apache.felix.ipojo.composite.service.instantiator.ServiceImporter)1 SourceManager (org.apache.felix.ipojo.composite.util.SourceManager)1 Dependency (org.apache.felix.ipojo.handlers.dependency.Dependency)1 Attribute (org.apache.felix.ipojo.metadata.Attribute)1 Before (org.junit.Before)1 Test (org.junit.Test)1 Filter (org.osgi.framework.Filter)1 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)1 BaseTest (org.ow2.chameleon.testing.helpers.BaseTest)1