E ai galela, blz!
Como foi o final de ano? Um feliz 2005 pra todos… 
Bem, vamos ao problema.
Estou tentando fazer reflection de um valor que eu recebi da página para um campo Array.
Pra mim eu deveria tratar o array como um objeto, porém quando eu tento atribuir o valor do array tá subindo uma IllegalArgumentException.
Algém tem idéia de como identificar que tipo que é o array. se ele é um Object[], String[], int[], float[], etc…
Segue abaixo o que estou tentando fazer… Como não consegui identificar estou dando a possibilidade apenas de String[].
Valeu galera…
Qualquer ajuda vai quebra um galhão…
public void parameterReflection(Hashtable hashtable) {
Enumeration e = hashtable.keys();
while (e.hasMoreElements()) {
try {
String key = (String) e.nextElement();
Field f = this.getClass().getDeclaredField(key);
if (f.getType() == Integer.TYPE)
f.setInt(this,new Integer((String)hashtable.get(key)).intValue());
else if (f.getType() == Boolean.TYPE)
f.setBoolean(this,new Boolean((String)hashtable.get(key)).booleanValue());
else if (f.getType() == Byte.TYPE)
f.setByte(this,new Byte((String)hashtable.get(key)).byteValue());
else if (f.getType() == Double.TYPE)
f.setDouble(this,new Double((String)hashtable.get(key)).doubleValue());
else if (f.getType() == Character.TYPE)
f.setChar(this,String.valueOf(hashtable.get(key)).charAt(0));
else if (f.getType() == Float.TYPE)
f.setFloat(this,new Float((String)hashtable.get(key)).floatValue());
else if (f.getType() == Long.TYPE)
f.setLong(this,new Long((String)hashtable.get(key)).longValue());
else if (f.getType() == Short.TYPE)
f.setShort(this,new Short((String)hashtable.get(key)).shortValue());
else if (f.getType().isArray()) {
// TODO Inplement other type of arrays.
// Aqui que eu precisava identificar qual o tipo do array
// para fazer o cast corretamente
String s1 = (String) hashtable.get(key);
if (s1 != null && s1.substring(0,1).equals("[") &&
s1.substring(s1.length() -1 ,s1.length()).equals("]") )
s1 = s1.substring(1 ,s1.length() -1);
f.set(this,StringUtils.split(s1,","));
}
else
f.set(this,hashtable.get(key));
} catch (SecurityException e1) {
e1.printStackTrace();
} catch (IllegalArgumentException e1) {
e1.printStackTrace();
} catch (NoSuchFieldException e1) {
e1.printStackTrace();
} catch (IllegalAccessException e1) {
e1.printStackTrace();
}
}
}
