node.getGUI().setBodyColor(NodeState.FINISHED.color);
}
private void handleForEach(Node node) throws XBayaException {
final ForEachNode forEachNode = (ForEachNode) node;
EndForEachNode endForEachNode = null;
Collection<Node> repeatNodes = node.getOutputPort(0).getToNodes();
// we will support only one for now
if (repeatNodes.size() != 1) {
throw new WorkFlowInterpreterException("Only one node allowed inside foreach");
}
Iterator<Node> iterator = repeatNodes.iterator();
if (iterator.hasNext()) {
Node middleNode = iterator.next();
if (!(middleNode instanceof WSNode)) {
throw new WorkFlowInterpreterException("Encountered Node inside foreach that is not a WSNode" + middleNode);
}
Iterator<Node> endForEachNodeItr = middleNode.getOutputPort(0).getToNodes().iterator();
while (endForEachNodeItr.hasNext()) {
Node node2 = endForEachNodeItr.next();
if (!(node2 instanceof EndForEachNode)) {
throw new WorkFlowInterpreterException("Found More than one node inside foreach");
} else {
endForEachNode = (EndForEachNode) node2;
}
}
final WSNode foreachWSNode = (WSNode) middleNode;
WorkflowInvoker workflowInvoker = this.invokerMap.get(forEachNode.getInputPort(0).getFromNode());
final LinkedList<String> listOfValues = new LinkedList<String>();
if (workflowInvoker != null) {
if (workflowInvoker instanceof GenericInvoker) {
String message = ((GenericInvoker) workflowInvoker).getOutputs().toString();
XmlElement msgElmt = XmlConstants.BUILDER.parseFragmentFromString(message);
Iterator children = msgElmt.children().iterator();
while (children.hasNext()) {
Object object = children.next();
if (object instanceof XmlElement) {
XmlElement child = (XmlElement) object;
Iterator valItr = child.children().iterator();
if (valItr.hasNext()) {
Object object2 = valItr.next();
if (object2 instanceof String) {
listOfValues.add(object2.toString());
}
}
}
}
}
if (listOfValues.size() > 0) {
forEachNode.getGUI().setBodyColor(NodeState.EXECUTING.color);
foreachWSNode.getGUI().setBodyColor(NodeState.EXECUTING.color);
endForEachNode.getGUI().setBodyColor(NodeState.EXECUTING.color);
final EndForEachNode tempendForEachNode = endForEachNode;
final SystemComponentInvoker systemInvoker = new SystemComponentInvoker();
this.invokerMap.put(endForEachNode, systemInvoker);
new Thread() {
@Override
public void run() {