| | 1 | = Automatic generation of marshaling methods = |
| | 2 | |
| | 3 | [[TracNav]] |
| | 4 | Since it is an extremely boring task to write marshal and unmarshal methods, there is a tool that enables automatic generation of this code. |
| | 5 | |
| | 6 | 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: |
| | 7 | |
| | 8 | {{{ |
| | 9 | javaparty retro TParam |
| | 10 | }}} |
| | 11 | |
| | 12 | |
| | 13 | This produces a file called TParam.h in the current directory. This file contains all necessary declarations to make the class transportable. |
| | 14 | |
| | 15 | * Insert all declarations from file TParam.h into the original source code of class TParam. |
| | 16 | * Declare class TParam public. |
| | 17 | * Replace java.io.Serializable 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. |
| | 18 | |
| | 19 | 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: |
| | 20 | |
| | 21 | {{{ |
| | 22 | mkdir transport |
| | 23 | cd transport |
| | 24 | cat > Param.java <<EOF |
| | 25 | public class Param implements java.io.Serializable { |
| | 26 | int intValue; |
| | 27 | float floatValue; |
| | 28 | Object objectReference; |
| | 29 | } |
| | 30 | EOF |
| | 31 | mkdir classes |
| | 32 | javac -d classes Param.java |
| | 33 | javaparty -cp classes retro Param |
| | 34 | ls -las |
| | 35 | }}} |
| | 36 | |
| | 37 | 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: |
| | 38 | |
| | 39 | {{{ |
| | 40 | java -classpath jpc.jar;jp.jar;karmi.jar;%CLASSPATH% |
| | 41 | gjc.v6.RetroTransport TParam |
| | 42 | }}} |
| | 43 | |
| | 44 | Anyway, you should get output similar to the following: |
| | 45 | |
| | 46 | {{{ |
| | 47 | drwxr-xr-x 3 user group 107 May 6 15:28 ./ |
| | 48 | drwxr-xr-x 3 user group 60 May 6 15:28 ../ |
| | 49 | -rw-r--r-- 1 user group 2381 May 6 15:28 Param.h |
| | 50 | -rw-r--r-- 1 user group 124 May 6 15:28 Param.java |
| | 51 | drwxr-xr-x 2 user group 62 May 6 15:28 classes/ |
| | 52 | }}} |
| | 53 | |
| | 54 | The file Param.java contains the original class, and the Param.h contains the additional methods, that must be inserted into Param.java 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. |
| | 55 | |