/** * */ package pt.ist.renderers.converters; import pt.ist.renderers.components.converters.Converter; public class EnumConverter extends Converter { private Class enumClass; public EnumConverter() { super(); } public EnumConverter(Class enumClass) { super(); this.enumClass = enumClass; } @Override public Object convert(Class type, Object value) { Object[] enums; if (this.enumClass == null) { enums = type.getEnumConstants(); } else { enums = this.enumClass.getEnumConstants(); if (enums == null) { enums = this.enumClass.getEnclosingClass().getEnumConstants(); } } for (int i = 0; i < enums.length; i++) { if (enums[i].toString().equals(value)) { return enums[i]; } } return null; } }