Object array = Array.newInstance(componentType, children.size());
int index = 0;
for (Object child : children) {
if (!componentType.isAssignableFrom(child.getClass())) {
String message = MessageFormat.format("Can't cast {0} into {1} array", child, componentType);
throw new MapperException(message);
}
Array.set(array, index++, child);
}
return array;
}