A cópia do código é a seguinte:
pacote com.java.db;
importar java.lang.reflect.Constructor;
importar java.lang.reflect.field;
importar java.lang.reflect.invocationTargeTexception;
importar java.lang.reflect.method;
importar java.util.arraylist;
importar java.util.arrays;
importar java.util.iterator;
importar java.util.list;
importar java.util.map;
importação com.java.entity.bookfelf;
importação com.java.util.getMetAdataclouMName;
classe pública GetNewInstances <T> {
Classe [] Cl = {};
Objeto [] ob = {};
/**
* Defina para esvaziar após cada uso, caso contrário, ele acumulará
*/
public void setNullToarrays () {
this.cl = nova classe [] {};
this.ob = new Object [] {};
}
/**
* Copiar Array de Objeto
*
* @param obj
* O valor real necessário no método de construção
* @retornar
*/
Public Object [] getObjectArrays (objeto obj) {
ob = Arrays.copyof (ob, ob.length + 1);
ob [ob.Length - 1] = obj;
retornar ob;
}
/**
* Array da classe de cópia
*
* @param cla
* Classe para adicionar
*
* @retornar
*/
@Suppresswarnings ("sem controle")
classe pública [] getClassarrays (classe <?> cla) {
if (cla! = null) {
Cl = Arrays.copyof (Cl, Cl.Length + 1);
cl [cl.length - 1] = cla;
retornar cl;
}outro{
retornar cl;
}
}
/**
* Obtenha uma instância da classe
*
* @param clazz
* Classe a ser instanciada
* Classe @return após instanciação
* @throws instantiationException
* @THOWSOWSECTALACCESSECCECTIMENTO
* @THOWSOWS ILAGELARGUMENTEXCECTION
* @Throws SecurityException
* @Throws InvocationTargeTexception
* @THOWS NosuchMethOdException
*/
@Suppresswarnings ("sem controle")
objeto público getclassNewInstance (classe <?> clazz)
lança InstantiationException, ilegalAccessException,
IlegalargumentException, SecurityException,
InvocationTargeTexception, NosuchmethodException {
Objeto oj = nulo;
Contras = clazz.getDecLaredConstructors (); // Obtenha o construtor
Classe [] cla = contras [1] .getParameterTypes ();
System.out.println ("Dica o usuário para adicionar o tamanho do parâmetro do construtor de campo:"+cla.length);
for (int i = 0; i <cla.length; i ++) {
String classStr = CLA [i] .ToString ();
// System.out.println ("Tipo de argumento:"+classStr);
if (classstr.equals ("classe java.lang.string")) {
getClarsarrays (String.class);
} else if (ClassStr.equals ("int")) {
getClarsarrays (int.class);
} else if (ClassStr.equals ("Double")) {
getClarsarrays (duplo.class);
} else if (ClassStr.equals ("boolean")) {
getClassarrays (boolean.class);
} else if (ClassStr.equals ("Float")) {
getClassarrays (float.class);
} else if (ClassStr.equals ("classe java.lang.integer")) {
getClarsarrays (Integer.class);
} else if (Classtr.equals ("classe java.lang.float")) {
getClassarrays (float.class);
}
}
oj = clazz.NewInstance (); // retorna o construto de instanciação específico do objeto atual no BDOPERATERTER
retornar oj;
}
/**
* Obtenha classes de instância específicas através de construtores
* @param clazz
* @retornar
* @THOWSOWS ILAGELARGUMENTEXCECTION
* @Throws SecurityException
* @throws instantiationException
* @THOWSOWSECTALACCESSECCECTIMENTO
* @Throws InvocationTargeTexception
* @THOWS NosuchMethOdException
*/
Public Object GetObjcon (classe <?> clazz) lança ilegalArgumentException, segurançaException, InstantiationException, ilegalAccessException, InvocationTargeTexception, NoschmethodException {
Objeto obj = null;
obj = this.getclassNewInstance (clazz);
retornar obj;
}
/**
* Obtenha uma instância do objeto
* @param clazz
* @retornar
* @throws instantiationException
* @THOWSOWSECTALACCESSECCECTIMENTO
*/
Public Object GetNewInstance (Class clazz) lança instantionationException, ilegalaccescessception {
Objeto obj = null;
obj = clazz.newinstance ();
retornar obj;
}
/**
* Obtenha todas as propriedades da classe com base na reflexão
* @param clazz aula que precisa ser recuperada
* Coleção de atributos @return
* @Throws SecurityException
* @THOWSOWS ILAGELARGUMENTEXCECTION
* @throws instantiationException
* @THOWSOWSECTALACCESSECCECTIMENTO
* @Throws InvocationTargeTexception
* @THOWS NosuchMethOdException
*/
Public Field [] getfielsdarray (classe <ject> clazz) lança Segurança de SecurityException, IllegalargumentException, InstantiationException, IllegalAccescessception, InvocationTargeTexception, NoschmethodException {
Campo [] campos = nulo;
campos = clazz.getDecLaredFields ();
campos de retorno;
}
/**
* Obtenha atributos de formato de setter de acordo com a string
* @param str propriedade que precisa ser formatada
* @retornar
*/
public String getSetterstr (String str) {
String info = null;
String strvalue = str.substring (0,1) .touppercase ();
info = "set"+strvalue+str.substring (1, str.Length ());
retornar informações;
}
/**
* Restaure o setXx para xx
* @param str
* @retornar
*/
public String setSetStr (String str) {
String info = null;
String strvalue = str.substring (3, str.Length ());
String inferior = strvalue.substring (0) .tolowerCase (). Substring (0,1);
info = inferior+str.substring (4, str.length ());
retornar informações;
}
/**
* Obtenha o método na classe
* @param clazz aula necessária para obter o método
* @retornar
*/
Método público [] getMethodSarray (classe clazz) {
Método [] métodos = clazz.getMethods ();
métodos de retorno;
}
/**
* Instanciar o construtor de acordo com a lista <Pap>
* @param listmap
* @param clazz
* @param tableName Database Nome
* @retornar
* @THOWS NosuchMethOdException
* @Throws InvocationTargeTexception
* @Throws SecurityException
* @THOWSOWS ILAGELARGUMENTEXCECTION
* @THOWSOWSECTALACCESSECCECTIMENTO
* @throws instantiationException
*/
@Suppresswarnings ({"desmarcado"})
Lista pública <Becject> getListByMap (List <map <string, object>> listMap, classe clazz, string tablename) lança instantionationException, ilegalaccessException, ilegalArgumentException, Segurança de Segurança, InvocationTargeTexception, noschmethodException {
List <ject> listLast = new ArrayList <ject> ();
List <String> metalist = getMetAdataclouMName.getClouMnameList (tableName);
Iterator <map <string, object >> it = listmap.iterator ();
while (it.hasnext ()) {
Mapa <string, objeto> map = it.next ();
Iterator <string> iitt = metalist.iterator ();
while (iitt.hasnext ()) {
String info = iitt.Next ();
this.getObjectArrays (map.get (info));
}
System.out.println ("Chamada reflexão:"+this.cl.length+""+this.ob.length);
Objeto tobj = this.getclassNewInstance (clazz) .getclass (). GetConstructor (this.cl) .NewInstance (this.ob);
listlast.add (Tobj);
this.setNullToarrays ();
}
retornar listlast;
}
public static void main (string [] args) {
GetNewInstances ge = new getNewInstances ();
System.out.println (ge.getSetterstr ("namespace") == "setNamespace");
System.out.println ("1a" == "1a");
System.out.println (ge.setsetttr ("setNamespace"));
}
}