packagecom.lkb.autoCode.util;importcom.lkb.autoCode.constant.AutoCodeConstant;importjava.lang.reflect.Method;/*** DefultClassLoader 默认的类加载器
*
*@authorLilin
* @date 2016/5/24*/
public class DefultClassLoader{private Class> classType = null;private T reflectClass = null;/***@paramfullClassName 全包路径
*@throwsException*/
public DefultClassLoader(String fullClassName) throwsException {
classType=getClassType(fullClassName);
}/***@paramtype 模板类型
*@paramprovinceCode 省Id
*@paramcityCode 市Id
*@paramclassName 类名称
*@throwsException*/
public DefultClassLoader(String type, String provinceCode, String cityCode, String className) throwsException {
classType=getClassType(type, provinceCode, cityCode, className);
}/*** 获取classType
*
*@paramtype
*@paramprovinceCode
*@paramcityCode
*@return*@throwsException*/
public Class> getClassType(String type, String provinceCode, String cityCode, String suffix) throwsException {
Class> classType = Class.forName(AutoCodeConstant.BASE_SB_PACKAGE + "." + type + "." + provinceCode + "." + cityCode +suffix);returnclassType;
}/*** 获取base
*
*@paramfullClassName
*@return*@throwsException*/
public Class> getClassType(String fullClassName) throwsException {
Class> classType =Class.forName(fullClassName);returnclassType;
}/*** 获取对象client
*@return*@throwsException*/
public T getClassInstance() throwsException {return getClassInstance(null, null);
}/*** 获取对象client
*
*@paramclasses
*@paramobjects
*@return*@throwsException*/
public T getClassInstance(Class[] classes, Object[] objects) throwsException {
T client=(T) classType.getConstructor(classes).newInstance(objects);returnclient;
}/*** 执行不带参数的方法(忽略)
*
*@paramclassType
*@paraminstance
*@parammethod
*@return*@throwsException*/
public Object implementMethod(Class> classType, Object instance, String method) throwsException {return implementMethod(classType, instance, method, null, null);
}/*** 执行方法(忽略)
*
*@paramclassType
*@paraminstance
*@parammethod
*@paramparamTypes
*@paramparams
*@return*@throwsException*/
public Object implementMethod(Class> classType, Object instance, String method, Class[] paramTypes, Object[] params) throwsException {
Method getStrMethod;
Object result;if (paramTypes == null) {
getStrMethod=classType.getMethod(method);
result=getStrMethod.invoke(instance);
}else{
getStrMethod=classType.getMethod(method, paramTypes);
result=getStrMethod.invoke(instance, params);
}returnresult;
}
}