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 [8/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/graph/system/SystemNode.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/system/SystemNode.java?rev=1339718&view=auto
==============================================================================
--- incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/system/SystemNode.java (added)
+++ incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/system/SystemNode.java Thu May 17 17:12:15 2012
@@ -0,0 +1,133 @@
+/*
+ *
+ * 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.graph.system;
+
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException;
+import org.apache.airavata.workflow.model.graph.DataEdge;
+import org.apache.airavata.workflow.model.graph.DataPort;
+import org.apache.airavata.workflow.model.graph.EPRPort;
+import org.apache.airavata.workflow.model.graph.Edge;
+import org.apache.airavata.workflow.model.graph.Graph;
+import org.apache.airavata.workflow.model.graph.GraphException;
+import org.apache.airavata.workflow.model.graph.Port;
+import org.apache.airavata.workflow.model.graph.impl.NodeImpl;
+import org.apache.airavata.workflow.model.graph.util.GraphUtil;
+import org.apache.airavata.common.utils.WSConstants;
+import org.xmlpull.infoset.XmlElement;
+
+public abstract class SystemNode extends NodeImpl {
+
+    /**
+     * Constructs a SystemNode.
+     * 
+     * @param graph
+     */
+    protected SystemNode(Graph graph) {
+        super(graph);
+    }
+
+    /**
+     * Constructs a NodeImpl.
+     * 
+     * @param nodeElement
+     * @throws GraphException
+     */
+    public SystemNode(XmlElement nodeElement) throws GraphException {
+        super(nodeElement);
+    }
+
+    /**
+     * @throws GraphException
+     * @see org.apache.airavata.workflow.model.graph.impl.NodeImpl#edgeWasAdded(org.apache.airavata.workflow.model.graph.Edge)
+     */
+    @Override
+    protected void edgeWasAdded(Edge edge) throws GraphException {
+        super.edgeWasAdded(edge);
+        GraphUtil.validateConnection(edge);
+
+        Port fromPort = edge.getFromPort();
+        Port toPort = edge.getToPort();
+        if (edge instanceof DataEdge) {
+            if (fromPort instanceof EPRPort) {
+                // TODO
+                return;
+            }
+
+            DataPort fromDataPort = (DataPort) fromPort;
+            DataPort toDataPort = (DataPort) toPort;
+
+            QName fromType = fromDataPort.getType();
+            QName toType = toDataPort.getType();
+
+            if (fromDataPort.getNode() == this) {
+                // setType() propagates the change to the whole workflow.
+                if (!(toType == null || toType.equals(WSConstants.XSD_ANY_TYPE))) {
+                    fromDataPort.copyType(toDataPort);
+                }
+            } else if (toDataPort.getNode() == this) {
+                if (!(fromType == null || fromType.equals(WSConstants.XSD_ANY_TYPE))) {
+                    toDataPort.copyType(fromDataPort);
+                }
+            } else {
+                throw new WorkflowRuntimeException();
+            }
+        }
+    }
+
+    /**
+     * @see org.apache.airavata.workflow.model.graph.impl.NodeImpl#edgeWasRemoved(org.apache.airavata.workflow.model.graph.Edge)
+     */
+    @Override
+    protected void edgeWasRemoved(Edge removedEdge) {
+        super.edgeWasRemoved(removedEdge);
+
+        if (removedEdge instanceof DataEdge) {
+            // maybe only the way to propagate the type change is to reset
+            // everything and repropagate port types from WSPort.
+
+            List<SystemDataPort> systemDataPorts = GraphUtil.getPorts(getGraph(), SystemDataPort.class);
+            for (SystemDataPort port : systemDataPorts) {
+                port.resetType();
+            }
+
+            try {
+                GraphUtil.propagateTypes(getGraph());
+            } catch (GraphException e) {
+                // this should not happen.
+                throw new WorkflowRuntimeException(e);
+            }
+        }
+    }
+
+    /**
+     * @param port
+     * @throws GraphException
+     */
+    @SuppressWarnings("unused")
+    protected void portTypeChanged(SystemDataPort port) throws GraphException {
+        // Do nothing by default.
+    }
+}
\ No newline at end of file

Added: incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/util/GraphUtil.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/util/GraphUtil.java?rev=1339718&view=auto
==============================================================================
--- incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/util/GraphUtil.java (added)
+++ incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/util/GraphUtil.java Thu May 17 17:12:15 2012
@@ -0,0 +1,513 @@
+/*
+ *
+ * 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.graph.util;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+import org.apache.airavata.common.utils.WSConstants;
+import org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException;
+import org.apache.airavata.workflow.model.graph.ControlEdge;
+import org.apache.airavata.workflow.model.graph.ControlPort;
+import org.apache.airavata.workflow.model.graph.DataEdge;
+import org.apache.airavata.workflow.model.graph.DataPort;
+import org.apache.airavata.workflow.model.graph.EPRPort;
+import org.apache.airavata.workflow.model.graph.Edge;
+import org.apache.airavata.workflow.model.graph.Graph;
+import org.apache.airavata.workflow.model.graph.GraphException;
+import org.apache.airavata.workflow.model.graph.Node;
+import org.apache.airavata.workflow.model.graph.Port;
+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.graph.system.StreamSourceNode;
+import org.apache.airavata.workflow.model.graph.ws.WSGraph;
+import org.apache.airavata.workflow.model.graph.ws.WSNode;
+import org.apache.airavata.workflow.model.graph.ws.WSPort;
+import org.apache.airavata.workflow.model.utils.MessageConstants;
+
+public class GraphUtil {
+	// private static final MLogger logger = MLogger.getLogger();
+
+	/**
+	 * Returns the WSNodes included in a specified graph.
+	 *
+	 * @param graph
+	 *            The specified graph.
+	 * @return The WSNodes.
+	 */
+	public static Collection<WSNode> getWSNodes(Graph graph) {
+		return getNodes(graph, WSNode.class);
+	}
+
+	/**
+	 * Returns a List of InputNodes from a specified graph.
+	 *
+	 * @param graph
+	 *            the specified graph
+	 * @return The List of InputNodes.
+	 */
+	public static List<InputNode> getInputNodes(Graph graph) {
+		return getNodes(graph, InputNode.class);
+	}
+
+	/**
+	 * Returns a List of OutputNodes from a specified graph.
+	 *
+	 * @param graph
+	 *            the specified graph
+	 * @return The List of OutputNodes.
+	 */
+	public static List<OutputNode> getOutputNodes(Graph graph) {
+		return getNodes(graph, OutputNode.class);
+	}
+
+	/**
+	 * Returns a List of nodes of specific subclass of Node from a specified
+	 * graph.
+	 *
+	 * @param <N>
+	 *            One of the subclass of the Node.
+	 * @param graph
+	 *            The specified graph.
+	 * @param klass
+	 *            The specified subclass of Node.
+	 * @return The list of T
+	 */
+	@SuppressWarnings("unchecked")
+	public static <N extends Node> List<N> getNodes(Graph graph, Class<N> klass) {
+		List<N> nodes = new LinkedList<N>();
+		for (Node node : graph.getNodes()) {
+			if (klass.isInstance(node)) {
+				nodes.add((N) node);
+			}
+		}
+		return nodes;
+	}
+
+	/**
+	 * @param node
+	 * @return The output nodes.
+	 */
+	public static List<Node> getOutputNodes(Node node) {
+		List<Node> outputNodes = new ArrayList<Node>();
+		for (Port port : node.getOutputPorts()) {
+			Collection<Node> toNodes = port.getToNodes();
+			outputNodes.addAll(toNodes);
+		}
+		return outputNodes;
+	}
+
+	/**
+	 * Returns next nodes connected to a specified node.
+	 *
+	 * @param node
+	 *            The specified node.
+	 * @return The next nodes.
+	 */
+	public static List<Node> getNextNodes(Node node) {
+		List<Node> nextNodes = getOutputNodes(node);
+		for (Port port : node.getControlOutPorts()) {
+			Collection<Node> toNodes = port.getToNodes();
+			nextNodes.addAll(toNodes);
+		}
+		return nextNodes;
+	}
+
+	/**
+	 * Sorts the nodes alphabetically by their names.
+	 *
+	 * @param <T>
+	 * @param nodes
+	 * @return The list of nodes sorted.
+	 */
+	public static <T extends Node> List<T> sortByName(Collection<T> nodes) {
+		List<T> nodeList = new LinkedList<T>(nodes);
+		Comparator<Node> nameComparator = new Comparator<Node>() {
+			@Override
+			public int compare(Node node1, Node node2) {
+				String name1 = node1.getName();
+				String name2 = node2.getName();
+				return name1.compareToIgnoreCase(name2);
+			}
+		};
+		Collections.sort(nodeList, nameComparator);
+		return nodeList;
+	}
+
+	/**
+	 * @param graph
+	 * @param kind
+	 * @return The ports of specified kind.
+	 */
+	public static Collection<Port> getPorts(Graph graph, Port.Kind kind) {
+		Collection<Port> ports = new ArrayList<Port>();
+		for (Port port : graph.getPorts()) {
+			if (port.getKind() == kind) {
+				ports.add(port);
+			}
+		}
+		return ports;
+	}
+
+	/**
+	 * @param <P>
+	 * @param graph
+	 * @param klass
+	 * @return The ports
+	 */
+	@SuppressWarnings("unchecked")
+	public static <P extends Port> List<P> getPorts(Graph graph, Class<P> klass) {
+		List<P> ports = new LinkedList<P>();
+		for (Port port : graph.getPorts()) {
+			if (klass.isInstance(port)) {
+				ports.add((P) port);
+			}
+		}
+		return ports;
+	}
+
+	private enum Color {
+		/**
+		 * This node hasn't been visited.
+		 */
+		WHITE,
+		/**
+		 * This node has been visited.
+		 */
+		GRAY,
+		/**
+		 * This not is not in cycle.
+		 */
+		BLACK;
+	}
+
+	/**
+	 * @param graph
+	 * @return true if there is a cycle in the graph; false otherwise.
+	 */
+	public static boolean containsCycle(Graph graph) {
+		Map<Node, Color> coloredNodes = new HashMap<Node, Color>();
+		for (Node node : graph.getNodes()) {
+			coloredNodes.put(node, Color.WHITE);
+		}
+
+		for (Node node : graph.getNodes()) {
+			if (coloredNodes.get(node) == Color.WHITE) {
+				if (visit(node, coloredNodes)) {
+					return true;
+				}
+			}
+		}
+		return false;
+	}
+
+	private static boolean visit(Node node, Map<Node, Color> coloredNodes) {
+		coloredNodes.put(node, Color.GRAY);
+		for (Node nextNode : getNextNodes(node)) {
+			Color nextNodeColor = coloredNodes.get(nextNode);
+			if (nextNodeColor == Color.GRAY) {
+				return true;
+			} else if (nextNodeColor == Color.WHITE) {
+				if (visit(nextNode, coloredNodes)) {
+					return true;
+				}
+			}
+		}
+		coloredNodes.put(node, Color.BLACK);
+		return false;
+	}
+
+	/**
+	 * @param edge
+	 * @throws GraphException
+	 */
+	public static void validateConnection(Edge edge) throws GraphException {
+		Port fromPort = edge.getFromPort();
+		Port toPort = edge.getToPort();
+		if (edge instanceof ControlEdge) {
+			if (!(fromPort instanceof ControlPort && toPort instanceof ControlPort)) {
+				throw new GraphException(MessageConstants.UNEXPECTED_ERROR);
+			}
+		} else if (edge instanceof DataEdge) {
+			if (fromPort instanceof EPRPort) {
+				// TODO
+				return;
+			}
+			if (!(fromPort instanceof DataPort || fromPort instanceof EPRPort)
+					|| !(toPort instanceof DataPort)) {
+				throw new GraphException(MessageConstants.UNEXPECTED_ERROR);
+			}
+
+			DataPort fromDataPort = (DataPort) fromPort;
+			DataPort toDataPort = (DataPort) toPort;
+
+			QName fromType = fromDataPort.getType();
+			QName toType = toDataPort.getType();
+
+			if (toDataPort.getEdges().size() > 1) {
+				throw new GraphException(
+						MessageConstants.MORE_THAN_ONE_CONNECTIONS);
+			}
+
+			// if connection came from the CEP register component it should be
+			// ok
+			if (fromPort.getNode() instanceof WSNode) {
+				if ("registerStream".equals(((WSNode) fromPort.getNode())
+						.getOperationName())) {
+					return;
+				}
+			}
+
+			if (!(fromType == null
+					|| fromType.equals(WSConstants.XSD_ANY_TYPE)
+					|| fromType.equals(new QName(WSConstants.XSD_NS_URI,
+							"anyType"))
+					|| toType == null
+					|| toType.equals(WSConstants.XSD_ANY_TYPE)
+					|| toType.equals(new QName(WSConstants.XSD_NS_URI,
+							"anyType")) || fromType.equals(toType)) && (fromType == null
+					|| fromType.equals(WSConstants.LEAD_ANY_TYPE)
+					|| fromType.equals(new QName(WSConstants.LEAD_NS_URI,
+							"anyType"))
+					|| toType == null
+					|| toType.equals(WSConstants.LEAD_ANY_TYPE)
+					|| toType.equals(new QName(WSConstants.LEAD_NS_URI,
+							"anyType")) || fromType.equals(toType))) {
+				throw new GraphException(
+						"Cannot connect ports with different types:"
+								+ " \nfrom=\t" + fromType + " \nto=\t" + toType
+								+ "");
+			}
+		}
+	}
+
+	/**
+	 * @param graph
+	 * @throws GraphException
+	 */
+	public static void propagateTypes(Graph graph) throws GraphException {
+		List<WSPort> wsPorts = getPorts(graph, WSPort.class);
+		for (WSPort wsPort : wsPorts) {
+			List<DataEdge> edges = wsPort.getEdges();
+			for (DataEdge edge : edges) {
+				DataPort fromPort = edge.getFromPort();
+
+				DataPort toPort = edge.getToPort();
+				if (fromPort == wsPort) {
+					toPort.copyType(wsPort);
+				} else if (toPort == wsPort) {
+					fromPort.copyType(wsPort);
+				} else {
+					throw new WorkflowRuntimeException();
+				}
+			}
+		}
+
+	}
+
+
+    /**
+     *
+     * @param graph
+     * @return
+     */
+	public static LinkedList<StreamSourceNode> getStreamSourceNodes(
+			WSGraph graph) {
+		List<NodeImpl> nodes = graph.getNodes();
+		LinkedList<StreamSourceNode> ret = new LinkedList<StreamSourceNode>();
+		for (NodeImpl nodeImpl : nodes) {
+			if (nodeImpl instanceof StreamSourceNode) {
+				ret.add((StreamSourceNode) nodeImpl);
+			}
+		}
+		return ret;
+	}
+
+	/**
+	 * @param node
+	 * @return null if not the same
+	 */
+	public static String isSameLabeledInput(Node node) {
+		if (!isAllInputsConnected(node)) {
+			throw new WorkflowRuntimeException("Node inputs not connected" + node);
+		}
+		if (!isAllInputsLabeled(node)) {
+			throw new WorkflowRuntimeException(
+					"Some or all of the node inputs not labeled" + node);
+		}
+		List<DataPort> inputPorts = node.getInputPorts();
+		String label = inputPorts.get(0).getEdge(0).getLabel();
+		for (DataPort dataPort : inputPorts) {
+			// 0 because its got only one
+			if (!label.equals(dataPort.getEdge(0).getLabel())) {
+				return null;
+			}
+		}
+		return label;
+	}
+
+	/**
+	 * @param node
+	 * @return
+	 */
+	public static boolean isAllInputsLabeled(Node node) {
+		List<DataPort> inputPorts = node.getInputPorts();
+		for (DataPort dataPort : inputPorts) {
+			// 0 because its got only one
+			Edge edge = dataPort.getEdge(0);
+			if (edge == null || edge.getLabel() == null) {
+				return false;
+			}
+		}
+		return true;
+	}
+
+	/**
+	 * @param node
+	 * @return
+	 */
+	public static boolean isAllInputsConnected(Node node) {
+		List<DataPort> inputPorts = node.getInputPorts();
+		for (DataPort dataPort : inputPorts) {
+			// 0 because its got only one
+			Edge edge = dataPort.getEdge(0);
+			if (edge == null) {
+				return false;
+			}
+		}
+		return true;
+	}
+
+    /**
+     *
+     * @param node
+     * @return
+     */
+	public static boolean isRegulerNode(Node node) {
+		if (node instanceof WSNode) {
+			return true;
+		}
+		return false;
+	}
+
+    /**
+     *
+     * @param node
+     * @return
+     */
+	public static String getEncodedInputLabels(Node node) {
+		if (!isAllInputsConnected(node)) {
+			throw new WorkflowRuntimeException("Node inputs not connected" + node);
+		}
+		if (!isAllInputsLabeled(node)) {
+			throw new WorkflowRuntimeException(
+					"Some or all of the node inputs not labeled" + node);
+		}
+		List<DataPort> inputPorts = node.getInputPorts();
+		String label = "";
+		for (DataPort dataPort : inputPorts) {
+			label += "#" + dataPort.getEdge(0).getLabel();
+		}
+		return label;
+
+	}
+
+	/**
+	 * @param wsGraph
+	 * @return
+	 */
+	public static List<Node> getJoinRequiredNodes(WSGraph wsGraph) {
+		List<NodeImpl> nodes = wsGraph.getNodes();
+		List<Node> ret = new LinkedList<Node>();
+		for (NodeImpl node : nodes) {
+			if (node.getRequireJoin()) {
+				ret.add(node);
+			}
+		}
+		return ret;
+	}
+
+
+
+	/**
+	 * @param wsGraph
+	 * @return
+	 */
+	public static HashMap<String, LinkedList<Node>> partitionGraphOnLabel(
+			WSGraph wsGraph) {
+		HashMap<String, LinkedList<Node>> returnMap = new HashMap<String, LinkedList<Node>>();
+		List<NodeImpl> nodes = wsGraph.getNodes();
+		for (NodeImpl node : nodes) {
+			if (!isInputOutputNode(node)) {
+				LinkedList<Node> list = returnMap.get(node.getLabel());
+				if (null == list) {
+					list = new LinkedList<Node>();
+					returnMap.put(node.getLabel(), list);
+				}
+				list.add(node);
+			}
+		}
+		return returnMap;
+	}
+
+	/**
+	 * @param node
+	 * @return
+	 */
+	private static boolean isInputOutputNode(NodeImpl node) {
+		return node instanceof InputNode || node instanceof StreamSourceNode
+				|| node instanceof OutputNode;
+	}
+
+	
+
+	/**
+	 * @param name
+	 * @param nodeList
+	 * @param key
+	 * @return
+	 */
+	public static String getSubWorkflowName(String name,
+			LinkedList<Node> nodeList, String key) {
+		String ret = name + "_subworkflow";
+		for (Node node : nodeList) {
+			ret += node.getID();
+
+		}
+
+		if(ret.length()>40){
+			ret = ret.substring(0, 40);
+		}
+		// TODO Auto-generated method stub
+		return ret;
+	}
+
+}
\ No newline at end of file

Added: incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/ws/WSGraph.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/ws/WSGraph.java?rev=1339718&view=auto
==============================================================================
--- incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/ws/WSGraph.java (added)
+++ incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/ws/WSGraph.java Thu May 17 17:12:15 2012
@@ -0,0 +1,335 @@
+/*
+ *
+ * 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.graph.ws;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.airavata.common.exception.UtilsException;
+import org.apache.airavata.common.utils.XMLUtil;
+import org.apache.airavata.workflow.model.graph.DataEdge;
+import org.apache.airavata.workflow.model.graph.DataPort;
+import org.apache.airavata.workflow.model.graph.GraphException;
+import org.apache.airavata.workflow.model.graph.GraphFactory;
+import org.apache.airavata.workflow.model.graph.GraphSchema;
+import org.apache.airavata.workflow.model.graph.Node;
+import org.apache.airavata.workflow.model.graph.impl.EdgeImpl;
+import org.apache.airavata.workflow.model.graph.impl.GraphImpl;
+import org.apache.airavata.workflow.model.graph.impl.NodeImpl;
+import org.apache.airavata.workflow.model.graph.util.GraphUtil;
+import org.xmlpull.infoset.XmlElement;
+
+public class WSGraph extends GraphImpl {
+
+    private XmlElement metadata;
+
+    private XmlElement inputMetadata;
+
+    private XmlElement outputMetadata;
+
+    private boolean editable=true;
+    /**
+     * Constructs a WSGraph.
+     * 
+     * @param factory
+     */
+    public WSGraph(GraphFactory factory) {
+        super(factory);
+    }
+
+    /**
+     * Returns the metadata.
+     * 
+     * @return The metadata
+     */
+    public XmlElement getMetadata() {
+        return this.metadata;
+    }
+
+    /**
+     * Sets metadata.
+     * 
+     * @param metadata
+     *            The metadata to set.
+     */
+    public void setMetadata(XmlElement metadata) {
+        this.metadata = metadata;
+    }
+
+    /**
+     * Returns the inputMetadata.
+     * 
+     * @return The inputMetadata
+     */
+    public XmlElement getInputMetadata() {
+        return this.inputMetadata;
+    }
+
+    /**
+     * Sets inputMetadata.
+     * 
+     * @param inputMetadata
+     *            The inputMetadata to set.
+     */
+    public void setInputMetadata(XmlElement inputMetadata) {
+        this.inputMetadata = inputMetadata;
+    }
+
+    /**
+     * Returns the outputMetadata.
+     * 
+     * @return The outputMetadata
+     */
+    public XmlElement getOutputMetadata() {
+        return this.outputMetadata;
+    }
+
+    /**
+     * Sets outputMetadata.
+     * 
+     * @param outputMetadata
+     *            The outputMetadata to set.
+     */
+    public void setOutputMetadata(XmlElement outputMetadata) {
+        this.outputMetadata = outputMetadata;
+    }
+
+    /**
+     * @see org.apache.airavata.workflow.model.graph.impl.GraphImpl#toXML(org.xmlpull.infoset.XmlElement)
+     */
+    @Override
+    protected void toXML(XmlElement graphElement) {
+        super.toXML(graphElement);
+
+        try {
+            graphElement.setAttributeValue(GraphSchema.NS, GraphSchema.GRAPH_TYPE_ATTRIBUTE, GraphSchema.GRAPH_TYPE_WS);
+
+            if (this.metadata != null) {
+                XmlElement metadataElement = graphElement.addElement(GraphSchema.NS, GraphSchema.GRAPH_METADATA_TAG);
+                // Clone the metadata to avoid parent problem because this can be
+                // called multiple times.
+                metadataElement.addChild(XMLUtil.deepClone(this.metadata));
+            }
+
+            if (this.inputMetadata != null) {
+                XmlElement metadataElement = graphElement.addElement(GraphSchema.NS,
+                        GraphSchema.GRAPH_INPUT_METADATA_TAG);
+                // Clone the metadata to avoid parent problem because this can be
+                // called multiple times.
+                metadataElement.addChild(XMLUtil.deepClone(this.inputMetadata));
+            }
+
+            if (this.outputMetadata != null) {
+                XmlElement metadataElement = graphElement.addElement(GraphSchema.NS,
+                        GraphSchema.GRAPH_OUTPUT_METADATA_TAG);
+                // Clone the metadata to avoid parent problem because this can be
+                // called multiple times.
+                metadataElement.addChild(XMLUtil.deepClone(this.outputMetadata));
+            }
+        } catch (UtilsException e) {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * @see org.apache.airavata.workflow.model.graph.impl.GraphImpl#parse(org.xmlpull.infoset.XmlElement)
+     */
+    @Override
+    protected void parse(XmlElement graphElement) throws GraphException {
+        super.parse(graphElement);
+
+        XmlElement metadataElement = graphElement.element(GraphSchema.GRAPH_METADATA_TAG);
+        if (metadataElement != null) {
+            for (XmlElement appinfo : metadataElement.requiredElementContent()) {
+                this.metadata = appinfo;
+                // It should have only one element.
+                break;
+            }
+        }
+
+        XmlElement inputMetadataElement = graphElement.element(GraphSchema.GRAPH_INPUT_METADATA_TAG);
+        if (inputMetadataElement != null) {
+            for (XmlElement appinfo : inputMetadataElement.requiredElementContent()) {
+                this.inputMetadata = appinfo;
+                // It should have only one element.
+                break;
+            }
+        }
+
+        XmlElement outputMetadataElement = graphElement.element(GraphSchema.GRAPH_OUTPUT_METADATA_TAG);
+        if (outputMetadataElement != null) {
+            for (XmlElement appinfo : outputMetadataElement.requiredElementContent()) {
+                this.outputMetadata = appinfo;
+                // It should have only one element.
+                break;
+            }
+        }
+    }
+
+    public boolean equals(WSGraph graph) {
+        return !notEquals(graph);
+    }
+
+    /***
+     * Finding Not equal is much efficient
+     * 
+     * @param graph
+     * @return
+     */
+    public boolean notEquals(WSGraph graph) {
+        if (graph.getNodes().size() != this.getNodes().size()) {
+            return true;
+        }
+        // sizes are the same
+        // try the names
+        List<NodeImpl> thisNodes = this.getNodes();
+        for (NodeImpl thisNode : thisNodes) {
+            Node matchingNode = find(thisNode.getID(), graph.getNodes());
+            if (null == matchingNode) {
+                // not found so this is not equal
+                return true;
+            } else {
+                // ok found, now check whether the connections match
+                if (!inputEdgesMatch(thisNode, matchingNode)) {
+                    return true;
+                }
+            }
+        }
+
+        return false;
+    }
+
+    /**
+     * @param thisNode
+     * @param matchingNode
+     * @return
+     */
+    private boolean inputEdgesMatch(NodeImpl thisNode, Node matchingNode) {
+        List<DataPort> thisInputPorts = thisNode.getInputPorts();
+        // see whether the inputs are connected to component with same id
+        for (int i = 0; i < thisInputPorts.size(); i++) {
+            if (null != thisInputPorts.get(i).getFromNode()
+                    && !thisInputPorts.get(i).getFromNode().getID()
+                            .equals(matchingNode.getInputPort(i).getFromNode().getID())) {
+                return false;
+            }
+        }
+
+        return true;
+    }
+
+    /**
+     * @param name
+     * @param nodes
+     * @return
+     */
+    private Node find(String id, List<NodeImpl> nodes) {
+        for (Node node : nodes) {
+            if (node.getID().equals(id)) {
+                return node;
+            }
+        }
+        return null;
+    }
+
+
+
+ 
+
+
+    /**
+     * @return
+     * @throws GraphException
+     * 
+     */
+    private LinkedList<Node> topologicalSort() throws GraphException {
+        List<EdgeImpl> alledges = this.getEdges();
+        HashSet<EdgeImpl> edgeSet = new HashSet<EdgeImpl>(alledges);
+        List<Node> workQueue = new LinkedList<Node>(GraphUtil.getInputNodes(this));
+        workQueue.addAll(GraphUtil.getStreamSourceNodes(this));
+        LinkedList<Node> sortedOrder = new LinkedList<Node>();
+        while (!workQueue.isEmpty()) {
+            Node currentNode = workQueue.remove(0);
+            sortedOrder.add(currentNode);
+            List<DataPort> outputPorts = currentNode.getOutputPorts();
+            for (DataPort dataPort : outputPorts) {
+                List<DataEdge> curentEdges = dataPort.getEdges();
+                for (DataEdge dataEdge : curentEdges) {
+                    edgeSet.remove(dataEdge);
+                    if (isAllEdgesRemoved(edgeSet, dataEdge.getToPort().getNode())) {
+                        workQueue.add(dataEdge.getToPort().getNode());
+                    }
+                }
+            }
+        }
+        if (edgeSet.isEmpty()) {
+            return sortedOrder;
+        } else {
+            throw new GraphException("Graph Topological sorting failed, Graph has at least one cycle");
+        }
+    }
+
+    /**
+     * @param edgeSet
+     * @param node
+     * @return
+     */
+    private boolean isAllEdgesRemoved(HashSet<EdgeImpl> edgeSet, NodeImpl node) {
+
+        List<DataPort> inputPorts = node.getInputPorts();
+        for (DataPort dataPort : inputPorts) {
+            List<DataEdge> edgesToCheck = dataPort.getEdges();
+            for (DataEdge dataEdge : edgesToCheck) {
+                if (edgeSet.contains(dataEdge)) {
+                    return false;
+                }
+            }
+
+            //
+        }
+        return true;
+    }
+
+    /**
+     * @return
+     * 
+     * 
+     */
+    private HashMap<String, LinkedList<Node>> getGraphPartitionSets() {
+        HashMap<String, LinkedList<Node>> partiotionGraph = GraphUtil.partitionGraphOnLabel(this);
+        return partiotionGraph;
+    }
+
+	@Override
+	public boolean isEditable() {
+		return editable;
+	}
+
+	@Override
+	public void setEditable(boolean editable) {
+		this.editable=editable;
+	}
+
+
+}
\ No newline at end of file

Added: incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/ws/WSGraphFactory.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/ws/WSGraphFactory.java?rev=1339718&view=auto
==============================================================================
--- incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/ws/WSGraphFactory.java (added)
+++ incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/ws/WSGraphFactory.java Thu May 17 17:12:15 2012
@@ -0,0 +1,242 @@
+/*
+ *
+ * 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.graph.ws;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.airavata.common.utils.IOUtil;
+import org.apache.airavata.common.utils.XMLUtil;
+import org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException;
+import org.apache.airavata.workflow.model.graph.ControlEdge;
+import org.apache.airavata.workflow.model.graph.ControlPort;
+import org.apache.airavata.workflow.model.graph.DataEdge;
+import org.apache.airavata.workflow.model.graph.EPRPort;
+import org.apache.airavata.workflow.model.graph.GraphException;
+import org.apache.airavata.workflow.model.graph.GraphFactory;
+import org.apache.airavata.workflow.model.graph.GraphSchema;
+import org.apache.airavata.workflow.model.graph.Port;
+import org.apache.airavata.workflow.model.graph.Port.Kind;
+import org.apache.airavata.workflow.model.graph.amazon.InstanceDataPort;
+import org.apache.airavata.workflow.model.graph.amazon.InstanceNode;
+import org.apache.airavata.workflow.model.graph.amazon.TerminateInstanceNode;
+import org.apache.airavata.workflow.model.graph.impl.EdgeImpl;
+import org.apache.airavata.workflow.model.graph.impl.NodeImpl;
+import org.apache.airavata.workflow.model.graph.impl.PortImpl;
+import org.apache.airavata.workflow.model.graph.system.BlockNode;
+import org.apache.airavata.workflow.model.graph.system.ConstantNode;
+import org.apache.airavata.workflow.model.graph.system.EndBlockNode;
+import org.apache.airavata.workflow.model.graph.system.EndForEachNode;
+import org.apache.airavata.workflow.model.graph.system.EndifNode;
+import org.apache.airavata.workflow.model.graph.system.ForEachNode;
+import org.apache.airavata.workflow.model.graph.system.IfNode;
+import org.apache.airavata.workflow.model.graph.system.InputNode;
+import org.apache.airavata.workflow.model.graph.system.MemoNode;
+import org.apache.airavata.workflow.model.graph.system.OutputNode;
+import org.apache.airavata.workflow.model.graph.system.ReceiveNode;
+import org.apache.airavata.workflow.model.graph.system.StreamSourceNode;
+import org.apache.airavata.workflow.model.graph.system.SystemDataPort;
+import org.apache.airavata.workflow.model.utils.MessageConstants;
+import org.xmlpull.infoset.XmlElement;
+
+/**
+ * The GraphFactory class is a factory to create nodes, ports, and edges.
+ * 
+ */
+public class WSGraphFactory implements GraphFactory {
+
+    /**
+     * Creates a empty Graph
+     * 
+     * @return the empty graph created
+     */
+    public static WSGraph createGraph() {
+        return createWSGraph();
+    }
+
+    /**
+     * Reads a specified file and creates a graph.
+     * 
+     * @param file
+     * @return The graph created
+     * @throws GraphException
+     * @throws IOException
+     */
+    public static WSGraph createGraph(File file) throws GraphException, IOException {
+        String graphString = IOUtil.readFileToString(file);
+        return createGraph(graphString);
+    }
+
+    /**
+     * @param graphString
+     * @return the graph created
+     * @throws GraphException
+     */
+    public static WSGraph createGraph(String graphString) throws GraphException {
+        XmlElement graphElement;
+        try {
+            graphElement = XMLUtil.stringToXmlElement(graphString);
+        } catch (RuntimeException e) {
+            throw new GraphException(MessageConstants.XML_ERROR, e);
+        }
+        return createGraph(graphElement);
+    }
+
+    /**
+     * @param graphElement
+     * @return The graph created
+     * @throws GraphException
+     */
+    public static WSGraph createGraph(XmlElement graphElement) throws GraphException {
+        try {
+            WSGraph graph = createWSGraph();
+            graph.parse(graphElement);
+            return graph;
+        } catch (RuntimeException e) {
+            throw new GraphException(MessageConstants.XML_ERROR, e);
+        }
+    }
+
+    /**
+     * @see org.apache.airavata.workflow.model.graph.GraphFactory#createNode(org.xmlpull.infoset.XmlElement)
+     */
+    public NodeImpl createNode(XmlElement nodeElement) throws GraphException {
+        String type = nodeElement.attributeValue(GraphSchema.NS, GraphSchema.NODE_TYPE_ATTRIBUTE);
+        if (type == null) {
+            // Old graphs don't have the namespace for the attribute.
+            type = nodeElement.attributeValue(GraphSchema.NODE_TYPE_ATTRIBUTE);
+        }
+
+        NodeImpl node;
+        if (GraphSchema.NODE_TYPE_WS.equals(type)) {
+            node = new WSNode(nodeElement);
+        } else if (GraphSchema.NODE_TYPE_STREAM_SOURCE.equals(type)) {
+            node = new StreamSourceNode(nodeElement);
+        } else if (GraphSchema.NODE_TYPE_WORKFLOW.equals(type)) {
+            node = new WorkflowNode(nodeElement);
+        } else if (GraphSchema.NODE_TYPE_INPUT.equals(type)) {
+            node = new InputNode(nodeElement);
+        } else if (GraphSchema.NODE_TYPE_OUTPUT.equals(type)) {
+            node = new OutputNode(nodeElement);
+        } else if (GraphSchema.NODE_TYPE_CONSTANT.equals(type)) {
+            node = new ConstantNode(nodeElement);
+        } else if (GraphSchema.NODE_TYPE_SPLIT.equals(type)) {
+            node = new ForEachNode(nodeElement);
+        } else if (GraphSchema.NODE_TYPE_MERGE.equals(type)) {
+            node = new EndForEachNode(nodeElement);
+        } else if (GraphSchema.NODE_TYPE_IF.equals(type)) {
+            node = new IfNode(nodeElement);
+        } else if (GraphSchema.NODE_TYPE_ENDIF.equals(type)) {
+            node = new EndifNode(nodeElement);
+        } else if (GraphSchema.NODE_TYPE_MEMO.equals(type)) {
+            node = new MemoNode(nodeElement);
+        } else if (GraphSchema.NODE_TYPE_RECEIVE.equals(type)) {
+            node = new ReceiveNode(nodeElement);
+        } else if (GraphSchema.NODE_TYPE_BLOCK.equals(type)) {
+            node = new BlockNode(nodeElement);
+        } else if (GraphSchema.NODE_TYPE_ENDBLOCK.equals(type)) {
+            node = new EndBlockNode(nodeElement);
+        } else if (GraphSchema.NODE_TYPE_INSTANCE.equals(type)) {
+            node = new InstanceNode(nodeElement);
+        } else if (GraphSchema.NODE_TYPE_TERMINATE.equals(type)) {
+            node = new TerminateInstanceNode(nodeElement);
+        } else {
+            // Default is WsNode for backward compatibility.
+            node = new WSNode(nodeElement);
+        }
+        return node;
+    }
+
+    /**
+     * @see org.apache.airavata.workflow.model.graph.GraphFactory#createPort(org.xmlpull.infoset.XmlElement)
+     */
+    public PortImpl createPort(XmlElement portElement) {
+        String type = portElement.attributeValue(GraphSchema.NS, GraphSchema.PORT_TYPE_ATTRIBUTE);
+        if (type == null) {
+            // Old graphs don't have the namespace for the attribute.
+            type = portElement.attributeValue(GraphSchema.PORT_TYPE_ATTRIBUTE);
+        }
+        PortImpl port;
+        if (GraphSchema.PORT_TYPE_WS_DATA.equals(type)) {
+            port = new WSPort(portElement);
+        } else if (GraphSchema.PORT_TYPE_SYSTEM_DATA.equals(type)) {
+            port = new SystemDataPort(portElement);
+        } else if (GraphSchema.PORT_TYPE_CONTROL.equals(type)) {
+            port = new ControlPort(portElement);
+        } else if (GraphSchema.PORT_TYPE_EPR.equals(type)) {
+            port = new EPRPort(portElement);
+        } else if (GraphSchema.PORT_TYPE_INSTANCE.equals(type)) {
+            port = new InstanceDataPort(portElement);
+        } else {
+            // Default is WsPort because of backword compatibility
+            port = new WSPort(portElement);
+        }
+        return port;
+    }
+
+    /**
+     * @see org.apache.airavata.workflow.model.graph.GraphFactory#createEdge(org.apache.airavata.workflow.model.graph.Port,
+     *      org.apache.airavata.workflow.model.graph.Port)
+     */
+    public EdgeImpl createEdge(Port fromPort, Port toPort) {
+        Kind fromKind = fromPort.getKind();
+        Kind toKind = toPort.getKind();
+        if (!((fromKind == Kind.DATA_OUT && toKind == Kind.DATA_IN)
+                || (fromKind == Kind.CONTROL_OUT && toKind == Kind.CONTROL_IN) || (fromKind == Kind.EPR && toKind == Kind.DATA_IN))) {
+            throw new WorkflowRuntimeException();
+        }
+        EdgeImpl edge;
+        if (toKind == Kind.DATA_IN) {
+            edge = new DataEdge();
+        } else if (toKind == Kind.CONTROL_IN) {
+            edge = new ControlEdge();
+        } else {
+            // Should not happen.
+            throw new WorkflowRuntimeException();
+        }
+        return edge;
+    }
+
+    /**
+     * @see org.apache.airavata.workflow.model.graph.GraphFactory#createEdge(org.xmlpull.infoset.XmlElement)
+     */
+    public EdgeImpl createEdge(XmlElement edgeElement) {
+        String type = edgeElement.attributeValue(GraphSchema.NS, GraphSchema.EDGE_TYPE_ATTRIBUTE);
+        EdgeImpl edge;
+        if (GraphSchema.EDGE_TYPE_DATA.equals(type)) {
+            edge = new DataEdge(edgeElement);
+        } else if (GraphSchema.PORT_TYPE_CONTROL.equals(type)) {
+            edge = new ControlEdge(edgeElement);
+        } else {
+            // Default is WsPort because of backword compatibility
+            edge = new DataEdge(edgeElement);
+        }
+        return edge;
+    }
+
+    /**
+     * @return The graph created.
+     */
+    private static WSGraph createWSGraph() {
+        return new WSGraph(new WSGraphFactory());
+    }
+}
\ No newline at end of file

Added: incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/ws/WSNode.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/ws/WSNode.java?rev=1339718&view=auto
==============================================================================
--- incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/ws/WSNode.java (added)
+++ incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/ws/WSNode.java Thu May 17 17:12:15 2012
@@ -0,0 +1,187 @@
+/*
+ *
+ * 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.graph.ws;
+
+import javax.xml.namespace.QName;
+
+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.graph.Edge;
+import org.apache.airavata.workflow.model.graph.ForEachExecutableNode;
+import org.apache.airavata.workflow.model.graph.Graph;
+import org.apache.airavata.workflow.model.graph.GraphException;
+import org.apache.airavata.workflow.model.graph.GraphSchema;
+import org.apache.airavata.workflow.model.graph.impl.NodeImpl;
+import org.apache.airavata.workflow.model.graph.util.GraphUtil;
+import org.apache.airavata.workflow.model.utils.MessageConstants;
+import org.xmlpull.infoset.XmlElement;
+
+public class WSNode extends NodeImpl implements ForEachExecutableNode{
+
+    protected String wsdlID;
+
+    protected QName portTypeQName;
+
+    protected String operationName;
+
+    /**
+     * Constructs a WsdlNode.
+     * 
+     * @param nodeElement
+     * @throws GraphException
+     */
+    public WSNode(XmlElement nodeElement) throws GraphException {
+        super(nodeElement);
+    }
+
+    /**
+     * Constructs a WSNode.
+     * 
+     * @param graph
+     */
+    public WSNode(Graph graph) {
+        super(graph);
+    }
+
+    /**
+     * @see org.apache.airavata.workflow.model.graph.Node#getComponent()
+     */
+    @Override
+    public WSComponent getComponent() {
+        return (WSComponent) super.getComponent();
+    }
+
+    /**
+     * Returns the WSDL ID.
+     * 
+     * @return the WSDL ID
+     */
+    public String getWSDLID() {
+        return this.wsdlID;
+    }
+
+    /**
+     * @param wsdlID
+     */
+    public void setWSDLID(String wsdlID) {
+        this.wsdlID = wsdlID;
+    }
+
+    /**
+     * @return The name of portType.
+     */
+    public QName getPortTypeQName() {
+        if (this.portTypeQName == null) {
+            if (getComponent() == null) {
+                // XXX This happens while parsing xwf created by the version
+                // 2.2.6_1 or below.
+                return null;
+            }
+            this.portTypeQName = getComponent().getPortTypeQName();
+        }
+        return this.portTypeQName;
+    }
+
+    /**
+     * @return The name of the operation.
+     */
+    public String getOperationName() {
+        if (this.operationName == null) {
+            if (getComponent() == null) {
+                // XXX This happens while parsing xwf created by the version
+                // 2.2.6_1 or below.
+                return null;
+            }
+            this.operationName = getComponent().getOperationName();
+        }
+        return this.operationName;
+    }
+
+    /**
+     * @throws GraphException
+     * @see org.apache.airavata.workflow.model.graph.impl.NodeImpl#edgeWasAdded(org.apache.airavata.workflow.model.graph.Edge)
+     */
+    @Override
+    protected void edgeWasAdded(Edge edge) throws GraphException {
+        GraphUtil.validateConnection(edge);
+    }
+
+    /**
+     * @return the node xml
+     */
+    @Override
+    public XmlElement toXML() {
+        XmlElement nodeElement = super.toXML();
+        nodeElement.setAttributeValue(GraphSchema.NS, GraphSchema.NODE_TYPE_ATTRIBUTE, GraphSchema.NODE_TYPE_WS);
+
+        XmlElement wsdlElement = nodeElement.addElement(GraphSchema.NS, GraphSchema.NODE_WSDL_QNAME_TAG);
+        // wsdlElement.setText(getWSDLQName().toString());
+        wsdlElement.setText(getWSDLID());
+
+        XmlElement portTypeElement = nodeElement.addElement(GraphSchema.NS, GraphSchema.NODE_WSDL_PORT_TYPE_TAG);
+        portTypeElement.setText(getPortTypeQName().toString());
+
+        XmlElement operationElement = nodeElement.addElement(GraphSchema.NS, GraphSchema.NODE_WSDL_OPERATION_TAG);
+        operationElement.setText(getOperationName());
+
+        return nodeElement;
+    }
+
+    /**
+     * @see org.apache.airavata.workflow.model.graph.impl.NodeImpl#parse(org.xmlpull.infoset.XmlElement)
+     */
+    @Override
+    protected void parse(XmlElement nodeElement) throws GraphException {
+        super.parse(nodeElement);
+
+        XmlElement wsdlElement = nodeElement.element(null, GraphSchema.NODE_WSDL_QNAME_TAG);
+        if (wsdlElement != null) {
+            this.wsdlID = wsdlElement.requiredText();
+            // String wsdlQNameString = wsdlElement.requiredText();
+            // this.wsdlQName = QName.valueOf(wsdlQNameString);
+        }
+
+        XmlElement portTypeElement = nodeElement.element(null, GraphSchema.NODE_WSDL_PORT_TYPE_TAG);
+        if (portTypeElement != null) {
+            String portTypeString = portTypeElement.requiredText();
+            this.portTypeQName = QName.valueOf(portTypeString);
+        }
+
+        XmlElement operationElement = nodeElement.element(null, GraphSchema.NODE_WSDL_OPERATION_TAG);
+        if (operationElement != null) {
+            this.operationName = operationElement.requiredText();
+        }
+    }
+
+    @Override
+    @Deprecated
+    protected void parseComponent(XmlElement componentElement) throws GraphException {
+        try {
+            String componentString = componentElement.requiredText();
+            WSComponent wsdlComponent = WSComponentFactory.createComponent(componentString);
+            setComponent(wsdlComponent);
+        } catch (ComponentException e) {
+            throw new GraphException(MessageConstants.COMPONENT_FORMAT_ERROR, e);
+        }
+    }
+}
\ No newline at end of file

Added: incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/ws/WSPort.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/ws/WSPort.java?rev=1339718&view=auto
==============================================================================
--- incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/ws/WSPort.java (added)
+++ incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/ws/WSPort.java Thu May 17 17:12:15 2012
@@ -0,0 +1,128 @@
+/*
+ *
+ * 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.graph.ws;
+
+import javax.xml.namespace.QName;
+
+import org.apache.airavata.common.utils.WSConstants;
+import org.apache.airavata.workflow.model.component.ComponentPort;
+import org.apache.airavata.workflow.model.component.system.SystemComponentDataPort;
+import org.apache.airavata.workflow.model.component.ws.WSComponentPort;
+import org.apache.airavata.workflow.model.graph.DataPort;
+import org.apache.airavata.workflow.model.graph.GraphException;
+import org.apache.airavata.workflow.model.graph.GraphSchema;
+import org.apache.airavata.workflow.model.graph.impl.NodeImpl;
+import org.apache.airavata.workflow.model.graph.system.EndForEachNode;
+import org.apache.airavata.workflow.model.graph.system.ForEachNode;
+import org.xmlpull.infoset.XmlElement;
+
+public class WSPort extends DataPort {
+
+    private WSComponentPort componentPort;
+
+    /**
+     * Constructs a WSPort.
+     */
+    public WSPort() {
+        super();
+    }
+
+    /**
+     * Constructs a WsPort.
+     * 
+     * @param portElement
+     */
+    public WSPort(XmlElement portElement) {
+        super(portElement);
+    }
+
+    /**
+     * Returns the typeQName.
+     * 
+     * @return The typeQName
+     */
+    @Override
+    public QName getType() {
+        return getComponentPort().getType();
+    }
+
+    /**
+     * @see org.apache.airavata.workflow.model.graph.DataPort#copyType(org.apache.airavata.workflow.model.graph.DataPort)
+     */
+    @Override
+    public void copyType(DataPort port) throws GraphException {
+        QName newType = port.getType();
+        QName type = getType();
+
+        NodeImpl node = port.getNode();
+        if (node instanceof ForEachNode || node instanceof EndForEachNode) {
+            // XXX ignore the check for foreach because we cannot parse arrays
+            // from WSDL.
+            return;
+        }
+
+        if (!(newType == null || newType.equals(WSConstants.XSD_ANY_TYPE) || type == null
+                || type.equals(WSConstants.XSD_ANY_TYPE) || newType.equals(type))) {
+            String message = "The type (" + newType + ")  must be same as the type  " + " (" + type + ") of " + getID()
+                    + ".";
+            throw new GraphException(message);
+        }
+    }
+
+    /**
+     * @param componentPort
+     */
+    @Override
+    public void setComponentPort(ComponentPort componentPort) {
+        super.setComponentPort(componentPort);
+        this.componentPort = (WSComponentPort) componentPort;
+    }
+
+    /**
+     * @see org.apache.airavata.workflow.model.graph.impl.PortImpl#getComponentPort()
+     */
+    @Override
+    public WSComponentPort getComponentPort() {
+        if (this.componentPort == null) {
+            ComponentPort port = super.getComponentPort();
+            if (port instanceof WSComponentPort) {
+                this.componentPort = (WSComponentPort) port;
+            }
+            if (port instanceof SystemComponentDataPort) {
+                // XXX to handle the xwf created by version 2.6.2_XX or earlier.
+                SystemComponentDataPort systemPort = (SystemComponentDataPort) port;
+                this.componentPort = new WSComponentPort(systemPort.getName(), systemPort.getType(), null);
+            }
+        }
+        return this.componentPort;
+    }
+
+    /**
+     * @see org.apache.airavata.workflow.model.graph.impl.PortImpl#toXML()
+     */
+    @Override
+    protected XmlElement toXML() {
+        XmlElement portElement = super.toXML();
+        portElement.setAttributeValue(GraphSchema.NS, GraphSchema.PORT_TYPE_ATTRIBUTE, GraphSchema.PORT_TYPE_WS_DATA);
+        return portElement;
+    }
+}
\ No newline at end of file

Added: incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/ws/WorkflowNode.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/ws/WorkflowNode.java?rev=1339718&view=auto
==============================================================================
--- incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/ws/WorkflowNode.java (added)
+++ incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/ws/WorkflowNode.java Thu May 17 17:12:15 2012
@@ -0,0 +1,66 @@
+/*
+ *
+ * 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.graph.ws;
+
+import org.apache.airavata.workflow.model.component.ws.WorkflowComponent;
+import org.apache.airavata.workflow.model.graph.Graph;
+import org.apache.airavata.workflow.model.graph.GraphException;
+import org.apache.airavata.workflow.model.graph.GraphSchema;
+import org.xmlpull.infoset.XmlElement;
+
+public class WorkflowNode extends WSNode {
+
+    /**
+     * Constructs a WorkflowNode.
+     * 
+     * @param nodeElement
+     * @throws GraphException
+     */
+    public WorkflowNode(XmlElement nodeElement) throws GraphException {
+        super(nodeElement);
+    }
+
+    /**
+     * Constructs a WorkflowNode.
+     * 
+     * @param graph
+     */
+    public WorkflowNode(Graph graph) {
+        super(graph);
+    }
+
+    /**
+     * @see org.apache.airavata.workflow.model.graph.ws.WSNode#getComponent()
+     */
+    @Override
+    public WorkflowComponent getComponent() {
+        return (WorkflowComponent) super.getComponent();
+    }
+
+    @Override
+    public XmlElement toXML() {
+        XmlElement nodeElement = super.toXML();
+        nodeElement.setAttributeValue(GraphSchema.NS, GraphSchema.NODE_TYPE_ATTRIBUTE, GraphSchema.NODE_TYPE_WORKFLOW);
+        return nodeElement;
+    }
+
+}
\ No newline at end of file

Added: incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/ode/ODEBPELTransformer.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/ode/ODEBPELTransformer.java?rev=1339718&view=auto
==============================================================================
--- incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/ode/ODEBPELTransformer.java (added)
+++ incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/ode/ODEBPELTransformer.java Thu May 17 17:12:15 2012
@@ -0,0 +1,630 @@
+/*
+ *
+ * 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.Iterator;
+import java.util.LinkedList;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+import org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException;
+import org.apache.airavata.common.utils.StringUtil;
+import org.gpel.model.GpelActivity;
+import org.gpel.model.GpelAssign;
+import org.gpel.model.GpelAssignCopy;
+import org.gpel.model.GpelAssignCopyFrom;
+import org.gpel.model.GpelAssignCopyTo;
+import org.gpel.model.GpelElse;
+import org.gpel.model.GpelElseIf;
+import org.gpel.model.GpelFlow;
+import org.gpel.model.GpelIf;
+import org.gpel.model.GpelInvoke;
+import org.gpel.model.GpelProcess;
+import org.gpel.model.GpelReceive;
+import org.gpel.model.GpelReply;
+import org.gpel.model.GpelSequence;
+import org.gpel.model.GpelVariable;
+import org.gpel.model.GpelVariablesContainer;
+import org.xmlpull.infoset.XmlElement;
+import org.xmlpull.infoset.XmlNamespace;
+
+import xsul5.XmlConstants;
+import xsul5.wsdl.WsdlDefinitions;
+import xsul5.wsdl.WsdlMessage;
+import xsul5.wsdl.WsdlMessagePart;
+import xsul5.wsdl.WsdlPortType;
+import xsul5.wsdl.WsdlPortTypeInput;
+import xsul5.wsdl.WsdlPortTypeOperation;
+
+public class ODEBPELTransformer {
+
+    /**
+     * KEEP_SRC_ELEMENT_NAME_STR
+     */
+    private static final String KEEP_SRC_ELEMENT_NAME_STR = "keepSrcElementName";
+    /**
+     * WORKFLOW_INPUT_STR
+     */
+    private static final String WORKFLOW_INPUT_STR = "WorkflowInput";
+    /**
+     * LEAD_HEADER_STR
+     */
+    private static final String LEAD_HEADER_STR = "leadHeader";
+    /**
+     * NO_STR
+     */
+    private static final String NO_STR = "no";
+    /**
+     * VALIDATE_STR
+     */
+    private static final String VALIDATE_STR = "validate";
+    /**
+     * INPUT_VARIABLE_STR
+     */
+    private static final String INPUT_VARIABLE_STR = "inputVariable";
+    /**
+     * VARIABLE_STR
+     */
+    private static final String VARIABLE_STR = "variable";
+    /**
+     * PART_STR
+     */
+    private static final String PART_STR = "part";
+    /**
+     * OPERATION_STR
+     */
+    private static final String OPERATION_STR = "operation";
+    /**
+     * PORT_TYPE_STR
+     */
+    private static final String PORT_TYPE_STR = "portType";
+    /**
+     * QUERY_STR
+     */
+    private static final String QUERY_STR = "query";
+    /**
+     * YES_STR
+     */
+    private static final String YES_STR = "yes";
+    /**
+     * CREATE_INSTANCE_STR
+     */
+    private static final String CREATE_INSTANCE_STR = "createInstance";
+    /**
+     * NAME
+     */
+    private static final String NAME = "name";
+
+    public ODEBPELTransformer() {
+    }
+
+    public void generateODEBPEL(GpelProcess gpelProcess, String workflowName, WsdlDefinitions workflowWSDL,
+            Map<String, WsdlDefinitions> wsdls) {
+
+        XmlElement bpelXml = gpelProcess.xml();
+        if (null != bpelXml.attributeValue(NAME)) {
+            // already done
+            return;
+        }
+
+        gpelProcess.xml().setAttributeValue(NAME, StringUtil.convertToJavaIdentifier(workflowName));
+        GpelActivity activity = gpelProcess.getActivity();
+
+        addImports(gpelProcess, workflowWSDL, wsdls);
+
+        if (activity instanceof GpelSequence) {
+
+            LinkedList<GpelAssign> result = new LinkedList<GpelAssign>();
+
+            formatXpathFromValueCopy(((GpelSequence) activity).activities().iterator());
+            evaluateFlowAndSequenceForAddingInits(wsdls, workflowWSDL, ((GpelSequence) activity).activities()
+                    .iterator(), result);
+            addVariableManipulationBeforeInvoke(((GpelSequence) activity).activities().iterator());
+            findReplaceAssign(((GpelSequence) activity).activities().iterator());
+            Iterator<GpelActivity> iterator = ((GpelSequence) activity).activities().iterator();
+            while (iterator.hasNext()) {
+                GpelActivity next = iterator.next();
+                if (next instanceof GpelReceive) {
+                    ((GpelReceive) next).xml().setAttributeValue(CREATE_INSTANCE_STR, YES_STR);
+                    break;
+                }
+            }
+
+            for (GpelAssign gpelAssignCopy : result) {
+                // second element because the receive would be the first element
+                activity.xml().addChild(1, gpelAssignCopy.xml());
+            }
+        }
+        LinkedList<GpelInvoke> invokeList = new LinkedList<GpelInvoke>();
+
+        replaceVariableMessageTypeValuesWithMessageNameInsteadOfPortType(gpelProcess, wsdls, activity, invokeList);
+
+    }
+
+    private void replaceVariableMessageTypeValuesWithMessageNameInsteadOfPortType(GpelProcess gpelProcess,
+            Map<String, WsdlDefinitions> wsdls, GpelActivity activity, LinkedList<GpelInvoke> invokeList) {
+        if (isSequence(activity)) {
+            findInvokes(activity, invokeList);
+            GpelVariablesContainer variables = gpelProcess.getVariables();
+            for (GpelInvoke gpelInvoke : invokeList) {
+                String variable = gpelInvoke.getInputVariableName();
+                String opName = gpelInvoke.getOperationNcName();
+                QName portType = gpelInvoke.getPortTypeQName();
+                GpelVariable gpelVar = findVariable(variables, variable);
+                QName messageQname = findMessage(gpelProcess, portType, opName, true, wsdls);
+                String nsPrefix = findNamespacePrefix(gpelProcess, messageQname);
+                gpelVar.setMessageTypeQName(new QName(messageQname.getNamespaceURI(), messageQname.getLocalPart(),
+                        nsPrefix));
+
+                variable = gpelInvoke.gelOutputVariableName();
+                gpelVar = findVariable(variables, variable);
+                messageQname = findMessage(gpelProcess, portType, opName, false, wsdls);
+                nsPrefix = findNamespacePrefix(gpelProcess, messageQname);
+                gpelVar.setMessageTypeQName(new QName(messageQname.getNamespaceURI(), messageQname.getLocalPart(),
+                        nsPrefix));
+            }
+
+        }
+    }
+
+    /**
+     * @param gpelProcess
+     * @param messageQname
+     * @return
+     */
+    private String findNamespacePrefix(GpelProcess gpelProcess, QName messageQname) {
+        Iterator<XmlNamespace> iterator = gpelProcess.xml().namespaces().iterator();
+        while (iterator.hasNext()) {
+            XmlNamespace xmlNamespace = (XmlNamespace) iterator.next();
+            if (xmlNamespace.getName().equals(messageQname.getNamespaceURI())) {
+                return xmlNamespace.getPrefix();
+            }
+        }
+
+        throw new WorkflowRuntimeException("Cannot locate the Namespace  for Qname:" + messageQname + " in the BPEL");
+    }
+
+    /**
+     * @param portType
+     * @param opName
+     * @param b
+     */
+    private QName findMessage(GpelProcess gpelProcess, QName portType, String opName, boolean input,
+            Map<String, WsdlDefinitions> wsdls) {
+        Iterator<String> iterator = wsdls.keySet().iterator();
+        while (iterator.hasNext()) {
+            String key = (String) iterator.next();
+            WsdlDefinitions wsdlDefinitions = wsdls.get(key);
+            WsdlPortType pType = wsdlDefinitions.getPortType(portType.getLocalPart());
+            WsdlPortTypeOperation operation = null;
+            if (null != pType && null != (operation = pType.getOperation(opName))) {
+
+                if (input) {
+                    WsdlPortTypeInput messageRef = operation.getInput();
+                    if (null != messageRef && null != messageRef.getMessage()) {
+                        WsdlMessage message = wsdlDefinitions.getMessage(messageRef.getMessage().getLocalPart());
+                        if (null != message) {
+                            return new QName(wsdlDefinitions.getTargetNamespace(), message.getName(), key);
+                        }
+                    }
+                } else {
+                    xsul5.wsdl.WsdlPortTypeOutput messageRef = operation.getOutput();
+                    if (null != messageRef && null != messageRef.getMessage()) {
+                        WsdlMessage message = wsdlDefinitions.getMessage(messageRef.getMessage().getLocalPart());
+                        if (null != message) {
+                            return new QName(wsdlDefinitions.getTargetNamespace(), message.getName(), key);
+                        }
+                    }
+                }
+
+            }
+        }
+        throw new WorkflowRuntimeException("Unable to find the Message for the PortType " + portType + " operation:"
+                + opName);
+    }
+
+    private GpelVariable findVariable(GpelVariablesContainer variables, String variable) {
+        Iterator<GpelVariable> iterator = variables.variables().iterator();
+
+        while (iterator.hasNext()) {
+            GpelVariable gpelVariable = iterator.next();
+            if (variable.equals(gpelVariable.getName())) {
+                return gpelVariable;
+            }
+        }
+        throw new WorkflowRuntimeException("Unable to fine the variable :" + variable + "  in the BPEL variables "
+                + variables);
+    }
+
+    /**
+     * @param invokeList
+     */
+    private void findInvokes(GpelActivity activity, LinkedList<GpelInvoke> invokeList) {
+        if (isFlow(activity)) {
+            Iterator<GpelActivity> iterator = ((GpelFlow) activity).activities().iterator();
+            findInvokes(iterator, invokeList);
+
+        } else if (activity instanceof GpelSequence) {
+            Iterator<GpelActivity> iterator = ((GpelSequence) activity).activities().iterator();
+            findInvokes(iterator, invokeList);
+        } else if (activity instanceof GpelIf) {
+            Iterator<GpelActivity> iterator = ((GpelIf) activity).activities().iterator();
+            findInvokes(iterator, invokeList);
+            iterator = ((GpelIf) activity).getElse().activities().iterator();
+            findInvokes(iterator, invokeList);
+        }
+
+    }
+
+    /**
+     * @param invokeList
+     */
+    private void findInvokes(Iterator<GpelActivity> iterator, LinkedList<GpelInvoke> invokeList) {
+        while (iterator.hasNext()) {
+            GpelActivity next = iterator.next();
+            if (isSequence(next) || isFlow(next) || isIf(next)) {
+                findInvokes(next, invokeList);
+            } else if (isInvoke(next)) {
+                invokeList.add((GpelInvoke) next);
+            }
+        }
+    }
+
+    /**
+	 * 
+	 */
+    private void addImports(GpelProcess process, WsdlDefinitions workflowWSDL, Map<String, WsdlDefinitions> wsdls) {
+        Iterator<String> iterator = wsdls.keySet().iterator();
+        while (iterator.hasNext()) {
+            String id = iterator.next();
+            WsdlDefinitions wsdl = wsdls.get(id);
+            XmlElement importElement = process.xml().newElement(process.xml().getNamespace(), "import");
+            importElement.setAttributeValue("importType", "http://schemas.xmlsoap.org/wsdl/");
+            importElement.setAttributeValue("location", wsdl.xml().attributeValue("name") + ".wsdl");
+            importElement.setAttributeValue("namespace", wsdl.getTargetNamespace());
+            process.xml().addChild(0, importElement);
+
+        }
+
+        XmlElement importElement = process.xml().newElement(process.xml().getNamespace(), "import");
+        importElement.setAttributeValue("importType", "http://schemas.xmlsoap.org/wsdl/");
+
+        importElement.setAttributeValue("location", workflowWSDL.xml().attributeValue("name") + ".wsdl");
+        importElement.setAttributeValue("namespace", workflowWSDL.getTargetNamespace());
+        process.xml().addChild(0, importElement);
+
+        process.xml().declareNamespace(
+                XmlConstants.BUILDER.newNamespace("leadcntx",
+                        "http://lead.extreme.indiana.edu/namespaces/2005/10/lead-context-header"));
+
+    }
+
+    private void findReplaceAssign(GpelActivity activity) {
+        if (isFlow(activity)) {
+            Iterator<GpelActivity> iterator = ((GpelFlow) activity).activities().iterator();
+            findReplaceAssign(iterator);
+
+        } else if (activity instanceof GpelSequence) {
+            Iterator<GpelActivity> iterator = ((GpelSequence) activity).activities().iterator();
+            findReplaceAssign(iterator);
+        }
+    }
+
+    private void findReplaceAssign(Iterator<GpelActivity> iterator) {
+        while (iterator.hasNext()) {
+            GpelActivity next = iterator.next();
+            if (isSequence(next) || isFlow(next)) {
+                findReplaceAssign(next);
+            } else if (isAssign(next)) {
+                GpelAssign assign = (GpelAssign) next;
+                Iterator<GpelAssignCopy> itr = assign.copyOperations().iterator();
+                while (itr.hasNext()) {
+                    GpelAssignCopy copy = itr.next();
+                    String query = copy.getFrom().xml().attributeValue(QUERY_STR);
+                    if (query != null) {
+                        copy.getFrom().xml().addElement(copy.getFrom().xml().getNamespace(), QUERY_STR)
+                                .addChild("<![CDATA[" + query + "]]>");
+                    }
+                    query = copy.getTo().xml().attributeValue(QUERY_STR);
+                    if (query != null) {
+                        copy.getTo().xml().addElement(copy.getFrom().xml().getNamespace(), QUERY_STR)
+                                .addChild("<![CDATA[" + query + "]]>");
+                    }
+                }
+            }
+        }
+    }
+
+    private void formatXpathFromValueCopy(GpelActivity activity) {
+        if (isFlow(activity)) {
+            Iterator<GpelActivity> iterator = ((GpelFlow) activity).activities().iterator();
+            formatXpathFromValueCopy(iterator);
+
+        } else if (activity instanceof GpelSequence) {
+            Iterator<GpelActivity> iterator = ((GpelSequence) activity).activities().iterator();
+            formatXpathFromValueCopy(iterator);
+        }
+    }
+
+    private void formatXpathFromValueCopy(Iterator<GpelActivity> iterator) {
+        while (iterator.hasNext()) {
+            GpelActivity next = iterator.next();
+            if (isSequence(next) || isFlow(next)) {
+                formatXpathFromValueCopy(next);
+            } else if (isAssign(next)) {
+                GpelAssign assign = (GpelAssign) next;
+                Iterator<GpelAssignCopy> itr = assign.copyOperations().iterator();
+                while (itr.hasNext()) {
+                    GpelAssignCopy copy = itr.next();
+                    String query = copy.getFrom().xml().attributeValue(QUERY_STR);
+                    XmlElement copyElmt = copy.getFrom().xml();
+                    // remove if attribute is found earlier
+                    if (null != query) {
+                        copyElmt.removeAttribute(copyElmt.attribute(QUERY_STR));
+                        copyElmt.setAttributeValue(QUERY_STR, "/" + extractDataType(query));
+                    }
+
+                    query = copy.getTo().xml().attributeValue(QUERY_STR);
+                    XmlElement toElmt = copy.getTo().xml();
+                    // remove if attribute is found earlier
+                    if (null != query) {
+                        toElmt.removeAttribute(toElmt.attribute(QUERY_STR));
+                        toElmt.setAttributeValue(QUERY_STR, "/" + extractDataType(query));
+                    }
+
+                }
+            }
+        }
+    }
+
+    private void evaluateFlowAndSequenceForAddingInits(Map<String, WsdlDefinitions> wsdls,
+            WsdlDefinitions workflowWSDL, GpelActivity activity, LinkedList<GpelAssign> list) {
+        if (isFlow(activity)) {
+            Iterator<GpelActivity> iterator = ((GpelFlow) activity).activities().iterator();
+            evaluateFlowAndSequenceForAddingInits(wsdls, workflowWSDL, iterator, list);
+
+        } else if (activity instanceof GpelSequence) {
+            Iterator<GpelActivity> iterator = ((GpelSequence) activity).activities().iterator();
+            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 WorkflowRuntimeException("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 WorkflowRuntimeException("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);
+
+            }
+            last = next;
+        }
+    }
+
+    /**
+     * @param query
+     * @return
+     */
+    private String getElementName(String query) {
+        int index = query.indexOf('/');
+        if (-1 != index) {
+            return query.substring(index + 1);
+        }
+        return query;
+    }
+
+    private void addVariableManipulationBeforeInvoke(GpelActivity activity) {
+
+        if (isFlow(activity)) {
+            Iterator<GpelActivity> iterator = ((GpelFlow) activity).activities().iterator();
+            addVariableManipulationBeforeInvoke(iterator);
+
+        } else if (activity instanceof GpelSequence) {
+            Iterator<GpelActivity> iterator = ((GpelSequence) activity).activities().iterator();
+            addVariableManipulationBeforeInvoke(iterator);
+        }
+        // else do nothing
+
+    }
+
+    private void addVariableManipulationBeforeInvoke(Iterator<GpelActivity> iterator) {
+        GpelActivity last = null;
+        while (iterator.hasNext()) {
+            GpelActivity next = iterator.next();
+            if (isSequence(next) || isFlow(next)) {
+                addVariableManipulationBeforeInvoke(next);
+            } else if (isInvoke(next)) {
+                if (last == null || !isAssign(last)) {
+                    throw new WorkflowRuntimeException("Assign activity not found for the Invoke" + next.xmlStringPretty());
+                }
+
+                // we are good and should add the header copy.
+                XmlNamespace ns = last.xml().getNamespace();
+                GpelAssignCopyFrom headerFrom = new GpelAssignCopyFrom(ns);
+                headerFrom.xml().setAttributeValue(PART_STR, LEAD_HEADER_STR);
+                headerFrom.xml().setAttributeValue(VARIABLE_STR, WORKFLOW_INPUT_STR);
+
+                GpelAssignCopyTo headerTo = new GpelAssignCopyTo(ns);
+                headerTo.xml().setAttributeValue(PART_STR, LEAD_HEADER_STR);
+                headerTo.xml().setAttributeValue(VARIABLE_STR, next.xml().attributeValue(INPUT_VARIABLE_STR));
+                GpelAssignCopy headerCopy = new GpelAssignCopy(ns, headerFrom, headerTo);
+                GpelAssign assign = (GpelAssign) last;
+                assign.addCopy(headerCopy);
+
+                GpelAssignCopyFrom nodeIDFrom = new GpelAssignCopyFrom(ns);
+                nodeIDFrom.setLiteral(XmlConstants.BUILDER.parseFragmentFromString("<dummyelement>"
+                        + next.xml().attributeValue(NAME) + "</dummyelement>"));
+                GpelAssignCopyTo nodeIDTo = new GpelAssignCopyTo(ns);
+
+                nodeIDTo.xml().setAttributeValue(PART_STR, LEAD_HEADER_STR);
+                nodeIDTo.xml().setAttributeValue(VARIABLE_STR, next.xml().attributeValue(INPUT_VARIABLE_STR));
+                // TODO is this ok?? what of the query language
+                nodeIDTo.setQuery("/leadcntx:workflow-node-id");
+
+                GpelAssignCopy nodeIDCopy = new GpelAssignCopy(ns, nodeIDFrom, nodeIDTo);
+                nodeIDCopy.xml().setAttributeValue(KEEP_SRC_ELEMENT_NAME_STR, NO_STR);
+                assign.addCopy(nodeIDCopy);
+
+                GpelAssignCopyFrom timeStepFrom = new GpelAssignCopyFrom(ns);
+                timeStepFrom.setLiteral(XmlConstants.BUILDER.parseFragmentFromString("<dummyelement>" + "5"
+                        + "</dummyelement>"));
+                GpelAssignCopyTo timeStepTo = new GpelAssignCopyTo(ns);
+                timeStepTo.xml().setAttributeValue(PART_STR, LEAD_HEADER_STR);
+                timeStepTo.xml().setAttributeValue(VARIABLE_STR, next.xml().attributeValue(INPUT_VARIABLE_STR));
+                // TODO is this ok?? what of the query language
+                timeStepTo.setQuery("/leadcntx:workflow-time-step");
+
+                GpelAssignCopy timeStepCopy = new GpelAssignCopy(ns, timeStepFrom, timeStepTo);
+                timeStepCopy.xml().setAttributeValue(KEEP_SRC_ELEMENT_NAME_STR, NO_STR);
+                assign.addCopy(timeStepCopy);
+
+            }
+            last = next;
+        }
+    }
+
+    /**
+     * @param query
+     */
+    private String extractDataType(String query) {
+        int index = query.indexOf(':');
+        if (index == -1) {
+            throw new WorkflowRuntimeException("Invalid query no : delimeter found " + query);
+        }
+        String[] split = query.substring(index + 1).trim().split("/");
+        if (split.length == 0) {
+            throw new WorkflowRuntimeException("Unknown Xpath " + query.substring(index));
+        }
+        return split[split.length - 1];
+    }
+
+    private boolean isSequence(GpelActivity activity) {
+        return activity instanceof GpelSequence;
+    }
+
+    private boolean isFlow(GpelActivity activity) {
+        return activity instanceof GpelFlow;
+    }
+
+    private boolean isAssign(GpelActivity activity) {
+        return activity instanceof GpelAssign;
+    }
+
+    private boolean isInvoke(GpelActivity activity) {
+        return activity instanceof GpelInvoke;
+    }
+
+    private boolean isReply(GpelActivity activity) {
+        return activity instanceof GpelReply;
+    }
+
+    private boolean isIf(GpelActivity activity) {
+        return activity instanceof GpelIf;
+    }
+
+    private boolean isElse(GpelActivity activity) {
+        return activity instanceof GpelElse;
+    }
+
+    private boolean isElseIf(GpelActivity activity) {
+        return activity instanceof GpelElseIf;
+    }
+}
\ No newline at end of file