parent
212646d9cf
commit
d8321996f3
|
@ -98,7 +98,7 @@ public class ParamCoordinator implements SessionObject {
|
|||
|
||||
private boolean createObj(String className) {
|
||||
try {
|
||||
MyFileClassLoader classLoader = new MyFileClassLoader(
|
||||
UserDefinedClassLoader classLoader = new UserDefinedClassLoader(
|
||||
Main.USER_DEFINED_PARAMS_FOLDER);
|
||||
Class<?> cls = classLoader.loadClass(className);
|
||||
Object instance = cls.newInstance();
|
||||
|
|
|
@ -54,7 +54,7 @@ public class ParametersFactory {
|
|||
|
||||
private boolean createObj(String className) {
|
||||
try {
|
||||
MyFileClassLoader cl = new MyFileClassLoader(
|
||||
UserDefinedClassLoader cl = new UserDefinedClassLoader(
|
||||
Main.USER_DEFINED_PARAMS_FOLDER);
|
||||
Class<?> cls = cl.loadClass(className);
|
||||
Constructor<?> contructor = cls
|
||||
|
|
|
@ -5,7 +5,7 @@ import java.io.FileInputStream;
|
|||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
|
||||
public class MyFileClassLoader extends ClassLoader {
|
||||
public class UserDefinedClassLoader extends ClassLoader {
|
||||
|
||||
private String classPath;
|
||||
|
||||
|
@ -13,16 +13,16 @@ public class MyFileClassLoader extends ClassLoader {
|
|||
this.classPath = classPath;
|
||||
}
|
||||
|
||||
private MyFileClassLoader() {
|
||||
private UserDefinedClassLoader() {
|
||||
}
|
||||
|
||||
public MyFileClassLoader(String classPath) {
|
||||
public UserDefinedClassLoader(String classPath) {
|
||||
this();
|
||||
this.setClassPath(classPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* 锟斤拷锟斤拷锟斤拷锟斤拷址锟斤拷指锟斤拷锟斤拷目录锟斤拷锟斤拷锟洁,锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟<EFBFBD>
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
protected Class<?> findClass(String name) throws ClassNotFoundException {
|
||||
|
@ -36,15 +36,15 @@ public class MyFileClassLoader extends ClassLoader {
|
|||
}
|
||||
|
||||
/**
|
||||
* 锟斤拷锟斤拷锟斤拷锟斤拷址锟斤拷锟斤拷锟斤拷 byte 锟斤拷锟斤拷锟<EFBFBD>
|
||||
*
|
||||
*
|
||||
* @param name
|
||||
* 锟斤拷锟斤拷锟街凤拷 锟斤拷锟界: com.cmw.entity.SysEntity
|
||||
* @return 锟斤拷锟斤拷锟斤拷锟侥硷拷 byte 锟斤拷锟斤拷锟<EFBFBD>
|
||||
*
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
private byte[] loadClassData(String name) throws IOException {
|
||||
File file = getFile(name);
|
||||
File file = getClassFile(name);
|
||||
@SuppressWarnings("resource")
|
||||
FileInputStream fis = new FileInputStream(file);
|
||||
byte[] arrData = new byte[(int) file.length()];
|
||||
|
@ -53,17 +53,15 @@ public class MyFileClassLoader extends ClassLoader {
|
|||
}
|
||||
|
||||
/**
|
||||
* 锟斤拷锟斤拷锟斤拷锟斤拷址锟斤拷锟揭伙拷锟<EFBFBD>File 锟斤拷锟斤拷
|
||||
*
|
||||
* @param name
|
||||
* 锟斤拷锟斤拷锟街凤拷
|
||||
* @return File 锟斤拷锟斤拷
|
||||
* @return
|
||||
* @throws FileNotFoundException
|
||||
*/
|
||||
private File getFile(String name) throws FileNotFoundException {
|
||||
private File getClassFile(String name) throws FileNotFoundException {
|
||||
File dir = new File(classPath);
|
||||
if (!dir.exists())
|
||||
throw new FileNotFoundException(classPath + " 目录锟斤拷锟斤拷锟节o拷");
|
||||
throw new FileNotFoundException(classPath + " not exists!");
|
||||
String _classPath = classPath.replaceAll("[\\\\]", "/");
|
||||
int offset = _classPath.lastIndexOf("/");
|
||||
name = name.replaceAll("[.]", "/");
|
||||
|
@ -73,7 +71,7 @@ public class MyFileClassLoader extends ClassLoader {
|
|||
_classPath += name + ".class";
|
||||
dir = new File(_classPath);
|
||||
if (!dir.exists())
|
||||
throw new FileNotFoundException(dir + " 锟斤拷锟斤拷锟节o拷");
|
||||
throw new FileNotFoundException(dir + " not exists!");
|
||||
return dir;
|
||||
}
|
||||
|
|
@ -4,7 +4,7 @@ import static org.junit.Assert.*;
|
|||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.bench4q.agent.parameterization.impl.MyFileClassLoader;
|
||||
import org.bench4q.agent.parameterization.impl.UserDefinedClassLoader;
|
||||
import org.junit.Test;
|
||||
|
||||
public class Test_MyFileClassLoader {
|
||||
|
@ -13,7 +13,7 @@ public class Test_MyFileClassLoader {
|
|||
@Test
|
||||
public void test() throws ClassNotFoundException, InstantiationException,
|
||||
IllegalAccessException {
|
||||
MyFileClassLoader fileClsLoader = new MyFileClassLoader(Test_ClassPath);
|
||||
UserDefinedClassLoader fileClsLoader = new UserDefinedClassLoader(Test_ClassPath);
|
||||
|
||||
Class<?> cls = fileClsLoader
|
||||
.loadClass("com.cmw.entity.sys.AccordionEntity");
|
||||
|
|
Loading…
Reference in New Issue