panda.cast.castor.ClassCastor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of panda-core Show documentation
Show all versions of panda-core Show documentation
Panda Core is the core module of Panda Framework, it contains commonly used utility classes similar to apache-commons.
package panda.cast.castor;
import panda.cast.CastContext;
import panda.lang.Classes;
@SuppressWarnings("rawtypes")
public class ClassCastor extends AnySingleCastor {
public ClassCastor() {
super(Class.class);
}
@Override
protected Class castValue(Object value, CastContext context) {
if (value instanceof CharSequence) {
String s = value.toString();
if (s.length() < 1) {
return defaultValue();
}
try {
return Classes.getClass(s);
}
catch (ClassNotFoundException e) {
return castError(value, context, e);
}
}
return castError(value, context);
}
}