in src/main/java/org/apache/commons/configuration2/beanutils/BeanHelper.java [159:196]
public void initBean(final Object bean, final BeanDeclaration data) {
initBeanProperties(bean, data);
final Map<String, Object> nestedBeans = data.getNestedBeanDeclarations();
if (nestedBeans != null) {
if (bean instanceof Collection) {
// This is safe because the collection stores the values of the
// nested beans.
@SuppressWarnings("unchecked")
final Collection<Object> coll = (Collection<Object>) bean;
if (nestedBeans.size() == 1) {
final Map.Entry<String, Object> e = nestedBeans.entrySet().iterator().next();
final String propName = e.getKey();
final Class<?> defaultClass = getDefaultClass(bean, propName);
if (e.getValue() instanceof List) {
// This is safe, provided that the bean declaration is implemented
// correctly.
@SuppressWarnings("unchecked")
final List<BeanDeclaration> decls = (List<BeanDeclaration>) e.getValue();
decls.forEach(decl -> coll.add(createBean(decl, defaultClass)));
} else {
coll.add(createBean((BeanDeclaration) e.getValue(), defaultClass));
}
}
} else {
nestedBeans.forEach((propName, prop) -> {
final Class<?> defaultClass = getDefaultClass(bean, propName);
if (prop instanceof Collection) {
final Collection<Object> beanCollection = createPropertyCollection(propName, defaultClass);
((Collection<BeanDeclaration>) prop).forEach(elemDef -> beanCollection.add(createBean(elemDef)));
initProperty(bean, propName, beanCollection);
} else {
initProperty(bean, propName, createBean((BeanDeclaration) prop, defaultClass));
}
});
}
}
}