@SuppressWarnings("unchecked")
public Object getValue(TypeInfo info, ClassLoader cl) throws Throwable
{
Collection result = (Collection)super.getValue(info, cl);
TypeInfo typeInfo = getClassInfo(cl);
if (typeInfo != null && typeInfo instanceof ClassInfo == false)
throw new IllegalArgumentException(typeInfo.getName() + " is not a class");
if (typeInfo == null)
{
// No type specified
if (info == null)
{
info = getElementClassInfo(cl, null);
if (info == null)
return null;
info = info.getArrayType();
}
// Not a class
if (info instanceof ClassInfo == false)
return null;
// Not an interface
if (((ClassInfo) info).isInterface())
return null;
// Type is too general
if (Object.class.getName().equals(info.getName()))
return null;
// Try to use the passed type
typeInfo = info;
}
Object array = typeInfo.newArrayInstance(result.size());
int i = 0;
for(Object element : result)
Array.set(array, i++, element);
return array;
}