Now, the java 2 javascript compiler of the java2script can be extended. There is a tutorial for demonstrating the extension mechanism.
This extension mechanism can be used to override default behavior of java2script compiler. So, why do we need to override the default behavior of the java2script compiler? Let’s have a simple example. Suppose an application that uses a library that can not be converted to java script, an ejb invocation:
EJBX x = EJBUtil.newInstance(EJBX.class, jndiName);
x.methodA();
Now if we use the default java2script compiler the code would be something like:
var x = foo.bar.EJBUtil.newInstance(….);
x.methodA();
But, we now that this will not work. It seems to be unsolvable before the extension mechanism is introduced. But now the java2script compiler can be extended to convert such these codes to another java script code that does work on a browser and also does not use the library.
Now if we extend the java2script compiler we can generate a stub invocation like this, that sould work without any ejb import or invocation:
ServletFacade.runEJBMethod(“foo.bar.EJBX”, “methodA”, jndiName);
//And the ServletFacade could be an stub for calling a servlet that can run EJBs
So, with this mechanism, one can convert any source code in his own way.