You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@taverna.apache.org by st...@apache.org on 2015/02/17 12:36:33 UTC

[13/70] [abbrv] incubator-taverna-common-activities git commit: taverna-wsdl-generic/

http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/c8b66752/taverna-wsdl-generic/src/main/java/net/sf/taverna/wsdl/xmlsplitter/XMLInputSplitter.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/main/java/net/sf/taverna/wsdl/xmlsplitter/XMLInputSplitter.java b/taverna-wsdl-generic/src/main/java/net/sf/taverna/wsdl/xmlsplitter/XMLInputSplitter.java
new file mode 100644
index 0000000..031de03
--- /dev/null
+++ b/taverna-wsdl-generic/src/main/java/net/sf/taverna/wsdl/xmlsplitter/XMLInputSplitter.java
@@ -0,0 +1,290 @@
+/*******************************************************************************
+ * Copyright (C) 2007 The University of Manchester   
+ * 
+ *  Modifications to the initial code base are copyright of their
+ *  respective authors, or their employers as appropriate.
+ * 
+ *  This program is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public License
+ *  as published by the Free Software Foundation; either version 2.1 of
+ *  the License, or (at your option) any later version.
+ *    
+ *  This program is distributed in the hope that it will be useful, but
+ *  WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *    
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.wsdl.xmlsplitter;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import net.sf.taverna.wsdl.parser.ArrayTypeDescriptor;
+import net.sf.taverna.wsdl.parser.BaseTypeDescriptor;
+import net.sf.taverna.wsdl.parser.ComplexTypeDescriptor;
+import net.sf.taverna.wsdl.parser.TypeDescriptor;
+
+import org.apache.axis.encoding.Base64;
+import org.jdom.Document;
+import org.jdom.Element;
+import org.jdom.JDOMException;
+import org.jdom.Namespace;
+import org.jdom.input.SAXBuilder;
+import org.jdom.output.XMLOutputter;
+
+public class XMLInputSplitter {
+
+	private TypeDescriptor typeDescriptor;
+	private String[] outputNames;
+	private String[] inputNames;
+	private String[] inputTypes;
+
+	public XMLInputSplitter(TypeDescriptor typeDescriptor, String inputNames[],
+			String inputTypes[], String[] outputNames) {
+		this.typeDescriptor = typeDescriptor;
+		this.outputNames = outputNames;
+		this.inputTypes = inputTypes;
+		this.inputNames = inputNames;
+	}
+
+	public Map<String, String> execute(Map<String, Object> inputMap)
+			throws JDOMException, IOException {
+		Map<String, String> result = new HashMap<String, String>();
+		Element outputElement = (this.typeDescriptor.getName().length() > 0 ? new Element(
+				this.typeDescriptor.getName())
+				: new Element(this.typeDescriptor.getType()));
+
+		if (typeDescriptor instanceof ComplexTypeDescriptor) {
+			executeForComplexType(inputMap, result, outputElement);
+
+		} else {
+			for (String key : inputMap.keySet()) {
+				Object dataObject = inputMap.get(key);
+
+				if (dataObject instanceof List) {
+					Element dataElement = buildElementFromObject(key, "");
+					for (Object dataItem : ((List<?>) dataObject)) {
+						Element itemElement = buildElementFromObject(key,
+								dataItem);
+						dataElement.addContent(itemElement);
+					}
+
+					XMLOutputter outputter = new XMLOutputter();
+					String xmlText = outputter.outputString(dataElement);
+
+					result.put(outputNames[0], xmlText);
+				} else {
+					Element dataElement = buildElementFromObject(key,
+							dataObject);
+					outputElement.addContent(dataElement);
+					XMLOutputter outputter = new XMLOutputter();
+					String xmlText = outputter.outputString(outputElement);
+					result.put(outputNames[0], xmlText);
+				}
+
+			}
+		}
+
+		return result;
+
+	}
+
+	private void executeForComplexType(Map<String, Object> inputMap,
+			Map<String, String> result, Element outputElement)
+			throws JDOMException, IOException {
+		ComplexTypeDescriptor complexDescriptor = (ComplexTypeDescriptor) typeDescriptor;
+		for (TypeDescriptor elementType : complexDescriptor.getElements()) {
+			String key = elementType.getName();
+			Object dataObject = inputMap.get(key);			
+			if (dataObject==null) {
+				if (elementType.isOptional()) {
+					continue;
+				} if (elementType.isNillable()) {
+					dataObject = "xsi:nil";
+				} else {
+					dataObject="";
+				}
+			}
+
+			if (dataObject instanceof List) {
+				Element arrayElement = buildElementFromObject(key, "");
+
+				String itemkey = "item";
+				boolean wrapped = false;
+				if (elementType instanceof ArrayTypeDescriptor) {
+					wrapped = ((ArrayTypeDescriptor) elementType).isWrapped();
+					TypeDescriptor arrayElementType = ((ArrayTypeDescriptor) elementType)
+							.getElementType();
+					if (!wrapped) {
+						itemkey = elementType.getName();
+					} else {
+						if (arrayElementType.getName() != null
+								&& arrayElementType.getName().length() > 0) {
+							itemkey = arrayElementType.getName();
+						} else {
+							itemkey = arrayElementType.getType();
+						}
+					}
+
+				}
+
+				for (Object itemObject : ((List<?>)dataObject)) {
+
+					Element dataElement = buildElementFromObject(itemkey,
+							itemObject);
+					dataElement.setNamespace(Namespace.getNamespace(elementType
+							.getNamespaceURI()));
+					if (!wrapped) {
+						dataElement.setName(itemkey);
+						outputElement.addContent(dataElement);
+					} else {
+						arrayElement.addContent(dataElement);
+					}
+				}
+				if (wrapped)
+					outputElement.addContent(arrayElement);
+			} else {
+				Element dataElement = buildElementFromObject(key, dataObject);
+				outputElement.addContent(dataElement);
+			}
+		}
+		for (TypeDescriptor attribute : complexDescriptor.getAttributes()) {
+			String key = attribute.getName();
+			Object dataObject = inputMap.get("1" + key);
+			if (dataObject == null) {
+				dataObject = inputMap.get(key);
+			}
+			if (dataObject != null) {
+				outputElement.setAttribute(key, dataObject.toString(), Namespace
+						.getNamespace(attribute.getNamespaceURI()));
+			}
+		}
+		
+		outputElement.setNamespace(Namespace.getNamespace(typeDescriptor
+				.getNamespaceURI()));
+		XMLOutputter outputter = new XMLOutputter();
+		String xmlText = outputter.outputString(outputElement);
+		result.put(outputNames[0], xmlText);
+	}
+
+	private Element buildElementFromObject(String key, Object dataObject)
+			throws JDOMException, IOException {
+
+		Element dataElement = null;
+
+		if (isXMLInput(key)) {
+			dataElement = createDataElementForXMLInput(dataObject, key);
+		} else {
+			dataElement = new Element(key);
+			setDataElementNamespace(key, dataElement);
+			Namespace xsiNs = org.jdom.Namespace
+				.getNamespace("xsi",
+						"http://www.w3.org/2001/XMLSchema-instance");
+			if (dataObject.toString().equals("xsi:nil")) {
+				dataElement.setAttribute("nil", "true", xsiNs); // changes nil value
+			} else {
+				if (dataObject instanceof byte[]) {
+				
+					dataElement
+							.setAttribute(
+									"type",
+									"xsd:base64Binary",
+									xsiNs);
+					dataObject = Base64
+							.encode(((byte[]) dataObject));
+				}
+				dataElement.setText(dataObject.toString());
+			}
+
+		}
+		return dataElement;
+	}
+
+	private Element createDataElementForXMLInput(Object dataObject, String key)
+			throws JDOMException, IOException {
+		Element dataElement = null;
+		String xml = dataObject.toString();
+		if (xml.length() > 0) {
+			Document doc = new SAXBuilder().build(new StringReader(xml));
+			dataElement = doc.getRootElement();
+			dataElement.detach();
+		} else {
+			dataElement = new Element(key);
+		}
+
+		setDataElementNamespace(key, dataElement);
+		return dataElement;
+	}
+
+	// set the namespace if it can be determined from the element TypeDescriptor
+	// by the key
+	private void setDataElementNamespace(String key, Element dataElement) {
+		if (typeDescriptor instanceof ComplexTypeDescriptor) {
+			TypeDescriptor elementTypeDescriptor = ((ComplexTypeDescriptor) typeDescriptor)
+					.elementForName(key);
+			if (elementTypeDescriptor != null) {
+				String nsURI = null;
+				if (elementTypeDescriptor instanceof BaseTypeDescriptor) {
+					nsURI = elementTypeDescriptor.getNamespaceURI();
+					// this is some protective code against old workflows that
+					// had the base element namespace incorrectly
+					// declared (it was using the type NS, rather than the
+					// element NS.
+					if (nsURI.contains("XMLSchema")
+							&& nsURI.contains("http://www.w3.org")) {
+						nsURI = typeDescriptor.getNamespaceURI();
+					}
+				} else {
+					nsURI = elementTypeDescriptor.getNamespaceURI();
+				}
+				if (nsURI != null && nsURI.length() > 0) {
+					updateElementNamespace(dataElement, nsURI);
+				}
+			}
+		}
+	}
+
+	/**
+	 * Updates the element namespace, and also iterates all descendant elements.
+	 * If these elements have no default namespace, or is blank then it is also
+	 * set to namespaceURI (JDOM by default will not set the child elements to
+	 * the same namespace as the element modified but will override them with
+	 * blank namespaces).
+	 * 
+	 * @param dataElement
+	 * @param namespaceURI
+	 */
+	private void updateElementNamespace(Element dataElement, String namespaceURI) {
+		dataElement.setNamespace(Namespace.getNamespace(namespaceURI));
+		Iterator<?> iterator = dataElement.getDescendants();
+		while (iterator.hasNext()) {
+			Object descendantObject = iterator.next();
+			if (descendantObject instanceof Element) {
+				Element childElement = (Element) descendantObject;
+				if (childElement.getNamespaceURI() == null) {
+					childElement.setNamespace(Namespace
+							.getNamespace(namespaceURI));
+				}
+			}
+		}
+	}
+
+	private boolean isXMLInput(String key) {
+		boolean result = false;
+		for (int i = 0; i < inputNames.length; i++) {
+			if (inputNames[i].equals(key)) {
+				result = inputTypes[i].indexOf("'text/xml'") != -1;
+			}
+		}
+		return result;
+	}
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/c8b66752/taverna-wsdl-generic/src/main/java/net/sf/taverna/wsdl/xmlsplitter/XMLOutputSplitter.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/main/java/net/sf/taverna/wsdl/xmlsplitter/XMLOutputSplitter.java b/taverna-wsdl-generic/src/main/java/net/sf/taverna/wsdl/xmlsplitter/XMLOutputSplitter.java
new file mode 100644
index 0000000..4ad5061
--- /dev/null
+++ b/taverna-wsdl-generic/src/main/java/net/sf/taverna/wsdl/xmlsplitter/XMLOutputSplitter.java
@@ -0,0 +1,212 @@
+/*
+ * Copyright (C) 2003 The University of Manchester 
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.  Authorship
+ * of the modifications may be determined from the ChangeLog placed at
+ * the end of this file.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ ****************************************************************
+ * Source code information
+ * -----------------------
+ * Filename           $RCSfile: XMLOutputSplitter.java,v $
+ * Revision           $Revision: 1.2 $
+ * Release status     $State: Exp $
+ * Last modified on   $Date: 2008/08/08 10:28:07 $
+ *               by   $Author: stain $
+ * Created on 16-May-2006
+ *****************************************************************/
+package net.sf.taverna.wsdl.xmlsplitter;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import net.sf.taverna.wsdl.parser.ArrayTypeDescriptor;
+import net.sf.taverna.wsdl.parser.BaseTypeDescriptor;
+import net.sf.taverna.wsdl.parser.ComplexTypeDescriptor;
+import net.sf.taverna.wsdl.parser.TypeDescriptor;
+
+import org.apache.axis.encoding.Base64;
+import org.jdom.Attribute;
+import org.jdom.Document;
+import org.jdom.Element;
+import org.jdom.JDOMException;
+import org.jdom.input.SAXBuilder;
+import org.jdom.output.XMLOutputter;
+
+public class XMLOutputSplitter {
+
+	private TypeDescriptor typeDescriptor;
+	private String[] outputNames;
+	private String[] inputNames;
+	private String[] outputTypes;
+
+	public XMLOutputSplitter(TypeDescriptor typeDescriptor,
+			String[] outputNames, String[] outputTypes,String[] inputNames) {
+		this.typeDescriptor = typeDescriptor;
+		this.outputNames = outputNames;
+		this.inputNames = inputNames;
+		this.outputTypes = outputTypes;
+	}
+
+	@SuppressWarnings("unchecked")
+	public Map<String, Object> execute(Map<String, String> inputMap)
+			throws XMLSplitterExecutionException {
+
+		Map<String, Object> result = new HashMap<String, Object>();
+		List<String> outputNameList = Arrays.asList(outputNames);
+
+		String xml = inputMap.get(inputNames[0]);
+		try {
+			Document doc = new SAXBuilder().build(new StringReader(xml));
+			List<Element> children = doc.getRootElement().getChildren();
+			if (typeDescriptor instanceof ArrayTypeDescriptor) {
+				if (outputNames.length > 1)
+					throw new XMLSplitterExecutionException(
+							"Unexpected, multiple output names for ArrayType");
+				executeForArrayType(result, children);
+			} else {
+				executeForComplexType(result, outputNameList, children, doc.getRootElement().getAttributes());
+			}
+
+			// populate missing outputs with empty strings for basic types,
+			// empty elements for complex/array types.
+			for (int i = 0; i < outputNames.length; i++) {
+				if (result.get(outputNames[i]) == null) {
+					if (outputTypes[i].equals("'text/xml'")) {
+						result
+								.put(outputNames[i], "<" + outputNames[i]
+										+ " />");
+					} else if (outputTypes[i].startsWith("l('")) {
+						result.put(outputNames[i], new ArrayList<Object>());
+					} else {
+						result.put(outputNames[i], "");
+					}
+
+				}
+			}
+		} catch (JDOMException e) {
+			throw new XMLSplitterExecutionException("Unable to parse XML: " + xml, e);
+		} catch (IOException e) {
+			throw new XMLSplitterExecutionException("IOException parsing XML: " + xml,
+					e);
+		}
+
+		return result;
+	}
+
+	private void executeForArrayType(Map<String, Object> result,
+			List<Element> children) {
+		ArrayTypeDescriptor arrayDescriptor = (ArrayTypeDescriptor) typeDescriptor;
+		List<String> values = new ArrayList<String>();
+		XMLOutputter outputter = new XMLOutputter();
+
+		boolean isInnerBaseType = arrayDescriptor.getElementType() instanceof BaseTypeDescriptor;
+		if (isInnerBaseType) {
+			values = extractBaseTypeArrayFromChildren(children);
+		} else {
+			for (Element child : children) {
+				values.add(outputter.outputString(child));
+			}
+		}
+		result.put(outputNames[0], values);
+	}
+
+	@SuppressWarnings({ "unchecked" })
+	private void executeForComplexType(Map<String, Object> result,
+			List<String> outputNameList, List<Element> children, List<Attribute> list)
+			throws IOException {               
+
+		XMLOutputter outputter = new XMLOutputter();
+		for (Element child : children) {
+			
+			if (outputNameList.contains(child.getName())) {
+				int i = outputNameList.indexOf(child.getName());
+				TypeDescriptor descriptorForChild = ((ComplexTypeDescriptor) typeDescriptor)
+						.elementForName(outputNames[i]);
+				if (outputTypes[i].startsWith("l(")
+						&& descriptorForChild instanceof ArrayTypeDescriptor
+						&& !((ArrayTypeDescriptor) descriptorForChild)
+								.isWrapped()) {
+					boolean isXMLContent = outputTypes[i].contains("text/xml");
+					result.put(child.getName(), extractDataListFromChildList(
+							children, isXMLContent));
+                    break;
+				} else {
+					if (outputTypes[i].equals("'text/xml'")
+							|| outputTypes[i].equals("l('text/xml')")) {
+						String xmlText = outputter.outputString(child);
+						result.put(child.getName(), xmlText);
+					} else if (outputTypes[i]
+							.equals("'application/octet-stream'")) { // base64Binary
+						
+						byte[] data = Base64.decode(child
+								.getText());
+						result.put(child.getName(), data);
+					} else if (outputTypes[i].equals("l('text/plain')")) { // an
+																			// inner
+																			// element
+																			// containing
+																			// a
+																			// list
+						result.put(child.getName(),
+								extractBaseTypeArrayFromChildren(child
+										.getChildren()));
+					} else {
+						result.put(child.getName(), child.getText());
+					}
+				}
+			}
+		}
+		for (Attribute attribute : list) {
+			if (outputNameList.contains("1" + attribute.getName())) {
+				result.put("1" + attribute.getName(), attribute.getValue());
+			} else if (outputNameList.contains(attribute.getName())) {
+				result.put(attribute.getName(), attribute.getValue());
+			}
+		}
+	}
+
+	private List<String> extractDataListFromChildList(List<Element> children,
+			boolean isXMLContent) {
+		List<String> result = new ArrayList<String>();
+		XMLOutputter outputter = new XMLOutputter();
+		for (Element child : children) {
+			if (!isXMLContent) {
+				result.add(child.getTextTrim());
+			} else {
+				result.add(outputter.outputString(child));
+			}
+		}
+		return result;
+	}
+
+	private List<String> extractBaseTypeArrayFromChildren(List<Element> children) {
+		List<String> result = new ArrayList<String>();
+		for (Element child : children) {
+			result.add(child.getTextTrim());
+		}
+		return result;
+	}
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/c8b66752/taverna-wsdl-generic/src/main/java/net/sf/taverna/wsdl/xmlsplitter/XMLSplitterExecutionException.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/main/java/net/sf/taverna/wsdl/xmlsplitter/XMLSplitterExecutionException.java b/taverna-wsdl-generic/src/main/java/net/sf/taverna/wsdl/xmlsplitter/XMLSplitterExecutionException.java
new file mode 100644
index 0000000..6ec1720
--- /dev/null
+++ b/taverna-wsdl-generic/src/main/java/net/sf/taverna/wsdl/xmlsplitter/XMLSplitterExecutionException.java
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * Copyright (C) 2007 The University of Manchester   
+ * 
+ *  Modifications to the initial code base are copyright of their
+ *  respective authors, or their employers as appropriate.
+ * 
+ *  This program is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public License
+ *  as published by the Free Software Foundation; either version 2.1 of
+ *  the License, or (at your option) any later version.
+ *    
+ *  This program is distributed in the hope that it will be useful, but
+ *  WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *    
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.wsdl.xmlsplitter;
+
+public class XMLSplitterExecutionException extends Exception {
+
+	private static final long serialVersionUID = 5623707293500493612L;
+
+	public XMLSplitterExecutionException(String msg, Throwable cause) {
+		super(msg, cause);
+	}
+
+	public XMLSplitterExecutionException(String msg) {
+		super(msg);
+	}
+}

http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/c8b66752/taverna-wsdl-generic/src/main/java/net/sf/taverna/wsdl/xmlsplitter/XMLSplitterSerialisationHelper.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/main/java/net/sf/taverna/wsdl/xmlsplitter/XMLSplitterSerialisationHelper.java b/taverna-wsdl-generic/src/main/java/net/sf/taverna/wsdl/xmlsplitter/XMLSplitterSerialisationHelper.java
new file mode 100644
index 0000000..e6e0fbb
--- /dev/null
+++ b/taverna-wsdl-generic/src/main/java/net/sf/taverna/wsdl/xmlsplitter/XMLSplitterSerialisationHelper.java
@@ -0,0 +1,359 @@
+/*
+ * Copyright (C) 2003 The University of Manchester 
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.  Authorship
+ * of the modifications may be determined from the ChangeLog placed at
+ * the end of this file.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ ****************************************************************
+ * Source code information
+ * -----------------------
+ * Filename           $RCSfile: XMLSplitterSerialisationHelper.java,v $
+ * Revision           $Revision: 1.2 $
+ * Release status     $State: Exp $
+ * Last modified on   $Date: 2008/08/08 10:28:08 $
+ *               by   $Author: stain $
+ * Created on 16-May-2006
+ *****************************************************************/
+package net.sf.taverna.wsdl.xmlsplitter;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+
+import net.sf.taverna.wsdl.parser.ArrayTypeDescriptor;
+import net.sf.taverna.wsdl.parser.AttributeTypeDescriptor;
+import net.sf.taverna.wsdl.parser.BaseTypeDescriptor;
+import net.sf.taverna.wsdl.parser.ComplexTypeDescriptor;
+import net.sf.taverna.wsdl.parser.TypeDescriptor;
+
+import org.apache.log4j.Logger;
+import org.jdom.Content;
+import org.jdom.Element;
+import org.jdom.Namespace;
+
+/**
+ * A helper class that supports the XMLOutputSplitter and XMLInputSplitter,
+ * providing the ability for each to be serialised/deserialised to and from the
+ * extensions XML for the ScuflModel XML when storing a workflow. This XML
+ * describes the TypeDescriptor tree that the Splitter wraps.
+ * 
+ * @author Stuart Owen
+ * @author Asger Askov-Bleking
+ * 
+ */
+
+public class XMLSplitterSerialisationHelper {
+
+	public final static Namespace XScuflNS = Namespace.getNamespace("s",
+			"http://org.embl.ebi.escience/xscufl/0.1alpha");
+
+	private static Logger logger = Logger
+			.getLogger(XMLSplitterSerialisationHelper.class);
+
+	/**
+	 * Generates the extensions XML that describes the TypeDescriptor to allow
+	 * an XMLInputSplitter or XMLOutputSplitter to be reconstructed using
+	 * consumeXML.
+	 */
+	public static Element typeDescriptorToExtensionXML(TypeDescriptor descriptor) {
+		Element result = new Element("extensions", XScuflNS);
+		Element type = null;
+		if (descriptor instanceof ComplexTypeDescriptor) {
+			type = constructElementForComplexType(
+					(ComplexTypeDescriptor) descriptor, new ArrayList<String>());
+		}
+		else if (descriptor instanceof ArrayTypeDescriptor) {
+			type = constructElementForArrayType(
+					(ArrayTypeDescriptor) descriptor, new ArrayList<String>());
+		}
+		result.addContent(type);
+		return result;
+	}
+
+	/**
+	 * Generates the TypeDescriptor structurefrom the extensions XML element
+	 * provided. This assumes that the root of the structure is <complextype/>.
+	 * This will be the same xml generated by provideXML.
+	 */
+	public static TypeDescriptor extensionXMLToTypeDescriptor(Element element) {
+		Element child = (Element) element.getChildren().get(0);
+		return buildTypeDescriptorFromElement(child,
+				new HashMap<String, TypeDescriptor>());
+	}
+
+	private static Element constructElementForArrayType(
+			ArrayTypeDescriptor descriptor, List<String> existingsTypes) {
+		Element result = new Element("arraytype", XScuflNS);
+		if (existingsTypes.contains(descriptor.getQname().toString())) {
+			result.setAttribute("id", descriptor.getQname().toString());
+			populateElement(result, descriptor);
+			result.removeAttribute("qname");
+		} else {
+			existingsTypes.add(descriptor.getQname().toString());
+			populateElement(result, descriptor);
+			Element elementType = new Element("elementtype", XScuflNS);
+			if (descriptor.getElementType() instanceof ComplexTypeDescriptor) {
+				elementType.addContent(constructElementForComplexType(
+						(ComplexTypeDescriptor) descriptor.getElementType(),
+						existingsTypes));
+			} else if (descriptor.getElementType() instanceof ArrayTypeDescriptor) {
+				elementType.addContent(constructElementForArrayType(
+						(ArrayTypeDescriptor) descriptor.getElementType(),
+						existingsTypes));
+			} else if (descriptor.getElementType() instanceof BaseTypeDescriptor) {
+				Element element = new Element("basetype", XScuflNS);
+				populateElement(element, descriptor.getElementType());
+				elementType.addContent(element);
+			}
+			result.addContent(elementType);
+		}
+		return result;
+	}
+
+	private static Element constructElementForComplexType(
+			ComplexTypeDescriptor descriptor, List<String> existingsTypes) {
+		Element result = new Element("complextype", XScuflNS);
+		if (existingsTypes.contains(descriptor.getQname().toString())) {
+			result.setAttribute("id", descriptor.getQname().toString());
+			populateElement(result, descriptor);
+			result.removeAttribute("qname");
+		} else {
+			existingsTypes.add(descriptor.getQname().toString());
+			populateElement(result, descriptor);
+			Element elements = new Element("elements", XScuflNS);
+			for (TypeDescriptor desc : descriptor.getElements()) {
+				Element element = null;
+				if (desc instanceof ComplexTypeDescriptor) {
+					element = constructElementForComplexType(
+							(ComplexTypeDescriptor) desc, existingsTypes);
+				} else if (desc instanceof ArrayTypeDescriptor) {
+					element = constructElementForArrayType(
+							(ArrayTypeDescriptor) desc, existingsTypes);
+				} else if (desc instanceof BaseTypeDescriptor) {
+					element = new Element("basetype", XScuflNS);
+					populateElement(element, desc);
+				}
+				if (element != null)
+					elements.addContent(element);
+			}
+			result.addContent(elements);
+			List<TypeDescriptor> attributeDescriptors = descriptor.getAttributes();
+			if (attributeDescriptors != null && attributeDescriptors.size() > 0) {
+				Element attributes = new Element("attributes", XScuflNS);
+				for (TypeDescriptor desc : attributeDescriptors) {
+					Element attribute = new Element("attribute", XScuflNS);
+					populateElement(attribute, desc);
+					attributes.addContent(attribute);
+				}
+				result.addContent(attributes);
+			}
+		}
+		return result;
+	}
+
+	private static void populateElement(Element element,
+			TypeDescriptor descriptor) {
+		element.setAttribute("optional", String
+				.valueOf(descriptor.isOptional()));
+		element.setAttribute("unbounded", String.valueOf(descriptor
+				.isUnbounded()));
+		if (descriptor instanceof ArrayTypeDescriptor) {
+			element.setAttribute("wrapped", String
+					.valueOf(((ArrayTypeDescriptor) descriptor).isWrapped()));
+		}
+		element.setAttribute("typename", descriptor.getType());
+		element.setAttribute("name", descriptor.getName() == null ? ""
+				: descriptor.getName());
+		element.setAttribute("qname", descriptor.getQname().toString());
+		if (descriptor.getDocumentation() != null){
+           Element annotationElement =
+                   new Element("annotation", Namespace.getNamespace("xsd", "http://www.w3.org/2001/XMLSchema"));
+           Element documentationElemenet =
+                    new Element("documentation", Namespace.getNamespace("xsd", "http://www.w3.org/2001/XMLSchema"));
+            documentationElemenet.setText(descriptor.getDocumentation());
+            annotationElement.addContent(documentationElemenet);
+            element.addContent(annotationElement);
+		}
+
+	}
+
+	private static TypeDescriptor buildTypeDescriptorFromElement(
+			Element element, HashMap<String, TypeDescriptor> existingsTypes) {
+		TypeDescriptor result = null;
+		if (element.getAttributeValue("id") != null) {
+			TypeDescriptor stored = existingsTypes.get(element
+					.getAttributeValue("id"));
+			if (stored == null)
+				logger.fatal("Missing reference to parent type with id="
+						+ element.getAttributeValue("id"));
+			else {
+				result = createFromCache(stored, element);
+			}
+		}
+
+		if (result == null) {
+			if (element.getName().equalsIgnoreCase("complextype")) {
+				result = new ComplexTypeDescriptor();
+				populateDescriptor(element, result);
+				existingsTypes.put(result.getQname().toString(), result);
+				Element elements = element.getChild("elements", XScuflNS);
+				for (Iterator<?> iterator = elements.getChildren().iterator(); iterator
+						.hasNext();) {
+					Element childElement = (Element) iterator.next();
+					((ComplexTypeDescriptor) result).getElements().add(
+							buildTypeDescriptorFromElement(childElement,
+									existingsTypes));
+				}
+				Element attributes = element.getChild("attributes", XScuflNS);
+				if (attributes != null) {
+					for (Iterator<?> iterator = attributes.getChildren().iterator(); iterator
+					.hasNext();) {
+						Element childElement = (Element) iterator.next();
+						((ComplexTypeDescriptor) result).getAttributes().add(
+								buildTypeDescriptorFromElement(childElement,
+										existingsTypes));
+					}
+				}
+
+			} else if (element.getName().equalsIgnoreCase("arraytype")) {
+
+				result = new ArrayTypeDescriptor();
+				populateDescriptor(element, result);
+				existingsTypes.put(result.getQname().toString(), result);
+				Element elementType = element.getChild("elementtype", XScuflNS);
+				((ArrayTypeDescriptor) result)
+						.setElementType(buildTypeDescriptorFromElement(
+								(Element) elementType.getChildren().get(0),
+								existingsTypes));
+				if (element.getAttribute("wrapped") != null) {
+					((ArrayTypeDescriptor) result).setWrapped(element
+							.getAttributeValue("wrapped").equalsIgnoreCase(
+									"true"));
+				} else {
+					// prior to the addition of the wrapped attribute, in the
+					// majority of cases an array
+					// would not be wrapped if it was flagged as unbounded.
+					((ArrayTypeDescriptor) result).setWrapped(!result
+							.isUnbounded());
+				}
+
+			} else if (element.getName().equalsIgnoreCase("basetype")) {
+				result = new BaseTypeDescriptor();
+				populateDescriptor(element, result);
+			} else if (element.getName().equalsIgnoreCase("attribute")) {
+				result = new AttributeTypeDescriptor();
+				populateDescriptor(element, result);
+			} else if (element.getName().equalsIgnoreCase("attribute")) {
+				result = new AttributeTypeDescriptor();
+				populateDescriptor(element, result);
+			}
+		}
+
+		return result;
+	}
+
+	/**
+	 * Performs a shallow copy of the descriptor stored, but updates its name,
+	 * isbounded and optional This means that descriptors of the same type do
+	 * not need to be repeated throught the stored XML but also takes into
+	 * account parameters of the same type may have different name and
+	 * attributes to that stored
+	 * 
+	 * @param descriptor
+	 * @param element
+	 * @return
+	 */
+	private static TypeDescriptor createFromCache(TypeDescriptor descriptor,
+			Element element) {
+		TypeDescriptor result = null;
+		if (descriptor instanceof ArrayTypeDescriptor) {
+			ArrayTypeDescriptor array = new ArrayTypeDescriptor();
+			array.setQname(descriptor.getQname());
+			array.setElementType(((ArrayTypeDescriptor) descriptor)
+					.getElementType());
+			array.setWrapped(((ArrayTypeDescriptor) descriptor).isWrapped());
+			result = array;
+		} else if (descriptor instanceof ComplexTypeDescriptor) {
+			ComplexTypeDescriptor complex = new ComplexTypeDescriptor();
+			complex.setQname(descriptor.getQname());
+			complex.setElements(((ComplexTypeDescriptor) descriptor)
+					.getElements());
+			result = complex;
+		} else {
+			throw new IllegalArgumentException("Unexpected type descriptor: "
+					+ descriptor);
+		}
+		result.setType(descriptor.getType());
+
+		String name = element.getAttributeValue("name");
+		result.setName(name != null ? name : descriptor.getName());
+
+		String optional = element.getAttributeValue("optional");
+		if (optional != null) {
+			result.setOptional(optional.equalsIgnoreCase("true"));
+		} else {
+			result.setOptional(descriptor.isOptional());
+		}
+
+		String unbounded = element.getAttributeValue("unbounded");
+		if (unbounded != null) {
+			result.setUnbounded(unbounded.equalsIgnoreCase("true"));
+		} else {
+			result.setUnbounded(descriptor.isUnbounded());
+		}
+
+		return result;
+	}
+
+	private static void populateDescriptor(Element element,
+			TypeDescriptor result) {
+		result.setName(element.getAttributeValue("name"));
+		result.setType(element.getAttributeValue("typename"));
+		result.setOptional(element.getAttributeValue("optional")
+				.equalsIgnoreCase("true"));
+		result.setUnbounded(element.getAttributeValue("unbounded")
+				.equalsIgnoreCase("true"));
+
+		Element annotationChild =
+               element.getChild("annotation", Namespace.getNamespace("xsd", "http://www.w3.org/2001/XMLSchema"));
+        if (annotationChild != null){
+           List documentationChildren = annotationChild
+                    .getChildren("documentation", Namespace.getNamespace("xsd", "http://www.w3.org/2001/XMLSchema"));
+			 
+           String documentation = "";
+            for (Object documentationChild : documentationChildren) {
+                documentation += ((Element)documentationChild).getText();
+            }
+            if (!documentation.isEmpty()){
+               result.setDocumentation(documentation);
+            }
+        }
+
+		// qname has been added since 1.3.2-RC1 so need to test if missing for
+		// older workflows
+		// if missing it is resolved to an empty namespace and typename:
+		// {}typename
+		String qname = element.getAttributeValue("qname");
+		if (qname != null)
+			result.setQnameFromString(qname);
+	}
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/c8b66752/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/parser/TypeDescriptorTest.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/parser/TypeDescriptorTest.java b/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/parser/TypeDescriptorTest.java
new file mode 100644
index 0000000..c7be469
--- /dev/null
+++ b/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/parser/TypeDescriptorTest.java
@@ -0,0 +1,240 @@
+/*
+ * Copyright (C) 2003 The University of Manchester 
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.  Authorship
+ * of the modifications may be determined from the ChangeLog placed at
+ * the end of this file.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ ****************************************************************
+ * Source code information
+ * -----------------------
+ * Filename           $RCSfile: TypeDescriptorTest.java,v $
+ * Revision           $Revision: 1.2 $
+ * Release status     $State: Exp $
+ * Last modified on   $Date: 2007/11/30 12:13:38 $
+ *               by   $Author: sowen70 $
+ * Created on 17-May-2006
+ *****************************************************************/
+package net.sf.taverna.wsdl.parser;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+public class TypeDescriptorTest extends TestCase {
+
+	// array of strings
+	public void testRetrieveSignitureForArrayDescriptor() {
+		ArrayTypeDescriptor desc = new ArrayTypeDescriptor();
+		desc.setName("AnArray");
+		desc.setType("arrayofstring");
+
+		BaseTypeDescriptor base = new BaseTypeDescriptor();
+		base.setName("");
+		base.setType("string");
+
+		desc.setElementType(base);
+
+		String[] names = new String[1];
+		Class<?>[] types = new Class[1];
+
+		List<TypeDescriptor> params = new ArrayList<TypeDescriptor>();
+		params.add(desc);
+		TypeDescriptor.retrieveSignature(params, names, types);
+
+		assertEquals("AnArray", names[0]);
+		assertEquals(String[].class, types[0]);
+	}
+
+	// array of strings, but type for array is defined as string
+	// (which is logically warped, but some wsdl's describe their string arrays
+	// this way).
+	public void testRetrieveSignitureForArrayDescriptor3() {
+		ArrayTypeDescriptor desc = new ArrayTypeDescriptor();
+		desc.setName("AnArray");
+		desc.setType("string");
+
+		BaseTypeDescriptor base = new BaseTypeDescriptor();
+		base.setName("");
+		base.setType("string");
+
+		desc.setElementType(base);
+
+		String[] names = new String[1];
+		Class<?>[] types = new Class[1];
+
+		List<TypeDescriptor> params = new ArrayList<TypeDescriptor>();
+		params.add(desc);
+		TypeDescriptor.retrieveSignature(params, names, types);
+
+		assertEquals("AnArray", names[0]);
+		assertEquals(String[].class, types[0]);
+	}
+
+	// array of complex types
+	public void testRetrieveSignitureForArrayDescriptor2() {
+		ArrayTypeDescriptor desc = new ArrayTypeDescriptor();
+		desc.setName("AnArray");
+		desc.setType("complextype");
+
+		ComplexTypeDescriptor complex = new ComplexTypeDescriptor();
+		complex.setName("complex");
+		complex.setType("complextype");
+
+		desc.setElementType(complex);
+
+		String[] names = new String[1];
+		Class<?>[] types = new Class[1];
+
+		List<TypeDescriptor> params = new ArrayList<TypeDescriptor>();
+		params.add(desc);
+		TypeDescriptor.retrieveSignature(params, names, types);
+
+		assertEquals("AnArray", names[0]);
+		assertEquals(org.w3c.dom.Element.class, types[0]);
+	}
+
+	public void testForCyclicTrue() {
+		ComplexTypeDescriptor a = new ComplexTypeDescriptor();
+		a.setName("a");
+		a.setType("outertype");
+
+		ComplexTypeDescriptor b = new ComplexTypeDescriptor();
+		b.setName("b");
+		b.setType("middletype");
+
+		ComplexTypeDescriptor c = new ComplexTypeDescriptor();
+		c.setName("c");
+		c.setType("innertype");
+
+		a.getElements().add(b);
+		b.getElements().add(c);
+		c.getElements().add(a);
+
+		assertTrue("should be identified as cyclic", TypeDescriptor.isCyclic(a));
+	}
+
+	public void testForCyclicTrueWithArray() {
+		ComplexTypeDescriptor a = new ComplexTypeDescriptor();
+		a.setName("a");
+		a.setType("outertype");
+
+		ArrayTypeDescriptor b = new ArrayTypeDescriptor();
+		b.setName("b");
+		b.setType("arraytype");
+
+		ComplexTypeDescriptor c = new ComplexTypeDescriptor();
+		c.setName("c");
+		c.setType("innertype");
+
+		a.getElements().add(b);
+		b.setElementType(c);
+		c.getElements().add(a);
+
+		assertTrue("should be identified as cyclic", TypeDescriptor.isCyclic(a));
+	}
+
+	public void testForCyclicFalse() {
+		ComplexTypeDescriptor a = new ComplexTypeDescriptor();
+		a.setName("a");
+		a.setType("person");
+
+		ComplexTypeDescriptor b = new ComplexTypeDescriptor();
+		b.setName("b");
+		b.setType("name");
+
+		ComplexTypeDescriptor c = new ComplexTypeDescriptor();
+		c.setName("c");
+		c.setType("age");
+
+		a.getElements().add(b);
+		a.getElements().add(c);
+
+		assertFalse("should be not identified as cyclic", TypeDescriptor
+				.isCyclic(a));
+	}
+
+	public void testQNameAsString() {
+		ComplexTypeDescriptor a = new ComplexTypeDescriptor();
+		a.setQnameFromString("{URI}localPart");
+		assertEquals("URI", a.getQname().getNamespaceURI());
+		assertEquals("localPart", a.getQname().getLocalPart());
+
+		a = new ComplexTypeDescriptor();
+		a.setQnameFromString("{}localPart");
+		assertEquals("", a.getQname().getNamespaceURI());
+		assertEquals("localPart", a.getQname().getLocalPart());
+	}
+	
+	public void testBaseTypeKnownSigniture() {
+		TypeDescriptor decimal=new BaseTypeDescriptor();
+		decimal.setName("adecimal");
+		decimal.setType("decimal");
+		
+		List<TypeDescriptor> params=new ArrayList<TypeDescriptor>();
+		String [] names=new String[1];
+		Class<?> [] types=new Class[1];
+		params.add(decimal);
+		TypeDescriptor.retrieveSignature(params, names, types);
+		
+		assertEquals("should only be 1 type",1,types.length);
+		assertEquals("should only be 1 name",1,names.length);
+		
+		assertEquals("name should be adecimal","adecimal",names[0]);
+		assertEquals("type should be double",Double.TYPE,types[0]);
+	}
+	
+	public void testBaseTypeUnrecognisedSigniture() {
+		TypeDescriptor date=new BaseTypeDescriptor();
+		date.setName("adate");
+		date.setType("date");
+		
+		List<TypeDescriptor> params=new ArrayList<TypeDescriptor>();
+		String [] names=new String[1];
+		Class<?> [] types=new Class[1];
+		params.add(date);
+		TypeDescriptor.retrieveSignature(params, names, types);
+		
+		assertEquals("should only be 1 type",1,types.length);
+		assertEquals("should only be 1 name",1,names.length);
+		
+		assertEquals("name should be adecimal","adate",names[0]);
+		assertEquals("type should be string",String.class,types[0]);
+	}
+	
+	public void testComplex() {
+		TypeDescriptor complex=new ComplexTypeDescriptor();
+		complex.setName("acomplex");
+		complex.setType("complextype");
+		
+		List<TypeDescriptor> params=new ArrayList<TypeDescriptor>();
+		String [] names=new String[1];
+		Class<?> [] types=new Class[1];
+		params.add(complex);
+		TypeDescriptor.retrieveSignature(params, names, types);
+		
+		assertEquals("should only be 1 type",1,types.length);
+		assertEquals("should only be 1 name",1,names.length);
+		
+		assertEquals("name should be adecimal","acomplex",names[0]);
+		assertEquals("type should be string",org.w3c.dom.Element.class,types[0]);
+	}
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/c8b66752/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/parser/WSDLParserTest.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/parser/WSDLParserTest.java b/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/parser/WSDLParserTest.java
new file mode 100644
index 0000000..f111619
--- /dev/null
+++ b/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/parser/WSDLParserTest.java
@@ -0,0 +1,295 @@
+/*******************************************************************************
+ * Copyright (C) 2007 The University of Manchester   
+ * 
+ *  Modifications to the initial code base are copyright of their
+ *  respective authors, or their employers as appropriate.
+ * 
+ *  This program is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public License
+ *  as published by the Free Software Foundation; either version 2.1 of
+ *  the License, or (at your option) any later version.
+ *    
+ *  This program is distributed in the hope that it will be useful, but
+ *  WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *    
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.wsdl.parser;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.net.URL;
+import java.util.List;
+
+import javax.wsdl.Operation;
+import javax.xml.namespace.QName;
+
+import net.sf.taverna.wsdl.testutils.WSDLTestHelper;
+
+import org.junit.Test;
+
+public class WSDLParserTest {
+	
+	@Test
+	public void testGetOperations() throws Exception {
+		WSDLParser parser = new WSDLParser(wsdlResourcePath("eutils/eutils_lite.wsdl"));
+		List<Operation> operations = parser.getOperations();
+		assertEquals(
+				"wrong number of operations found (wsdl may have changed)", 12,
+				operations.size());
+		Operation op = operations.get(0);
+		assertEquals("wrong name for first operation", "run_eGquery", op
+				.getName());
+		assertEquals("wrong style", "document", parser.getStyle());
+	}
+
+	private String wsdlResourcePath(String wsdlName) throws Exception {
+		return WSDLTestHelper.wsdlResourcePath(wsdlName);
+	}
+
+	@Test
+	public void testGetActionURI() throws Exception {
+		WSDLParser parser = new WSDLParser(wsdlResourcePath("eutils/eutils_lite.wsdl"));
+		String actionURI = parser.getSOAPActionURI("run_eInfo");
+		assertEquals("action uri is wrong", "einfo", actionURI);
+	}
+
+	@Test
+	public void testComplexTypeFromImport() throws Exception {
+		WSDLParser parser = new WSDLParser(wsdlResourcePath("eutils/eutils_lite.wsdl"));
+
+		List<TypeDescriptor> inputs = parser
+				.getOperationInputParameters("run_eInfo");
+		List<TypeDescriptor> outputs = parser
+				.getOperationOutputParameters("run_eInfo");
+		assertEquals("wrong number of inputs", 1, inputs.size());
+		assertEquals("wrong number of outputs", 1, outputs.size());
+		assertTrue("input should be complex",
+				inputs.get(0) instanceof ComplexTypeDescriptor);
+		ComplexTypeDescriptor complexTypeDesc = (ComplexTypeDescriptor) inputs
+				.get(0);
+		assertEquals("wrong name", "parameters", complexTypeDesc.getName());
+		assertEquals("wrong number of elements", 3, complexTypeDesc
+				.getElements().size());
+
+		TypeDescriptor typeDesc = complexTypeDesc
+				.getElements().get(0);
+
+		assertEquals("wrong name", "db", typeDesc.getName());
+		assertEquals("wrong type", "string", typeDesc.getType());
+		assertTrue("db should be optional", typeDesc.isOptional());
+		assertFalse("db should not be unbounded", typeDesc.isUnbounded());
+
+		typeDesc = complexTypeDesc.getElements().get(1);
+		assertEquals("wrong name", "tool", typeDesc.getName());
+		assertEquals("wrong type", "string", typeDesc.getType());
+		assertTrue("tool should be optional", typeDesc.isOptional());
+		assertFalse("tool should not be unbounded", typeDesc.isUnbounded());
+
+		typeDesc = complexTypeDesc.getElements().get(2);
+		assertEquals("wrong name", "email", typeDesc.getName());
+		assertEquals("wrong type", "string", typeDesc.getType());
+		assertTrue("email should be optional", typeDesc.isOptional());
+		assertFalse("email should not be unbounded", typeDesc.isUnbounded());
+	}
+
+	@Test
+	public void testNestedComplexTypes() throws Exception {
+		WSDLParser parser = new WSDLParser(wsdlResourcePath("bind.wsdl"));
+
+		List<TypeDescriptor> inputs = parser
+				.getOperationInputParameters("BIVGetComplexRecord");
+		List<TypeDescriptor> outputs = parser
+				.getOperationOutputParameters("BIVGetComplexRecord");
+
+		assertEquals("wrong number of inputs", 1, inputs.size());
+		assertEquals("wrong number of outputs", 1, outputs.size());
+
+		assertEquals("wrong name for input", "bid", (inputs
+				.get(0)).getName());
+		assertEquals("wrong type for input", "int", (inputs
+				.get(0)).getType());
+
+		assertEquals("wrong name for output", "BIVComplex",
+				(outputs.get(0)).getName());
+		assertEquals("wrong type for output", "BIVComplex",
+				(outputs.get(0)).getType());
+		assertTrue("wrong descriptor class for output",
+				outputs.get(0) instanceof ComplexTypeDescriptor);
+
+		ComplexTypeDescriptor typeDesc = (ComplexTypeDescriptor) outputs.get(0);
+		assertEquals("wrong number of inner elements", 3, typeDesc
+				.getElements().size());
+		assertEquals("wrong name for first element", "bid",
+				(typeDesc.getElements().get(0)).getName());
+		assertEquals("wrong name for 2nd element", "spokeModel",
+				(typeDesc.getElements().get(1)).getName());
+		assertEquals("wrong name for 3rd element", "subunit",
+				(typeDesc.getElements().get(2)).getName());
+
+		assertTrue("3rd element should be instance of ArrayTypeDescriptor",
+				typeDesc.getElements().get(2) instanceof ArrayTypeDescriptor);
+		ArrayTypeDescriptor arrayTypeDesc = (ArrayTypeDescriptor) typeDesc
+				.getElements().get(2);
+
+		assertEquals("wrong type for 3rd element", "BIVMolecule", arrayTypeDesc
+				.getType());
+
+		typeDesc = (ComplexTypeDescriptor) arrayTypeDesc.getElementType();
+
+		assertEquals("wrong type for 3rd element", "BIVMolecule", typeDesc
+				.getType());
+
+		assertEquals("wrong number of elements in nested complex type", 7,
+				typeDesc.getElements().size());
+		assertEquals("wrong name for first element", "id",
+				(typeDesc.getElements().get(0)).getName());
+		assertEquals("wrong type for first element", "int",
+				(typeDesc.getElements().get(0)).getType());
+
+		assertEquals("wrong name for last element", "smid-hits",
+				(typeDesc.getElements().get(6)).getName());
+		assertEquals("wrong type for last element", "int",
+				(typeDesc.getElements().get(6)).getType());
+	}
+	
+	@Test
+	public void testMissingStyleInBinding() throws Exception {
+		WSDLParser parser = new WSDLParser(wsdlResourcePath("SBWReader.wsdl"));
+		assertEquals("Style should default to document if missing", "document",
+				parser.getStyle());
+	}
+
+	@Test
+	public void testBaseTypes() throws Exception {
+		WSDLParser parser = new WSDLParser(wsdlResourcePath("bind.wsdl"));
+
+		List<TypeDescriptor> inputs = parser
+				.getOperationInputParameters("BIVGetRecord");
+		assertEquals("wrong number of inputs", 1, inputs.size());
+		assertTrue("should not be base type",
+				inputs.get(0) instanceof BaseTypeDescriptor);
+		assertEquals("wrong name", "bid", (inputs.get(0))
+				.getName());
+		assertEquals("wrong type", "int", (inputs.get(0))
+				.getType());
+	}
+
+	@Test
+	public void testArrayType() throws Exception {
+		WSDLParser parser = new WSDLParser(wsdlResourcePath("bind.wsdl"));
+
+		List<TypeDescriptor> inputs = parser
+				.getOperationInputParameters("BIVGetRecords");
+		List<TypeDescriptor> outputs = parser
+				.getOperationOutputParameters("BIVGetRecords");
+		assertEquals("wrong number of inputs", 1, inputs.size());
+		assertTrue("input should be of AArrayTypeDescriptor",
+				inputs.get(0) instanceof ArrayTypeDescriptor);
+
+		ArrayTypeDescriptor arrayTypeDesc = (ArrayTypeDescriptor) inputs.get(0);
+
+		assertEquals("wrong name", "ids", arrayTypeDesc.getName());
+		assertEquals("wrong type", "ArrayOf_xsd_int", arrayTypeDesc.getType());
+
+		TypeDescriptor typeDesc = arrayTypeDesc.getElementType();
+
+		assertTrue("element should be of type BaseTypeDescriptor",
+				typeDesc instanceof BaseTypeDescriptor);
+		assertEquals("wrong type", "int", typeDesc.getType());
+
+		assertEquals("wrong number of outputs", 1, outputs.size());
+
+		assertTrue("output should be of ArrayTypeDescriptor",
+				outputs.get(0) instanceof ArrayTypeDescriptor);
+
+		arrayTypeDesc = (ArrayTypeDescriptor) outputs.get(0);
+		assertEquals("wrong name", "BIVRecords", arrayTypeDesc.getName());
+		assertEquals("wrong type", "ArrayOfBIVRecord", arrayTypeDesc.getType());
+
+		typeDesc = arrayTypeDesc.getElementType();
+
+		assertEquals("wrong type", "BIVRecord", typeDesc.getType());
+	}
+
+	@Test
+	public void testGoVizNoOutputs() throws Exception {
+		WSDLParser parser = new WSDLParser(wsdlResourcePath("GoViz.wsdl"));
+
+		List<TypeDescriptor> inputs = parser
+				.getOperationInputParameters("destroySession");
+		List<TypeDescriptor> outputs = parser
+				.getOperationOutputParameters("destroySession");
+
+		assertEquals("wrong number of inputs", 1, inputs.size());
+		assertEquals("wrong number of outputs", 0, outputs.size());
+
+		TypeDescriptor typeDesc = inputs.get(0);
+		assertTrue("input should be BaseType",
+				typeDesc instanceof BaseTypeDescriptor);
+		assertEquals("wrong name", "sessionID", typeDesc.getName());
+		assertEquals("wrong type", "string", typeDesc.getType());
+	}
+
+	@Test
+	public void testGetUseEncoded() throws Exception {
+		WSDLParser parser = new WSDLParser(wsdlResourcePath("bind.wsdl"));
+		String use = parser.getUse("BIVGetRecords");
+		assertEquals("use should be encoded", "encoded", use);
+	}
+
+	@Test
+	public void testGetUseLiteral() throws Exception {
+		WSDLParser parser = new WSDLParser(wsdlResourcePath("eutils/eutils_lite.wsdl"));
+		String use = parser.getUse("run_eInfo");
+		assertEquals("use should be literal", "literal", use);
+	}
+
+	@Test
+	public void testGetOperationNamespace() throws Exception {
+		WSDLParser parser = new WSDLParser(wsdlResourcePath("CurrencyExchangeService.wsdl"));
+		String operationNamespace = parser.getOperationNamespaceURI("getRate");
+		assertEquals("operation namespace is wrong",
+				"urn:xmethods-CurrencyExchange", operationNamespace);
+	}
+	
+	@Test
+	public void testGetOperationNamespace2() throws Exception {
+		WSDLParser parser = new WSDLParser(wsdlResourcePath("eutils/eutils_lite.wsdl"));
+		String operationNamespace = parser
+				.getOperationNamespaceURI("run_eInfo");
+		assertEquals("operation namespace is wrong",
+				"http://www.ncbi.nlm.nih.gov/soap/eutils/einfo",
+				operationNamespace);
+	}
+
+	@Test
+	public void testGetOperationElementQName() throws Exception {
+		WSDLParser parser = new WSDLParser(wsdlResourcePath("eutils/eutils_lite.wsdl"));
+		QName operationQName = parser.getOperationQname("run_eInfo");
+		assertEquals("element name is wrong", "eInfoRequest", operationQName
+				.getLocalPart());
+		assertEquals("operation namespace is wrong",
+				"http://www.ncbi.nlm.nih.gov/soap/eutils/einfo", operationQName
+						.getNamespaceURI());
+	}
+
+	@Test
+	public void testGetOperationElementQName2() throws Exception {
+		URL tav744Url = getClass().getResource(
+				"/net/sf/taverna/wsdl/parser/TAV-744/InstrumentService__.wsdl");
+		WSDLParser parser = new WSDLParser(tav744Url.toExternalForm());
+		QName operationQName = parser.getOperationQname("getList");
+		assertEquals("operation element name is wrong", "GetListRequest",
+				operationQName.getLocalPart());
+		assertEquals("operation namespace is wrong",
+				"http://InstrumentService.uniparthenope.it/InstrumentService",
+				operationQName.getNamespaceURI());
+	}
+}

http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/c8b66752/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/parser/WSRFParserTest.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/parser/WSRFParserTest.java b/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/parser/WSRFParserTest.java
new file mode 100644
index 0000000..8c6cede
--- /dev/null
+++ b/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/parser/WSRFParserTest.java
@@ -0,0 +1,57 @@
+/*******************************************************************************
+ * Copyright (C) 2007 The University of Manchester   
+ * 
+ *  Modifications to the initial code base are copyright of their
+ *  respective authors, or their employers as appropriate.
+ * 
+ *  This program is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public License
+ *  as published by the Free Software Foundation; either version 2.1 of
+ *  the License, or (at your option) any later version.
+ *    
+ *  This program is distributed in the hope that it will be useful, but
+ *  WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *    
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.wsdl.parser;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.net.URL;
+
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Check that WSDLParser can detect WSRF.
+ * Tests {@link WSDLParser#checkWSRF()}
+ * 
+ * @author Stian Soiland-Reyes
+ *
+ */
+public class WSRFParserTest {
+	
+	private URL counterServiceWSDL;
+	private WSDLParser wsdlParser;
+
+	@Before
+	public void findWSDL() {
+		String path = "wsrf/counterService/CounterService_.wsdl";
+		counterServiceWSDL = getClass().getResource(path);	
+		assertNotNull("Coult not find test WSDL " + path, counterServiceWSDL);
+	}
+	
+	@Test
+	public void isWSRF() throws Exception {
+		wsdlParser = new WSDLParser(counterServiceWSDL.toExternalForm());
+		assertTrue("Not recognized as WSRF service", wsdlParser.isWsrfService());
+	}
+
+	
+}

http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/c8b66752/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/soap/EncodedBodyBuilderTest.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/soap/EncodedBodyBuilderTest.java b/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/soap/EncodedBodyBuilderTest.java
new file mode 100644
index 0000000..141305b
--- /dev/null
+++ b/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/soap/EncodedBodyBuilderTest.java
@@ -0,0 +1,108 @@
+/*******************************************************************************
+ * Copyright (C) 2007 The University of Manchester   
+ * 
+ *  Modifications to the initial code base are copyright of their
+ *  respective authors, or their employers as appropriate.
+ * 
+ *  This program is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public License
+ *  as published by the Free Software Foundation; either version 2.1 of
+ *  the License, or (at your option) any later version.
+ *    
+ *  This program is distributed in the hope that it will be useful, but
+ *  WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *    
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.wsdl.soap;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import net.sf.taverna.wsdl.parser.WSDLParser;
+import net.sf.taverna.wsdl.testutils.LocationConstants;
+import net.sf.taverna.wsdl.testutils.WSDLTestHelper;
+
+import org.apache.axis.message.SOAPBodyElement;
+import org.junit.Test;
+
+
+public class EncodedBodyBuilderTest implements LocationConstants {
+	
+	private String wsdlResourcePath(String wsdlName) throws Exception {
+		return WSDLTestHelper.wsdlResourcePath(wsdlName);
+	}
+
+	@Test
+	public void testSimpleCase() throws Exception {
+		Map<String,Object> inputMap = new HashMap<String, Object>();
+		
+		BodyBuilder builder = createBuilder(wsdlResourcePath("TestServices-rpcencoded.wsdl"), "countString");
+		
+		assertTrue("Wrong type of builder created",builder instanceof EncodedBodyBuilder);
+		
+		inputMap.put("str", "Roger Ramjet");
+		SOAPBodyElement body = builder.build(inputMap);
+		
+		String xml = body.getAsString();
+		
+		assertTrue("Contents of body are not as expected: actual body:"+xml,xml.contains("<str xsi:type=\"xsd:string\">Roger Ramjet</str>"));
+	}
+	
+	@Test
+	public void testStringArray() throws Exception {
+		Map<String,Object> inputMap = new HashMap<String, Object>();
+		
+		BodyBuilder builder = createBuilder(wsdlResourcePath("TestServices-rpcencoded.wsdl"), "countStringArray");
+		
+		assertTrue("Wrong type of builder created",builder instanceof EncodedBodyBuilder);
+		List<String> array=new ArrayList<String>();
+		array.add("one");
+		array.add("two");
+		array.add("three");
+		inputMap.put("array", array);
+		SOAPBodyElement body = builder.build(inputMap);
+		
+		String xml = body.getAsString();
+		
+		assertTrue("Contents of body are not as expected: actual body:"+xml,xml.contains("<string>one</string><string>two</string><string>three</string>"));
+	}
+	
+	@Test
+	public void testComplexType() throws Exception {
+		BodyBuilder builder = createBuilder(wsdlResourcePath("TestServices-rpcencoded.wsdl"), "personToString");
+		
+		assertTrue("Wrong type of builder created",builder instanceof EncodedBodyBuilder);
+		
+		String p = "<Person xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><name xsi:type=\"xsd:string\">bob</name><age xsi:type=\"xsd:int\">12</age></Person>";
+		
+		Map<String,Object> inputMap = new HashMap<String, Object>();
+		
+		inputMap.put("p",p);
+		SOAPBodyElement body = builder.build(inputMap);
+		
+		String xml = body.getAsString();
+		
+		System.out.println(xml);
+		
+		assertTrue("Type definition of Person is missing",xml.contains("<p xsi:type=\"ns1:Person\">"));
+		assertFalse("There shouldn't be ns2 declaration",xml.contains("xmlns:ns2"));
+		assertTrue("Missing data content",xml.contains("<name xsi:type=\"xsd:string\">bob</name><age xsi:type=\"xsd:int\">12</age>"));
+		
+	}
+	
+	protected BodyBuilder createBuilder(String wsdl, String operation) throws Exception {
+		WSDLParser parser = new WSDLParser(wsdl);
+		
+		return BodyBuilderFactory.instance().create(parser, operation, parser.getOperationInputParameters(operation));
+	}
+}

http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/c8b66752/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/soap/LiteralBodyBuilderTest.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/soap/LiteralBodyBuilderTest.java b/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/soap/LiteralBodyBuilderTest.java
new file mode 100644
index 0000000..340f885
--- /dev/null
+++ b/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/soap/LiteralBodyBuilderTest.java
@@ -0,0 +1,170 @@
+/*******************************************************************************
+ * Copyright (C) 2007 The University of Manchester   
+ * 
+ *  Modifications to the initial code base are copyright of their
+ *  respective authors, or their employers as appropriate.
+ * 
+ *  This program is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public License
+ *  as published by the Free Software Foundation; either version 2.1 of
+ *  the License, or (at your option) any later version.
+ *    
+ *  This program is distributed in the hope that it will be useful, but
+ *  WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *    
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.wsdl.soap;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+import net.sf.taverna.wsdl.parser.WSDLParser;
+import net.sf.taverna.wsdl.testutils.LocationConstants;
+import net.sf.taverna.wsdl.testutils.WSDLTestHelper;
+
+import org.apache.axis.message.SOAPBodyElement;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.w3c.dom.Node;
+
+public class LiteralBodyBuilderTest implements LocationConstants{
+	
+	private String wsdlResourcePath(String wsdlName) throws Exception {
+		return WSDLTestHelper.wsdlResourcePath(wsdlName);
+	}
+
+	@Test
+	public void testUnqualifiedNamespaces() throws Exception {
+		BodyBuilder builder = createBuilder(wsdlResourcePath("whatizit.wsdl"), "queryPmid");
+		
+		assertTrue("Is is the wrong type, it should be LiteralBodyBuilder",builder instanceof LiteralBodyBuilder);
+		
+		String parameters = "<parameters xmlns=\"http://www.ebi.ac.uk/webservices/whatizit/ws\"><pipelineName xmlns=\"\">swissProt</pipelineName><pmid xmlns=\"\">1234</pmid></parameters>";
+		Map<String,Object> inputMap = new HashMap<String, Object>();
+		inputMap.put("parameters", parameters);
+		
+		SOAPBodyElement body = builder.build(inputMap);
+		
+		String xml = body.getAsString();
+		
+		assertTrue("Content of body is incorrect in the definition of the pipelineName and pmid:"+xml,xml.contains("<pipelineName xmlns=\"\">swissProt</pipelineName><pmid xmlns=\"\">1234</pmid>"));
+		assertTrue("Wrapping element should have its namespace declared",xml.contains("<ns1:queryPmid"));
+	}
+	
+	@Test
+	public void testQualifiedUnwrapped() throws Exception {
+		BodyBuilder builder = createBuilder(wsdlResourcePath("TestServices-unwrapped.wsdl"), "countString");
+		
+		assertTrue("Is is the wrong type, it should be LiteralBodyBuilder",builder instanceof LiteralBodyBuilder);
+		Map<String,Object>inputMap = new HashMap<String, Object>();
+		inputMap.put("str", "bob");
+		
+		String xml = builder.build(inputMap).getAsString();
+		
+		assertEquals("XML should containe qualifed namespace for str",xml,"<ns1:str xmlns:ns1=\"http://testing.org\">bob</ns1:str>");
+	}
+	
+	@Test
+	public void testUnwrappedSimple() throws Exception {
+		BodyBuilder builder = createBuilder(wsdlResourcePath("TestServices-unwrapped.wsdl"), "countString");
+		
+		assertTrue("Wrong type of builder, it should be Literal based",builder instanceof LiteralBodyBuilder);
+		
+		Map<String,Object> inputMap = new HashMap<String, Object>();
+		inputMap.put("str", "12345");
+		
+		SOAPBodyElement body = builder.build(inputMap);
+		
+		assertEquals("Input element should be named str:","str",body.getNodeName());
+		assertEquals("Value should be 12345:","12345",body.getFirstChild().getNextSibling().getNodeValue());
+	}
+	
+	@Test
+	public void testUnwrappedArray() throws Exception {
+		BodyBuilder builder = createBuilder(wsdlResourcePath("TestServices-unwrapped.wsdl"), "countStringArray");
+		
+		assertTrue("Wrong type of builder, it should be Literal based",builder instanceof LiteralBodyBuilder);
+		
+		Map<String,Object> inputMap = new HashMap<String, Object>();
+		inputMap.put("array", "<array><item>1</item><item>2</item><item>3</item></array>");
+		
+		SOAPBodyElement body = builder.build(inputMap);
+		
+		String xml = body.getAsString();
+		assertEquals("Outer element should be named array. xml = "+xml,"array",body.getNodeName());
+		
+		Node itemElement = body.getFirstChild().getNextSibling();
+		assertEquals("Array element should be named item. xml = "+xml,"item",itemElement.getNodeName());
+		assertEquals("First Array element should have the value '1'. xml = "+xml,"1",itemElement.getFirstChild().getNodeValue());
+	}
+	
+	@Test 
+	public void testOperationElementNameEUtils() throws Exception {
+		BodyBuilder builder = createBuilder(wsdlResourcePath("eutils/eutils_lite.wsdl"), "run_eInfo");
+
+		assertTrue("Wrong type of builder, it should be Literal based",builder instanceof LiteralBodyBuilder);
+		Map<String,Object> inputMap = new HashMap<String, Object>();
+		inputMap.put("parameters",
+		// Note: Don't use xmlns="" as it would also affect <parameters>
+				// - which should not affect the namespace of the soap body
+				// element. The element qname of the SOAPBodyElement should be
+				// determined by the schema only
+				"<parameters xmlns:e='http://www.ncbi.nlm.nih.gov/soap/eutils/einfo'>"
+						+ "<e:db>database</e:db>" + "<e:tool>myTool</e:tool>"
+						+ "<e:email>nobody@nowhere.net</e:email>"
+						+ "</parameters>");
+		SOAPBodyElement body = builder.build(inputMap);
+		assertEquals("QName of SOAP body's element did not match expected qname ", 
+				new QName("http://www.ncbi.nlm.nih.gov/soap/eutils/einfo", "eInfoRequest"), 
+				body.getQName());
+	}
+	
+	@Test 
+	public void testOperationElementNameTAV744() throws Exception {
+		URL tav744Url = getClass().getResource(
+				"/net/sf/taverna/wsdl/parser/TAV-744/InstrumentService__.wsdl");
+		
+		BodyBuilder builder = createBuilder(tav744Url.toExternalForm(), "getList");
+
+		assertTrue("Wrong type of builder, it should be Literal based",builder instanceof LiteralBodyBuilder);
+		Map<String,Object> inputMap = new HashMap<String, Object>();
+		// No inputs
+		SOAPBodyElement body = builder.build(inputMap);
+		assertEquals("QName of SOAP body's element did not match expected qname ", 
+				new QName("http://InstrumentService.uniparthenope.it/InstrumentService", "GetListRequest"), 
+				body.getQName());
+	}
+	
+	@Test
+	public void testRPCLiteral() throws Exception {
+		BodyBuilder builder = createBuilder(wsdlResourcePath("MyService-rpc-literal.wsdl"), "countString");
+		
+		assertTrue("Wrong type of builder, it should be Literal based",builder instanceof LiteralBodyBuilder);
+		
+		Map<String,Object> inputMap = new HashMap<String, Object>();
+		inputMap.put("str", "abcdef");
+		
+		SOAPBodyElement body = builder.build(inputMap);
+		
+		assertEquals("Outer element should be named countString","countString",body.getNodeName());
+		Node strNode = body.getFirstChild();
+		assertEquals("Inner element should be called 'str'","str",strNode.getNodeName());
+		assertEquals("str content should be abcdef","abcdef",strNode.getFirstChild().getNextSibling().getNodeValue());
+	}
+	
+	protected BodyBuilder createBuilder(String wsdl, String operation) throws Exception {
+		WSDLParser parser = new WSDLParser(wsdl);
+		return BodyBuilderFactory.instance().create(parser, operation, parser.getOperationInputParameters(operation));
+	}
+}

http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/c8b66752/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/soap/SOAPResponseEncodedTest.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/soap/SOAPResponseEncodedTest.java b/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/soap/SOAPResponseEncodedTest.java
new file mode 100644
index 0000000..ab5e7a2
--- /dev/null
+++ b/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/soap/SOAPResponseEncodedTest.java
@@ -0,0 +1,97 @@
+/*
+ * Copyright (C) 2003 The University of Manchester 
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.  Authorship
+ * of the modifications may be determined from the ChangeLog placed at
+ * the end of this file.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ ****************************************************************
+ * Source code information
+ * -----------------------
+ * Filename           $RCSfile: SOAPResponseEncodedTest.java,v $
+ * Revision           $Revision: 1.4 $
+ * Release status     $State: Exp $
+ * Last modified on   $Date: 2008/08/29 16:15:54 $
+ *               by   $Author: sowen70 $
+ * Created on 08-May-2006
+ *****************************************************************/
+package net.sf.taverna.wsdl.soap;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.ByteArrayInputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import net.sf.taverna.wsdl.parser.WSDLParser;
+import net.sf.taverna.wsdl.testutils.LocationConstants;
+import net.sf.taverna.wsdl.testutils.WSDLTestHelper;
+
+import org.apache.axis.message.SOAPBodyElement;
+import org.junit.Test;
+import org.w3c.dom.Document;
+
+public class SOAPResponseEncodedTest  implements LocationConstants {
+	private String wsdlResourcePath(String wsdlName) throws Exception {
+		return WSDLTestHelper.wsdlResourcePath(wsdlName);
+	}
+	
+	@SuppressWarnings("unchecked")
+	@Test
+	public void testSimpleRPC() throws Exception {
+		
+		WSDLParser wsdlParser = new WSDLParser(wsdlResourcePath("ma.wsdl"));
+
+		String xml1 = "<ns1:whatGeneInStageResponse soapenv:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:ns1=\"urn:hgu.webservice.services\" xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"><whatGeneInStageReturn soapenc:arrayType=\"ns2:GeneExpressedQueryShortDetails[0]\" xsi:type=\"soapenc:Array\" xmlns:ns2=\"http://SubmissionQuery.WSDLGenerated.hgu\" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><agene xsi:type=\"string\">a gene</agene></whatGeneInStageReturn></ns1:whatGeneInStageResponse>";
+
+		List<SOAPBodyElement> response = new ArrayList<SOAPBodyElement>();
+
+		DocumentBuilder builder = DocumentBuilderFactory.newInstance()
+				.newDocumentBuilder();
+		Document doc = builder.parse(new ByteArrayInputStream(xml1.getBytes()));
+		response.add(new SOAPBodyElement(doc.getDocumentElement()));
+
+		SOAPResponseEncodedParser parser = new SOAPResponseEncodedParser(wsdlParser.getOperationOutputParameters("whatGeneInStage"));
+		parser.setStripAttributes(true);
+
+		Map outputMap = parser.parse(response);
+
+		assertNotNull("no output map returned", outputMap);
+
+		assertEquals("map should contain 1 element", 1, outputMap.size());
+
+		Object result = outputMap.get("whatGeneInStageReturn");
+
+		assertNotNull(
+				"output map should have contained entry for 'whatGeneInStageReturn'",
+				result);
+
+		assertEquals("output data should be a string", String.class, result.getClass());
+
+		assertEquals(
+				"incorrect xml content in output",
+				"<whatGeneInStageReturn><agene>a gene</agene></whatGeneInStageReturn>",
+				result.toString());
+	}
+}

http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/c8b66752/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/soap/SOAPResponseLiteralTest.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/soap/SOAPResponseLiteralTest.java b/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/soap/SOAPResponseLiteralTest.java
new file mode 100644
index 0000000..f756371
--- /dev/null
+++ b/taverna-wsdl-generic/src/test/java/net/sf/taverna/wsdl/soap/SOAPResponseLiteralTest.java
@@ -0,0 +1,174 @@
+/*
+ * Copyright (C) 2003 The University of Manchester 
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.  Authorship
+ * of the modifications may be determined from the ChangeLog placed at
+ * the end of this file.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ ****************************************************************
+ * Source code information
+ * -----------------------
+ * Filename           $RCSfile: SOAPResponseLiteralTest.java,v $
+ * Revision           $Revision: 1.2 $
+ * Release status     $State: Exp $
+ * Last modified on   $Date: 2007/11/30 12:13:37 $
+ *               by   $Author: sowen70 $
+ * Created on 11-May-2006
+ *****************************************************************/
+package net.sf.taverna.wsdl.soap;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.ByteArrayInputStream;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import net.sf.taverna.wsdl.parser.BaseTypeDescriptor;
+import net.sf.taverna.wsdl.parser.ComplexTypeDescriptor;
+import net.sf.taverna.wsdl.parser.TypeDescriptor;
+
+import org.apache.axis.message.SOAPBodyElement;
+import org.junit.Test;
+import org.w3c.dom.Document;
+
+public class SOAPResponseLiteralTest{
+
+	@SuppressWarnings("unchecked")
+	@Test
+	public void testLiteralParserResultInTextBlock() throws Exception {
+		List response = new ArrayList();
+		String xml = "<testResponse><out>&lt;data name=&quot;a&quot;&gt;some data&lt;/data&gt;&lt;data name=&quot;b&quot;&gt;some more data&lt;/data&gt;</out></testResponse>";
+		DocumentBuilder builder = DocumentBuilderFactory.newInstance()
+				.newDocumentBuilder();
+		Document doc = builder.parse(new ByteArrayInputStream(xml.getBytes()));
+
+		response.add(new SOAPBodyElement(doc.getDocumentElement()));
+
+		TypeDescriptor descriptor = new ComplexTypeDescriptor();
+		descriptor.setName("testResponse");
+
+		SOAPResponseLiteralParser parser = new SOAPResponseLiteralParser(
+				Collections.singletonList(descriptor));
+
+		Map outputMap = parser.parse(response);
+
+		assertNotNull("no output map returned", outputMap);
+		assertEquals("map should contain 1 element", 1, outputMap.size());
+
+		Object testResponse = outputMap.get("testResponse");
+
+		assertNotNull("there should be an output named 'testReponse'",
+				testResponse);
+		assertEquals("output data should be a string", String.class,
+				testResponse.getClass());
+
+		assertEquals(
+				"xml is wrong",
+				"<testResponse><out>&lt;data name=&quot;a&quot;&gt;some data&lt;/data&gt;&lt;data name=&quot;b&quot;&gt;some more data&lt;/data&gt;</out></testResponse>",
+				testResponse.toString());
+	}
+
+	@SuppressWarnings("unchecked")
+	@Test
+	public void testLiteralParser() throws Exception {
+		List response = new ArrayList();
+		String xml = "<testResponse><out><data name=\"a\">some data</data><data name=\"b\">some more data</data></out></testResponse>";
+		DocumentBuilder builder = DocumentBuilderFactory.newInstance()
+				.newDocumentBuilder();
+		Document doc = builder.parse(new ByteArrayInputStream(xml.getBytes()));
+
+		response.add(new SOAPBodyElement(doc.getDocumentElement()));
+
+		TypeDescriptor descriptor = new ComplexTypeDescriptor();
+		descriptor.setName("testResponse");
+
+		SOAPResponseLiteralParser parser = new SOAPResponseLiteralParser(
+				Collections.singletonList(descriptor));
+
+		Map outputMap = parser.parse(response);
+
+		assertNotNull("no output map returned", outputMap);
+		assertEquals("map should contain 1 element", 1, outputMap.size());
+
+		Object testResponse = outputMap.get("testResponse");
+
+		assertNotNull("there should be an output named 'testReponse'",
+				testResponse);
+		assertEquals("output data should be a string", String.class,
+				testResponse.getClass());
+
+		assertEquals(
+				"xml is wrong",
+				"<testResponse><out><data name=\"a\">some data</data><data name=\"b\">some more data</data></out></testResponse>",
+				testResponse.toString());
+	}
+	
+	@SuppressWarnings("unchecked")
+	@Test
+	public void testUnwrappedLiteralResponseParsing() throws Exception {
+		List response = new ArrayList();
+		
+		String xml = "<getStringReturn xmlns=\"http://testing.org\">a string</getStringReturn>";
+		DocumentBuilder builder = DocumentBuilderFactory.newInstance()
+		.newDocumentBuilder();
+		Document doc = builder.parse(new ByteArrayInputStream(xml.getBytes()));
+
+		response.add(new SOAPBodyElement(doc.getDocumentElement()));
+
+		TypeDescriptor descriptor = new BaseTypeDescriptor();
+		descriptor.setName("getStringReturn");
+		
+		SOAPResponseLiteralParser parser = new SOAPResponsePrimitiveLiteralParser(
+				Collections.singletonList(descriptor));
+
+		Map outputMap = parser.parse(response);
+
+		assertNotNull("no output map returned", outputMap);
+		assertEquals("map should contain 1 element", 1, outputMap.size());
+
+		Object stringReturn = outputMap.get("getStringReturn");
+		
+		assertEquals("value of data returned is wrong","a string",stringReturn.toString());
+	}
+	
+	@SuppressWarnings("unchecked")
+	@Test
+	public void testEmptyResponse() throws Exception {
+		List response = new ArrayList();
+		
+		TypeDescriptor descriptor = new BaseTypeDescriptor();
+		descriptor.setName("getStringReturn");
+		
+		SOAPResponseLiteralParser parser = new SOAPResponseLiteralParser(
+				Collections.singletonList(descriptor));
+
+		Map outputMap = parser.parse(response);
+
+		assertNotNull("no output map returned", outputMap);
+		assertEquals("map should contain 1 element", 0, outputMap.size());
+	}
+
+}
+