本文整理汇总了Java中org.smart4j.framework.util.ClassUtil类的典型用法代码示例。如果您正苦于以下问题:Java ClassUtil类的具体用法?Java ClassUtil怎么用?Java ClassUtil使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ClassUtil类属于org.smart4j.framework.util包,在下文中一共展示了ClassUtil类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import org.smart4j.framework.util.ClassUtil; //导入依赖的package包/类
public static void init() {
Class<?>[] classList = {
//获取所有带有service和controller注解的类
ClassHelper.class,
//AOP框架
AopHelper.class,
//实例化类
BeanHelper.class,
//依赖注入,实例化注解类
IocHelper.class,
//获取Action里的请求方式和路径,并建立request与handler的映射关系
ControllerHelper.class
};
for (Class<?> cls : classList) {
//加载类
ClassUtil.loadClass(cls.getName());
}
}
示例2: createPathParamList
import org.smart4j.framework.util.ClassUtil; //导入依赖的package包/类
private List<Object> createPathParamList(Matcher requestPathMatcher, Class<?>[] actionParamTypes) {
//定义参数列表
List<Object> paramList = new ArrayList<>();
for (int i = 0; i < requestPathMatcher.groupCount(); i++) {
String param = requestPathMatcher.group(i);
Class<?> paramType = actionParamTypes[i - 1];
if (ClassUtil.isInt(paramType)) {
paramList.add(CastUtil.castInt(param));
} else if (ClassUtil.isLong(paramType)) {
paramList.add(CastUtil.castLong(param));
} else if (ClassUtil.isDouble(paramType)) {
paramList.add(CastUtil.castDouble(param));
} else if (ClassUtil.isString(paramType)) {
paramList.add(param);
}
}
return paramList;
}
示例3: initSQL
import org.smart4j.framework.util.ClassUtil; //导入依赖的package包/类
/**
* 初始化 SQL 脚本
*/
public static void initSQL(String sqlPath) {
try {
File sqlFile = new File(ClassUtil.getClassPath() + sqlPath);
List<String> sqlList = FileUtils.readLines(sqlFile);
for (String sql : sqlList) {
update(sql);
}
} catch (Exception e) {
logger.error("初始化 SQL 脚本出错!", e);
throw new RuntimeException(e);
}
}
示例4: createTargetClassList
import org.smart4j.framework.util.ClassUtil; //导入依赖的package包/类
private static List<Class<?>> createTargetClassList(Aspect aspect) {
List<Class<?>> targetClassList = new ArrayList<>();
// 获取 Aspect 注解的相关属性
String pkg = aspect.pkg();
String cls = aspect.cls();
Class<? extends Annotation> annotation = aspect.annotation();
// 若包名不为空,则需进一步判断类名是否为空
if (StringUtil.isNotEmpty(pkg)) {
if (StringUtil.isNotEmpty(cls)) {
// 若类名不为空,则仅添加该类
targetClassList.add(ClassUtil.loadClass(pkg + "." + cls, false));
} else {
// 若注解不为空且不是 Aspect 注解,则添加指定包名下带有该注解的所有类
if (!annotation.equals(Aspect.class)) {
targetClassList.addAll(CLASS_SCANNER.getClassListByAnnotation(pkg, annotation));
} else {
// 否则添加该包名下所有类
targetClassList.addAll(CLASS_SCANNER.getClassList(pkg));
}
}
} else {
// 若注解不为空且不是 Aspect 注解,则添加应用包名下带有该注解的所有类
if (!annotation.equals(Aspect.class)) {
targetClassList.addAll(ClassHelper.getClassListByAnnotation(annotation));
}
}
return targetClassList;
}
示例5: getClassList
import org.smart4j.framework.util.ClassUtil; //导入依赖的package包/类
public final List<Class<?>> getClassList() {
List<Class<?>> classList = new ArrayList<>();
try {
Enumeration<URL> urls = ClassUtil.getClassLoader().getResources(packageName.replace(".", "/"));
while (urls.hasMoreElements()) {
URL url = urls.nextElement();
if (url != null) {
String protocal = url.getProtocol();
if (protocal.equals("file")) {
String packagePath = url.getPath().replaceAll("%20", " ");
addClass(classList, packagePath, packageName);
} else if (protocal.equals("jar")) {
JarURLConnection jarURLConnection = (JarURLConnection) url.openConnection();
JarFile jarFile = jarURLConnection.getJarFile();
Enumeration<JarEntry> jarEntries = jarFile.entries();
while (jarEntries.hasMoreElements()) {
JarEntry jarEntry = jarEntries.nextElement();
String jarEntryName = jarEntry.getName();
// 判断该 entry 是否为 class
if (jarEntryName.endsWith(".class")) {
// 获取类名
String className = jarEntryName.substring(0, jarEntryName.lastIndexOf("."))
.replaceAll("/", ".");
// 执行添加类操作
doAddClass(classList, className);
}
}
}
}
}
} catch (IOException e) {
logger.error("获取类出错!", e);
}
return classList;
}
示例6: doAddClass
import org.smart4j.framework.util.ClassUtil; //导入依赖的package包/类
private void doAddClass(List<Class<?>> classList, String className) {
Class<?> cls = ClassUtil.loadClass(className, false);
if (checkAddClass(cls)) {
classList.add(cls);
}
}