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);
}
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;
}
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;
}
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);
}
}
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;
}
Aggregations