Automatic generation of marshaling methods

Since it is an extremely boring task to write marshal and unmarshal methods, there is a tool that enables automatic generation of this code.

Assume you would like to enhance class Param from the beginning with fast marshaling. After you have compiled it to a class file, you can invoke the marshaling code generator with the following command:

javaparty retro TParam

This produces a file called TParam.h in the current directory. This file contains all necessary declarations to make the class transportable.

  • Insert all declarations from file TParam.h into the original source code of class TParam.
  • Declare class TParam public.
  • Replace by uka.transport.Transportable in the implements clause. Since Transportable extends Serializable you do not need both declarations for use of either the regular serialization or the fast marshaling.

For a quick start on SuSE Linux 8.0 with tcsh, you can copy and paste the following commands to your shell to see the transport generator at work:

mkdir transport
cd transport
cat > <<EOF
public class Param implements {
   int    intValue;
   float  floatValue;
   Object objectReference;
mkdir classes
javac -d classes
javaparty -cp classes retro Param
ls -las

On other unix systems, the above should work as well. On Windows, there is no convenient wrapper invocation script 'javaparty', so you have to invoke the generator by hand and care about the location of the JavaParty related jar files:

java -classpath jpc.jar;jp.jar;karmi.jar;%CLASSPATH%
      gjc.v6.RetroTransport TParam

Anyway, you should get output similar to the following:

drwxr-xr-x    3 user    group          107 May  6 15:28 ./
drwxr-xr-x    3 user    group           60 May  6 15:28 ../
-rw-r--r--    1 user    group         2381 May  6 15:28 Param.h
-rw-r--r--    1 user    group          124 May  6 15:28
drwxr-xr-x    2 user    group           62 May  6 15:28 classes/

The file contains the original class, and the Param.h contains the additional methods, that must be inserted into to get the fast marshaling functionality. Do not forget to also change the implements declaration and the visibility modifier of the class as denoted above.

Last modified 12 years ago Last modified on Aug 22, 2005 9:05:02 AM