final Object config = metadata.get("config");
if (config instanceof List) {
final List configs = (List) config;
for (final Object citem : configs) {
if (citem instanceof Map) {
final PropertyBuilder pbuild = PropertyBuilder.builder();
final Map<String, Object> itemmeta = (Map<String, Object>) citem;
final String typestr = metaStringProp(itemmeta, CONFIG_TYPE);
try {
pbuild.type(Property.Type.valueOf(typestr));
} catch (IllegalArgumentException e) {
throw new ConfigurationException("Invalid property type: " + typestr);
}
String propName = metaStringProp(itemmeta, CONFIG_NAME);
pbuild
.name(propName)
.title(metaStringProp(itemmeta, CONFIG_TITLE))
.description(metaStringProp(itemmeta, CONFIG_DESCRIPTION));
final Object reqValue = itemmeta.get(CONFIG_REQUIRED);
final boolean required;
if (reqValue instanceof Boolean) {
required = (Boolean) reqValue;
} else {
required = reqValue instanceof String && Boolean.parseBoolean((String) reqValue);
}
pbuild.required(required);
final Object defObj = itemmeta.get(CONFIG_DEFAULT);
pbuild.defaultValue(null != defObj ? defObj.toString() : null);
final List<String> valueList;
final String valuesstr = metaStringProp(itemmeta, CONFIG_VALUES);
if (null != valuesstr) {
final String[] split = null != valuesstr ? valuesstr.split(",") : null;
valueList = Arrays.asList(split);
} else {
Object vlist = itemmeta.get(CONFIG_VALUES);
if (vlist instanceof List) {
valueList = (List<String>) vlist;
} else {
valueList = null;
}
}
final List<String> values;
if (null != valueList) {
final ArrayList<String> valuesA = new ArrayList<String>();
for (final String s : valueList) {
valuesA.add(s.trim());
}
values = valuesA;
} else {
values = null;
}
pbuild.values(values);
final String scopeString = metaStringProp(itemmeta, CONFIG_SCOPE);
if(null!=scopeString) {
try {
pbuild.scope(PropertyScope.valueOf(scopeString.trim()));
} catch (IllegalArgumentException e) {
throw new ConfigurationException("Invalid property scope: " + scopeString);
}
}
if(useConventionalPropertiesMapping) {
final String projectPropertyPrefix =
PropertyResolverFactory.projectPropertyPrefix
(
PropertyResolverFactory
.pluginPropertyPrefix(
provider.getService(),
provider.getName()
)
) ;
dbuilder.mapping(propName, projectPropertyPrefix + propName);
final String frameworkPropertyPrefix =
PropertyResolverFactory.frameworkPropertyPrefix
(
PropertyResolverFactory
.pluginPropertyPrefix(
provider.getService(),
provider.getName()
)
);
dbuilder.frameworkMapping(propName, frameworkPropertyPrefix + propName);
}
//rendering options
final Object renderingOpts = itemmeta.get(CONFIG_RENDERING_OPTIONS);
if(null != renderingOpts && renderingOpts instanceof Map){
Map<String,Object> renderingOptsMap=(Map<String,Object>) renderingOpts;
pbuild.renderingOptions(renderingOptsMap);
}
try {
dbuilder.property(pbuild.build());
} catch (IllegalStateException e) {
throw new ConfigurationException(e.getMessage());
}
}