复制代码 代码如下:
package com.java.db;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import com.java.entity.BookShelf;
import com.java.util.GetmetaDataCloumName;
public class GetNewInstances
Class[] cl = {};
Object[] ob = {};
public void setNullToArrays(){
this.cl = new Class[]{};
this.ob = new Object[]{};
}
public Object[] getObjectArrays(Object obj) {
ob = Arrays.copyOf(ob,ob.length + 1);
ob[ob.length - 1] = obj;
return ob;
}
@SuppressWarnings("unchecked")
public Class[] getClassArrays(Class> cla) {
if (cla != null) {
cl = Arrays.copyOf(cl,cl.length + 1);
cl[cl.length - 1] = cla;
return cl;
}else{
return cl;
}
}
@SuppressWarnings("unchecked")
public Object getClassNewInstance(Class> clazz)
throws InstantiationException, IllegalAccessException,
IllegalArgumentException, SecurityException,
InvocationTargetException, NoSuchMethodException {
Object oj = null;
Constructor[] cons = clazz.getDeclaredConstructors();// 得到构造函数
Class[] cla = cons[1].getParameterTypes();
System.out.println("提示用户是否需要添加字段 构造函数参数的大小:"+cla.length);
for (int i = 0; i < cla.length; i++) {
String classStr = cla[i].toString();
// System.out.println("参数的类型:"+classStr);
if (classStr.equals("class java.lang.String")) {
getClassArrays(String.class);
} else if (classStr.equals("int")) {
getClassArrays(int.class);
} else if (classStr.equals("double")) {
getClassArrays(double.class);
} else if (classStr.equals("boolean")) {
getClassArrays(boolean.class);
} else if (classStr.equals("float")) {
getClassArrays(float.class);
} else if (classStr.equals("class java.lang.Integer")) {
getClassArrays(Integer.class);
}else if(classStr.equals("class java.lang.Float")){
getClassArrays(Float.class);
}
}
oj = clazz.newInstance();//返回当前对象 具体的实例化构造在BDOperater
return oj;
}
public Object getObjCon(Class> clazz) throws IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException{
Object obj=null;
obj = this.getClassNewInstance(clazz);
return obj;
}
public Object getNewinstance(Class clazz) throws InstantiationException, IllegalAccessException{
Object obj = null;
obj = clazz.newInstance();
return obj;
}
public Field[] getFielsdArray(Class



