use of org.mule.runtime.config.internal.dsl.model.config.ConfigurationPropertiesException in project mule by mulesoft.
the class DefaultConfigurationPropertiesProvider method createAttributesFromYamlObject.
protected void createAttributesFromYamlObject(String parentPath, Object parentYamlObject, Object yamlObject) {
if (yamlObject instanceof List) {
List list = (List) yamlObject;
if (list.get(0) instanceof Map) {
list.forEach(value -> createAttributesFromYamlObject(parentPath, yamlObject, value));
} else {
if (!(list.get(0) instanceof String)) {
throw new ConfigurationPropertiesException(createStaticMessage("List of complex objects are not supported as property values. Offending key is " + parentPath), this);
}
String[] values = new String[list.size()];
list.toArray(values);
String value = join(",", list);
configurationAttributes.put(parentPath, new DefaultConfigurationProperty(this, parentPath, value));
}
} else if (yamlObject instanceof Map) {
if (parentYamlObject instanceof List) {
throw new ConfigurationPropertiesException(createStaticMessage("Configuration properties does not support type a list of complex types. Complex type keys are: " + join(",", ((Map) yamlObject).keySet())), this);
}
Map<String, Object> map = (Map) yamlObject;
map.entrySet().stream().forEach(entry -> createAttributesFromYamlObject(createKey(parentPath, entry.getKey()), yamlObject, entry.getValue()));
} else {
if (!(yamlObject instanceof String)) {
throw new ConfigurationPropertiesException(createStaticMessage(format("YAML configuration properties only supports string values, make sure to wrap the value with \" so you force the value to be an string. Offending property is %s with value %s", parentPath, yamlObject)), this);
}
String resultObject = createValue(parentPath, (String) yamlObject);
configurationAttributes.put(parentPath, new DefaultConfigurationProperty(this, parentPath, resultObject));
}
}
Aggregations