private Object getObjectInstance(String typeName){
try {
Class cl = Class.forName(typeName);
try {
java.lang.reflect.Constructor co = cl.getConstructor();
try {
return co.newInstance();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
} catch (SecurityException e1) {
e1.printStackTrace();
} catch (NoSuchMethodException e1) {
e1.printStackTrace();
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return null;
}
public String generate(TreeLogger logger, GeneratorContext context, String typeName) throws UnableToCompleteException {
.......
Object object = getObjectInstance(typeName); // Create a new instance of the object parsing
JField[] fields = classType.getFields();
for (int i = 0; i < fields.length; i++){
Class c = object.getClass();
try {
Field fielda = c.getField("aaa");
try {
if (field.getType().getParameterizedQualifiedSourceName().equals("java.lang.String[]")){
String[] fieldValue = (String[]) fielda.get(object);
System.out.println(fieldValue[0]);
}else if(field.getType().getParameterizedQualifiedSourceName().equals("int[]")){
int[] fieldValue = (int[]) fielda.get(object);
System.out.println(fieldValue[0].toString());
}else
.....
.....
.....
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
} catch (SecurityException e) {
e.printStackTrace();
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
.....
Have someone other idea?
-- You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
No comments:
Post a Comment