Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GWT client and server implementations of the same class

Tags:

rpc

client

gwt

Is there any way to have the same class implemented differently on the client vs the server?

To avoid the "Why do you want to do that?" question.. I will elaborate

I am converting a very large Java client/server application. Currently it uses a Swing GUI client and talks to the server via Spring remoting (RPC). Using GWT RPC with Spring services is not a problem, there are several excellent examples available and the all seem to work well.

Several classes that are common to both the client and the server contain data that is passed back and forth. These classes also contain some behavior that is implemented by using the standard JRE classes. For example, one class contains, parses and formats date and time, including time zone, DST, etc. in a locale specific way. I could rewrite/refactor it but the application is over 10 million SLOC, resulting in literally millions of references to this class alone, so a major rewrite is not cost effective.

To use this as an example, GWT provides excellent i18n support for parsing and formatting dates. But the implementation is different to the way the JRE does it.

So I'm looking for a cleaver way where by I can inject an implementation into the shell of my DateTime class, depending on whether it is in the client (using GWT and native JS) or in the server (using the JRE). Is there a cunning way to do this? Perhaps using the module file XXXXX.gwt.xml. I'm looking for a generic solution.

like image 538
helipilot50 Avatar asked Mar 18 '11 08:03

helipilot50


1 Answers

You'd want to use the <super-source> for overriding one package implementation with another. This is what GWT uses to emulate the Java Runtime classes, and (among others) provide different implementations for client and server of the com.google.gwt.regexp.shared.* classes.

like image 107
Thomas Broyer Avatar answered Oct 14 '22 20:10

Thomas Broyer