You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@taverna.apache.org by re...@apache.org on 2015/03/19 14:43:40 UTC
[12/35] incubator-taverna-common-activities git commit: package names
changed to org.apache.taverna.*
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/433612be/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
deleted file mode 100644
index 031de03..0000000
--- a/taverna-wsdl-generic/src/main/java/net/sf/taverna/wsdl/xmlsplitter/XMLInputSplitter.java
+++ /dev/null
@@ -1,290 +0,0 @@
-/*******************************************************************************
- * 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/433612be/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
deleted file mode 100644
index 4ad5061..0000000
--- a/taverna-wsdl-generic/src/main/java/net/sf/taverna/wsdl/xmlsplitter/XMLOutputSplitter.java
+++ /dev/null
@@ -1,212 +0,0 @@
-/*
- * 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/433612be/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
deleted file mode 100644
index 6ec1720..0000000
--- a/taverna-wsdl-generic/src/main/java/net/sf/taverna/wsdl/xmlsplitter/XMLSplitterExecutionException.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*******************************************************************************
- * 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/433612be/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
deleted file mode 100644
index e6e0fbb..0000000
--- a/taverna-wsdl-generic/src/main/java/net/sf/taverna/wsdl/xmlsplitter/XMLSplitterSerialisationHelper.java
+++ /dev/null
@@ -1,359 +0,0 @@
-/*
- * 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/433612be/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/ArrayTypeDescriptor.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/ArrayTypeDescriptor.java b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/ArrayTypeDescriptor.java
new file mode 100644
index 0000000..32364ee
--- /dev/null
+++ b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/ArrayTypeDescriptor.java
@@ -0,0 +1,56 @@
+/*
+* 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.taverna.wsdl.parser;
+
+
+/**
+ * A TypeDescriptor that specifically describes an array type
+ *
+ */
+public class ArrayTypeDescriptor extends TypeDescriptor {
+ private TypeDescriptor elementType;
+ private boolean wrapped;
+
+ public boolean isWrapped() {
+ return wrapped;
+ }
+
+ public void setWrapped(boolean wrapped) {
+ this.wrapped = wrapped;
+ }
+
+ public TypeDescriptor getElementType() {
+ return elementType;
+ }
+
+ public void setElementType(TypeDescriptor elementType) {
+ this.elementType = elementType;
+ }
+
+ @Override
+ public String getName() {
+ String name = super.getName();
+ if (name == null) {
+ return "ArrayOf" + getElementType().getType();
+ }
+ return name;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/433612be/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/AttributeTypeDescriptor.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/AttributeTypeDescriptor.java b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/AttributeTypeDescriptor.java
new file mode 100644
index 0000000..ff80b01
--- /dev/null
+++ b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/AttributeTypeDescriptor.java
@@ -0,0 +1,29 @@
+/*
+* 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.taverna.wsdl.parser;
+
+/**
+ * A TypeDescriptor specifically for attributes.
+ *
+ * @author David Withers
+ */
+public class AttributeTypeDescriptor extends TypeDescriptor {
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/433612be/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/BaseTypeDescriptor.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/BaseTypeDescriptor.java b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/BaseTypeDescriptor.java
new file mode 100644
index 0000000..deed212
--- /dev/null
+++ b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/BaseTypeDescriptor.java
@@ -0,0 +1,31 @@
+/*
+* 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.taverna.wsdl.parser;
+
+
+/**
+ * A TypeDescriptor specifically for basic types (e.g. string, float, int,
+ * base64binary)
+ *
+ */
+public class BaseTypeDescriptor extends TypeDescriptor {
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/433612be/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/ComplexTypeDescriptor.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/ComplexTypeDescriptor.java b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/ComplexTypeDescriptor.java
new file mode 100644
index 0000000..e428277
--- /dev/null
+++ b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/ComplexTypeDescriptor.java
@@ -0,0 +1,71 @@
+/*
+* 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.taverna.wsdl.parser;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * A TypeDescriptor that specifically describes a complex type
+ *
+ */
+public class ComplexTypeDescriptor extends TypeDescriptor {
+ private List<TypeDescriptor> elements = new ArrayList<TypeDescriptor>();
+ private List<TypeDescriptor> attributes = new ArrayList<TypeDescriptor>();
+
+ public List<TypeDescriptor> getElements() {
+ return elements;
+ }
+
+ public void setElements(List<TypeDescriptor> elements) {
+ this.elements = elements;
+ }
+
+ public TypeDescriptor elementForName(String name) {
+ TypeDescriptor result=null;
+ for (TypeDescriptor desc : getElements()) {
+ if (desc.getName().equals(name)) {
+ result=desc;
+ break;
+ }
+ }
+ return result;
+ }
+
+ public List<TypeDescriptor> getAttributes() {
+ return attributes;
+ }
+
+ public void setAttributes(List<TypeDescriptor> attributes) {
+ this.attributes = attributes;
+ }
+
+ public TypeDescriptor attributeForName(String name) {
+ TypeDescriptor result=null;
+ for (TypeDescriptor desc : getAttributes()) {
+ if (desc.getName().equals(name)) {
+ result=desc;
+ break;
+ }
+ }
+ return result;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/433612be/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/GenericWSDLParser.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/GenericWSDLParser.java b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/GenericWSDLParser.java
new file mode 100644
index 0000000..73c22aa
--- /dev/null
+++ b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/GenericWSDLParser.java
@@ -0,0 +1,52 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+
+package org.apache.taverna.wsdl.parser;
+
+import java.util.LinkedHashMap;
+import java.util.List;
+import javax.xml.namespace.QName;
+import org.apache.ws.commons.schema.XmlSchemaObject;
+
+/**
+ * @author Dmitry Repchevsky
+ */
+
+public interface GenericWSDLParser {
+
+ String getDocumentBaseURI();
+ List<QName> getServices();
+ List<String> getPorts(QName serviceName);
+ List<String> getOperations(String portName);
+ WSRF_Version isWSRFPort(String portName);
+
+ String getOperationStyle(String portName, String operationName) throws UnknownOperationException;
+ String getSOAPActionURI(String portName, String operationName) throws UnknownOperationException;
+ QName getRPCRequestMethodName(String portName, String operationName) throws UnknownOperationException;
+ QName getRPCResponseMethodName(String portName, String operationName) throws UnknownOperationException;
+ String getSoapInputUse(String portName, String operationName) throws UnknownOperationException;
+ String getSoapOutputUse(String portName, String operationName) throws UnknownOperationException;
+
+ String getSoapAddress(String portName);
+ String getOperationEndpointLocation(String operationName) throws UnknownOperationException;
+ String getOperationDocumentation(String portName, String operationName) throws UnknownOperationException;
+
+ LinkedHashMap<String, XmlSchemaObject> getInputParameters(String portName, String operationName) throws UnknownOperationException;
+ LinkedHashMap<String, XmlSchemaObject> getOutputParameters(String portName, String operationName) throws UnknownOperationException;
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/433612be/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/LSInputImpl.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/LSInputImpl.java b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/LSInputImpl.java
new file mode 100644
index 0000000..f917af8
--- /dev/null
+++ b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/LSInputImpl.java
@@ -0,0 +1,118 @@
+/*
+* 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.taverna.wsdl.parser;
+
+import java.io.InputStream;
+import java.io.Reader;
+import org.w3c.dom.ls.LSInput;
+import org.xml.sax.InputSource;
+
+/**
+ * @author Dmitry Repchevsky
+ */
+
+public class LSInputImpl implements LSInput {
+ private String baseURI;
+ private InputSource source;
+
+ public LSInputImpl(InputSource source) {
+ this.source = source;
+ }
+
+ @Override
+ public Reader getCharacterStream() {
+ return source.getCharacterStream();
+ }
+
+ @Override
+ public void setCharacterStream(Reader reader) {
+ source.setCharacterStream(reader);
+ }
+
+ @Override
+ public InputStream getByteStream() {
+ return source.getByteStream();
+ }
+
+ @Override
+ public void setByteStream(InputStream input) {
+ source.setByteStream(input);
+ }
+
+ @Override
+ public String getStringData() {
+ return null;
+ }
+
+ @Override
+ public void setStringData(String stringData) {
+
+ }
+
+ @Override
+ public String getSystemId() {
+ return source.getSystemId();
+ }
+
+ @Override
+ public void setSystemId(String systemId) {
+ source.setSystemId(systemId);
+ }
+
+ @Override
+ public String getPublicId() {
+ return source.getPublicId();
+ }
+
+ @Override
+ public void setPublicId(String publicId) {
+ source.setPublicId(publicId);
+ }
+
+ @Override
+ public String getBaseURI() {
+ return baseURI;
+ }
+
+ @Override
+ public void setBaseURI(String baseURI) {
+ this.baseURI = baseURI;
+ }
+
+ @Override
+ public String getEncoding() {
+ return source.getEncoding();
+ }
+
+ @Override
+ public void setEncoding(String encoding) {
+ source.setEncoding(encoding);
+ }
+
+ @Override
+ public boolean getCertifiedText() {
+ return false;
+ }
+
+ @Override
+ public void setCertifiedText(boolean certifiedText) {
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/433612be/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/SchemaResolver.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/SchemaResolver.java b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/SchemaResolver.java
new file mode 100644
index 0000000..78c6a35
--- /dev/null
+++ b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/SchemaResolver.java
@@ -0,0 +1,139 @@
+/*
+* 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.taverna.wsdl.parser;
+
+import java.io.CharArrayWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringReader;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.ArrayList;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+import org.apache.ws.commons.schema.resolver.URIResolver;
+import org.w3c.dom.Element;
+import org.w3c.dom.ls.LSInput;
+import org.w3c.dom.ls.LSResourceResolver;
+import org.xml.sax.EntityResolver;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+/**
+ * Schema Resolver that resolves schemas for various APIs at a time (SAX, DOM and Apache XML Schema 2.0)
+ * It also used for keeping a List of DOM Elements defined in WSDL Types.
+ *
+ * @author Dmitry Repchevsky
+ */
+
+public class SchemaResolver extends ArrayList<Element> implements EntityResolver, URIResolver, LSResourceResolver {
+ public final String baseUri;
+
+ public SchemaResolver(String baseUri) {
+ this.baseUri = baseUri;
+ }
+
+ @Override
+ public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
+ if (publicId != null) {
+ for (Element element : this) {
+ String targetNamespace = element.getAttribute("targetNamespace");
+ if (publicId.equals(targetNamespace)) {
+ InputSource source = getInputSource(element);
+ source.setPublicId(publicId);
+
+ return source;
+ }
+ }
+ }
+
+ return resolveEntity2(publicId, systemId, this.baseUri);
+ }
+
+
+ @Override
+ public InputSource resolveEntity(String targetNamespace, String schemaLocation, String baseUri) {
+ try {
+ return baseUri == null || baseUri.isEmpty() ? resolveEntity(targetNamespace, schemaLocation) :
+ resolveEntity2(targetNamespace, schemaLocation, baseUri);
+ }
+ catch(Exception ex) {}
+
+ return null;
+ }
+
+ private InputSource resolveEntity2(String targetNamespace, String schemaLocation, String baseUri) throws IOException
+ {
+ URL url = new URL(new URL(baseUri), schemaLocation);
+
+ InputStream in = url.openStream();
+ InputSource source = new InputSource(in);
+ source.setPublicId(targetNamespace);
+ source.setSystemId(url.toString());
+
+ return source;
+ }
+
+ public InputSource getInputSource(Element element) throws IOException {
+ CharArrayWriter writer = new CharArrayWriter();
+
+ try {
+ TransformerFactory.newInstance().newTransformer().transform(new DOMSource(element), new StreamResult(writer));
+ } catch (TransformerException ex) {
+ throw new IOException(ex.getMessage(), ex);
+ }
+ InputSource source = new InputSource(new StringReader(writer.toString()));
+
+ String publicId = element.getAttribute("targetNamespace");
+ source.setPublicId(publicId);
+
+ if (publicId.isEmpty()) {
+ //source.setPublicId(element.getNamespaceURI());
+ // if the element has no targetNamespace defined, provide a synthetic systemId, so both publicId = "" + systenId never clashes.
+ URI base = URI.create(baseUri);
+ URI synthetic;
+ try {
+ synthetic = new URI(base.getScheme(), base.getUserInfo(), base.getHost(), base.getPort(), base.getPath(), base.getQuery(), String.valueOf(element.hashCode()));
+ } catch(URISyntaxException ex) {
+ synthetic = base; // never ever happens
+ }
+ source.setSystemId(synthetic.toString());
+ } else {
+ source.setSystemId(baseUri);
+ }
+
+ return source;
+ }
+
+ @Override
+ public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) {
+ try {
+ InputSource source = resolveEntity(publicId != null ? publicId : namespaceURI, systemId);
+ if (source != null) {
+ return new LSInputImpl(source);
+ }
+ } catch (Exception ex) {}
+
+ return null;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/433612be/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/TypeDescriptor.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/TypeDescriptor.java b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/TypeDescriptor.java
new file mode 100644
index 0000000..f7bcbcf
--- /dev/null
+++ b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/TypeDescriptor.java
@@ -0,0 +1,297 @@
+/*
+* 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.taverna.wsdl.parser;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+
+/**
+ * Base class for all descriptors for type
+ *
+ */
+public class TypeDescriptor {
+ private String name;
+
+ private String type;
+
+ private boolean optional;
+
+ private boolean unbounded;
+
+ private QName qname;
+
+ private boolean nillable = false;
+
+ private String documentation;
+
+ public boolean isNillable() {
+ return nillable;
+ }
+
+ public QName getQname() {
+ if (qname != null)
+ return qname;
+ else if (type != null) {
+ return new QName("", type);
+ }
+ return new QName("", "");
+ }
+
+ public void setQnameFromString(String qname) {
+ String[] split = qname.split("}");
+ if (split.length == 1) {
+ this.qname = new QName("", qname);
+ } else {
+ String uri = split[0];
+ uri = uri.replaceAll("\\{", "");
+ uri = uri.replaceAll("\\}", "");
+ this.qname = new QName(uri, split[1]);
+ }
+ }
+
+ public String getMimeType() {
+ return translateJavaType(determineClassType(this));
+ }
+
+ public void setQname(QName qname) {
+ this.qname = qname;
+ }
+
+ public String getNamespaceURI() {
+ return getQname().getNamespaceURI();
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ int i;
+ if ((i = name.lastIndexOf('>')) != -1) {
+ this.name = name.substring(i + 1);
+ } else {
+ this.name = name;
+ }
+ }
+
+ /**
+ * @return the depth determined from the syntactic mime type of the original
+ * port. i.e text/plain = 0, l('text/plain') = 1, l(l('text/plain')) =
+ * 2, ... etc.
+ */
+ public int getDepth() {
+ String syntacticType=getMimeType();
+ if (syntacticType == null) {
+ return 0;
+ } else {
+ return syntacticType.split("l\\(").length - 1;
+ }
+ }
+
+ public boolean isOptional() {
+ return optional;
+ }
+
+ public void setOptional(boolean optional) {
+ this.optional = optional;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public boolean isUnbounded() {
+ return unbounded;
+ }
+
+ public void setUnbounded(boolean unbounded) {
+ this.unbounded = unbounded;
+ }
+
+ @Override
+ public String toString() {
+ return name + ":" + type;
+ }
+
+ /**
+ * Translate a java type into a taverna type string
+ */
+ public static String translateJavaType(Class<?> type) {
+ if (type.equals(String[].class)) {
+ return "l('text/plain')";
+ } else if (type.equals(org.w3c.dom.Element.class)) {
+ return "'text/xml'";
+ }
+
+ else if (type.equals(org.w3c.dom.Element[].class)) {
+ return "l('text/xml')";
+ } else if (type.equals(byte[].class)) {
+ return "'application/octet-stream'";
+ } else {
+ return "'text/plain'";
+ }
+ }
+
+ public static void retrieveSignature(List<TypeDescriptor> params, String[] names,
+ Class<?>[] types) {
+ for (int i = 0; i < names.length; i++) {
+ TypeDescriptor descriptor = params.get(i);
+ names[i] = descriptor.getName();
+
+ types[i]=determineClassType(descriptor);
+ }
+ }
+
+ private static Class<?> determineClassType(TypeDescriptor descriptor) {
+ String s = descriptor.getType().toLowerCase();
+ Class<?> type;
+ if (descriptor instanceof ArrayTypeDescriptor) {
+ if (((ArrayTypeDescriptor) descriptor).getElementType() instanceof BaseTypeDescriptor) {
+ type = String[].class;
+ } else if (((ArrayTypeDescriptor) descriptor).isUnbounded()) {
+ type = org.w3c.dom.Element[].class;
+ }
+ else {
+ type = org.w3c.dom.Element.class;
+ }
+ } else {
+ if ("string".equals(s)) {
+ type = String.class;
+ } else if ("double".equals(s) || "decimal".equals(s)) {
+ type = Double.TYPE;
+ } else if ("float".equals(s)) {
+ type = Float.TYPE;
+ } else if ("int".equals(s) || "integer".equals(s)) {
+ type = Integer.TYPE;
+ } else if ("boolean".equals(s)) {
+ type = Boolean.TYPE;
+ } else if ("base64binary".equals(s)) {
+ type = byte[].class;
+ } else {
+ //treat any other basetype as a String.
+ if (descriptor instanceof BaseTypeDescriptor) {
+ type=String.class;
+ }
+ else {
+ type = org.w3c.dom.Element.class;
+ }
+ }
+ }
+ return type;
+ }
+
+ /**
+ * Determines whether the descriptor describes a data structure that is
+ * cyclic, i.e. contains inner elements that contain references to outer
+ * elements, leading to a state of infinate recursion.
+ *
+ * @param descriptor
+ * @return
+ */
+ public static boolean isCyclic(TypeDescriptor descriptor) {
+ boolean result = false;
+ if (!(descriptor instanceof BaseTypeDescriptor)) {
+ if (descriptor instanceof ComplexTypeDescriptor) {
+ result = testForCyclic((ComplexTypeDescriptor) descriptor,
+ new ArrayList<String>());
+ } else {
+ result = testForCyclic((ArrayTypeDescriptor) descriptor,
+ new ArrayList<String>());
+ }
+ }
+ return result;
+ }
+
+ @SuppressWarnings("unchecked")
+ private static boolean testForCyclic(ComplexTypeDescriptor descriptor,
+ List<String> parents) {
+ boolean result = false;
+ String descKey = descriptor.getQname().toString();
+ if (parents.contains(descKey))
+ result = true;
+ else {
+ parents.add(descKey);
+ List elements = descriptor.getElements();
+ for (Iterator iterator = elements.iterator(); iterator.hasNext();) {
+ TypeDescriptor elementDescriptor = (TypeDescriptor) iterator
+ .next();
+ if (elementDescriptor instanceof ComplexTypeDescriptor) {
+ result = testForCyclic(
+ (ComplexTypeDescriptor) elementDescriptor, parents);
+ } else if (elementDescriptor instanceof ArrayTypeDescriptor) {
+ result = testForCyclic(
+ (ArrayTypeDescriptor) elementDescriptor, parents);
+ }
+
+ if (result)
+ break;
+ }
+
+ parents.remove(descKey);
+ }
+ return result;
+ }
+
+ private static boolean testForCyclic(ArrayTypeDescriptor descriptor,
+ List<String> parents) {
+ boolean result = false;
+ String descKey = descriptor.getQname().toString();
+ if (parents.contains(descKey))
+ result = true;
+ else {
+ parents.add(descKey);
+
+ TypeDescriptor elementDescriptor = descriptor
+ .getElementType();
+ if (elementDescriptor instanceof ComplexTypeDescriptor) {
+ result = testForCyclic(
+ (ComplexTypeDescriptor) elementDescriptor, parents);
+ } else if (elementDescriptor instanceof ArrayTypeDescriptor) {
+ result = testForCyclic((ArrayTypeDescriptor) elementDescriptor,
+ parents);
+ }
+
+ parents.remove(descKey);
+ }
+ return result;
+ }
+
+ public void setNillable(boolean nillable) {
+ this.nillable = nillable;
+
+
+ }
+
+ public String getDocumentation() {
+ return documentation;
+ }
+
+ public void setDocumentation(String documentation) {
+ this.documentation = documentation;
+ }
+}