From e1c93d6b15caeee675731ee66cc1f6bfe11308cd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=B6ren=20Henning?= <stu114708@informatik.uni-kiel.de>
Date: Thu, 31 Mar 2016 22:25:38 +0200
Subject: [PATCH] organize writers hierarchy

---
 .../graph/export/AbstractTransformer.java     |  2 +-
 .../analysis/graph/export/AbstractWriter.java | 38 +++++++++++++++++++
 .../graph/export/dot/AbstractDotWriter.java   | 38 +++++++++----------
 .../analysis/graph/export/dot/DotWriter2.java | 13 ++++---
 4 files changed, 64 insertions(+), 27 deletions(-)
 create mode 100644 src/main/java/kieker/analysis/graph/export/AbstractWriter.java

diff --git a/src/main/java/kieker/analysis/graph/export/AbstractTransformer.java b/src/main/java/kieker/analysis/graph/export/AbstractTransformer.java
index 08c48d95..41983a63 100644
--- a/src/main/java/kieker/analysis/graph/export/AbstractTransformer.java
+++ b/src/main/java/kieker/analysis/graph/export/AbstractTransformer.java
@@ -14,7 +14,7 @@ public abstract class AbstractTransformer<O> implements VertexVisitor, EdgeVisit
 
 	protected Graph graph;
 
-	public AbstractTransformer(final Graph graph) {
+	protected AbstractTransformer(final Graph graph) {
 		this.graph = graph;
 	}
 
diff --git a/src/main/java/kieker/analysis/graph/export/AbstractWriter.java b/src/main/java/kieker/analysis/graph/export/AbstractWriter.java
new file mode 100644
index 00000000..789e53c0
--- /dev/null
+++ b/src/main/java/kieker/analysis/graph/export/AbstractWriter.java
@@ -0,0 +1,38 @@
+package kieker.analysis.graph.export;
+
+import kieker.analysis.graph.Edge;
+import kieker.analysis.graph.Graph;
+import kieker.analysis.graph.Vertex;
+
+public abstract class AbstractWriter extends AbstractTransformer<Void> {
+
+	protected AbstractWriter(final Graph graph) {
+		super(graph);
+		start();
+	}
+
+	@Override
+	protected final void mapVertex(final Vertex vertex) {
+		writeVertex(vertex);
+	}
+
+	@Override
+	protected final void mapEdge(final Edge edge) {
+		writeEdge(edge);
+	}
+
+	@Override
+	protected final Void getTransformation() {
+		finish();
+		return null;
+	}
+
+	protected abstract void start();
+
+	protected abstract void finish();
+
+	protected abstract void writeVertex(Vertex vertex);
+
+	protected abstract void writeEdge(Edge edge);
+
+}
diff --git a/src/main/java/kieker/analysis/graph/export/dot/AbstractDotWriter.java b/src/main/java/kieker/analysis/graph/export/dot/AbstractDotWriter.java
index bf7f2894..5ede4e06 100644
--- a/src/main/java/kieker/analysis/graph/export/dot/AbstractDotWriter.java
+++ b/src/main/java/kieker/analysis/graph/export/dot/AbstractDotWriter.java
@@ -6,29 +6,21 @@ import kieker.analysis.graph.Direction;
 import kieker.analysis.graph.Edge;
 import kieker.analysis.graph.Graph;
 import kieker.analysis.graph.Vertex;
-import kieker.analysis.graph.export.AbstractTransformer;
+import kieker.analysis.graph.export.AbstractWriter;
 import kieker.analysis.graph.util.dot.DotWriter;
 
 //TODo rename, extends AbstractWriter
-class AbstractDotWriter extends AbstractTransformer<Void> {
+class AbstractDotWriter extends AbstractWriter {
 
 	protected final DotWriter dotWriter;
 
-	AbstractDotWriter(final Graph graph, final DotWriter dotWriter) {
+	protected AbstractDotWriter(final Graph graph, final DotWriter dotWriter) {
 		super(graph);
 		this.dotWriter = dotWriter;
-
-		// TODO Better put this in own method
-		try {
-			dotWriter.start(graph.getName());
-			// TODO more stuff
-		} catch (IOException e) {
-			// TODO Handle IO Exception
-		}
 	}
 
 	@Override
-	protected void mapVertex(final Vertex vertex) {
+	protected void writeVertex(final Vertex vertex) {
 		try {
 			if (vertex.hasChildGraph()) {
 				Graph childGraph = vertex.getChildGraph();
@@ -46,28 +38,34 @@ class AbstractDotWriter extends AbstractTransformer<Void> {
 
 			}
 		} catch (IOException e) {
-			// TODO Handle IO Exception
+			handleIOException(e);
 		}
 	}
 
 	@Override
-	protected void mapEdge(final Edge edge) {
-		// TODO Auto-generated method stub
-
+	protected void writeEdge(final Edge edge) {
 		try {
-
 			String sourceId = edge.getVertex(Direction.OUT).getId().toString();
 			String targetId = edge.getVertex(Direction.IN).getId().toString();
 			dotWriter.addEdge(sourceId, targetId); // TODO
 		} catch (IOException e) {
-			// TODO Handle IO Exception
+			handleIOException(e);
 		}
 
 	}
 
 	@Override
-	protected Void getTransformation() {
-		return null;
+	protected void start() {
+		// Do nothing
+	}
+
+	@Override
+	protected void finish() {
+		// Do nothing
+	}
+
+	protected void handleIOException(final IOException ioException) {
+		// TODO Handle IO Exception
 	}
 
 }
diff --git a/src/main/java/kieker/analysis/graph/export/dot/DotWriter2.java b/src/main/java/kieker/analysis/graph/export/dot/DotWriter2.java
index 417f897b..ed83a3cf 100644
--- a/src/main/java/kieker/analysis/graph/export/dot/DotWriter2.java
+++ b/src/main/java/kieker/analysis/graph/export/dot/DotWriter2.java
@@ -11,25 +11,26 @@ public class DotWriter2 extends AbstractDotWriter {
 
 	public DotWriter2(final Graph graph, final Writer writer) {
 		super(graph, new DotWriter(writer));
+	}
 
-		// TODO Better put this in own method
+	// TODO does not work so far
+	@Override
+	protected void start() {
 		try {
 			dotWriter.start(graph.getName());
 			// TODO more stuff
 		} catch (IOException e) {
-			// TODO Handle IO Exception
+			handleIOException(e);
 		}
 	}
 
 	@Override
-	protected Void getTransformation() {
-		// TODO own method
+	protected void finish() {
 		try {
 			dotWriter.finish();
 		} catch (IOException e) {
-			// TODO Handle IO Exception
+			handleIOException(e);
 		}
-		return null;
 	}
 
 }
-- 
GitLab