@SuppressWarnings("unchecked")
    public static <T extends Enum> T fromString(Class<T> enumKlass, String enumStr, boolean caseSensitive) {
        if (StringUtils.isEmpty(enumStr) || enumKlass == null) {
            // not valid
            return null;
        }
        Object[] types = enumKlass.getEnumConstants();
        if (types == null) {
            // not an enum
            return null;
        }
        Object enumInstance = null;
        for (int i = 0; i < types.length; i++) {
            enumInstance = types[i];
            if (caseSensitive == false) {
                if (StringUtils.equalsIgnoreCase(ObjectUtils.toString(enumInstance), enumStr)) {
                    return (T) (enumInstance);
                }
            }
            else {
                if (StringUtils.equals(ObjectUtils.toString(enumInstance), enumStr)) {
                    return (T) (enumInstance);
                }
            }
        }
        // not found
        throw new IllegalArgumentException("Unknown enumeration [" + enumStr + "] for enum class [" + enumKlass + "]");
    }