You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by sa...@apache.org on 2012/05/17 19:12:21 UTC

svn commit: r1339718 [9/10] - in /incubator/airavata/trunk: ./ modules/airavata-client/ modules/distribution/ modules/distribution/src/main/assembly/ modules/workflow-model/ modules/workflow-model/src/ modules/workflow-model/src/main/ modules/workflow-...

Added: incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/ode/ODEClient.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/ode/ODEClient.java?rev=1339718&view=auto
==============================================================================
--- incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/ode/ODEClient.java (added)
+++ incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/ode/ODEClient.java Thu May 17 17:12:15 2012
@@ -0,0 +1,155 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.workflow.model.ode;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.airavata.workflow.model.component.ComponentException;
+import org.apache.airavata.workflow.model.component.ws.WSComponentPort;
+import org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException;
+import org.apache.airavata.workflow.model.gpel.script.BPELScript;
+import org.apache.airavata.workflow.model.gpel.script.BPELScriptType;
+import org.apache.airavata.workflow.model.graph.GraphException;
+import org.apache.airavata.workflow.model.graph.impl.NodeImpl;
+import org.apache.airavata.workflow.model.graph.system.InputNode;
+import org.apache.airavata.workflow.model.graph.system.OutputNode;
+import org.apache.airavata.workflow.model.wf.Workflow;
+
+public class ODEClient {
+
+    public static final String STREAM_SOURCE_NS = "http://extreme.indiana.edu/streaming/source";
+
+    public ODEClient() {
+
+    }
+
+    public List<InputNode> getInputNodes(Workflow workflow) {
+        LinkedList<InputNode> ret = new LinkedList<InputNode>();
+        List<NodeImpl> nodes = workflow.getGraph().getNodes();
+        for (NodeImpl nodeImpl : nodes) {
+            if (nodeImpl instanceof InputNode) {
+                ret.add((InputNode) nodeImpl);
+            }
+
+        }
+        return ret;
+    }
+
+    /**
+     * Returns workflow inputs and can be used to get workflow input metadata
+     * 
+     * @param workflow
+     * @return
+     */
+    public List<WSComponentPort> getInputs(Workflow workflow) {
+        List<WSComponentPort> inputs;
+        try {
+            if (workflow.getWorkflowWSDL() == null) {
+                BPELScript script = new BPELScript(workflow);
+                script.create(BPELScriptType.BPEL2);
+                workflow.setWorkflowWSDL(script.getWorkflowWSDL().getWsdlDefinitions());
+                workflow.setGpelProcess(script.getGpelProcess());
+
+            }
+            inputs = workflow.getInputs();
+            return inputs;
+        } catch (GraphException e) {
+            throw new WorkflowRuntimeException(e);
+        } catch (ComponentException e) {
+            throw new WorkflowRuntimeException(e);
+        }
+
+    }
+
+    /**
+     * Returns a WSDL that is ready to be used as the WSIF invokable WSDL to initiate the process
+     *
+     * @param xRegistryURI
+     * @param gssCredential
+     * @param qname
+     *            Qname of the workflow that was used to store in XRegistry
+     * @param dscUrl
+     * @param odeEprEndingWithPort
+     *            Something that look like https://kili.extreme.indiana.edu:17433
+     * @return
+     */
+    // public WsdlDefinitions getWorkflowWSDL(URI xRegistryURI, GSSCredential gssCredential, QName qname,
+    // String odeEprEndingWithPort) {
+    // try {
+    // XRegistryAccesser xregistryAccesser = new XRegistryAccesser(gssCredential, xRegistryURI);
+    // Workflow workflow = xregistryAccesser.getWorkflow(qname);
+    // // The REsulting WSDL is not affected by the DSCURL this is
+    // // necessary to create the other scripts
+    // // So send in some dummy URI for DSC
+    // URI dscUrl = XBayaConstants.DEFAULT_DSC_URL;
+    // return workflow.getOdeInvokableWSDL(dscUrl, odeEprEndingWithPort);
+    // } catch (Exception e) {
+    // throw new XBayaRuntimeException(e);
+    // }
+    // }
+
+    // public ResourceData[] getStreamResources(XRegistryClient client) throws XRegistryClientException {
+    // ResourceData[] result = client.findResource(STREAM_SOURCE_NS);
+    // return result;
+    // }
+    //
+    // public void deployStreamSource(XRegistryClient client, String name, String wsdlURL) throws
+    // XRegistryClientException {
+    // QName qname = new QName(STREAM_SOURCE_NS, name);
+    // if (isResourceExist(client, qname)) {
+    // throw new XRegistryClientException("Resource Already exist by qname:" + qname);
+    // }
+    // client.registerResource(qname, wsdlURL);
+    // }
+
+    /**
+     * @param client
+     * @param qname
+     * @return
+     * @throws XregistryException
+     */
+    // private boolean isResourceExist(XRegistryClient client, QName qname) throws XRegistryClientException {
+    // String resource = client.getResource(qname);
+    // if (resource != null && !"".equals(resource)) {
+    // return true;
+    // }
+    // return false;
+    // }
+
+    /**
+     * @param workflow
+     * @return
+     */
+    public LinkedList<OutputNode> getoutNodes(Workflow workflow) {
+        List<NodeImpl> nodes = workflow.getGraph().getNodes();
+        LinkedList<OutputNode> ret = new LinkedList<OutputNode>();
+        for (NodeImpl nodeImpl : nodes) {
+            if (nodeImpl instanceof OutputNode) {
+                ret.add((OutputNode) nodeImpl);
+            }
+        }
+        return ret;
+
+    }
+
+}
\ No newline at end of file

Added: incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/ode/ODEDeploymentDescriptor.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/ode/ODEDeploymentDescriptor.java?rev=1339718&view=auto
==============================================================================
--- incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/ode/ODEDeploymentDescriptor.java (added)
+++ incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/ode/ODEDeploymentDescriptor.java Thu May 17 17:12:15 2012
@@ -0,0 +1,184 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.workflow.model.ode;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import javax.xml.namespace.QName;
+
+import org.apache.airavata.workflow.model.graph.GraphException;
+import org.gpel.model.GpelPartnerLink;
+import org.gpel.model.GpelPartnerLinksContainer;
+import org.gpel.model.GpelProcess;
+import org.xmlpull.infoset.XmlAttribute;
+import org.xmlpull.infoset.XmlElement;
+import org.xmlpull.infoset.XmlInfosetBuilder;
+import org.xmlpull.infoset.XmlNamespace;
+
+import xsul5.XmlConstants;
+import xsul5.wsdl.WsdlDefinitions;
+import xsul5.wsdl.WsdlPort;
+import xsul5.wsdl.WsdlPortType;
+import xsul5.wsdl.WsdlService;
+
+public class ODEDeploymentDescriptor {
+
+    /**
+     * NAME
+     */
+    private static final String NAME = "name";
+    /**
+     * PROCESS
+     */
+    private static final String PROCESS = "process";
+
+    private static XmlInfosetBuilder builder = XmlConstants.BUILDER;
+
+    public ODEDeploymentDescriptor() {
+    }
+
+    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);
+
+                                }
+                            }
+                        }
+                    }
+                }
+
+            }
+        }
+
+        Set<String> keys = newNamespaceMap.keySet();
+        for (String key : keys) {
+            String nsPrefix = newNamespaceMap.get(key);
+            deploy.setAttributeValue("xmlns:" + nsPrefix, key);
+        }
+        return deploy;
+    }
+}
\ No newline at end of file

Added: incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/ode/ODEWSDLTransformer.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/ode/ODEWSDLTransformer.java?rev=1339718&view=auto
==============================================================================
--- incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/ode/ODEWSDLTransformer.java (added)
+++ incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/ode/ODEWSDLTransformer.java Thu May 17 17:12:15 2012
@@ -0,0 +1,434 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.workflow.model.ode;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.Map;
+import java.util.Set;
+
+import javax.xml.namespace.QName;
+
+import org.apache.airavata.common.utils.StringUtil;
+import org.apache.airavata.common.utils.WSDLUtil;
+import org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException;
+import org.apache.airavata.workflow.model.gpel.DSCUtil;
+import org.apache.airavata.workflow.model.utils.WorkflowConstants;
+import org.xmlpull.infoset.XmlBuilderException;
+import org.xmlpull.infoset.XmlInfosetBuilder;
+import org.xmlpull.infoset.XmlNamespace;
+
+import xsul5.wsdl.WsdlBinding;
+import xsul5.wsdl.WsdlBindingOperation;
+import xsul5.wsdl.WsdlDefinitions;
+import xsul5.wsdl.WsdlMessage;
+import xsul5.wsdl.WsdlMessagePart;
+import xsul5.wsdl.WsdlPort;
+import xsul5.wsdl.WsdlPortType;
+import xsul5.wsdl.WsdlPortTypeOperation;
+import xsul5.wsdl.WsdlService;
+
+public class ODEWSDLTransformer {
+
+    /**
+     * SCHEMA_LOCATION_URI
+     */
+    private static final String SCHEMA_LOCATION_URI = "lead-context.xsd";
+    /**
+     * SCHEMA
+     */
+    private static final String SCHEMA = "schema";
+    /**
+     * IMPORT
+     */
+    private static final String IMPORT = "import";
+    /**
+     * NAMESPACE
+     */
+    private static final String NAMESPACE = "namespace";
+    /**
+     * SCHEMA_LOCATION
+     */
+    private static final String SCHEMA_LOCATION = "schemaLocation";
+    /**
+     * LEAD_CONTEXT_HEADER_NS
+     */
+    private static final String LEAD_CONTEXT_HEADER_NS = "http://lead.extreme.indiana.edu/namespaces/2005/10/lead-context-header";
+    /**
+     * LC
+     */
+    private static final String LC = "lc";
+    /**
+     * LC_CONTEXT
+     */
+    private static final String LC_CONTEXT = "lc:context";
+    /**
+     * ELEMENT
+     */
+    private static final String ELEMENT = "element";
+    /**
+     * BODY
+     */
+    private static final String BODY = "body";
+    /**
+     * MESSAGE
+     */
+    private static final String MESSAGE = "message";
+    /**
+     * HEADER
+     */
+    private static final String HEADER = "header";
+    /**
+     * LITERAL
+     */
+    private static final String LITERAL = "literal";
+    /**
+     * USE
+     */
+    private static final String USE = "use";
+    /**
+     * LEAD_HEADER
+     */
+    private static final String LEAD_HEADER = "leadHeader";
+    /**
+     * PART
+     */
+    private static final String PART = "part";
+    /**
+     * INPUT
+     */
+    private static final String INPUT = "input";
+    /**
+     * PARTS
+     */
+    private static final String PARTS = "parts";
+    /**
+     * BUILDER
+     */
+    private static final XmlInfosetBuilder BUILDER = xsul5.XmlConstants.BUILDER;
+
+    /**
+     * Constructs a ODEWSDLTransformer.
+     * 
+     */
+    public ODEWSDLTransformer() {
+
+    }
+
+    /**
+     * @param workflowName
+     * @param dscUrl
+     * @param workflowWsdl
+     * @param wsdls
+     */
+    public void trasnformToODEWsdls(String workflowName, URI dscUrl, WsdlDefinitions workflowWsdl,
+            Map<String, WsdlDefinitions> wsdls) {
+
+        addCrosscutImportsIfNecessary(workflowWsdl);
+        makeWorkflowWSDLConcrete(workflowWsdl, workflowName, dscUrl);
+        changePartnerLinkNS(workflowWsdl);
+        addImportsAndHeaderMessage(workflowWsdl);
+        transformServiceWsdls(wsdls, dscUrl);
+
+    }
+
+    /**
+     * This is a safe or idempotant Operation
+     * 
+     * @param workflowWsdl
+     * @param workflowName
+     */
+    public void makeWorkflowWSDLConcrete(WsdlDefinitions workflowWsdl, String workflowName, URI dscUrl) {
+
+        addBindings(workflowWsdl, dscUrl);
+        setODEAddress(workflowWsdl, workflowName);
+    }
+
+    private void changePartnerLinkNS(WsdlDefinitions workflowWsdl) {
+        org.xmlpull.infoset.XmlElement xml = workflowWsdl.xml();
+        Iterator<XmlNamespace> itr = xml.namespaces().iterator();
+
+        LinkedList<XmlNamespace> namespaces = new LinkedList<XmlNamespace>();
+        while (itr.hasNext()) {
+            XmlNamespace ns = itr.next();
+            if (!"http://schemas.xmlsoap.org/ws/2004/03/partner-link/".equals(ns.getName())) {
+                namespaces.add(ns);
+            }
+        }
+
+        xml.removeAllNamespaceDeclarations();
+
+        for (XmlNamespace xmlNamespace : namespaces) {
+            xml.declareNamespace(xmlNamespace);
+        }
+
+        xml.setAttributeValue("xmlns:plnk", "http://docs.oasis-open.org/wsbpel/2.0/plnktype");
+
+        Iterator<org.xmlpull.infoset.XmlElement> plItr = xml.elements(null, "partnerLinkType").iterator();
+        while (plItr.hasNext()) {
+            org.xmlpull.infoset.XmlElement xmlElement = plItr.next();
+            XmlNamespace plinkNs = BUILDER.newNamespace("http://docs.oasis-open.org/wsbpel/2.0/plnktype");
+            xmlElement.setNamespace(plinkNs);
+            Iterator childItr = xmlElement.children().iterator();
+            while (childItr.hasNext()) {
+                Object object = (Object) childItr.next();
+                if (object instanceof org.xmlpull.infoset.XmlElement) {
+                    ((org.xmlpull.infoset.XmlElement) object).setNamespace(plinkNs);
+                }
+            }
+        }
+    }
+
+    private void transformServiceWsdls(Map<String, WsdlDefinitions> wsdls, URI dscUrl) {
+        Set<String> keys = wsdls.keySet();
+
+        for (String string : keys) {
+            WsdlDefinitions wsdl = wsdls.get(string);
+            // Replacing the gfac xsd remote urls
+            // this was done because avoid network inaccisibilities
+            WSDLUtil.replaceAttributeValue(wsdl.getTypes(), "schemaLocation",
+                    "http://www.extreme.indiana.edu/gfac/gfac-simple-types.xsd", "gfac-simple-types.xsd");
+            addBindings(wsdl, dscUrl);
+            addImportsAndHeaderMessage(wsdl);
+        }
+    }
+
+    private void setODEAddress(WsdlDefinitions workflowWsdl, String workflowName) {
+        Iterator<WsdlService> serviceItr = workflowWsdl.services().iterator();
+        if (serviceItr.hasNext()) {
+            Iterator<WsdlPort> portItr = serviceItr.next().ports().iterator();
+            if (portItr.hasNext()) {
+                org.xmlpull.infoset.XmlElement address = portItr.next().xml().element("address");
+                if (!(WorkflowConstants.DEFAULT_ODE_URL + "/ode/processes/" + StringUtil
+                        .convertToJavaIdentifier(workflowName)).equals(address.attributeValue("location"))) {
+                    address.removeAllAttributes();
+                    address.setAttributeValue("location", WorkflowConstants.DEFAULT_ODE_URL + "/ode/processes/"
+                            + StringUtil.convertToJavaIdentifier(workflowName));
+                }
+            }
+        }
+    }
+
+    /**
+     * @param wsdl
+     */
+    private void addBindings(WsdlDefinitions wsdl, URI dscUrl) {
+        Iterator<WsdlBinding> itr = wsdl.bindings().iterator();
+        int count = 0;
+        while (itr.hasNext()) {
+            itr.next();
+            ++count;
+        }
+        if (0 == count) {
+            DSCUtil.convertToCWSDL(wsdl, dscUrl);
+        }
+
+    }
+
+    private void addImportsAndHeaderMessage(WsdlDefinitions wsdl) {
+        try {
+
+            // Add the namespace to the lead context
+
+            org.xmlpull.infoset.XmlElement types = wsdl.getTypes();
+            // get the ns of schema from existing element
+            XmlNamespace schemaNs = BUILDER.newNamespace("xsd", "http://www.w3.org/2001/XMLSchema");
+
+            addCrosscutImportsIfNecessary(wsdl);
+
+            org.xmlpull.infoset.XmlElement schema = BUILDER.newFragment(schemaNs, SCHEMA);
+            types.addElement(0, schema);
+
+            org.xmlpull.infoset.XmlElement importElement = BUILDER.newFragment(schema.getNamespace(), IMPORT);
+            importElement.setAttributeValue(NAMESPACE, LEAD_CONTEXT_HEADER_NS);
+            importElement.setAttributeValue(SCHEMA_LOCATION, SCHEMA_LOCATION_URI);
+            schema.addElement(0, importElement);
+
+            wsdl.xml().declareNamespace(BUILDER.newNamespace(LC, LEAD_CONTEXT_HEADER_NS));
+
+            Iterator<WsdlPortType> iterator = wsdl.portTypes().iterator();
+            while (iterator.hasNext()) {
+                WsdlPortType portType = iterator.next();
+                Iterator<WsdlPortTypeOperation> operations = portType.operations().iterator();
+                while (operations.hasNext()) {
+                    WsdlPortTypeOperation operation = operations.next();
+                    WsdlMessagePart leadHeaderPart = new WsdlMessagePart(LEAD_HEADER);
+                    leadHeaderPart.setName(LEAD_HEADER);
+                    // we hand set this element to xml because when you use the
+                    // API it doent add the namespace correctly
+                    leadHeaderPart.xml().setAttributeValue(ELEMENT, LC_CONTEXT);
+
+                    wsdl.getMessage(operation.getInput().getMessage().getLocalPart()).addPart(leadHeaderPart);
+                }
+            }
+
+            Iterator<WsdlBinding> bindingItr = wsdl.bindings().iterator();
+            while (bindingItr.hasNext()) {
+                WsdlBinding wsdlBinding = (WsdlBinding) bindingItr.next();
+                Iterator<WsdlBindingOperation> operationsItr = wsdlBinding.operations().iterator();
+                while (operationsItr.hasNext()) {
+                    WsdlBindingOperation wsdlBindingOperation = (WsdlBindingOperation) operationsItr.next();
+                    org.xmlpull.infoset.XmlElement input = wsdlBindingOperation.xml().element(INPUT);
+                    org.xmlpull.infoset.XmlElement body = input.element(BODY);
+                    if (body == null) {
+                        // This is a HTTP binding so continue with the next
+                        continue;
+
+                    }
+
+                    body.setAttributeValue(PARTS, INPUT);
+                    XmlNamespace ns = body.getNamespace();
+
+                    org.xmlpull.infoset.XmlElement header = input.newElement(ns, HEADER);
+                    header.setAttributeValue(PART, LEAD_HEADER);
+                    header.setAttributeValue(USE, LITERAL);
+                    String inputMessage = findInputMessage(wsdlBindingOperation, wsdl);
+                    header.setAttributeValue(MESSAGE, inputMessage);
+                    body.removeAttribute(body.attribute(PARTS));
+                    String inputPartName = null;
+
+                    WsdlMessage wsdlMessage = wsdl.getMessage(findInputMessaQname(wsdlBindingOperation, wsdl)
+                            .getLocalPart());
+                    Iterable<WsdlMessagePart> parts = wsdlMessage.parts();
+                    Iterator<WsdlMessagePart> partsItr = parts.iterator();
+                    while (partsItr.hasNext()) {
+                        WsdlMessagePart wsdlMessagePart = (WsdlMessagePart) partsItr.next();
+                        if (!LEAD_HEADER.equals(wsdlMessagePart.getName())) {
+                            inputPartName = wsdlMessagePart.getName();
+                            break;
+                        }
+                    }
+
+                    if (null == inputPartName) {
+                        throw new WorkflowRuntimeException("Could not find a partname in message :" + inputMessage
+                                + " for binding :" + wsdlBindingOperation);
+                    }
+
+                    body.setAttributeValue(PARTS, inputPartName);
+
+                    input.addChild(header);
+
+                }
+            }
+        } catch (XmlBuilderException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * 
+     * @param wsdl
+     */
+    private void addCrosscutImportsIfNecessary(WsdlDefinitions wsdl) {
+        org.xmlpull.infoset.XmlElement types = wsdl.getTypes();
+        XmlNamespace schemaNs = BUILDER.newNamespace("xsd", "http://www.w3.org/2001/XMLSchema");
+        Iterable<org.xmlpull.infoset.XmlElement> schemas = types.elements(null, SCHEMA);
+        for (org.xmlpull.infoset.XmlElement schema : schemas) {
+
+            if (WSDLUtil.attributeExist(schema, "type", "crosscutns:LeadCrosscutParameters")) {
+                // so its there now check whether the impport is already there
+                boolean found = false;
+                Iterable<org.xmlpull.infoset.XmlElement> imports = schema.elements(schemaNs, IMPORT);
+                for (org.xmlpull.infoset.XmlElement importElement : imports) {
+                    found = found
+                            || WSDLUtil.attributeExist(importElement, "namespace",
+                                    "http://lead.extreme.indiana.edu/namespaces/2006/lead-crosscut-parameters/");
+                }
+                if (!found) {
+                    org.xmlpull.infoset.XmlElement crosscutImport = BUILDER.newFragment(schemaNs, "import");
+                    crosscutImport.setAttributeValue("namespace",
+                            "http://lead.extreme.indiana.edu/namespaces/2006/lead-crosscut-parameters/");
+                    crosscutImport.setAttributeValue("schemaLocation", "lead-crosscut-parameters.xsd");
+                    schema.addChild(0, crosscutImport);
+                }
+            }
+
+            if (WSDLUtil.attributeExist(schema, "type", "globalTypens:LEADFileIDArrayType")) {
+                // so its there now check whether the impport is already there
+                boolean found = false;
+                Iterable<org.xmlpull.infoset.XmlElement> imports = schema.elements(schemaNs, IMPORT);
+                for (org.xmlpull.infoset.XmlElement importElement : imports) {
+                    found = found
+                            || WSDLUtil.attributeExist(importElement, "namespace",
+                                    "http://www.extreme.indiana.edu/lead/xsd");
+                }
+                if (!found) {
+                    org.xmlpull.infoset.XmlElement crosscutImport = BUILDER.newFragment(schemaNs, "import");
+                    crosscutImport.setAttributeValue("namespace", "http://www.extreme.indiana.edu/lead/xsd");
+                    crosscutImport.setAttributeValue("schemaLocation", "gfac-simple-types.xsd");
+                    schema.addChild(0, crosscutImport);
+                }
+            }
+        }
+    }
+
+    /**
+     * @param wsdlBindingOperation
+     * @param wsdl
+     * @return
+     */
+    private String findInputMessage(WsdlBindingOperation wsdlBindingOperation, WsdlDefinitions wsdl) {
+
+        QName message = findInputMessaQname(wsdlBindingOperation, wsdl);
+        return message.getPrefix() + ":" + message.getLocalPart();
+    }
+
+    private QName findInputMessaQname(WsdlBindingOperation wsdlBindingOperation, WsdlDefinitions wsdl) {
+        String operationName = wsdlBindingOperation.getName();
+        WsdlPortType portType = wsdl.getPortType(wsdlBindingOperation.getBinding().getPortType().getLocalPart());
+        WsdlPortTypeOperation operation = portType.getOperation(operationName);
+        QName message = operation.getInput().getMessage();
+        return message;
+    }
+
+    public void setOdeLocation(String ODEEprEndingWithPort, String workflowName, WsdlDefinitions wsdl) {
+        Iterator<WsdlService> serviceItr = wsdl.services().iterator();
+        if (serviceItr.hasNext()) {
+            WsdlService service = serviceItr.next();
+            Iterator<WsdlPort> portItr = service.ports().iterator();
+            if (portItr.hasNext()) {
+                WsdlPort port = portItr.next();
+                org.xmlpull.infoset.XmlElement address = port.xml().element("address");
+                if (address != null) {
+                    URI uri = null;
+                    try {
+                        uri = new URI(ODEEprEndingWithPort + "/ode/processes/"
+                                + StringUtil.convertToJavaIdentifier(workflowName));
+                    } catch (URISyntaxException e) {
+                        throw new RuntimeException(e);
+                    }
+                    address.setAttributeValue("location", uri.toString());
+                } else {
+                    throw new IllegalStateException("No address found in :" + wsdl.xmlStringPretty());
+                }
+            } else {
+                throw new IllegalStateException("No port found in :" + wsdl.xmlStringPretty());
+            }
+        } else {
+            throw new IllegalStateException("No service found in :" + wsdl.xmlStringPretty());
+        }
+    }
+
+}
\ No newline at end of file

Added: incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/ode/WSDLCleaner.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/ode/WSDLCleaner.java?rev=1339718&view=auto
==============================================================================
--- incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/ode/WSDLCleaner.java (added)
+++ incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/ode/WSDLCleaner.java Thu May 17 17:12:15 2012
@@ -0,0 +1,98 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.workflow.model.ode;
+
+import java.util.ArrayList;
+
+import org.xmlpull.infoset.XmlAttribute;
+import org.xmlpull.infoset.XmlElement;
+
+import xsul5.wsdl.WsdlBinding;
+import xsul5.wsdl.WsdlDefinitions;
+import xsul5.wsdl.WsdlPort;
+import xsul5.wsdl.WsdlService;
+
+/**
+ * ODE does not work well with the wsdls with SOAP 1.2 binding and HTTP bindings that are generated by wsdls generated
+ * by Axis2. This class is intended to remove the extra bindings and the extra ports.
+ * 
+ */
+public class WSDLCleaner {
+
+    public static void cleanWSDL(WsdlDefinitions definition) {
+        WsdlDefinitions wsdl = definition;
+        Iterable<WsdlBinding> bindings = wsdl.bindings();
+        ArrayList<WsdlBinding> removedBindings = new ArrayList<WsdlBinding>();
+        for (WsdlBinding wsdlBinding : bindings) {
+            XmlElement innerBinding = wsdlBinding.xml().element("binding");
+            if (null != innerBinding
+                    && !"http://schemas.xmlsoap.org/wsdl/soap/".equals(innerBinding.getNamespace().getName())) {
+
+                removedBindings.add(wsdlBinding);
+            }
+        }
+        // to mitigate the Concurrent modifications this is done separately
+        for (WsdlBinding wsdlBinding : removedBindings) {
+            wsdl.xml().removeElement(wsdlBinding.xml());
+        }
+
+        ArrayList<WsdlPort> removePorts = new ArrayList<WsdlPort>();
+        Iterable<WsdlService> services = wsdl.services();
+        for (WsdlService wsdlService : services) {
+            Iterable<WsdlPort> ports = wsdlService.ports();
+            for (WsdlPort wsdlPort : ports) {
+                for (WsdlBinding removedBinding : removedBindings) {
+                    if (removedBinding.getName().equals(wsdlPort.getBinding().getLocalPart())) {
+                        removePorts.add(wsdlPort);
+                        break;
+                    }
+                }
+            }
+            for (WsdlPort wsdlPort : removePorts) {
+                wsdlService.xml().removeElement(wsdlPort.xml());
+            }
+            removePorts.clear();
+        }
+
+        // remove attributeFormDefault and elementFormDefault
+        Iterable<XmlElement> schemas = wsdl.getTypes().elements(null, "schema");
+        for (XmlElement schema : schemas) {
+            XmlAttribute attributeFormDefault = schema.attribute("attributeFormDefault");
+            schema.removeAttribute(attributeFormDefault);
+
+            XmlAttribute elementFormDefault = schema.attribute("elementFormDefault");
+            schema.removeAttribute(elementFormDefault);
+        }
+    }
+
+    //
+    // public void addUniqueMessageNameIfNecessary(WsdlDefinitions definition){
+    //
+    //
+    // Iterable<WsdlMessage> messages = definition.messages();
+    // for (WsdlMessage wsdlMessage : messages) {
+    // String msgName = wsdlMessage.getName();
+    // WSDLUtil.replaceAttributeValue(element, name, oldValue, newValue)
+    // }
+    // }
+
+}
\ No newline at end of file

Added: incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/utils/ApplicationVersion.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/utils/ApplicationVersion.java?rev=1339718&view=auto
==============================================================================
--- incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/utils/ApplicationVersion.java (added)
+++ incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/utils/ApplicationVersion.java Thu May 17 17:12:15 2012
@@ -0,0 +1,39 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.workflow.model.utils;
+
+public class ApplicationVersion {
+
+    /**
+     * Version number
+     */
+    public final static String VERSION = "0.3-INCUBATING";
+
+    /**
+     * Prints the version
+     * 
+     * @param args
+     */
+    public static void main(String[] args) {
+        System.out.println(VERSION);
+    }
+}
\ No newline at end of file

Added: incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/utils/MessageConstants.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/utils/MessageConstants.java?rev=1339718&view=auto
==============================================================================
--- incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/utils/MessageConstants.java (added)
+++ incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/utils/MessageConstants.java Thu May 17 17:12:15 2012
@@ -0,0 +1,45 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.workflow.model.utils;
+
+public interface MessageConstants {
+
+    /**
+     * Error message for XML format errors.
+     */
+    public static final String XML_ERROR = "XML format error.";
+
+    /**
+     * Error message when the format of a component is wrong.
+     */
+    public static final String COMPONENT_FORMAT_ERROR = "The component is in wrong format.";
+
+    /**
+     * Error message for unexpected errors. When you see this, fix it!!
+     */
+    public static final String UNEXPECTED_ERROR = "Unexpected error.";
+
+    /**
+     * MORE_THAN_ONE_CONNECTIONS
+     */
+    public static final String MORE_THAN_ONE_CONNECTIONS = "Cannot connect more than one output ports to an input port.";
+}
\ No newline at end of file

Added: incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/utils/WorkflowConstants.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/utils/WorkflowConstants.java?rev=1339718&view=auto
==============================================================================
--- incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/utils/WorkflowConstants.java (added)
+++ incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/utils/WorkflowConstants.java Thu May 17 17:12:15 2012
@@ -0,0 +1,52 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.workflow.model.utils;
+
+
+public class WorkflowConstants {
+
+    /**
+     * The name of the application
+     */
+    public static final String APPLICATION_NAME = "XBaya Dashboard";
+
+    /**
+     * Namespace URI
+     */
+    public static final String NS_URI_XBAYA = "http://airavata.apache.org/xbaya/";
+
+    /**
+     * Format name for png image
+     */
+    public static final String PNG_FORMAT_NAME = "PNG";
+
+    /**
+     * ODE URL
+     */
+    public static final String DEFAULT_ODE_URL = "https://pagodatree.cs.indiana.edu:17443";
+
+    /**
+     * WORKFLOW Namespace
+     */
+    public static final String LEAD_NS = "http://extreme.indiana.edu/lead/workflow";
+
+}
\ No newline at end of file

Added: incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/wf/TridentTransformer.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/wf/TridentTransformer.java?rev=1339718&view=auto
==============================================================================
--- incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/wf/TridentTransformer.java (added)
+++ incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/wf/TridentTransformer.java Thu May 17 17:12:15 2012
@@ -0,0 +1,61 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.workflow.model.wf;
+
+import java.util.LinkedList;
+
+import org.apache.airavata.common.utils.XMLUtil;
+import org.apache.airavata.workflow.model.xsd.GFacSimpleTypesXSD;
+import org.apache.airavata.workflow.model.xsd.LeadContextHeaderXSD;
+import org.apache.airavata.workflow.model.xsd.LeadCrosscutXSD;
+import org.xmlpull.infoset.XmlElement;
+
+import xsul5.wsdl.WsdlDefinitions;
+
+public class TridentTransformer {
+
+    public void process(WsdlDefinitions wsdl) {
+        XmlElement types = wsdl.getTypes();
+        Iterable<XmlElement> schemas = types.elements(null, "schema");
+        LinkedList<XmlElement> removeList = new LinkedList<XmlElement>();
+        for (XmlElement schema : schemas) {
+            String tns = schema.attributeValue("targetNamespace");
+            if (null != tns && -1 != tns.indexOf("http://www.extreme.indiana.edu/xbaya")) {
+            } else {
+                removeList.add(schema);
+            }
+        }
+        for (XmlElement schema : removeList) {
+            types.removeChild(schema);
+        }
+
+        types.addChild(XMLUtil.stringToXmlElement(GFacSimpleTypesXSD.XSD));
+        types.addChild(XMLUtil.stringToXmlElement(LeadCrosscutXSD.XSD));
+        types.addChild(XMLUtil.stringToXmlElement(LeadContextHeaderXSD.XSD));
+
+        XmlElement xml = wsdl.xml();
+        XMLUtil.removeElements(xml, "partnerLinkType");
+        XMLUtil.removeElements(xml, "default");
+
+    }
+
+}
\ No newline at end of file

Added: incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/wf/Workflow.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/wf/Workflow.java?rev=1339718&view=auto
==============================================================================
--- incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/wf/Workflow.java (added)
+++ incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/wf/Workflow.java Thu May 17 17:12:15 2012
@@ -0,0 +1,917 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.workflow.model.wf;
+
+import java.awt.image.BufferedImage;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.imageio.ImageIO;
+import javax.xml.namespace.QName;
+
+import org.apache.airavata.common.exception.UtilsException;
+import org.apache.airavata.common.utils.StringUtil;
+import org.apache.airavata.common.utils.WSDLUtil;
+import org.apache.airavata.common.utils.XMLUtil;
+import org.apache.airavata.workflow.model.component.Component;
+import org.apache.airavata.workflow.model.component.ComponentException;
+import org.apache.airavata.workflow.model.component.ws.WSComponent;
+import org.apache.airavata.workflow.model.component.ws.WSComponentFactory;
+import org.apache.airavata.workflow.model.component.ws.WSComponentKey;
+import org.apache.airavata.workflow.model.component.ws.WSComponentPort;
+import org.apache.airavata.workflow.model.exceptions.WorkflowException;
+import org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException;
+import org.apache.airavata.workflow.model.gpel.script.BPELScript;
+import org.apache.airavata.workflow.model.gpel.script.BPELScriptType;
+import org.apache.airavata.workflow.model.graph.GraphException;
+import org.apache.airavata.workflow.model.graph.GraphSchema;
+import org.apache.airavata.workflow.model.graph.Node;
+import org.apache.airavata.workflow.model.graph.impl.NodeImpl;
+import org.apache.airavata.workflow.model.graph.util.GraphUtil;
+import org.apache.airavata.workflow.model.graph.ws.WSGraph;
+import org.apache.airavata.workflow.model.graph.ws.WSGraphFactory;
+import org.apache.airavata.workflow.model.graph.ws.WSNode;
+import org.apache.airavata.workflow.model.ode.ODEBPELTransformer;
+import org.apache.airavata.workflow.model.ode.ODEDeploymentDescriptor;
+import org.apache.airavata.workflow.model.ode.ODEWSDLTransformer;
+import org.apache.airavata.workflow.model.ode.WSDLCleaner;
+import org.apache.airavata.workflow.model.utils.WorkflowConstants;
+import org.apache.airavata.workflow.model.utils.ApplicationVersion;
+import org.apache.commons.codec.binary.Base64;
+import org.gpel.GpelConstants;
+import org.gpel.model.GpelProcess;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.xmlpull.infoset.XmlElement;
+import org.xmlpull.infoset.XmlInfosetBuilder;
+import org.xmlpull.infoset.XmlNamespace;
+
+import xsul5.XmlConstants;
+import xsul5.wsdl.WsdlDefinitions;
+
+public class Workflow implements Cloneable {
+
+    /**
+     * Namespace prefix
+     */
+    public static final String NS_PREFIX_XWF = "xwf";
+
+    /**
+     * Namespace URI
+     */
+    public static final String NS_URI_XWF = WorkflowConstants.NS_URI_XBAYA + "xwf";
+
+    /**
+     * Namespace
+     */
+    public static final XmlNamespace NS_XWF = XMLUtil.BUILDER.newNamespace(NS_PREFIX_XWF, NS_URI_XWF);
+
+    /**
+     * WORKFLOW_TAG
+     */
+    public static final String WORKFLOW_TAG = "workflow";
+
+    private static final String VERSION_ATTRIBUTE = "version";
+
+    private static final String WSDLS_TAG = "wsdls";
+
+    private static final String WSDL_TAG = "wsdl";
+
+    private static final String BPEL_TAG = "bpel";
+
+    private static final String WORKFLOW_WSDL_TAG = "workflowWSDL";
+
+    private static final String IMAGE_TAG = "image";
+
+    private static final String ID_ATTRIBUTE = "id";
+
+    private static final Logger logger = LoggerFactory.getLogger(Workflow.class);
+
+    private WSGraph graph;
+
+    private BufferedImage image;
+
+    private URI gpelTemplateID;
+
+    private URI gpelInstanceID;
+
+    private GpelProcess gpelProcess;
+
+    private WsdlDefinitions workflowWSDL;
+
+    private WsdlDefinitions odeInvokableWSDL;
+
+    private WsdlDefinitions odeWorkflowWSDL;
+
+    private GpelProcess odeProcess;
+
+    private Map<String, WsdlDefinitions> odeWsdlMap;
+
+    private boolean editable=true;
+    /**
+     * used only during the parsing xwf or loading from GPEL.
+     */
+    private Map<String, WsdlDefinitions> wsdlMap;
+
+    private XmlElement odeDeploymentDiscriptor;
+
+    private QName qname;
+
+    private volatile WorkflowExecutionState executionState = WorkflowExecutionState.NONE;
+
+    private WsdlDefinitions tridentWSDL;
+
+    /**
+     * Constructs a Workflow.
+     */
+    public Workflow() {
+        this.wsdlMap = new HashMap<String, WsdlDefinitions>();
+
+        // Create a empty graph here to avoid null checks.
+        this.graph = WSGraphFactory.createGraph();
+    }
+
+   
+    /**
+     * Constructs a Workflow.
+     * 
+     * @param workflowString
+     *            Workflow XML in String.
+     * @throws GraphException
+     * @throws ComponentException
+     */
+
+    public Workflow(String workflowString) throws GraphException, ComponentException {
+        this();
+        try {
+            XmlElement workflowElement = XMLUtil.stringToXmlElement(workflowString);
+            parse(workflowElement);
+        } catch (RuntimeException e) {
+            throw new GraphException(e);
+        }
+    }
+
+    /**
+     * Constructs a Workflow.
+     * 
+     * @param workflowElement
+     * @throws GraphException
+     * @throws ComponentException
+     */
+    public Workflow(XmlElement workflowElement) throws GraphException, ComponentException {
+        this();
+        parse(workflowElement);
+    }
+
+
+    /**
+     * This is used for ODE
+     * 
+     * @return The Template ID like id
+     */
+    public URI getUniqueWorkflowName() {
+
+        try {
+            return new URI(WorkflowConstants.LEAD_NS + "/" + this.getName());
+        } catch (URISyntaxException e) {
+            throw new WorkflowRuntimeException(e);
+        }
+    }
+
+    public URI getNameSpace() {
+        try {
+            return new URI(WorkflowConstants.LEAD_NS);
+        } catch (URISyntaxException e) {
+            throw new WorkflowRuntimeException(e);
+        }
+    }
+
+    /**
+     * Returns the gpelInstanceID.
+     * 
+     * @return The gpelInstanceID
+     */
+    public URI getGPELInstanceID() {
+        return this.gpelInstanceID;
+    }
+
+    /**
+     * Sets gpelInstanceID.
+     * 
+     * @param gpelInstanceID
+     *            The gpelInstanceID to set.
+     */
+    public void setGPELInstanceID(URI gpelInstanceID) {
+        this.gpelInstanceID = gpelInstanceID;
+    }
+
+    /**
+     * Returns the name.
+     * 
+     * @return The name
+     */
+    public String getName() {
+        return this.graph.getName();
+    }
+
+    /**
+     * Sets name.
+     * 
+     * @param name
+     *            The name to set.
+     */
+    public void setName(String name) {
+        this.graph.setName(name);
+    }
+
+    /**
+     * Returns the description.
+     * 
+     * @return The description
+     */
+    public String getDescription() {
+        return this.graph.getDescription();
+    }
+
+    /**
+     * Sets description.
+     * 
+     * @param description
+     *            The description to set.
+     */
+    public void setDescription(String description) {
+        this.graph.setDescription(description);
+    }
+
+    /**
+     * @return The metadata, appinfo.
+     */
+    public XmlElement getMetadata() {
+        return this.graph.getMetadata();
+    }
+
+    /**
+     * @param metadata
+     */
+    public void setMetadata(XmlElement metadata) {
+        this.graph.setMetadata(metadata);
+    }
+
+    /**
+     * @return The output metadata, appinfo.
+     */
+    public XmlElement getInputMetadata() {
+        return this.graph.getInputMetadata();
+    }
+
+    /**
+     * @return The input metadata, appinfo.
+     */
+    public XmlElement getOutputMetadata() {
+        return this.graph.getOutputMetadata();
+    }
+
+    /**
+     * Returns the graph.
+     * 
+     * @return The graph
+     */
+    public WSGraph getGraph() {
+        return this.graph;
+    }
+
+    /**
+     * Sets graph.
+     * 
+     * @param graph
+     *            The graph to set.
+     */
+    public void setGraph(WSGraph graph) {
+        this.graph = graph;
+    }
+
+    /**
+     * Returns the image.
+     * 
+     * @return The image
+     */
+    public BufferedImage getImage() {
+        return this.image;
+    }
+
+    /**
+     * Sets image.
+     * 
+     * @param image
+     *            The image to set.
+     */
+    public void setImage(BufferedImage image) {
+        this.image = image;
+    }
+
+    /**
+     * Returns the gpelProcess.
+     * 
+     * @return The gpelProcess
+     */
+    public GpelProcess getGpelProcess() {
+        return this.gpelProcess;
+    }
+
+    /**
+     * Sets gpelProcess.
+     * 
+     * @param gpelProcess
+     *            The gpelProcess to set.
+     */
+    public void setGpelProcess(GpelProcess gpelProcess) {
+        this.gpelProcess = gpelProcess;
+    }
+
+    /**
+     * Returns the workflowWSDL.
+     * 
+     * @return The workflowWSDL
+     */
+    public WsdlDefinitions getWorkflowWSDL() {
+        return this.workflowWSDL;
+    }
+
+    /**
+     * Sets workflowWSDL.
+     * 
+     * @param workflowWSDL
+     *            The workflowWSDL to set.
+     */
+    public void setWorkflowWSDL(WsdlDefinitions workflowWSDL) {
+        this.workflowWSDL = workflowWSDL;
+    }
+
+    /**
+     * @return The set of WSDLs
+     */
+    public Map<String, WsdlDefinitions> getWSDLs() {
+
+        Map<String, WsdlDefinitions> wsdls = new LinkedHashMap<String, WsdlDefinitions>();
+        Map<WsdlDefinitions, String> ids = new HashMap<WsdlDefinitions, String>();
+        // Use LinkedHashMap to preserve the order of WSDLs, which is useful for
+        // some unit tests.
+
+        for (WSNode node : GraphUtil.getNodes(this.graph, WSNode.class)) {
+            WsdlDefinitions wsdl = node.getComponent().getWSDL();
+            if (wsdls.containsValue(wsdl)) {
+                String id = ids.get(wsdl);
+                node.setWSDLID(id);
+            } else {
+                // Assign unique key
+                String name = WSDLUtil.getWSDLName(wsdl);
+                String id = StringUtil.convertToJavaIdentifier(name);
+                while (wsdls.containsKey(id)) {
+                    id = StringUtil.incrementName(id);
+                }
+                wsdls.put(id, wsdl);
+                ids.put(wsdl, id);
+                node.setWSDLID(id);
+            }
+        }
+        return wsdls;
+    }
+
+    /**
+     * This method is called by GPELClient during loading a workflow.
+     * 
+     * @param id
+     * @param wsdl
+     */
+    public void addWSDL(String id, WsdlDefinitions wsdl) {
+        logger.info("id: " + id);
+        this.wsdlMap.put(id, wsdl);
+    }
+
+    /**
+     * Creates a node from a specified component and adds it to the graph.
+     * 
+     * @param component
+     *            The specified component
+     * @return The node added
+     */
+    public Node addNode(Component component) {
+        Node node = component.createNode(this.graph);
+        return node;
+    }
+
+    /**
+     * Removes a specified node from the graph.
+     * 
+     * @param node
+     *            The specified node
+     * @throws GraphException
+     */
+    public void removeNode(Node node) throws GraphException {
+        this.graph.removeNode(node);
+    }
+
+    /**
+     * Imports a specified workflow to the current workflow.
+     * 
+     * @param workflow
+     *            The specified workflow to import
+     * @throws GraphException
+     */
+    public void importWorkflow(Workflow workflow) throws GraphException {
+        this.graph.importGraph(workflow.getGraph());
+    }
+
+    /**
+     * Returns the inputs of the workflow.
+     * 
+     * @return The inputs of the workflow.
+     * @throws ComponentException
+     */
+    public List<WSComponentPort> getInputs() throws ComponentException {
+        if (this.workflowWSDL == null) {
+            throw new IllegalStateException();
+        }
+        WSComponent component = WSComponentFactory.createComponent(this.workflowWSDL);
+        return component.getInputPorts();
+    }
+
+    /**
+     * Returns the outputs of the workflow.
+     * 
+     * @return The outputs of the workflow.
+     * @throws ComponentException
+     */
+    public List<WSComponentPort> getOutputs() throws ComponentException {
+        if (this.workflowWSDL == null) {
+            throw new IllegalStateException();
+        }
+        WSComponent component = WSComponentFactory.createComponent(this.workflowWSDL);
+        return component.getOutputPorts();
+    }
+
+    /**
+     * Returns the XML Text of the workflow.
+     * 
+     * @return The XML Text of the workflow
+     */
+    @Deprecated
+    public String toXMLText() {
+        return XMLUtil.xmlElementToString(toXML());
+    }
+
+    public void setGraphID(String id){
+    	getGraph().setID(id);
+    }
+    
+    /**
+     * Returns the XmlElement of the workflow.
+     * 
+     * @return The XmlElement of the workflow
+     */
+    public XmlElement toXML() {
+        // This must be before graph.toXML() to set WSDL ID to each node.
+        Map<String, WsdlDefinitions> wsdls = getWSDLs();
+
+        XmlElement workflowElement = XMLUtil.BUILDER.newFragment(NS_XWF, WORKFLOW_TAG);
+
+        // Version
+        workflowElement.setAttributeValue(NS_XWF, VERSION_ATTRIBUTE, ApplicationVersion.VERSION);
+
+        // Date
+        // TODO add modification time
+        // XmlElement modifiedTimeElement = graphElement.addElement(
+        // XgraphSchema.NS, "modifiedTime");
+        // modifiedTimeElement.addChild(new GregorianCalendar().toString());
+
+        // Graph
+        workflowElement.addElement(this.graph.toXML());
+
+        // WSDLs
+        XmlElement wsdlsElement = workflowElement.addElement(NS_XWF, WSDLS_TAG);
+        for (String id : wsdls.keySet()) {
+            WsdlDefinitions wsdl = wsdls.get(id);
+            XmlElement wsdlElement = wsdlsElement.addElement(NS_XWF, WSDL_TAG);
+            wsdlElement.setAttributeValue(NS_XWF, ID_ATTRIBUTE, id);
+            wsdlElement.setText(XMLUtil.xmlElementToString(wsdl.xml()));
+        }
+
+        // Image
+        if (this.image != null) {
+            try {
+                ByteArrayOutputStream outStream = new ByteArrayOutputStream();
+                ImageIO.write(this.image, WorkflowConstants.PNG_FORMAT_NAME, outStream);
+                byte[] bytes = outStream.toByteArray();
+                byte[] base64 = Base64.encodeBase64Chunked(bytes);
+
+                XmlElement imageElement = workflowElement.addElement(NS_XWF, IMAGE_TAG);
+                imageElement.setText(new String(base64));
+            } catch (IOException e) {
+                // No image
+                logger.error(e.getMessage(), e);
+            }
+        }
+
+        // BPEL
+        if (this.gpelProcess != null) {
+            XmlElement bpelElement = workflowElement.addElement(NS_XWF, BPEL_TAG);
+            bpelElement.setText(this.gpelProcess.xmlStringPretty());
+        }
+
+        // Workflow WSDL
+        if (this.workflowWSDL != null) {
+            XmlElement workflowWSDLElement = workflowElement.addElement(NS_XWF, WORKFLOW_WSDL_TAG);
+            workflowWSDLElement.setText(this.workflowWSDL.xmlStringPretty());
+        }
+
+        return workflowElement;
+    }
+
+    /**
+     * Binds WSNodes to components
+     * 
+     * @throws ComponentException
+     * @throws GraphException
+     */
+    public void bindComponents() throws ComponentException, GraphException {
+        // This map is to avoid creating multiple instances for the a component
+        Map<WSComponentKey, WSComponent> components = new HashMap<WSComponentKey, WSComponent>();
+        for (WSNode node : GraphUtil.getWSNodes(this.graph)) {
+            String id = node.getWSDLID();
+            logger.info("id: " + id);
+            WsdlDefinitions wsdl = this.wsdlMap.get(id);
+
+            if (wsdl == null) {
+                // XXX This happens while loading a workflow that is created by
+                // the version 2.2.6_2 or below from GPEL.
+                // Need to look for wsdl manually.
+                // id should be look like
+                // {http://www.extreme.indiana.edu/math/}Adder
+                for (WsdlDefinitions w : this.wsdlMap.values()) {
+                    QName name = WSDLUtil.getWSDLQName(w);
+                    if (name.toString().equals(id)) {
+                        wsdl = w;
+                        break;
+                    }
+                }
+            }
+            if (wsdl == null) {
+                continue;
+            }
+            try {
+                QName portType = node.getPortTypeQName();
+                if (portType == null) {
+                    // XXX This happens while parsing xwf created by the version
+                    // 2.2.6_1 or below.
+                    portType = WSDLUtil.getFirstPortTypeQName(wsdl);
+                }
+                String operation = node.getOperationName();
+                if (operation == null) {
+                    // XXX This happens while parsing xwf created by the version
+                    // 2.2.6_1 or below.
+                    operation = WSDLUtil.getFirstOperationName(wsdl, portType);
+                }
+                WSComponentKey key = new WSComponentKey(id, portType, operation);
+
+                WSComponent component;
+                if (components.containsKey(key)) {
+                    component = components.get(key);
+                } else {
+                    component = WSComponentFactory.createComponent(wsdl, portType, operation);
+                    components.put(key, component);
+                }
+                node.setComponent(component);
+            } catch (UtilsException e) {
+                logger.error(e.getMessage(), e);
+            }
+        }
+
+        this.graph.fixParameterNodes();
+        GraphUtil.propagateTypes(this.graph);
+    }
+
+    /**
+     * @see java.lang.Object#clone()
+     */
+    @Override
+    public Workflow clone() {
+        XmlElement originalXML = toXML();
+        try {
+            XmlElement newXML = XMLUtil.deepClone(originalXML);
+            Workflow newWorkflow = new Workflow(newXML);
+            return newWorkflow;
+        } catch (GraphException e) {
+            // This should not happen.
+            throw new WorkflowRuntimeException(e);
+        } catch (WorkflowException e) {
+            // This should not happen.
+            throw new WorkflowRuntimeException(e);
+        } catch (UtilsException e) {
+            // This should not happen.
+            throw new WorkflowRuntimeException(e);
+        }
+    }
+
+    /**
+     * @param graph
+     * @return The workflow
+     */
+    public static Workflow graphToWorkflow(WSGraph graph) {
+        Workflow workflow = new Workflow();
+        workflow.setGraph(graph);
+
+        workflow.setName(graph.getName());
+        workflow.setDescription(graph.getDescription());
+        return workflow;
+    }
+
+    /**
+     * @param workflowElement
+     * @throws GraphException
+     * @throws ComponentException
+     */
+    private void parse(XmlElement workflowElement) throws GraphException, ComponentException {
+        // Graph
+        XmlElement graphElement = workflowElement.element(GraphSchema.GRAPH_TAG);
+        this.graph = WSGraphFactory.createGraph(graphElement);
+        WsdlDefinitions wsdl = null;
+        XmlElement wsdlsElement = workflowElement.element(WSDLS_TAG);
+        for (XmlElement wsdlElement : wsdlsElement.elements(null, WSDL_TAG)) {
+            String wsdlText = wsdlElement.requiredText();
+            try {
+                wsdl = WSDLUtil.stringToWSDL(wsdlText);
+            } catch (UtilsException e) {
+                logger.error(e.getMessage(), e);
+            }
+            String id = wsdlElement.attributeValue(NS_XWF, ID_ATTRIBUTE);
+            if (id == null || id.length() == 0) {
+                // xwf up to 2.2.6_2 doesn't have ID.
+                id = WSDLUtil.getWSDLQName(wsdl).toString();
+            }
+            addWSDL(id, wsdl);
+        }
+
+        bindComponents();
+
+        // Image
+        XmlElement imageElement = workflowElement.element(IMAGE_TAG);
+        if (imageElement != null) {
+            String base64 = imageElement.requiredText();
+            byte[] bytes = Base64.decodeBase64(base64.getBytes());
+            try {
+                this.image = ImageIO.read(new ByteArrayInputStream(bytes));
+            } catch (IOException e) {
+                // This should not happen and it's OK that image is broken. We
+                // can reproduce it anytime.
+                logger.error(e.getMessage(), e);
+            }
+        }
+
+        XmlElement bpelElement = workflowElement.element(BPEL_TAG);
+        if (bpelElement != null) {
+            try {
+                String bpelString = bpelElement.requiredText();
+                XmlNamespace gpelNS = XmlInfosetBuilder.newInstance().newNamespace(BPELScript.GPEL, BPELScript.GPELNS);
+                GpelConstants.GPEL_NS = gpelNS;
+                this.gpelProcess = new GpelProcess(XMLUtil.stringToXmlElement(bpelString));
+            } catch (RuntimeException e) {
+                String error = "Failed to parse the BPEL document.";
+                throw new GraphException(error, e);
+            }
+        }
+
+        XmlElement workflowWSDLElement = workflowElement.element(WORKFLOW_WSDL_TAG);
+        if (workflowWSDLElement != null) {
+            try {
+                String wsdlText = workflowWSDLElement.requiredText();
+                this.workflowWSDL = new WsdlDefinitions(XMLUtil.stringToXmlElement(wsdlText));
+            } catch (RuntimeException e) {
+                String error = "Failed to parse the workflow WSDL.";
+                throw new GraphException(error, e);
+            }
+        }
+    }
+
+    public XmlElement getODEDeploymentDescriptor(URI dscUrl, String odeEprEndingWithPort) throws GraphException,
+            ComponentException {
+        if (this.odeDeploymentDiscriptor == null) {
+            this.odeDeploymentDiscriptor = new ODEDeploymentDescriptor().generate(this.getName(),
+                    getOdeWorkflowWSDL(dscUrl, odeEprEndingWithPort), getOdeProcess(dscUrl, odeEprEndingWithPort),
+                    getOdeServiceWSDLs(dscUrl, odeEprEndingWithPort));
+        }
+        return this.odeDeploymentDiscriptor;
+
+    }
+
+    /**
+     * Returns the odeWorkflowWSDL.
+     * 
+     * @return The odeWorkflowWSDL
+     * @throws GraphException
+     * @throws ComponentException
+     */
+    public WsdlDefinitions getOdeInvokableWSDL(URI dscUrl, String odeEprEndingWithPort) throws GraphException,
+            ComponentException {
+        if (this.odeInvokableWSDL == null) {
+            generateODEScripts(dscUrl, odeEprEndingWithPort);
+        }
+        return this.odeInvokableWSDL;
+    }
+
+    /**
+     * Returns the odeProcess.
+     * 
+     * @return The odeProcess
+     * @throws ComponentException
+     * @throws GraphException
+     */
+    public GpelProcess getOdeProcess(URI dscUrl, String odeEprEndingWithPort) throws GraphException, ComponentException {
+        if (this.odeProcess == null) {
+            generateODEScripts(dscUrl, odeEprEndingWithPort);
+        }
+        return this.odeProcess;
+    }
+
+    /**
+     * Returns the odeWsdlMap.
+     * 
+     * @return The odeWsdlMap
+     * @throws ComponentException
+     * @throws GraphException
+     */
+    public Map<String, WsdlDefinitions> getOdeServiceWSDLs(URI dscUrl, String odeEprEndingWithPort)
+            throws GraphException, ComponentException {
+        if (this.odeWsdlMap == null) {
+            generateODEScripts(dscUrl, odeEprEndingWithPort);
+        }
+
+        return this.odeWsdlMap;
+    }
+
+    /**
+     * Returns the odeWorkflowWSDL.
+     * 
+     * @return The odeWorkflowWSDL
+     * @throws ComponentException
+     * @throws GraphException
+     */
+    public WsdlDefinitions getOdeWorkflowWSDL(URI dscUrl, String odeEprEndingWithPort) throws GraphException,
+            ComponentException {
+        if (this.odeWorkflowWSDL == null) {
+            generateODEScripts(dscUrl, odeEprEndingWithPort);
+        }
+
+        return this.odeWorkflowWSDL;
+    }
+
+    public WsdlDefinitions getTridentWorkflowWSDL(URI dscUrl, String odeEprEndingWithPort) throws GraphException,
+            ComponentException {
+        if (this.tridentWSDL == null) {
+            generateODEScripts(dscUrl, odeEprEndingWithPort);
+        }
+
+        return this.tridentWSDL;
+    }
+
+    private void generateODEScripts(URI dscUrl, String odeEprEndingWithPort) throws GraphException, ComponentException {
+        this.getGraph().setID(this.getName());
+
+        // find whether its Streaming
+        List<NodeImpl> nodes = this.graph.getNodes();
+        Node activeNode = null;
+        String operationName = null;
+
+        BPELScript script = null;
+
+        script = new BPELScript(this);
+        ODEWSDLTransformer wsdlTransformer = new ODEWSDLTransformer();
+        script.create(BPELScriptType.BPEL2);
+        this.odeProcess = script.getGpelProcess();
+        this.odeProcess.setTargetNamespace(WorkflowConstants.LEAD_NS);
+
+        WsdlDefinitions abstractWorkflowWsdl = script.getWorkflowWSDL().getWsdlDefinitions();
+        this.odeWorkflowWSDL = abstractWorkflowWsdl;
+        try {
+            this.odeInvokableWSDL = WSDLUtil.stringToWSDL(abstractWorkflowWsdl.xmlString());
+            wsdlTransformer.makeWorkflowWSDLConcrete(this.odeInvokableWSDL, this.getName(), dscUrl);
+            wsdlTransformer.setOdeLocation(odeEprEndingWithPort, this.getName(), this.odeInvokableWSDL);
+
+            this.odeWsdlMap = new HashMap<String, WsdlDefinitions>();
+            Collection<XmlElement> itr = script.getWSDLs();
+            for (XmlElement xmlElement : itr) {
+                WsdlDefinitions wsdl = WSDLUtil.stringToWSDL(XmlConstants.BUILDER.serializeToString(xmlElement));
+                String id = xmlElement.attributeValue(NS_XWF, ID_ATTRIBUTE);
+                if (id == null || id.length() == 0) {
+                    // xwf up to 2.2.6_2 doesn't have ID.
+                    id = WSDLUtil.getWSDLQName(wsdl).toString();
+                    if (null == id || "".equals(id) || (id.startsWith("{") && id.endsWith("}"))) {
+                        QName wsdlQname = new QName(NS_XWF.getName(), WSDLUtil.getFirstOperationName(wsdl,
+                                WSDLUtil.getFirstPortTypeQName(wsdl)));
+                        id = wsdlQname.toString();
+                        wsdl.xml().setAttributeValue("name", wsdlQname.getLocalPart());
+                    }
+                }
+                WSDLCleaner.cleanWSDL(wsdl);
+                this.odeWsdlMap.put(id, wsdl);
+            }
+        } catch (Exception e) {
+            logger.error(e.getMessage(), e);
+        }
+        new ODEBPELTransformer()
+                .generateODEBPEL(this.odeProcess, this.getName(), this.odeWorkflowWSDL, this.odeWsdlMap);
+
+        wsdlTransformer.trasnformToODEWsdls(this.getName(), dscUrl, this.odeWorkflowWSDL, this.odeWsdlMap);
+
+        String wsdlString = XMLUtil.xmlElementToString(this.odeWorkflowWSDL.xml());
+        this.tridentWSDL = new WsdlDefinitions(XMLUtil.stringToXmlElement(wsdlString));
+        new TridentTransformer().process(this.tridentWSDL);
+
+    }
+
+    /**
+     * @return
+     */
+    public QName getQname() {
+
+        return this.qname = new QName(WorkflowConstants.LEAD_NS, this.getName());
+
+    }
+
+    /**
+     * @param templateID
+     */
+    public void setGPELTemplateID(URI templateID) {
+        this.gpelTemplateID = templateID;
+
+    }
+
+    /**
+     * @return
+     */
+    public URI getGPELTemplateID() {
+        return this.gpelTemplateID;
+    }
+
+    public boolean equals(Workflow workflow) {
+        return this.graph.equals(workflow.getGraph());
+    }
+
+    /**
+     * @return
+     */
+    public synchronized WorkflowExecutionState getExecutionState() {
+        return this.executionState;
+    }
+
+    /**
+     * @param state
+     */
+    public synchronized void setExecutionState(WorkflowExecutionState state) {
+        this.executionState = state;
+    }
+
+	public boolean isEditable() {
+		return editable;
+	}
+
+
+	public void setEditable(boolean editable) {
+		this.editable = editable;
+		getGraph().setEditable(isEditable());
+	}
+
+	public void createScript() throws GraphException {
+        // Generate a BPEL process.
+        BPELScript script = new BPELScript(this);
+        script.create(BPELScriptType.GPEL);
+        this.setGpelProcess(script.getGpelProcess());
+        this.setWorkflowWSDL(script.getWorkflowWSDL().getWsdlDefinitions());
+    }
+}
\ No newline at end of file

Added: incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/wf/WorkflowExecutionState.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/wf/WorkflowExecutionState.java?rev=1339718&view=auto
==============================================================================
--- incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/wf/WorkflowExecutionState.java (added)
+++ incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/wf/WorkflowExecutionState.java Thu May 17 17:12:15 2012
@@ -0,0 +1,27 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.workflow.model.wf;
+
+public enum WorkflowExecutionState {
+
+    NONE, RUNNING, PAUSED, STEP, STOPPED
+}
\ No newline at end of file

Added: incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/xsd/GFacSimpleTypesXSD.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/xsd/GFacSimpleTypesXSD.java?rev=1339718&view=auto
==============================================================================
--- incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/xsd/GFacSimpleTypesXSD.java (added)
+++ incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/xsd/GFacSimpleTypesXSD.java Thu May 17 17:12:15 2012
@@ -0,0 +1,97 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.workflow.model.xsd;
+
+public class GFacSimpleTypesXSD {
+
+    public static final String XSD = " <xsd:schema elementFormDefault='unqualified' targetNamespace='http://www.extreme.indiana.edu/lead/xsd' \n"
+            + " 	xmlns='http://www.w3.org/2001/XMLSchema' \n"
+            + " 	xmlns:xsd='http://www.w3.org/2001/XMLSchema'\n"
+            + " 	xmlns:gfac='http://www.extreme.indiana.edu/lead/xsd'>\n"
+            + "      <xsd:simpleType name='LEADFileIDType'>\n"
+            + "        <xsd:restriction base='xsd:anyURI' />\n"
+            + "      </xsd:simpleType>\n"
+            + "      <xsd:simpleType name='LEADNameListFileType'>\n"
+            + "        <xsd:restriction base='xsd:anyURI' />\n"
+            + "      </xsd:simpleType>\n"
+            + "      <xsd:simpleType name='LEADNameListPropertiesFileType'>\n"
+            + "        <xsd:restriction base='xsd:anyURI' />\n"
+            + "      </xsd:simpleType>\n"
+            + "      <xsd:simpleType name='HostNameType'>\n"
+            + "        <xsd:restriction base='xsd:string' />\n"
+            + "      </xsd:simpleType>\n"
+            + "      <xsd:complexType name='DataIDType'>\n"
+            + "        <xsd:simpleContent>\n"
+            + "          <xsd:extension base='xsd:anyURI'>\n"
+            + "            <xsd:attribute name='location' type='xsd:string' use='optional' />\n"
+            + "          </xsd:extension>\n"
+            + "        </xsd:simpleContent>\n"
+            + "      </xsd:complexType>\n"
+            + "      <xsd:complexType name='LEADFileIDArrayType'>\n"
+            + "        <xsd:sequence>\n"
+            + "          <xsd:element maxOccurs='unbounded' minOccurs='0' name='value' type='xsd:anyURI' />\n"
+            + "        </xsd:sequence>\n"
+            + "      </xsd:complexType>\n"
+            + "      <xsd:complexType name='StringArrayType'>\n"
+            + "        <xsd:sequence>\n"
+            + "          <xsd:element maxOccurs='unbounded' minOccurs='0' name='value' type='xsd:string' />\n"
+            + "        </xsd:sequence>\n"
+            + "      </xsd:complexType>\n"
+            + "      <xsd:complexType name='IntegerArrayType'>\n"
+            + "        <xsd:sequence>\n"
+            + "          <xsd:element maxOccurs='unbounded' minOccurs='0' name='value' type='xsd:int' />\n"
+            + "        </xsd:sequence>\n"
+            + "      </xsd:complexType>\n"
+            + "      <xsd:complexType name='FloatArrayType'>\n"
+            + "        <xsd:sequence>\n"
+            + "          <xsd:element maxOccurs='unbounded' minOccurs='0' name='value' type='xsd:float' />\n"
+            + "        </xsd:sequence>\n"
+            + "      </xsd:complexType>\n"
+            + "      <xsd:complexType name='DoubleArrayType'>\n"
+            + "        <xsd:sequence>\n"
+            + "          <xsd:element maxOccurs='unbounded' minOccurs='0' name='value' type='xsd:double' />\n"
+            + "        </xsd:sequence>\n"
+            + "      </xsd:complexType>\n"
+            + "      <xsd:complexType name='BooleanArrayType'>\n"
+            + "        <xsd:sequence>\n"
+            + "          <xsd:element maxOccurs='unbounded' minOccurs='0' name='value' type='xsd:boolean' />\n"
+            + "        </xsd:sequence>\n"
+            + "      </xsd:complexType>\n"
+            + "      <xsd:complexType name='URIArrayType'>\n"
+            + "        <xsd:sequence>\n"
+            + "          <xsd:element maxOccurs='unbounded' minOccurs='0' name='value' type='xsd:anyURI' />\n"
+            + "        </xsd:sequence>\n"
+            + "      </xsd:complexType>\n"
+            + "      <xsd:complexType name='DataIDArrayType'>\n"
+            + "        <xsd:sequence>\n"
+            + "          <xsd:element maxOccurs='unbounded' minOccurs='0' name='value' type='gfac:DataIDType' />\n"
+            + "        </xsd:sequence>\n" + "      </xsd:complexType>\n" + "    </xsd:schema>\n";
+
+    /**
+     * @return
+     */
+    public static String getXml() {
+        // TODO Auto-generated method stub
+        return XSD;
+    }
+
+}
\ No newline at end of file