|
UseReflection
How to use reflection provided by gwt-ent
IntroductionFor maximum efficiency, GWT compiles your Java source into a monolithic script. Now gwt-ent provide a reflection implement by gwt code generator mechanism. This Framework support
How to use# add Annotation Or Reflection Marker interface into your pojo class @Reflectable
public class TestReflection{
}
public class TestReflection implements Reflection{
}
@Reflect_Domain
public class TestReflection{
}
# get ClassType. ClassType classType = TypeOracle.Instance.getClassType(TestReflection.class); For example: public void testReflection(){
TestReflection test = new TestReflection();
ClassType classType = TypeOracle.Instance.getClassType(TestReflection.class);
test.setString("set by code");
System.out.println("after SetByCode:" + test.getString());
System.out.println("after SetByCode:" + classType.invoke(test, "getString", null));
classType.invoke(test, "setString", new Object[]{"set by invoke"});
System.out.println("after SetByInvoke:" + classType.invoke(test, "getString", null));
}
}The output is : after SetByCode:set by code after SetByCode:set by code after SetByInvoke:set by invoke Control you javascript sizeGWTENT provide you more power to control how much reflection information created. The Class ScopeYou can control whether have:
Click Here For more Information The Field/Method ScopeYou can control whether have:
Click Here For more Information The TestCaseUnderstand Reflection Classeshttp://gwt-ent.googlecode.com/svn/trunk/gwtent/src/com/gwtent/client/reflection/
|
► Sign in to add a comment
Is there a way to do the equivalent of Class.forName(), assuming you don't know the name of the class beforehand? Or must you know it beforehand and use GWT.create()?
did somebody was able to use the reflection profided by this project?
Please provide some sample application.
Thanks Raghu
To visumagic
To Coll... To dandanteany chance of a 1.5 binary? Since my project depends on 1.5 I tried to build for 1.5 myself, but get this error at runtime; Errors in 'transient source for com.gwtent.client.reflection.TypeOracle_Visitor?'
Hi, jacob, I can't got this issue in my computer, can you try get the source code from svn, then try to compile it?
Hi James, When I try to use the gwtent.jar directly, I get: "ERROR? Failure to load module 'com.clcbio.CLCServer' java.lang.UnsupportedClassVersionError?: Bad version number in .class file
I guess this is beacuse the library is build for Java 6. Since I have to use Java 5, my only option is to build the jar-file myself. I have checked out the project from SVN, but cant build the jar-file. Instead I tried to include the source and compiled (Java 5) classes from the Eclipse project, into my own project. That lead to the above error, and I stopped trying. Perhaps you could compile a version af the jar-files for Java 5 or have a look at the ant build file so I might build it myself.Thanks a lot! Jacob
now I managed to run the ant script and build the jar. At runtime, I get this error again;
ERROR? Errors in 'transient source for com.gwtent.client.reflection.TypeOracle_Visitor?' ERROR? Line 1312: T cannot be resolved to a type ERROR? Line 1312: Syntax error on token "extends", . expected INFO? See snapshot: /tmp/com.gwtent.client.reflection.TypeOracle_Visitor15589?.java
The source from tmp/com.gwtent.client.reflection.TypeOracle_Visitor15589?.java, line 1300;
line 1312 is this one:
Hi, jacob, the issues you logged before was fixed, please refer to this link for more information.
http://code.google.com/p/gwt-ent/issues/detail?id=2&can=1 Thank you.
Hi James,
I am new to GWT. In my application I am trying to use gwt-ent 0.6 for reflection. I have used gwtent.jar file and kept it in my classpath and added the mapping for this in my gwt.xml file also. But the application is still not working. At runtime it is throwing lot of errors.
Errors:
Line 15: No source code is available for type javax.validation.Validator<T>; did you forget to inherit a required module?and many other errors but of same nature. Please help.
Thanks, Vineet
Hi, I am trying to instantiate a class and I am getting this exception
java.lang.NoClassDefFoundError?: javax/validation/ConstraintCan I use this library to instantiate any class which implements the reflection interface?
Hi, could you provide a bit more info about how to import the classes?
For instance I added the following to my gwt.xml
and the gwtent.jar and gwt-validation.jar to my classpath
but I am getting errors like The import com.google.gwt.validation cannot be resolved exc
TIA, Scott
Hi, I can't use your library, I got a lot of errors when I'm trying to use it. I have the following inherits on the gwt.xml file:
I'm getting a lot of errors, like:
What i'm missing? Regards.
Remove client/test and client/validate folders and build the jar again and try...
How about specifying class to be reflected in .gwt.xml file? I use a POJO from a library and cannot add @Reflectable to POJO so it would be great for me if I could specify this POJO class somewhere e.g. in my .gwt.xml file. Thanks
Hi, Sergey, I don't know if gwt provider some way to read constom settings from .gwt.xml file. GWT provide a way to process relation type, you can create your POJO class, using the POJO from other library, then using "@Reflectable(relationTypes=true)" in your POJO class, this will generate reflection information for that class as well. by default, relationTypes is true for @Reflect_Domain?
Thanks david & y.sowjanya, I will fix this in next version
Thanks James, it's exactly what I need.
Hi James, is <inherits name="com.gwtent.GwtEnt"/> correct module name ? I just put the gwtent.jar to my project but I can't get the setup right. There is also no info on this in your wiki. Thanks
Hi James, I get a lot of errors when i use the gwtent.jar file to implement reflection. Could you please provide some help in terms of the setup that we have to do in order to get it running. I am using gwt 2.0 and Java 5. Please do help. Thank you.
@dandante Just get the Constructor object from ClassType? and use newInstance from that. You'll need to probably use Field access and Method access after that to manipulate it since it returns an Object.