نسخة الكود كما يلي:
حزمة com.java.db ؛
استيراد java.lang.reflect.constructor ؛
استيراد java.lang.reflect.field ؛
استيراد java.lang.reflect.invocationTargetException ؛
استيراد java.lang.reflect.method ؛
استيراد java.util.arraylist ؛
استيراد java.util.arrays ؛
استيراد java.util.iterator ؛
استيراد java.util.list ؛
استيراد java.util.map ؛
استيراد com.java.entity.bookshelf ؛
استيراد com.java.util.getmetadatacloumname ؛
الفئة العامة getNewInstances <T> {
class [] cl = {} ؛
Object [] ob = {} ؛
/**
* تم تعيينه على فارغ بعد كل استخدام ، وإلا فإنه سوف يتراكم
*/
public void setNullToarrays () {
this.cl = فئة جديدة [] {} ؛
this.ob = كائن جديد [] {} ؛
}
/**
* نسخة كائن صفيف
*
* param obj
* القيمة الفعلية المطلوبة في طريقة البناء
* @يعود
*/
الكائن العام [] getObjectarrays (Object OBJ) {
ob = arrays.copyof (ob ، ob.length + 1) ؛
OB [OB.Length - 1] = OBJ ؛
إرجاع OB ؛
}
/**
* نسخة صفيف الفئة
*
* param cla
* فئة لإضافة
*
* @يعود
*/
suppressWarnings ("غير محدد")
الطبقة العامة [] getClassarrays (فئة <؟> cla) {
if (cla! = null) {
cl = arrays.copyof (cl ، cl.length + 1) ؛
Cl [cl.length - 1] = cla ؛
إرجاع CL ؛
}آخر{
إرجاع CL ؛
}
}
/**
* احصل على مثيل للفصل
*
* Param Clazz
* فئة ليتم إنشاء مثيل لها
* @فئة العودة بعد الاستئصال
* throws instantiationException
* therws incluccessexception
* therws inchalialArgumentException
* Throws SecurityException
* throws invocationTargetException
* throws nosuchmethodexception
*/
suppressWarnings ("غير محدد")
الكائن العام getClassNewInstance (فئة <؟> clazz)
يلقي instantiationException ، غير شرعي.
غير unshalalArgumentException ، SecurityException ،
InvocationTargetException ، nosuchmethodexception {
كائن oj = null ؛
cons = clazz.getDeclaredConstructors () ؛ // احصل على المُنشئ
class [] cla = cons [1] .getParameterTypes () ؛
System.out.println ("TIP المستخدم ما إذا كان يجب إضافة حجم معلمة منشئ الحقل:"+cla.length) ؛
لـ (int i = 0 ؛ i <cla.length ؛ i ++) {
سلسلة classStr = cla [i] .toString () ؛
// system.out.println ("نوع الوسيطة:"+classstr) ؛
if (classstr.equals ("class java.lang.string")) {
getClassArrays (string.class) ؛
} آخر إذا (classstr.equals ("int")) {
getClassarrays (int.class) ؛
} آخر إذا (classstr.equals ("double")) {
getClassarrays (double.class) ؛
} آخر إذا (classstr.equals ("boolean")) {
getClassarrays (boolean.class) ؛
} آخر إذا (classstr.equals ("float")) {
getClassarrays (float.class) ؛
} آخر إذا (classstr.equals ("class java.lang.integer")) {
getClassarrays (integer.class) ؛
} آخر إذا (classstr.equals ("class java.lang.float")) {
getClassarrays (float.class) ؛
}
}
oj = clazz.newinstance () ؛ // إرجاع بنية مثيل محدد للكائن الحالي في bdoperater
إرجاع OJ ؛
}
/**
* احصل على فئات مثيل محددة من خلال المُنشئين
* Param Clazz
* @يعود
* therws inchalialArgumentException
* Throws SecurityException
* throws instantiationException
* therws incluccessexception
* throws invocationTargetException
* throws nosuchmethodexception
*/
الكائن العام getObjCon (الفئة <؟> clazz) يلقي غير aluallyargumentexception ، securityexception ، instantiationException ، غير alustantAccessexception ، invocationTargetException ، nosuchmethodexception {
كائن obj = null ؛
obj = this.getClassNewInstance (clazz) ؛
إرجاع OBJ ؛
}
/**
* احصل على مثيل للكائن
* Param Clazz
* @يعود
* throws instantiationException
* therws incluccessexception
*/
الكائن العام getNewInstance (class clazz) يلقي instantiationException ، غير شرعي {{
كائن obj = null ؛
obj = clazz.newinstance () ؛
إرجاع OBJ ؛
}
/**
* احصل على جميع الخصائص في الفصل على أساس الانعكاس
* param clazz فئة يجب استردادها
* @مجموعة السمات @
* Throws SecurityException
* therws inchalialArgumentException
* throws instantiationException
* therws incluccessexception
* throws invocationTargetException
* throws nosuchmethodexception
*/
المجال العام [] getFielsDarray (الفئة <Object> clazz) يلقي SecurityException ، غير aluallargumentException ، instantiationException ، غير alukalAccessexception ، invocationTargetException ، nosuchmethodexception {
الحقل [] الحقول = فارغة ؛
الحقول = clazz.getDeclaredFields () ؛
حقول العودة
}
/**
* احصل على سمات تنسيق setter وفقًا للسلسلة
* @Param Str الخاصية التي يجب تنسيقها
* @يعود
*/
السلسلة العامة getSetTerstr (String str) {
معلومات السلسلة = فارغة ؛
String strvalue = str.substring (0،1) .ToupperCase () ؛
info = "set"+strvalue+str.substring (1 ، str.length ()) ؛
معلومات العودة ؛
}
/**
* استعادة setxx إلى xx
* param str
* @يعود
*/
SetSetStr String Public (String Str) {
معلومات السلسلة = فارغة ؛
String strvalue = str.substring (3 ، str.length ()) ؛
سلسلة أقل = strvalue.substring (0) .ToLowerCase (). substring (0،1) ؛
info = lower+str.substring (4 ، str.length ()) ؛
معلومات العودة ؛
}
/**
* احصل على الطريقة في الفصل
* @Param Clazz المطلوب للحصول على الطريقة
* @يعود
*/
الطريقة العامة [] getMethodSarray (class clazz) {
الطريقة [] الأساليب = clazz.getMethods () ؛
طرق العودة ؛
}
/**
* إنشاء مُنشئ وفقًا للقائمة <map>
* param listmap
* Param Clazz
* param tablename اسم قاعدة البيانات
* @يعود
* throws nosuchmethodexception
* throws invocationTargetException
* Throws SecurityException
* therws inchalialArgumentException
* therws incluccessexception
* throws instantiationException
*/
suppressWarnings ({"unchecked"})
القائمة العامة <Object> getListByMap (قائمة <map <string ، object >> listmap ، class clazz ، string tablename) يلقي instantiationException ، alfarlealAccessexception ، alfictalargumentexception ، securityexception ، invocationTargetException ، nosuchmethodexception {
قائمة <Object> listlast = new ArrayList <Object> () ؛
قائمة <String> metalist = getMetAdatacloumName.getCloumnamelist (tablename) ؛
iterator <map <string ، object >> it = listmap.iterator () ؛
بينما (it.hasnext ()) {
الخريطة <string ، object> map = it.next () ؛
iterator <string> iitt = metalist.iterator () ؛
بينما (iitt.hasnext ()) {
معلومات السلسلة = iitt.next () ؛
this.getObjectArrays (map.get (info)) ؛
}
System.out.println ("انعكاس الاتصال:"+this.cl.length+""+this.ob.length) ؛
كائن tobj = this.getClassNewInstance (clazz) .getClass (). getConstructor (this.cl) .newinstance (this.ob) ؛
listlast.add (tobj) ؛
this.setNullToArrays () ؛
}
إرجاع listlast ؛
}
الفراغ الثابت العام الرئيسي (سلسلة [] args) {
getNewInstances ge = new getNewInstances () ؛
system.out.println (ge.getSetTerstr ("مساحة الاسم") == "setNamesPace") ؛
System.out.println ("1A" == "1A") ؛
System.out.println (ge.setsetstr ("setNamesPace")) ؛
}
}