cn.featherfly.conversion.string.basic.ClassConvertor Maven / Gradle / Ivy
package cn.featherfly.conversion.string.basic;
import cn.featherfly.common.lang.GenericType;
import cn.featherfly.common.lang.LogUtils;
import cn.featherfly.common.lang.StringUtils;
import cn.featherfly.conversion.ConversionException;
/**
*
* class类转换器
*
*
* @author 钟冀
*/
@SuppressWarnings("rawtypes")
public class ClassConvertor extends AbstractBasicConvertor>{
/**
*/
public ClassConvertor() {
}
/**
* {@inheritDoc}
*/
@Override
public Class getSourceType() {
return Class.class;
}
/**
* {@inheritDoc}
*/
@Override
protected String doToString(Class value, GenericType genericType) {
if (value != null) {
return value.getName();
}
return "";
}
/**
* {@inheritDoc}
*/
@Override
protected Class doToObject(String value, GenericType genericType) {
if (StringUtils.isNotBlank(value)) {
try {
return Class.forName(value);
} catch (ClassNotFoundException e) {
LogUtils.debug(e, logger);
throw new ConversionException("#class_not_found", new Object[]{value});
}
}
return null;
}
}