How GWT.create() works with service?

112 views
Skip to first unread message

Kanagaraj M

unread,
Dec 14, 2011, 10:23:45 AM12/14/11
to google-we...@googlegroups.com
I wanted to know how GWT.create behaves in Dev mode and Production mode.
I was trying to debug the code. The comment in the code says
/*
      * In Production Mode, the compiler directly replaces calls to this method
      * with a new Object() type expression of the correct rebound type.
   */

In Dev mode it is creating a proxy for the service as GreetingService_Proxy and loading it.
But in production what will the equivalent JavaScript code for it.

GWT.create is mainly used for deferred binding. Something like i have different implementations for FileUpload.
But i am not able to understand why we need different implementations for a service. Is this to create different JavaScript implementations for AJAX calls.
Another things is, whenever i have different implementation the module.gwt.xml file will tell implementation to pick. how this will work in case of service?

Can any one please explain about this?

Thomas Broyer

unread,
Dec 14, 2011, 11:32:45 AM12/14/11
to google-we...@googlegroups.com
There are two kinds of deferred binding rules: replace-with and generate-with.

replace-with rules are used to switch between several implementations depending on binding properties (e.g. <when-property-is name="user.agent" value="ie6" />)

generate-with on the other hand calls a Generator for the class or interface. Such a rule can also use binding properties as conditions (you can even say "replace-with that class when such property is X; and generate with that one otherwise") but it's generally not the case.
The generator is passed the class/interface that's being GWT.create()d and uses reflection (not java.lang.reflect though) to generate one or several files, which generally include Java source code (that will be compiled just after being generated) but an also include other kinds of files (e.g. images or CSS files, in the case of ClientBundle or ImageBundle).

In the case of RPC services, the rule reads:
<generate-with class="com.google.gwt.user.rebind.rpc.ServiceInterfaceProxyGenerator">
<when-type-assignable class="com.google.gwt.user.client.rpc.RemoteService"/>
</generate-with>
and the ServiceInterfaceProxyGenerator generates the Xxx_Proxy class you're seeing in DevMode (which is also compiled on-the-fly).

Generators are used a lot in GWT: for I18N (Messages, Constants), UiBinder, ClientBundle, ImageBundle, SafeHtmlTemplates, PlaceHistoryMapper, AutoBeans, RequestFactory, RPC, etc.

Kanagaraj M

unread,
Dec 14, 2011, 10:22:22 PM12/14/11
to google-we...@googlegroups.com
Is there a way i can see the content of Xxx_Proxy?

And what would be the equivalent JavaScript code for it? will that vary depends on my user agent?

Thomas Broyer

unread,
Dec 15, 2011, 8:31:15 AM12/15/11
to google-we...@googlegroups.com


On Thursday, December 15, 2011 4:22:22 AM UTC+1, Kanagaraj M wrote:
Is there a way i can see the content of Xxx_Proxy?

Pass the -gen option to the DevMode or Compiler to tell it to output the generated files in the given folder.
 
And what would be the equivalent JavaScript code for it? will that vary depends on my user agent?

The generated Java code will be compiled to JS just like any code written "by hand". The deferred-binding rules apply as well, so a generated class can make use of GWT.create() to trigger user.agent-specific code paths, or generate other classes (for instance, RequestFactory generates an AutoBeanFactory interface whose implementation will in turn be generated by the AutoBean generator).
Reply all
Reply to author
Forward
0 new messages