Skip to content
Snippets Groups Projects
Commit 55f5d41f authored by Sören Henning's avatar Sören Henning
Browse files

worked on graph exporting

parent 1f23824a
No related branches found
No related tags found
1 merge request!17Get impletemented stages and Java 8
Showing
with 282 additions and 40 deletions
package kieker.analysis.graph; package kieker.analysis.graph;
import javax.xml.bind.JAXBContext; import kieker.analysis.graph.export.graphml.GraphMLExporter;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import org.graphdrawing.graphml.EdgeType;
import org.graphdrawing.graphml.GraphType;
import org.graphdrawing.graphml.GraphmlType;
import org.graphdrawing.graphml.KeyType;
import org.graphdrawing.graphml.NodeType;
import org.graphdrawing.graphml.ObjectFactory;
import kieker.analysis.graph.impl.GraphImpl; import kieker.analysis.graph.impl.GraphImpl;
public class GraphTester { public class GraphTester {
...@@ -52,7 +41,7 @@ public class GraphTester { ...@@ -52,7 +41,7 @@ public class GraphTester {
// BlueprintsExporter blueprintsExporter = new BlueprintsExporter(graph); // BlueprintsExporter blueprintsExporter = new BlueprintsExporter(graph);
// System.out.println(blueprintsExporter.exportGraph()); // System.out.println(blueprintsExporter.exportGraph());
node1snd.remove(); // node1snd.remove();
for (Vertex vertex : graph.getVertices()) { for (Vertex vertex : graph.getVertices()) {
System.out.println(vertex.getId()); System.out.println(vertex.getId());
...@@ -65,6 +54,12 @@ public class GraphTester { ...@@ -65,6 +54,12 @@ public class GraphTester {
Vertex node1sub3 = node1.getChildGraph().addVertex("n1::s3"); Vertex node1sub3 = node1.getChildGraph().addVertex("n1::s3");
node1sub3.addEdge("wormhole", node4); node1sub3.addEdge("wormhole", node4);
if (node1.hasChildGraph()) {
System.out.println("Node 1 has Child graph");
} else {
System.out.println("Node 1 does not have a child graph");
}
System.out.println("Node 1's child graph"); System.out.println("Node 1's child graph");
for (Vertex vertex : node1.getChildGraph().getVertices()) { for (Vertex vertex : node1.getChildGraph().getVertices()) {
...@@ -85,33 +80,35 @@ public class GraphTester { ...@@ -85,33 +80,35 @@ public class GraphTester {
System.out.println(edge.getId()); System.out.println(edge.getId());
} }
GraphmlType graphmlType = new GraphmlType(); GraphMLExporter graphMLExporter = new GraphMLExporter();
graphmlType.getKey().add(new KeyType());
GraphType graphType = new GraphType(); graphMLExporter.export(graph, System.out);
graphType.getDataOrNodeOrEdge().add(new NodeType());
graphType.getDataOrNodeOrEdge().add(new NodeType()); // JAXB Test
graphType.getDataOrNodeOrEdge().add(new EdgeType());
graphmlType.getGraphOrData().add(graphType); //
// GraphmlType graphmlType = new GraphmlType();
try { // graphmlType.getKey().add(new KeyType());
JAXBContext context = JAXBContext.newInstance(GraphmlType.class); // GraphType graphType = new GraphType();
Marshaller m = context.createMarshaller(); // graphType.getDataOrNodeOrEdge().add(new NodeType());
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); // graphType.getDataOrNodeOrEdge().add(new NodeType());
// graphType.getDataOrNodeOrEdge().add(new EdgeType());
ObjectFactory objectFactory = new ObjectFactory(); // graphmlType.getGraphOrData().add(graphType);
JAXBElement<GraphmlType> element = objectFactory.createGraphml(graphmlType); //
// try {
m.marshal(element, System.out); // JAXBContext context = JAXBContext.newInstance(GraphmlType.class);
} catch (JAXBException e) { // Marshaller m = context.createMarshaller();
// TODO Auto-generated catch block // m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
e.printStackTrace(); //
} // ObjectFactory objectFactory = new ObjectFactory();
// JAXBElement<GraphmlType> element = objectFactory.createGraphml(graphmlType);
// Use object factory //
// m.marshal(element, System.out);
// } catch (JAXBException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// http://blog.bdoughan.com/2012/07/jaxb-and-root-elements.html
// http://stackoverflow.com/questions/24519449/unable-to-marshal-type-as-an-element-because-it-is-missing-an-xmlrootelement-an
// http://stackoverflow.com/questions/819720/no-xmlrootelement-generated-by-jaxb
} }
} }
...@@ -4,6 +4,7 @@ import kieker.analysis.graph.Edge; ...@@ -4,6 +4,7 @@ import kieker.analysis.graph.Edge;
import kieker.analysis.graph.Graph; import kieker.analysis.graph.Graph;
import kieker.analysis.graph.Vertex; import kieker.analysis.graph.Vertex;
//TODO unused
public abstract class AbstractExporter<O> { public abstract class AbstractExporter<O> {
protected Graph graph; protected Graph graph;
......
package kieker.analysis.graph.export;
import kieker.analysis.graph.Edge;
import kieker.analysis.graph.Graph;
import kieker.analysis.graph.Vertex;
//TODO better name mapper
public abstract class AbstractTransformer<O> {
protected Graph graph;
public AbstractTransformer(final Graph graph) {
this.graph = graph;
}
public final O transform() {
for (final Vertex vertex : graph.getVertices()) {
mapVertex(vertex);
}
for (final Edge edge : graph.getEdges()) {
mapEdge(edge);
}
return getTransformation();
}
protected abstract void mapVertex(Vertex vertex);
protected abstract void mapEdge(Edge edge);
protected abstract O getTransformation();
}
package kieker.analysis.graph.export.dot;
import java.io.OutputStream;
import kieker.analysis.graph.Graph;
public class DotExporter {
public void export(final Graph graph, final OutputStream outputStream) {
GraphTransformer graphTransformer = new GraphTransformer(graph);
// TODO Receiving a dot object would be (maybe) better
String dotString = graphTransformer.transform();
}
}
package kieker.analysis.graph.export; package kieker.analysis.graph.export.dot;
import kieker.analysis.graph.Direction; import kieker.analysis.graph.Direction;
import kieker.analysis.graph.Edge; import kieker.analysis.graph.Edge;
import kieker.analysis.graph.Graph; import kieker.analysis.graph.Graph;
import kieker.analysis.graph.Vertex; import kieker.analysis.graph.Vertex;
import kieker.analysis.graph.export.AbstractTransformer;
import kieker.analysis.util.DotBuilder; import kieker.analysis.util.DotBuilder;
public class DotExporter extends AbstractExporter<String> { public class GraphTransformer extends AbstractTransformer<String> {
private final DotBuilder dotBuilder; private final DotBuilder dotBuilder;
public DotExporter(final Graph graph) { public GraphTransformer(final Graph graph) {
super(graph); super(graph);
dotBuilder = new DotBuilder(graph.getName()); dotBuilder = new DotBuilder(graph.getName());
} }
@Override @Override
protected void mapVertex(final Vertex vertex) { protected void mapVertex(final Vertex vertex) {
dotBuilder.addNode(vertex.getId().toString()); if (vertex.hasChildGraph()) {
// TODO Add style, label, etc Graph childGraph = vertex.getChildGraph();
// TODO Handle child graph GraphTransformer graphTransformer = new GraphTransformer(childGraph);
String childGraphString = graphTransformer.transform();
// TODO We need a subgraph cluster_XYZ { ... }
// TODO dotBuilder.addCluster();
} else {
dotBuilder.addNode(vertex.getId().toString());
// TODO Add style, label, etc
// TODO Handle child graph
}
} }
@Override @Override
...@@ -28,10 +38,11 @@ public class DotExporter extends AbstractExporter<String> { ...@@ -28,10 +38,11 @@ public class DotExporter extends AbstractExporter<String> {
String targetId = edge.getVertex(Direction.IN).getId().toString(); String targetId = edge.getVertex(Direction.IN).getId().toString();
dotBuilder.addEdge(sourceId, targetId); dotBuilder.addEdge(sourceId, targetId);
// TODO Add style, label, etc // TODO Add style, label, etc
} }
@Override @Override
protected String getExport() { protected String getTransformation() {
return dotBuilder.get(); return dotBuilder.get();
} }
......
package kieker.analysis.graph.export.graphml;
import java.io.OutputStream;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import org.graphdrawing.graphml.GraphType;
import org.graphdrawing.graphml.GraphmlType;
import org.graphdrawing.graphml.ObjectFactory;
import kieker.analysis.graph.Graph;
public class GraphMLExporter {
private static final Boolean FORMATTED_OUTPUT = Boolean.TRUE;
public void export(final Graph graph, final OutputStream outputStream) {
GraphmlType graphmlType = new GraphmlType();
GraphTypeTransformer graphTypeTransformer = new GraphTypeTransformer(graph);
GraphType graphType = graphTypeTransformer.transform();
graphmlType.getGraphOrData().add(graphType);
try {
JAXBContext context = JAXBContext.newInstance(GraphmlType.class);
Marshaller marshaller = context.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, FORMATTED_OUTPUT);
ObjectFactory objectFactory = new ObjectFactory();
JAXBElement<GraphmlType> rootElement = objectFactory.createGraphml(graphmlType);
marshaller.marshal(rootElement, outputStream);
} catch (JAXBException e) {
// TODO Auto-generated catch block
// TODO wrap exception
e.printStackTrace();
}
}
}
package kieker.analysis.graph.export.graphml;
import org.graphdrawing.graphml.EdgeType;
import org.graphdrawing.graphml.GraphType;
import org.graphdrawing.graphml.NodeType;
import kieker.analysis.graph.Edge;
import kieker.analysis.graph.Graph;
import kieker.analysis.graph.Vertex;
import kieker.analysis.graph.export.AbstractTransformer;
public class GraphTypeTransformer extends AbstractTransformer<GraphType> {
private final GraphType graphType;
public GraphTypeTransformer(final Graph graph) {
super(graph);
graphType = new GraphType();
}
@Override
protected void mapVertex(final Vertex vertex) {
NodeType nodeType = new NodeType();
// TODO Map Properties + id
if (vertex.hasChildGraph()) {
Graph childGraph = vertex.getChildGraph();
GraphTypeTransformer graphTypeTransformer = new GraphTypeTransformer(childGraph);
GraphType childGraphType = graphTypeTransformer.transform();
nodeType.setGraph(childGraphType);
}
graphType.getDataOrNodeOrEdge().add(nodeType);
}
@Override
protected void mapEdge(final Edge edge) {
EdgeType edgeType = new EdgeType();
// TODO Map Properties + id + source/target
graphType.getDataOrNodeOrEdge().add(edgeType);
}
@Override
protected GraphType getTransformation() {
return graphType;
}
}
...@@ -27,7 +27,7 @@ class VertexImpl extends ElementImpl implements Vertex { ...@@ -27,7 +27,7 @@ class VertexImpl extends ElementImpl implements Vertex {
@Override @Override
public boolean hasChildGraph() { public boolean hasChildGraph() {
return (this.childGraph == null); return this.childGraph != null;
} }
@Override @Override
......
package kieker.analysis.graph.traversal;
import kieker.analysis.graph.Edge;
import kieker.analysis.graph.Graph;
import kieker.analysis.graph.Vertex;
public class FlatGraphTraverser {
public void traverse(final Graph graph) {
for (Vertex vertex : graph.getVertices()) {
// TODO call (vertex) visitor
}
for (Edge edge : graph.getEdges()) {
// TODO Call (edge)visitor
}
}
}
package kieker.analysis.graph.traversal;
import kieker.analysis.graph.Edge;
import kieker.analysis.graph.Graph;
import kieker.analysis.graph.Vertex;
//TODO unused
public class NestedGraphTraverser {
public void traverse(final Graph graph) {
for (Vertex vertex : graph.getVertices()) {
// TODO call (vertex) visitor
NestedGraphTraverser childGraphTraverser = new NestedGraphTraverser();
// Visitor vistor;
// childGraphTraverser.addVisitor(visitor);
childGraphTraverser.traverse(graph);
// visitor.
}
for (Edge edge : graph.getEdges()) {
// TODO Call (edge)visitor
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment