swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Serialisation (saving) in Java


From: Marie-Edith Bissey
Subject: Serialisation (saving) in Java
Date: Thu, 14 Sep 2000 11:31:36 +0100 (WET DST)

Dear all,

I am  writing the same simulation in Objective C and Java, and am
wondering how serialisation (when saving data to an archiver in Lisp
format) should work in Java.
In Objective C, I created a new class ("SimulationData"), an
extention of SwarmObject, in which I initialised the parameters I
wanted to save. I show the extracts of code below the message.
Basically, the program in Java is written exactly as the program in
Objective C, but the resulting .scm file is incomplete, lacking the
value of the variable I am trying to save.
I think the problem is that the "Object" in my SimulationData class is
not the kind of object the ".putShallow$Object" method of
serialisation expects in Java. However, I cannot find any examples in
the documentation giving me more information on this!
I would be grateful if you could look at the extracts of code below
and tell me if there is something wrong with the Java translation of
the Objective C code.

Thank you very much in advance,

Yours,

Marie-Edith.


----- BEGIN OBJECTIVE C CODE ------------------------------
This code is in an "ExperimentSwarm" (extension of GUISwarm), where
setStartBudget is the parameter to save in the file "loop.scm" under 
the name of startBudget);

....
  id <LispArchiver> outFile;
  SimulationData * simLoop;
...
  setStartBudget=5;
  simLoop=[SimulationData create:[self getZone]];
  [simLoop initPara:setStartBudget];
  outFile=[LispArchiver create:self setPath:"loop.scm"];
  [outFile putShallow:"modelSwarm" object:simLoop];
  [outFile sync];
...

And the Class SimulationData is:

@interface SimulationData:SwarmObject
        {
        int startBudget;
        }
-initPara: (int)simStartBudget;
.....

and

@implementation SimulationData

-initPara: (int)simStartBudget
        {
        startBudget=simStartBudget;
        return self;
        }
....

The file "loop.scm" created is as expected:
(list
  (cons 'modelSwarm
     (make-instance 'SimulationData #:startBudget 5)))

------- END OBJECTIVE C CODE --------------------------

Now, I have written a very similar program in javaSwarm, the only
changes being syntaxic.

--------- BEGIN JAVA CODE -----------------

In the ExperSwarm:

...
LispArchiverImpl outfile;
SimulationData simLoop;
...
setStartBudget=5;
simLoop=new SimulationData(getZone());
simLoop.initPara(setStartBudget);
outfile=new LispArchiverImpl(this,"loop.scm");
outfile.putShallow$object("modelSwarm",simLoop);
outfile.sync();
....

The SimulationData class is:

public class SimulationData     extends SwarmObjectImpl
  {
  int startBudget;
  // constructor
  public SimulationData(Zone aZone) 
    {
    super(aZone);
    }

  public Object initPara(int simStartBudget)
    {
    startBudget=simStartBudget;
    return this;
    }
....
  }

But now, the file "loop.scm" is incomplete, and lacks the value of
startBudget.

(list
  (cons 'modelSwarm
     (make-instance 'SimulationData)))

--------- END JAVA CODE -------------------


__________________________________________________________________

Marie-Edith Bissey
Universita` del Piemonte Orientale "Amedeo Avogadro"
Facolta` di Science Politiche         email: address@hidden
Corso Borsalino 50                    tel: +39-0131-283749
15 100 Alessandria -- ITALIA          fax: +39-0131-263030
http://polis.unipmn.it/doc/bis/hp.htm


                  ==================================
   Swarm-Support is for discussion of the technical details of the day
   to day usage of Swarm.  For list administration needs (esp.
   [un]subscribing), please send a message to <address@hidden>
   with "help" in the body of the message.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]