public XmlElement generate(String workflowName, WsdlDefinitions workflowWSDL, GpelProcess gpelProcess, Map<String, WsdlDefinitions> wsdls) throws GraphException{
Iterator<WsdlService> services = workflowWSDL.services().iterator();
WsdlService service = null;
if(services.hasNext()){
service = services.next();
}else{
throw new IllegalStateException("NO Service found in the workflow WSDL:"+workflowName);
}
Iterator<WsdlPort> ports = service.ports().iterator();
WsdlPort port = null;
if(ports.hasNext()){
port = ports.next();
}else{
throw new IllegalStateException("NO Port found in the workflow WSDL:"+workflowName);
}
String targetNamespace = gpelProcess.getTargetNamespace();
String targetNamespacePrefix = "wfns";
XmlNamespace odeNs = builder.newNamespace("http://www.apache.org/ode/schemas/dd/2007/03");
XmlElement deploy = builder.newFragment(odeNs, "deploy");
deploy.declareNamespace(PROCESS, targetNamespace);
deploy.declareNamespace(targetNamespacePrefix, workflowWSDL.getTargetNamespace());
XmlElement process = deploy.addElement(odeNs, PROCESS);
process.setAttributeValue(NAME, PROCESS+":"+workflowName);
//active
XmlElement active = process.addElement(odeNs, "active");
active.addChild("true");
//provide
XmlElement provide = process.addElement
(odeNs, "provide");
provide.setAttributeValue("partnerLink", "workflowUserPartner");
XmlElement providerService = provide.addElement(odeNs, "service");
providerService.setAttributeValue("port", port.getName());
providerService.setAttributeValue(NAME, targetNamespacePrefix+":"+service.getName());
org.xmlpull.infoset.XmlElement wsdlXml = workflowWSDL.xml();
Iterable<org.xmlpull.infoset.XmlElement> partnerLinkTypes = wsdlXml.elements(null, "partnerLinkType");
GpelPartnerLinksContainer partnerLinks = gpelProcess.getPartnerLinks();
Iterable<GpelPartnerLink> partnerLinkList = partnerLinks.partnerLinks();
HashMap<String, String> newNamespaceMap = new HashMap<String, String>();
for (GpelPartnerLink link : partnerLinkList) {
String partnerRole = link.getPartnerRole();
if(null != partnerRole){
//These are the parrtner links that are non providers
XmlElement invoke = process.addElement(odeNs, "invoke");
invoke.setAttributeValue("partnerLink", link.getName());
XmlElement invokeService = invoke.addElement(odeNs, "service");
// invokeService.addAttribute("name", arg1)
QName partnerLinkTypeQName = link.getPartnerLinkTypeQName();
Iterator<org.xmlpull.infoset.XmlElement> plIterator = partnerLinkTypes.iterator();
while(plIterator.hasNext()){
org.xmlpull.infoset.XmlElement plType = plIterator.next();
XmlAttribute plTypeName = plType.attribute(NAME);
if(plTypeName.getValue().equals(partnerLinkTypeQName.getLocalPart())){
//found the correct partnerlink type
//now find the porttype
XmlAttribute plPortType = plType.element("role").attribute("portType");
String portTypeQnameString = plPortType.getValue();
String[] portTypeSegs = portTypeQnameString.split(":");
Iterator<org.xmlpull.infoset.XmlNamespace> namespaceIterator = wsdlXml.namespaces().iterator();
QName portTypeQname = null;
//find the qname of the porttype
while (namespaceIterator.hasNext()) {
org.xmlpull.infoset.XmlNamespace ns = (org.xmlpull.infoset.XmlNamespace) namespaceIterator.next();
if(ns.getPrefix().equals(portTypeSegs[0])){
portTypeQname = new QName(ns.getName(), portTypeSegs[1]);
}
}
//now go through the WSDLS and find the one with the proper port type
Set<String> keys = wsdls.keySet();
for (String key : keys) {
WsdlDefinitions wsdl = wsdls.get(key);
WsdlPortType portType = wsdl.getPortType(portTypeQname.getLocalPart());
if(null != portType && portType.getQName().equals(portTypeQname)){
// this is the right porttype so extract the service and you will be done
Iterator<WsdlService> svcIterator = wsdl.services().iterator();
String nsPrefix = null;
if(svcIterator.hasNext()){
WsdlService plService = svcIterator.next();
if(null == newNamespaceMap.get(wsdl.getTargetNamespace())){
nsPrefix = "p"+newNamespaceMap.size();
newNamespaceMap.put(wsdl.getTargetNamespace(), nsPrefix);
}else{
nsPrefix = newNamespaceMap.get(wsdl.getTargetNamespace());
}
String portName = null;
Iterator<WsdlPort> portItr = plService.ports().iterator();
if(portItr.hasNext()){
portName = portItr.next().getName();
}
invokeService.setAttributeValue(NAME, nsPrefix+":"+plService.getName());
invokeService.setAttributeValue("port", portName);
}
}
}