evaluateFlowAndSequenceForAddingInits(wsdls, workflowWSDL, iterator, list);
}
}
private void evaluateFlowAndSequenceForAddingInits(Map<String, WsdlDefinitions> wsdls, WsdlDefinitions workflowWSDL, Iterator<GpelActivity> iterator, LinkedList<GpelAssign> list){
GpelActivity last = null;
while(iterator.hasNext()){
GpelActivity next = iterator.next();
if(isSequence(next) || isFlow(next)){
evaluateFlowAndSequenceForAddingInits(wsdls, workflowWSDL, next, list);
}else if(isInvoke(next) || isReply(next)){
if(last == null || !isAssign(last)){
throw new XBayaRuntimeException("Assign activity not found for the Invoke "+next.xmlStringPretty());
}
GpelAssign assign = (GpelAssign)last;
XmlNamespace ns = assign.xml().getNamespace();
XmlElement container = XmlConstants.BUILDER.parseFragmentFromString("<dummyelement></dummyelement>");
String portTypeattr = next.xml().attributeValue(PORT_TYPE_STR);
String operation = next.xml().attributeValue(OPERATION_STR);
if(null == portTypeattr || "".equals(portTypeattr)){
throw new XBayaRuntimeException("No Porttype found for Invoke:"+next);
}
String portTypeName = portTypeattr.substring(portTypeattr.indexOf(':')+1);
String messagePartName = null;
if(isInvoke(next)){
Iterator<String> keys = wsdls.keySet().iterator();
while(keys.hasNext()){
String key = keys.next();
WsdlDefinitions wsdl = wsdls.get(key);
WsdlPortType portType = wsdl.getPortType(portTypeName);
if( null != portType){
WsdlPortTypeOperation wsdlOperation = portType.getOperation(operation);
WsdlMessagePart part = wsdl.getMessage(wsdlOperation.getInput().getMessage().getLocalPart()).parts().iterator().next();
XmlElement childElement = container.addElement(part.getElement().getLocalPart());
Iterator<GpelAssignCopy> copyItr = assign.copyOperations().iterator();
while(copyItr.hasNext()){
GpelAssignCopy copyItm = copyItr.next();
childElement.addElement(getElementName(copyItm.getTo().getQuery()));
if(messagePartName == null){
messagePartName = copyItm.getTo().xml().attributeValue(PART_STR);
}
}
break;
}
}
}else {
//reply
WsdlPortType portType = workflowWSDL.getPortType(portTypeName);
if( null != portType){
WsdlPortTypeOperation wsdlOperation = portType.getOperation(operation);
WsdlMessagePart part = workflowWSDL.getMessage(wsdlOperation.getOutput().getMessage().getLocalPart()).parts().iterator().next();
XmlElement childElement = container.addElement(part.getElement().getLocalPart());
Iterator<GpelAssignCopy> copyItr = assign.copyOperations().iterator();
while(copyItr.hasNext()){
GpelAssignCopy copyItm = copyItr.next();
childElement.addElement(getElementName(copyItm.getTo().getQuery()));
if(messagePartName == null){
messagePartName = copyItm.getTo().xml().attributeValue(PART_STR);
}
}
}
}
GpelAssignCopyFrom from = new GpelAssignCopyFrom(ns);
from.setLiteral(container);
GpelAssignCopyTo to = new GpelAssignCopyTo(ns);
to.xml().setAttributeValue(PART_STR, messagePartName);
if(isInvoke(next)){
to.xml().setAttributeValue(VARIABLE_STR, next.xml().attributeValue(INPUT_VARIABLE_STR));
}else{
to.xml().setAttributeValue(VARIABLE_STR, next.xml().attributeValue(VARIABLE_STR));
}
GpelAssignCopy newAssign = new GpelAssignCopy(ns, from, to);
newAssign.xml().setAttributeValue(VALIDATE_STR, NO_STR);
GpelAssign gpelAssign = new GpelAssign(ns, newAssign);
list.add(gpelAssign);