From 89240b65f1a2174c96875191661ce96445475b90 Mon Sep 17 00:00:00 2001
From: Sebastian Krings <sebastian@krin.gs>
Date: Fri, 28 Dec 2012 11:07:21 +0100
Subject: [PATCH] get unit analysis result (string form) from prolog and print
 on console

---
 .../core/command/GetPluginResultCommand.java  | 54 +++++++++++++++++++
 .../ui/eventb/StartUnitAnalysisHandler.java   | 15 ++----
 2 files changed, 59 insertions(+), 10 deletions(-)
 create mode 100644 de.prob.core/src/de/prob/core/command/GetPluginResultCommand.java

diff --git a/de.prob.core/src/de/prob/core/command/GetPluginResultCommand.java b/de.prob.core/src/de/prob/core/command/GetPluginResultCommand.java
new file mode 100644
index 00000000..4a32059f
--- /dev/null
+++ b/de.prob.core/src/de/prob/core/command/GetPluginResultCommand.java
@@ -0,0 +1,54 @@
+/**
+ * (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, Heinrich
+ * Heine Universitaet Duesseldorf This software is licenced under EPL 1.0
+ * (http://www.eclipse.org/org/documents/epl-v10.html)
+ * */
+
+package de.prob.core.command;
+
+import de.prob.parser.BindingGenerator;
+import de.prob.parser.ISimplifiedROMap;
+import de.prob.parser.ResultParserException;
+import de.prob.prolog.output.IPrologTermOutput;
+import de.prob.prolog.term.ListPrologTerm;
+import de.prob.prolog.term.PrologTerm;
+
+public final class GetPluginResultCommand implements IComposableCommand {
+
+	private final String resultID;
+	private String result;
+
+	public GetPluginResultCommand(final String resultID) {
+		this.resultID = resultID;
+	}
+
+	public String getResult() {
+		return result;
+	}
+
+	public void processResult(
+			final ISimplifiedROMap<String, PrologTerm> bindings)
+			throws CommandException {
+		ListPrologTerm list;
+		try {
+			list = BindingGenerator.getList(bindings, "Bindings");
+		} catch (ResultParserException e) {
+			CommandException commandException = new CommandException(
+					e.getLocalizedMessage(), e);
+			commandException.notifyUserOnce();
+			throw commandException;
+		}
+
+		for (PrologTerm term : list) {
+			int nextCharCode = BindingGenerator.getInteger(term).getValue()
+					.intValue();
+			result += (char) nextCharCode;
+		}
+	}
+
+	public void writeCommand(final IPrologTermOutput pto) {
+		pto.openTerm("getPluginOutput").printAtomOrNumber(resultID)
+				.printVariable("Bindings").closeTerm();
+	}
+
+}
diff --git a/de.prob.ui/src/de/prob/ui/eventb/StartUnitAnalysisHandler.java b/de.prob.ui/src/de/prob/ui/eventb/StartUnitAnalysisHandler.java
index e8c349d6..11b73083 100644
--- a/de.prob.ui/src/de/prob/ui/eventb/StartUnitAnalysisHandler.java
+++ b/de.prob.ui/src/de/prob/ui/eventb/StartUnitAnalysisHandler.java
@@ -38,12 +38,10 @@ import de.prob.core.LimitedLogger;
 import de.prob.core.command.ActivateUnitPluginCommand;
 import de.prob.core.command.ClearMachineCommand;
 import de.prob.core.command.ComposedCommand;
-import de.prob.core.command.GetCurrentStateIdCommand;
-import de.prob.core.command.GetStateValuesCommand;
+import de.prob.core.command.GetPluginResultCommand;
 import de.prob.core.command.SetPreferencesCommand;
 import de.prob.core.command.StartAnimationCommand;
 import de.prob.core.command.internal.InternalLoadCommand;
-import de.prob.core.domainobjects.Variable;
 import de.prob.exceptions.ProBException;
 import de.prob.logging.Logger;
 
@@ -131,17 +129,14 @@ public class StartUnitAnalysisHandler extends AbstractHandler implements
 				animator.execute(composed);
 
 				// TODO: get resulting state and fill attributes
-				String currentID = GetCurrentStateIdCommand.getID(animator);
-				GetStateValuesCommand stateValuesCommand = new GetStateValuesCommand(
-						currentID);
+				GetPluginResultCommand stateValuesCommand = new GetPluginResultCommand(
+						"Static Analysis Result");
 
 				animator.execute(stateValuesCommand);
 
-				List<Variable> vars = stateValuesCommand.getResult();
+				String output = stateValuesCommand.getResult();
 
-				for (Variable v : vars) {
-					System.out.println(v.getIdentifier());
-				}
+				System.out.println(output);
 
 				// shutdown animator
 				animator.shutdown();
-- 
GitLab