Object getValue(ControllerService plugin, AnnotatedElement annotated, Type type, String[] value) throws Exception {
if (type instanceof Class<?>) {
Class<?> clazz = (Class<?>)type;
if (clazz.isArray()) {
clazz = clazz.getComponentType();
ValueType valueType = plugin.resolveValueType(clazz);
if (valueType != null) {
Object array = Array.newInstance(clazz, value.length);
for (int i = 0;i < value.length;i++) {
Array.set(array, i, valueType.parse(annotated, value[i]));
}
return array;
}
} else {
ValueType valueType = plugin.resolveValueType(clazz);
if (valueType != null) {
return valueType.parse(annotated, value[0]);
}
}
} else if (type instanceof ParameterizedType) {
ParameterizedType parameterizedType = (ParameterizedType)type;
if (List.class.equals(parameterizedType.getRawType())) {
Type typeArg = parameterizedType.getActualTypeArguments()[0];
if (typeArg instanceof Class) {
ValueType valueType = plugin.resolveValueType((Class)typeArg);
if (valueType != null) {
ArrayList list = new ArrayList(value.length);
for (String s : value) {
list.add(valueType.parse(annotated, s));
}
return list;
}
}
}