From d8321996f3ad19336fe9369774d6dd277a43518d Mon Sep 17 00:00:00 2001 From: coderfengyun Date: Fri, 28 Mar 2014 10:56:56 +0800 Subject: [PATCH] refactor refactor --- .../impl/ParamCoordinator.java | 2 +- .../impl/ParametersFactory.java | 2 +- ...oader.java => UserDefinedClassLoader.java} | 26 +++++++++---------- .../Test_MyFileClassLoader.java | 4 +-- 4 files changed, 16 insertions(+), 18 deletions(-) rename Bench4Q-Agent/src/main/java/org/bench4q/agent/parameterization/impl/{MyFileClassLoader.java => UserDefinedClassLoader.java} (57%) diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/parameterization/impl/ParamCoordinator.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/parameterization/impl/ParamCoordinator.java index ec48b47a..91d6e5e9 100644 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/parameterization/impl/ParamCoordinator.java +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/parameterization/impl/ParamCoordinator.java @@ -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(); diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/parameterization/impl/ParametersFactory.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/parameterization/impl/ParametersFactory.java index 7a47dbd5..33ce7a7c 100644 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/parameterization/impl/ParametersFactory.java +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/parameterization/impl/ParametersFactory.java @@ -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 diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/parameterization/impl/MyFileClassLoader.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/parameterization/impl/UserDefinedClassLoader.java similarity index 57% rename from Bench4Q-Agent/src/main/java/org/bench4q/agent/parameterization/impl/MyFileClassLoader.java rename to Bench4Q-Agent/src/main/java/org/bench4q/agent/parameterization/impl/UserDefinedClassLoader.java index 0dff5e15..387cfcc8 100644 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/parameterization/impl/MyFileClassLoader.java +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/parameterization/impl/UserDefinedClassLoader.java @@ -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); } /** - * 锟斤拷锟斤拷锟斤拷锟斤拷址锟斤拷指锟斤拷锟斤拷目录锟斤拷锟斤拷锟洁,锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟� + * */ @Override protected Class findClass(String name) throws ClassNotFoundException { @@ -36,15 +36,15 @@ public class MyFileClassLoader extends ClassLoader { } /** - * 锟斤拷锟斤拷锟斤拷锟斤拷址锟斤拷锟斤拷锟斤拷 byte 锟斤拷锟斤拷锟� + * * * @param name - * 锟斤拷锟斤拷锟街凤拷 锟斤拷锟界: com.cmw.entity.SysEntity - * @return 锟斤拷锟斤拷锟斤拷锟侥硷拷 byte 锟斤拷锟斤拷锟� + * + * @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 { } /** - * 锟斤拷锟斤拷锟斤拷锟斤拷址锟斤拷锟揭伙拷锟�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; } diff --git a/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/parameterization/Test_MyFileClassLoader.java b/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/parameterization/Test_MyFileClassLoader.java index b2285f3f..e23a3144 100644 --- a/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/parameterization/Test_MyFileClassLoader.java +++ b/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/parameterization/Test_MyFileClassLoader.java @@ -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");