class Common {

	@SuppressWarnings("rawtypes")
	protected static Object toInstance(String value, Class<?> clazz) throws IllegalArgumentException,
			SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException,
			NoSuchMethodException {
		if (!clazz.isEnum()) {
			Constructor constructor = clazz.getConstructor(String.class);
			if (constructor != null) {
				return constructor.newInstance(value.trim());
			}
		} else {
			Class<? extends Enum> eclazz = clazz.asSubclass(Enum.class);
			for (Enum e : eclazz.getEnumConstants()) {
				if (e.name().equalsIgnoreCase(value.trim())) {
					return e;
				}
			}
		}
		return null;
	}

}