Skip to content
Snippets Groups Projects
Commit 5eb8b3e0 authored by Lars Erik Blümke's avatar Lars Erik Blümke
Browse files

preparing merge

parent 9392276e
No related branches found
No related tags found
No related merge requests found
package kieker.analysis.util;
import java.util.LinkedList;
import java.util.Queue;
import teetime.framework.AbstractStage;
import teetime.framework.InputPort;
public abstract class AbstractCombinerStage<I, J> extends AbstractStage {
protected final InputPort<I> inputPort1 = this.createInputPort();
protected final InputPort<J> inputPort2 = this.createInputPort();
private final Queue<I> elements1 = new LinkedList<>();
private final Queue<J> elements2 = new LinkedList<>();
public final InputPort<I> getInputPort1() {
return this.inputPort1;
}
public final InputPort<J> getInputPort2() {
return this.inputPort2;
}
@Override
protected void execute() {
final I element1 = this.getInputPort1().receive();
if (element1 != null) {
elements1.add(element1);
}
final J element2 = this.getInputPort2().receive();
if (element2 != null) {
elements2.add(element2);
}
if (elements1.size() > 0 && elements2.size() > 0) {
this.combine(elements1.poll(), elements2.poll());
}
}
protected abstract void combine(final I element1, final J element2);
}
package kieker.analysis.util;
import java.io.OutputStream;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
/**
* This stage marshals the content tree rooted at an incoming element at the
* first input port into an output stream at the second input port.
*
* A class object has to be passed at creation. Only elements of this type
* wrapped in a {@code JAXBElement} could be marshaled.
*
* @author Sören Henning
*
*/
public class JAXBMarshalStage<T> extends AbstractCombinerStage<JAXBElement<T>, OutputStream> {
private static final Boolean FORMATTED_OUTPUT_DEFAULT = Boolean.TRUE;
private final Marshaller marshaller;
public JAXBMarshalStage(final Class<T> elementsClass) {
this(elementsClass, FORMATTED_OUTPUT_DEFAULT);
}
public JAXBMarshalStage(final Class<T> elementsClass, final Boolean formattedOutput) {
try {
this.marshaller = JAXBContext.newInstance(elementsClass).createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, formattedOutput);
} catch (JAXBException e) {
// TODO Exception
throw new IllegalStateException(e);
}
}
@Override
protected void combine(final JAXBElement<T> jaxbElement, final OutputStream outputStream) {
try {
marshaller.marshal(jaxbElement, outputStream);
} catch (JAXBException e) {
// TODO Exception
throw new IllegalStateException("The received element could not be marshalled.", e);
}
}
}
package kieker.analysis.util.graph.export.dot;
import java.io.IOException;
import java.util.Map;
import java.util.Map.Entry;
import java.util.function.Function;
import java.util.stream.Collectors;
import kieker.analysis.util.graph.Direction;
import kieker.analysis.util.graph.Edge;
import kieker.analysis.util.graph.Graph;
import kieker.analysis.util.graph.Vertex;
import kieker.analysis.util.graph.export.AbstractTransformer;
import kieker.analysis.util.graph.util.dot.DotGraphWriter;
import kieker.analysis.util.graph.util.dot.attributes.DotClusterAttribute;
class DotElementExporter extends AbstractTransformer<Void> {
protected final DotGraphWriter dotGraphWriter;
protected final DotExportConfiguration configuration;
protected DotElementExporter(final Graph graph, final DotGraphWriter dotGraphWriter, final DotExportConfiguration configuration) {
super(graph);
this.dotGraphWriter = dotGraphWriter;
this.configuration = configuration;
}
@Override
protected void transformVertex(final Vertex vertex) {
try {
if (vertex.hasChildGraph()) {
Graph childGraph = vertex.getChildGraph();
dotGraphWriter.addClusterStart(vertex.getId().toString());
for (Entry<DotClusterAttribute, Function<Vertex, String>> attribute : configuration.getClusterAttributes().entrySet()) {
dotGraphWriter.addGraphAttribute(attribute.getKey().toString(), attribute.getValue().apply(vertex));
}
DotElementExporter childGraphWriter = new DotElementExporter(childGraph, dotGraphWriter, configuration);
childGraphWriter.transform();
dotGraphWriter.addClusterStop();
} else {
dotGraphWriter.addNode(vertex.getId().toString(), getAttributes(vertex));
}
} catch (IOException e) {
handleIOException(e);
}
}
@Override
protected void transformEdge(final Edge edge) {
try {
final String sourceId = edge.getVertex(Direction.OUT).getId().toString();
final String targetId = edge.getVertex(Direction.IN).getId().toString();
dotGraphWriter.addEdge(sourceId, targetId, getAttributes(edge));
} catch (IOException e) {
handleIOException(e);
}
}
protected void handleIOException(final IOException ioException) {
throw new IllegalStateException(ioException);
}
protected Map<String, String> getAttributes(final Edge edge) {
return configuration.getEdgeAttributes().entrySet().stream().collect(Collectors.toMap(
e -> e.getKey().toString(),
e -> e.getValue().apply(edge)));
}
protected Map<String, String> getAttributes(final Vertex vertex) {
return configuration.getNodeAttributes().entrySet().stream().collect(Collectors.toMap(
e -> e.getKey().toString(),
e -> e.getValue().apply(vertex)));
}
@Override
protected void beforeTransformation() {
// Do nothing
}
@Override
protected void afterTransformation() {
// Do nothing
}
@Override
protected Void getTransformation() {
return null;
}
}
package kieker.analysis.util.graph.export.dot;
import java.util.EnumMap;
import java.util.Map;
import java.util.function.Function;
import kieker.analysis.util.graph.Edge;
import kieker.analysis.util.graph.Graph;
import kieker.analysis.util.graph.Vertex;
import kieker.analysis.util.graph.util.dot.attributes.DotClusterAttribute;
import kieker.analysis.util.graph.util.dot.attributes.DotEdgeAttribute;
import kieker.analysis.util.graph.util.dot.attributes.DotGraphAttribute;
import kieker.analysis.util.graph.util.dot.attributes.DotNodeAttribute;
public class DotExportConfiguration {
final private Map<DotGraphAttribute, Function<Graph, String>> graphAttributes = new EnumMap<>(DotGraphAttribute.class);
final private Map<DotNodeAttribute, Function<Graph, String>> defaultNodeAttributes = new EnumMap<>(DotNodeAttribute.class);
final private Map<DotEdgeAttribute, Function<Graph, String>> defaultEdgeAttributes = new EnumMap<>(DotEdgeAttribute.class);
final private Map<DotNodeAttribute, Function<Vertex, String>> nodeAttributes = new EnumMap<>(DotNodeAttribute.class);
final private Map<DotEdgeAttribute, Function<Edge, String>> edgeAttributes = new EnumMap<>(DotEdgeAttribute.class);
final private Map<DotClusterAttribute, Function<Vertex, String>> clusterAttributes = new EnumMap<>(DotClusterAttribute.class);
public Map<DotGraphAttribute, Function<Graph, String>> getGraphAttributes() {
return graphAttributes;
}
public Map<DotNodeAttribute, Function<Graph, String>> getDefaultNodeAttributes() {
return defaultNodeAttributes;
}
public Map<DotEdgeAttribute, Function<Graph, String>> getDefaultEdgeAttributes() {
return defaultEdgeAttributes;
}
public Map<DotNodeAttribute, Function<Vertex, String>> getNodeAttributes() {
return nodeAttributes;
}
public Map<DotEdgeAttribute, Function<Edge, String>> getEdgeAttributes() {
return edgeAttributes;
}
public Map<DotClusterAttribute, Function<Vertex, String>> getClusterAttributes() {
return clusterAttributes;
}
}
package kieker.analysis.util.graph.export.dot;
import java.io.FileWriter;
import java.io.IOException;
import java.util.function.Function;
import kieker.analysis.util.graph.Graph;
import kieker.analysis.util.graph.mapping.SimpleFileNameMapper;
import kieker.analysis.util.graph.util.FileExtension;
public class DotFileWriterStage extends DotWriterStage {
public DotFileWriterStage(final Function<Graph, String> fileNameMapper) {
super(fileNameMapper.andThen(fileName -> {
try {
return new FileWriter(fileName);
} catch (IOException e) {
throw new IllegalArgumentException(e);
}
}));
}
public DotFileWriterStage(final String outputDirectory) {
this(new SimpleFileNameMapper(outputDirectory, FileExtension.DOT));
}
}
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