From fb41ab066c5776392eb2b32cabe969a8d957ee6d Mon Sep 17 00:00:00 2001
From: Joy Clark <joyclark2004@msn.com>
Date: Thu, 25 Oct 2012 13:49:43 +0200
Subject: [PATCH] PROBCORE-152 Working on serialization on the Prob 1 side

---
 de.prob.core/src/de/prob/core/Animator.java   | 22 +++++++++++++++++++
 .../src/de/prob/model/eventb/Model.java       |  6 +++++
 2 files changed, 28 insertions(+)

diff --git a/de.prob.core/src/de/prob/core/Animator.java b/de.prob.core/src/de/prob/core/Animator.java
index d2dd609c..dbb83136 100644
--- a/de.prob.core/src/de/prob/core/Animator.java
+++ b/de.prob.core/src/de/prob/core/Animator.java
@@ -6,12 +6,19 @@
 
 package de.prob.core;
 
+import java.io.BufferedWriter;
 import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
 import java.util.HashMap;
 import java.util.Map;
 
+import org.eclipse.emf.common.command.Command;
 import org.osgi.service.prefs.Preferences;
 
+import com.thoughtworks.xstream.XStream;
+import com.thoughtworks.xstream.io.json.JettisonMappedXmlDriver;
+
 import de.prob.core.command.IComposableCommand;
 import de.prob.core.domainobjects.History;
 import de.prob.core.domainobjects.MachineDescription;
@@ -23,6 +30,8 @@ import de.prob.core.internal.AnimatorImpl;
 import de.prob.core.internal.ServerTraceConnection;
 import de.prob.core.internal.TraceConnectionProvider;
 import de.prob.exceptions.ProBException;
+import de.prob.model.eventb.Model;
+
 
 /**
  * Animator is a singleton Proxy used to communicate with ProB. The method
@@ -337,4 +346,17 @@ public final class Animator {
 	public  void sendUserInterruptSignal() {
 		if (implementation != null) implementation.sendUserInterruptSignal();
 	}
+	
+	public static void serializeModel(Model model) {
+		XStream xstream = new XStream(new JettisonMappedXmlDriver());
+		String xml = xstream.toXML(model);
+		try {
+			FileWriter fw = new FileWriter("model.xml");
+			final BufferedWriter bw = new BufferedWriter(fw);
+			bw.write(xml);
+			bw.close();
+		} catch (IOException e1) {
+			System.out.println("could not create file");
+		}
+	}
 }
diff --git a/de.prob.core/src/de/prob/model/eventb/Model.java b/de.prob.core/src/de/prob/model/eventb/Model.java
index 5fe40c48..3d31386c 100644
--- a/de.prob.core/src/de/prob/model/eventb/Model.java
+++ b/de.prob.core/src/de/prob/model/eventb/Model.java
@@ -3,7 +3,13 @@ package de.prob.model.eventb;
 import java.util.ArrayList;
 import java.util.List;
 
+import de.prob.model.representation.Label;
+
 public class Model {
 
 	public List<Relationship> relationships = new ArrayList<Relationship>();
+
+	public void addRelationship(final Label from, final Label to) {
+		relationships.add(new Relationship(from, to));
+	}
 }
-- 
GitLab