cn.sylinx.hbatis.kit.ClassUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hbatis-core Show documentation
Show all versions of hbatis-core Show documentation
hbatis is a simple orm framework
The newest version!
package cn.sylinx.hbatis.kit;
import cn.sylinx.hbatis.log.GLog;
public abstract class ClassUtil {
public static boolean isClassExist(String className) {
try {
Class.forName(className, false, getDefaultClassLoader());
} catch (ClassNotFoundException e) {
GLog.error("class:{} not foud ", className);
return false;
}
return true;
}
public static ClassLoader getDefaultClassLoader() {
ClassLoader cl = null;
try {
cl = Thread.currentThread().getContextClassLoader();
} catch (Throwable ex) {
// Cannot access thread context ClassLoader - falling back...
}
if (cl == null) {
// No thread context class loader -> use class loader of this class.
cl = ClassUtil.class.getClassLoader();
if (cl == null) {
// getClassLoader() returning null indicates the bootstrap ClassLoader
try {
cl = ClassLoader.getSystemClassLoader();
} catch (Throwable ex) {
// Cannot access system ClassLoader - oh well, maybe the caller can live with
// null...
}
}
}
return cl;
}
}