001package org.javasimon.utils.bean; 002 003/** 004 * Class for converting String values to an instance of an enum of the specified type. 005 * 006 * @author <a href="mailto:ivan.mushketyk@gmail.com">Ivan Mushketyk</a> 007 */ 008public class ToEnumConverter implements Converter { 009 @Override 010 public Object convert(Class<?> tClass, String strVal) throws ConvertException { 011 try { 012 //noinspection unchecked,UnnecessaryLocalVariable 013 Class uncheckedClass = tClass; 014 return Enum.valueOf(uncheckedClass, strVal); 015 } catch (IllegalArgumentException e) { 016 throw new ConvertException(String.format("Failed to convert %s value to %s class", strVal, tClass.toString()), e); 017 } 018 } 019}