in gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/setter/CollectionFieldSetter.java [70:105]
protected void doSet(final Object value) throws IllegalAccessException {
Object obj = field.get(bean);
// If the field is not set, then create a new instance of the collection and set it
if (obj == null) {
Class type = field.getType();
if (List.class.isAssignableFrom(type)) {
obj = new ArrayList();
}
else if (Set.class.isAssignableFrom(type)) {
obj = new LinkedHashSet();
}
else if (Collection.class.isAssignableFrom(type)) {
obj = new ArrayList();
}
else {
try {
obj = type.newInstance();
}
catch (Exception e) {
throw new IllegalAnnotationError("Unsupported collection type: " + field.getType(), e);
}
}
field.set(bean, obj);
}
// This should never happen
if (!(obj instanceof Collection)) {
throw new IllegalAnnotationError("Field is not a collection type: " + field);
}
// noinspection unchecked
((Collection)obj).add(value);
}