public static <T extends Enum<T>> EnumListProperty<T> newEnumList(String name, TypeLiteral<List<T>> type) { return new EnumListProperty<T>(type, name); }
public EnumListProperty(TypeLiteral<List<T>> type, String name) { super(type, name, null); // set the possible values accoording with all the enum types. T[] enumConstants = (T[]) ((Class) ((Type[]) ((ParameterizedType) type.value).getActualTypeArguments())[0]) .getEnumConstants(); this.setPossibleValues(enumConstants); }
@SuppressWarnings("unchecked") @Override public List<T> getValue() { if (storedValue == null) { return null; } List value = (List) storedValue; if (propertyValueEvaluator != null) { value = propertyValueEvaluator.evaluate(this, storedValue); } // else not evaluator so return the storedValue // try to convert the String to the enum List convertedValue = new ArrayList(); boolean converted = false; try { String enumClassName = getType().substring("java.util.List<".length(), getType().length() - 1); for (Object v : value) { if (v instanceof String) { converted = true; Class<T> enumClass = (Class<T>) ClassUtils.getClass(enumClassName); convertedValue.add(Enum.valueOf(enumClass, (String) v)); } } } catch (ClassNotFoundException e) { TalendRuntimeException.unexpectedException(e); } return converted ? convertedValue : (List<T>) value; }