@Override
public Graph transform(RequestContext context, Graph graph)
throws TransformationException {
RequestNode gathererNode = new ProcessingElementNode("eu.admire.Gatherer");
List<RequestNode> list = new ArrayList<RequestNode>();
int i = 0; // number of created Observers
for (RequestNode node : graph.getNodes()) {
Map<String, Map<Integer, Connection>> outputs = node
.getAllOutputs();
for (String keyName : outputs.keySet()) {
for (Integer keyIndex : outputs.get(keyName).keySet()) {
Connection conn = outputs.get(keyName).get(keyIndex);
int targetCount = 0;
for(RequestNodeInput target : conn.getTargets()) {
RequestNode observerNode = new ProcessingElementNode("eu.admire.Observer");
Connection output = observerNode.getOutput("out", 0);
target.getRequestNode().replaceInput(target.getName(), target.getIndex(), output);
Connection input = observerNode.getInput("in", 0);
if (targetCount == 0)
{
node.replaceOutput(keyName, keyIndex, input);
}
else
{
observerNode.connectInput("in", 0, node.getOutput(keyName, keyIndex));
}
targetCount++;
Connection gathConn = observerNode.getOutput("observed", 0);
gathererNode.connectInput("input", i++, gathConn);
list.add(observerNode);