diff options
| author | Paul Buetow <paul@buetow.org> | 2008-06-01 22:45:59 +0000 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2008-06-01 22:45:59 +0000 |
| commit | 293c73f50f87b3d73d3947a9f79430b23ec4ddba (patch) | |
| tree | 129ece28dcda9d17bb6e0fc417d8b25bb82dac4c /sources/simulator/VSSimulatorCanvas.java | |
| parent | 8086082daaed71ee9105c156e3a1e8e63caf1990 (diff) | |
better serialization
Diffstat (limited to 'sources/simulator/VSSimulatorCanvas.java')
| -rw-r--r-- | sources/simulator/VSSimulatorCanvas.java | 61 |
1 files changed, 30 insertions, 31 deletions
diff --git a/sources/simulator/VSSimulatorCanvas.java b/sources/simulator/VSSimulatorCanvas.java index d6bc5d2..cfc6549 100644 --- a/sources/simulator/VSSimulatorCanvas.java +++ b/sources/simulator/VSSimulatorCanvas.java @@ -37,6 +37,7 @@ import events.implementations.*; import events.internal.*; import prefs.*; import prefs.editors.*; +import serialize.*; import utils.*; /** @@ -49,7 +50,7 @@ import utils.*; * @author Paul C. Buetow */ public class VSSimulatorCanvas extends Canvas - implements Runnable, Serializable { + implements Runnable, VSSerializable { /** The serial version uid */ private static final long serialVersionUID = 1L; @@ -1545,47 +1546,45 @@ public class VSSimulatorCanvas extends Canvas } } - /** - * Write object. - * - * @param objectOutputStream the object output stream - * - * @throws IOException Signals that an I/O exception has occurred. + /* (non-Javadoc) + * @see serialize.VSSerializable#serialize(serialize.VSSerialize, + * java.io.ObjectOutputStream) */ - public synchronized void writeObject(ObjectOutputStream objectOutputStream) + public synchronized void serialize(VSSerialize serialize, + ObjectOutputStream objectOutputStream) throws IOException { synchronized (processes) { - objectOutputStream.writeObject(processes); + objectOutputStream.writeObject(new Integer(numProcesses)); + for (VSProcess process : processes) + process.serialize(serialize, objectOutputStream); } - objectOutputStream.writeObject(taskManager); + + taskManager.serialize(serialize, objectOutputStream); } - /** - * Read object. - * - * @param objectInputStream the object input stream - * - * @throws IOException Signals that an I/O exception has occurred. - * @throws ClassNotFoundException the class not found exception + /* (non-Javadoc) + * @see serialize.VSSerializable#deserialize(serialize.VSSerialize, + * java.io.ObjectInputStream) */ @SuppressWarnings("unchecked") - public synchronized void readObject(ObjectInputStream objectInputStream) + public synchronized void deserialize(VSSerialize serialize, + ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException { - if (VSDeserializationHelper.DEBUG) + if (VSSerialize.DEBUG) System.out.println("Deserializing: VSSimulatorCanvas"); - VSPrefs prefs = (VSPrefs) VSDeserializationHelper.getObject("prefs"); - VSSimulator simulator = - (VSSimulator) VSDeserializationHelper.getObject("simulator"); - VSLogging logging = - (VSLogging) VSDeserializationHelper.getObject("logging"); - - this.processes = (ArrayList<VSProcess>) objectInputStream.readObject(); - this.numProcesses = processes.size(); - - this.taskManager = (VSTaskManager) objectInputStream.readObject(); - VSDeserializationHelper.setObject("taskManager", taskManager); + synchronized (processes) { + numProcesses = ((Integer) + objectInputStream.readObject()).intValue(); + + processes.clear(); + for (int i = 0; i < numProcesses; ++i) { + VSProcess process = createProcess(i); + process.deserialize(serialize, objectInputStream); + processes.add(process); + } + } - init(prefs, simulator, logging); + taskManager.deserialize(serialize, objectInputStream); } } |
