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/09/16 17:22:19 UTC
[1/8] incubator-taverna-common-activities git commit: experimental
wsdl-generic based on XSD schema
Repository: incubator-taverna-common-activities
Updated Branches:
refs/heads/wsdl-xsd-experimental [created] 979e61552
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/complex_type5.xsd
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/complex_type5.xsd b/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/complex_type5.xsd
new file mode 100644
index 0000000..431ea47
--- /dev/null
+++ b/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/complex_type5.xsd
@@ -0,0 +1,30 @@
+<!--
+-->
+<xs:schema
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://example.com"
+ targetNamespace="http://example.com"
+ attributeFormDefault="unqualified"
+ elementFormDefault="qualified"
+ version="1.0">
+
+ <xs:element name="person" type="tns:person"/>
+
+ <xs:complexType name="person">
+ <xs:complexContent>
+ <xs:extension base="tns:human">
+ <xs:sequence>
+ <xs:element name="hobby" type="xs:string"/>
+ </xs:sequence>
+ </xs:extension>
+ </xs:complexContent>
+ </xs:complexType>
+
+ <xs:complexType name="human">
+ <xs:sequence>
+ <xs:element name="name" type="xs:string"/>
+ <xs:element name="surname" type="xs:string"/>
+ </xs:sequence>
+ </xs:complexType>
+
+</xs:schema>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/complex_type6.xml
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/complex_type6.xml b/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/complex_type6.xml
new file mode 100644
index 0000000..1592f44
--- /dev/null
+++ b/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/complex_type6.xml
@@ -0,0 +1 @@
+<person xmlns="http://example.com" name="Napoleon" surname="Bonaparte" hobby="war"/>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/complex_type6.xsd
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/complex_type6.xsd b/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/complex_type6.xsd
new file mode 100644
index 0000000..8a943e4
--- /dev/null
+++ b/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/complex_type6.xsd
@@ -0,0 +1,29 @@
+<!--
+-->
+<xs:schema
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://example.com"
+ targetNamespace="http://example.com"
+ attributeFormDefault="unqualified"
+ elementFormDefault="qualified"
+ version="1.0">
+
+ <xs:element name="person" type="tns:person"/>
+ <xs:attributeGroup name="hobby">
+ <xs:attribute name="hobby" type="xs:string" />
+ </xs:attributeGroup>
+
+ <xs:complexType name="person">
+ <xs:complexContent>
+ <xs:extension base="tns:human">
+ <xs:attributeGroup ref="tns:hobby"/>
+ </xs:extension>
+ </xs:complexContent>
+ </xs:complexType>
+
+ <xs:complexType name="human">
+ <xs:attribute name="name" type="xs:string"/>
+ <xs:attribute name="surname" type="xs:string"/>
+ </xs:complexType>
+
+</xs:schema>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/complex_type7.xml
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/complex_type7.xml b/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/complex_type7.xml
new file mode 100644
index 0000000..3d7a469
--- /dev/null
+++ b/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/complex_type7.xml
@@ -0,0 +1,6 @@
+<person xmlns="http://example.com">
+ <fullname>
+ <name>Napoleon</name>
+ <surname>Bonaparte</surname>
+ </fullname>
+</person>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/complex_type7.xsd
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/complex_type7.xsd b/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/complex_type7.xsd
new file mode 100644
index 0000000..5fb3c32
--- /dev/null
+++ b/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/complex_type7.xsd
@@ -0,0 +1,28 @@
+<!--
+-->
+<xs:schema
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://example.com"
+ targetNamespace="http://example.com"
+ attributeFormDefault="unqualified"
+ elementFormDefault="qualified"
+ version="1.0">
+
+ <xs:element name="person" type="tns:person"/>
+
+ <xs:element name="fullname">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element name="name" type="xs:string"/>
+ <xs:element name="surname" type="xs:string"/>
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+
+ <xs:complexType name="person">
+ <xs:sequence>
+ <xs:element ref="tns:fullname" />
+ </xs:sequence>
+ </xs:complexType>
+
+</xs:schema>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/complex_type8.xml
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/complex_type8.xml b/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/complex_type8.xml
new file mode 100644
index 0000000..4a942e4
--- /dev/null
+++ b/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/complex_type8.xml
@@ -0,0 +1,4 @@
+<person xmlns="http://example.com">
+ <hobby>war</hobby>
+ <hobby>archeology</hobby>
+</person>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/complex_type8.xsd
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/complex_type8.xsd b/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/complex_type8.xsd
new file mode 100644
index 0000000..d84fc6f
--- /dev/null
+++ b/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/complex_type8.xsd
@@ -0,0 +1,31 @@
+<!--
+-->
+<xs:schema
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://example.com"
+ targetNamespace="http://example.com"
+ attributeFormDefault="unqualified"
+ elementFormDefault="qualified"
+ version="1.0">
+
+ <xs:element name="person" type="tns:person"/>
+
+ <xs:complexType name="person">
+ <xs:complexContent>
+ <xs:restriction base="tns:human">
+ <xs:sequence>
+ <xs:element name="hobby" type="xs:string" minOccurs="2" maxOccurs="unbounded" />
+ </xs:sequence>
+ </xs:restriction>
+ </xs:complexContent>
+ </xs:complexType>
+
+ <xs:complexType name="human">
+ <xs:sequence>
+ <xs:element name="name" type="xs:string"/>
+ <xs:element name="surname" type="xs:string"/>
+ </xs:sequence>
+ </xs:complexType>
+
+
+</xs:schema>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/simple_type1.xml
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/simple_type1.xml b/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/simple_type1.xml
new file mode 100644
index 0000000..40275b2
--- /dev/null
+++ b/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/simple_type1.xml
@@ -0,0 +1 @@
+<name xmlns="http://example.com">Napoleon</name>
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/simple_type1.xsd
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/simple_type1.xsd b/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/simple_type1.xsd
new file mode 100644
index 0000000..4a7c84b
--- /dev/null
+++ b/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/simple_type1.xsd
@@ -0,0 +1,15 @@
+<xs:schema
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://example.com"
+ targetNamespace="http://example.com"
+ attributeFormDefault="unqualified"
+ elementFormDefault="qualified"
+ version="1.0">
+
+ <xs:element name="name" type="tns:name"/>
+
+ <xs:simpleType name="name">
+ <xs:restriction base="xs:string"/>
+ </xs:simpleType>
+
+</xs:schema>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/simple_type2.xml
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/simple_type2.xml b/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/simple_type2.xml
new file mode 100644
index 0000000..607b2af
--- /dev/null
+++ b/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/simple_type2.xml
@@ -0,0 +1 @@
+<surname xmlns="http://example.com">Bonaparte</surname>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/simple_type2.xsd
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/simple_type2.xsd b/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/simple_type2.xsd
new file mode 100644
index 0000000..a9258b6
--- /dev/null
+++ b/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/simple_type2.xsd
@@ -0,0 +1,15 @@
+<xs:schema
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://example.com"
+ targetNamespace="http://example.com"
+ attributeFormDefault="unqualified"
+ elementFormDefault="qualified"
+ version="1.0">
+
+ <xs:element name="surname">
+ <xs:simpleType>
+ <xs:restriction base="xs:string"/>
+ </xs:simpleType>
+ </xs:element>
+
+</xs:schema>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/xml-schema-example-001.xml
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/xml-schema-example-001.xml b/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/xml-schema-example-001.xml
new file mode 100644
index 0000000..61a4e2b
--- /dev/null
+++ b/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/xml-schema-example-001.xml
@@ -0,0 +1,9 @@
+<publication doi="10.1371/journal.pone.0107889">
+ <title>BioSWR - Semantic Web Services Registry for Bioinformatics.</title>
+ <journal>PLoS ONE</journal>
+ <author>
+ <first_name>Dmitry</first_name>
+ <second_name>Repchevsky</second_name>
+ <affiliation>Barcelona Supercomputing Center</affiliation>
+ </author>
+</publication>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/xml-schema-example-001.xsd
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/xml-schema-example-001.xsd b/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/xml-schema-example-001.xsd
new file mode 100644
index 0000000..1fc1ceb
--- /dev/null
+++ b/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/xml-schema-example-001.xsd
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
+
+ <xs:element name="title" type="xs:string"/>
+ <xs:element name="affiliation" type="xs:string"/>
+
+ <xs:element name="author">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element name="first_name" type="xs:string"/>
+ <xs:element name="last_name" type="xs:string"/>
+ <xs:element ref="affiliation" minOccurs="1" maxOccurs="unbounded"/>
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+
+ <xs:element name="publication">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element ref="title"/>
+ <xs:element name="journal" type="xs:string"/>
+ <xs:element ref="author" minOccurs="1" maxOccurs="unbounded"/>
+
+ </xs:sequence>
+ <xs:attribute name="doi" type="xs:string"/>
+ </xs:complexType>
+ </xs:element>
+</xs:schema>
\ No newline at end of file
[5/8] incubator-taverna-common-activities git commit: experimental
wsdl-generic based on XSD schema
Posted by re...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/schema/XSParticle.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/schema/XSParticle.java b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/schema/XSParticle.java
new file mode 100644
index 0000000..fb10d15
--- /dev/null
+++ b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/schema/XSParticle.java
@@ -0,0 +1,193 @@
+/*
+* 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.schema;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+import org.apache.ws.commons.schema.XmlSchema;
+import org.apache.ws.commons.schema.XmlSchemaAny;
+import org.apache.ws.commons.schema.XmlSchemaCollection;
+import org.apache.ws.commons.schema.XmlSchemaElement;
+import org.apache.ws.commons.schema.XmlSchemaParticle;
+import org.apache.ws.commons.schema.XmlSchemaType;
+
+/**
+ * Represents an XML element node which is based on XML Schema particle.
+ *
+ * @author Dmitry Repchevsky
+ */
+
+public class XSParticle<T,V extends T> extends XSComponent<T,V, XmlSchemaParticle> {
+
+ public XSParticle(XmlSchemaParticle particle) {
+ super(particle);
+ }
+
+ @Override
+ public XmlSchemaType getType() {
+ if (component instanceof XmlSchemaElement) {
+ XmlSchemaElement element = XSParser.getElement((XmlSchemaElement)component);
+ XmlSchemaType type = element.getSchemaType();
+ if (type == null) {
+ QName typeName = element.getSchemaTypeName();
+ XmlSchema schema = element.getParent();
+ XmlSchemaCollection schemaCollection = schema.getParent();
+ if (schemaCollection != null) {
+ type = schemaCollection.getTypeByQName(typeName);
+ } else {
+ type = schema.getTypeByName(typeName);
+ }
+ }
+
+ return type;
+ } else if (component instanceof XmlSchemaAny) {
+
+ }
+ return null; // ??? TODO ???
+ }
+
+ @Override
+ public QName getName() {
+ if (component instanceof XmlSchemaElement) {
+ XmlSchemaElement element = (XmlSchemaElement)component; //XSParser.getElement((XmlSchemaElement)component);
+ return element.getWireName();
+ }
+ return null;
+ }
+
+ @Override
+ public Boolean validate() {
+ Boolean isValid;
+
+ final long min = component.getMinOccurs();
+ final long max = component.getMaxOccurs();
+
+ if (max > 1) {
+ int bad = 0;
+ int good = 0;
+ int total = getChildCount();
+
+ for (int i = 0; i < total; i++) {
+ XSComponent child = (XSComponent)getChildAt(i);
+ Boolean valid = child.validate();
+ if (valid != null) {
+ if (valid) {
+ good++;
+ } else {
+ bad++;
+ }
+ }
+ }
+
+ // ALL values must be the same - otherwise FALSE
+ isValid = (bad == 0 && good == 0) ? null : bad == total ? null : good == total ? Boolean.TRUE : Boolean.FALSE;
+ } else {
+ int bad = 0;
+ int good = XSModel.getSimpleType(this) != null ? getUserObject() != null ? 1 : 0 : 0;
+
+ for (int i = 0, n = getChildCount(); i < n; i++) {
+ XSComponent child = (XSComponent)getChildAt(i);
+ Boolean valid = child.validate();
+ if (valid != null) {
+ if (valid) {
+ good++;
+ } else {
+ bad++;
+ }
+ }
+ }
+
+ isValid = good > 0 && bad > 0 ? Boolean.FALSE : bad > 0 ? min == 0 ? null : Boolean.FALSE : good > 0 ? Boolean.TRUE : null;
+ }
+
+ return isValid;
+ }
+
+ @Override
+ public void write(XMLStreamWriter stream) throws XMLStreamException {
+ Boolean isValid = validate();
+ if (isValid != null && isValid) {
+
+ final QName qname = getName();
+ final String localName = qname.getLocalPart();
+ final String namespace = qname.getNamespaceURI();
+
+ final long max = component.getMaxOccurs();
+ if (max > 1) {
+ for (int i = 0, n = getChildCount(); i < n; i++) {
+ if (namespace != null && namespace.length() > 0) {
+ final String prefix = getPrefix(stream);
+ if (prefix != null) {
+ stream.writeStartElement(prefix, localName, namespace);
+ } else {
+ stream.writeStartElement(namespace, localName);
+ }
+ } else {
+ stream.writeStartElement(localName);
+ }
+
+ XSComponent child = (XSComponent)getChildAt(i);
+ child.write(stream);
+
+ stream.writeEndElement();
+ }
+ } else {
+ if (namespace != null && namespace.length() > 0) {
+ final String prefix = getPrefix(stream);
+ if (prefix != null) {
+ stream.writeStartElement(prefix, localName, namespace);
+ } else {
+ stream.writeStartElement(namespace, localName);
+ }
+ } else {
+ stream.writeStartElement(localName);
+ }
+
+ for (int i = 0, n = getChildCount(); i < n; i++) {
+ XSComponent child = (XSComponent)getChildAt(i);
+ child.write(stream);
+ }
+
+ Object object = getUserObject();
+ if (object != null) {
+ stream.writeCharacters(object.toString());
+ }
+
+ stream.writeEndElement();
+ }
+ }
+ }
+
+ @Override
+ public String getXPath() {
+ final XSComponent parent = (XSComponent)getParent();
+ final StringBuilder xpath = new StringBuilder(parent.getXPath());
+ final QName qname = getName();
+ final String localpart = qname.getLocalPart();
+ final String namespace = qname.getNamespaceURI();
+ if (namespace.isEmpty()) {
+ xpath.append('/').append(localpart);
+ } else {
+ xpath.append("/*[namespace-uri()='").append(namespace).append("' and local-name()='").append(localpart).append("']");
+ }
+ return xpath.toString();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/schema/XSType.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/schema/XSType.java b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/schema/XSType.java
new file mode 100644
index 0000000..14c51f3
--- /dev/null
+++ b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/schema/XSType.java
@@ -0,0 +1,105 @@
+/*
+* 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.schema;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+import org.apache.ws.commons.schema.XmlSchemaType;
+
+/**
+ * The node to hold a type value.
+ * This node is used as a child of a parent particle (usually element), which
+ * cardinality is more than 1. When cardinality of the parent particle is 1
+ * there is no need to make an additional node.
+ *
+ * @author Dmitry Repchevsky
+ */
+
+public class XSType<T,V extends T> extends XSComponent<T,V, XmlSchemaType> {
+
+ public XSType(XmlSchemaType type) {
+ this(type, null);
+ }
+
+ public XSType(XmlSchemaType type, Object object) {
+ super(type, object);
+ }
+
+ @Override
+ public XmlSchemaType getType() {
+ return component;
+ }
+
+ @Override
+ public QName getName() {
+ return component.getQName();
+ }
+
+ public boolean isSimpleType() {
+ return XSModel.getSimpleType(this) != null;
+ }
+
+ @Override
+ public Boolean validate() {
+ int bad = 0;
+ int good = isSimpleType() ? getUserObject() != null ? 1 : 0 : 0;
+
+ for (int i = 0, n = getChildCount(); i < n; i++) {
+ XSComponent child = (XSComponent)getChildAt(i);
+ Boolean valid = child.validate();
+ if (valid != null) {
+ if (valid) {
+ good++;
+ } else {
+ bad++;
+ }
+ }
+ }
+
+ Boolean isValid = good > 0 ? bad > 0 ? Boolean.FALSE : Boolean.TRUE : null;
+ return isValid;
+ }
+
+ @Override
+ public void write(XMLStreamWriter stream) throws XMLStreamException {
+ Boolean isValid = validate();
+ if (isValid != null && isValid) {
+ // suppose that attributes are ALWAYS before elements
+ for (int i = 0, n = getChildCount(); i < n; i++) {
+ XSComponent child = (XSComponent)getChildAt(i);
+ child.write(stream);
+ }
+
+ if (isSimpleType()) {
+ Object object = getUserObject();
+ if (object != null) {
+ stream.writeCharacters(object.toString());
+ }
+ }
+ }
+ }
+
+ @Override
+ public String getXPath() {
+ XSComponent parent = (XSComponent)getParent();
+ return parent.getXPath() + "[position()=" + (parent.getIndex(this) + 1) + "]";
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/schema/package-info.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/schema/package-info.java b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/schema/package-info.java
new file mode 100644
index 0000000..7850453
--- /dev/null
+++ b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/schema/package-info.java
@@ -0,0 +1,6 @@
+/**
+ * Package contains simplified "flat" XML Schema tree model, which is based on
+ * Apache XML Schema 2.1 library.
+ */
+
+package org.apache.taverna.wsdl.parser.schema;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/AbstractBodyBuilder.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/AbstractBodyBuilder.java b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/AbstractBodyBuilder.java
deleted file mode 100644
index 2cd6f3e..0000000
--- a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/AbstractBodyBuilder.java
+++ /dev/null
@@ -1,373 +0,0 @@
-/*
-* 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.soap;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import javax.wsdl.WSDLException;
-import javax.xml.bind.DatatypeConverter;
-import javax.xml.namespace.QName;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.soap.SOAPElement;
-import javax.xml.soap.SOAPException;
-import javax.xml.soap.SOAPFactory;
-import org.apache.taverna.wsdl.parser.ArrayTypeDescriptor;
-import org.apache.taverna.wsdl.parser.BaseTypeDescriptor;
-import org.apache.taverna.wsdl.parser.ComplexTypeDescriptor;
-import org.apache.taverna.wsdl.parser.TypeDescriptor;
-import org.apache.taverna.wsdl.parser.UnknownOperationException;
-import org.apache.taverna.wsdl.parser.WSDLParser;
-import org.apache.log4j.Logger;
-import org.w3c.dom.Attr;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-import org.xml.sax.SAXException;
-
-@SuppressWarnings("unchecked")
-public abstract class AbstractBodyBuilder implements BodyBuilder {
-
- private static Logger logger = Logger.getLogger(AbstractBodyBuilder.class);
-
- private String style;
- private WSDLParser parser;
- private String operationName;
-
- protected enum Style {
- DOCUMENT, RPC
- };
-
- protected enum Use {
- LITERAL, ENCODED
- };
-
- protected Map<String, String> namespaceMappings;
- protected List<TypeDescriptor> inputDescriptors;
-
- public AbstractBodyBuilder(String style, WSDLParser parser,
- String operationName, List<TypeDescriptor> inputDescriptors) {
- this.style = style;
- this.parser = parser;
- this.operationName = operationName;
- this.inputDescriptors = inputDescriptors;
- }
-
- protected Style getStyle() {
- Style result = Style.DOCUMENT;
- if (style.equalsIgnoreCase("rpc")) {
- result = Style.RPC;
- } else if (style.equalsIgnoreCase("document")) {
- result = Style.DOCUMENT;
- }
- return result;
- }
-
- protected abstract Use getUse();
-
- /**
- *
- * @return the namespace for the operation
- */
- private String getOperationNamespace() throws UnknownOperationException {
- return parser.getOperationNamespaceURI(operationName);
- }
-
- private QName getOperationQname() throws UnknownOperationException {
- return parser.getOperationQname(operationName);
- }
-
- @Override
- public SOAPElement build(Map inputMap) throws WSDLException,
- ParserConfigurationException, SOAPException, IOException,
- SAXException, UnknownOperationException {
-
- List<TypeDescriptor> inputs = parser.getOperationInputParameters(operationName);
-
- namespaceMappings = generateNamespaceMappings(inputs);
-
- QName operationQname = getOperationQname();
-
- String ns = namespaceMappings.get(operationQname.getNamespaceURI());
-
- SOAPElement body = ns == null ? SOAPFactory.newInstance().createElement(operationQname) :
- SOAPFactory.newInstance().createElement(operationQname.getLocalPart(), ns, operationQname.getNamespaceURI());
-
- // its important to preserve the order of the inputs!
- for (Iterator<TypeDescriptor> iterator = inputs.iterator(); iterator.hasNext();) {
- TypeDescriptor descriptor = iterator.next();
- String inputName = descriptor.getName();
- Object dataValue = inputMap.get(inputName);
-
- body = createBodyElementForData(operationName, namespaceMappings,
- operationQname.getNamespaceURI(), body, descriptor, inputName, dataValue);
- }
-
- return body;
- }
-
-
-
- protected SOAPElement createBodyElementForData(String operationName,
- Map<String, String> namespaceMappings, String operationNamespace,
- SOAPElement body, TypeDescriptor descriptor, String inputName,
- Object dataValue) throws ParserConfigurationException,
- SAXException, IOException, UnknownOperationException, SOAPException {
- if (dataValue != null) {
- String mimeType = getMimeTypeForInputName(inputName);
- String typeName = descriptor.getType();
-
- Element el;
- if (descriptor instanceof ArrayTypeDescriptor) {
- el = createElementForArrayType(namespaceMappings, inputName,
- dataValue, descriptor, mimeType, typeName);
-
- } else {
- el = createSkeletonElementForSingleItem(namespaceMappings,
- descriptor, inputName, typeName);
- populateElementWithObjectData(mimeType, el, dataValue, descriptor);
- }
-
- body = addElementToBody(operationNamespace, body, el);
- }
- return body;
- }
-
- protected abstract SOAPElement addElementToBody(
- String operationNamespace, SOAPElement body, Element el)
- throws SOAPException;
-
- protected abstract Element createSkeletonElementForSingleItem(
- Map<String, String> namespaceMappings, TypeDescriptor descriptor,
- String inputName, String typeName);
-
- /**
- * generates an XML DOM Element for an array
- *
- * @param namespaceMappings
- * @param inputName
- * @param dataValue
- * @param descriptor
- * @param mimeType
- * @param typeName
- * @return
- * @throws ParserConfigurationException
- * @throws SAXException
- * @throws IOException
- */
- protected abstract Element createElementForArrayType(
- Map<String, String> namespaceMappings, String inputName,
- Object dataValue, TypeDescriptor descriptor, String mimeType,
- String typeName) throws ParserConfigurationException, SAXException,
- IOException, UnknownOperationException;
-
- /**
- * Populates a DOM XML Element with the contents of a List of dataValues
- *
- * @param mimeType -
- * the mime type of the data
- * @param element -
- * the Element to be populated
- * @param dataValues -
- * the List of Objects containing the data
- * @param elementType -
- * the TypeDescriptor for the element being populated
- * @throws ParserConfigurationException
- * @throws SAXException
- * @throws IOException
- */
- protected void populateElementWithList(String mimeType, Element element,
- List dataValues, TypeDescriptor elementType)
- throws ParserConfigurationException, SAXException, IOException {
- for (Iterator dataIterator = dataValues.iterator(); dataIterator
- .hasNext();) {
- Object dataItem = dataIterator.next();
- String tag;
- if (elementType instanceof BaseTypeDescriptor) {
- tag = elementType.getType();
- } else {
- tag = elementType.getName();
- }
-
- Element item = element.getOwnerDocument().createElement(tag);
- populateElementWithObjectData(mimeType, item, dataItem, elementType);
- element.appendChild(item);
- }
- }
-
- /**
- * Populates a DOM XML Element with dataValue according to its mimetype
- *
- * @param mimeType
- * @param element
- * @param dataValue
- * @param descriptor
- * @throws ParserConfigurationException
- * @throws SAXException
- * @throws IOException
- */
- protected void populateElementWithObjectData(String mimeType,
- Element element, Object dataValue, TypeDescriptor descriptor)
- throws ParserConfigurationException, SAXException, IOException {
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- factory.setNamespaceAware(true);
- DocumentBuilder builder = factory.newDocumentBuilder();
-
- if (mimeType.equals("'text/xml'")) {
- Document doc = builder.parse(new ByteArrayInputStream(dataValue
- .toString().getBytes()));
- Element documentElement = doc.getDocumentElement();
-
- if (descriptor instanceof ComplexTypeDescriptor) {
- ComplexTypeDescriptor complexType = (ComplexTypeDescriptor) descriptor;
- NamedNodeMap attributes = documentElement.getAttributes();
- if (attributes != null) {
- for (int i = 0; i < attributes.getLength(); i++) {
- Node attributeNode = attributes.item(i);
- if (attributeNode instanceof Attr) {
- Attr attribute = (Attr) attributeNode;
- TypeDescriptor typeDescriptor = complexType.attributeForName(attribute.getName());
- if (typeDescriptor != null) {
- element.setAttributeNS(typeDescriptor.getNamespaceURI(), typeDescriptor.getName(), attribute.getValue());
- }
- }
- }
- }
- }
-
- Node child = documentElement.getFirstChild();
-
- while (child != null) {
- element.appendChild(element.getOwnerDocument().importNode(
- child, true));
- child = child.getNextSibling();
- }
- } else if (mimeType.equals("'application/octet-stream'")
- && dataValue instanceof byte[]) {
- String encoded = DatatypeConverter.printBase64Binary((byte[]) dataValue);
- element.appendChild(element.getOwnerDocument().createTextNode(
- encoded));
- } else {
- element.appendChild(element.getOwnerDocument().createTextNode(
- dataValue.toString()));
- }
- }
-
- /**
- * Provides the mime type for a given input
- *
- * @param inputName
- * @return
- */
- protected String getMimeTypeForInputName(String inputName) {
- for (TypeDescriptor desc : inputDescriptors) {
- if (desc.getName().equals(inputName))
- return desc.getMimeType();
- }
- return "";
- }
-
- /**
- * Generates a map of all the namespaces for the operation and all of the
- * types required to call the operation. Namesspace prefixes (the key) start
- * with ns1 representing the operation, and continue incrementally for all
- * additional namespaces (ns2, ns3 ... etc).
- *
- * @return
- * @param inputs -
- * List of input TypeDescriptor's
- * @throws UnknownOperationException
- * @throws IOException
- */
- protected Map<String, String> generateNamespaceMappings(List inputs)
- throws UnknownOperationException, IOException {
- Map<String, String> result = new HashMap<String, String>();
- int nsCount = 2;
-
- result.put(getOperationNamespace(), "ns1");
- result.put("http://www.w3.org/2001/XMLSchema", "xsd");
- result.put("http://www.w3.org/2001/XMLSchema-instance", "xsi");
-
- for (Iterator iterator = inputs.iterator(); iterator.hasNext();) {
- TypeDescriptor descriptor = (TypeDescriptor) iterator.next();
- nsCount = mapNamespace(descriptor, new ArrayList<TypeDescriptor>(),result, nsCount);
-
- }
-
- return result;
- }
-
- /**
- * creates a namespace prefix and adds the namespace to the namespaceMap for
- * a TypeDescriptor. Further recursive calls are made if this type contains
- * addition inner elements that are not already mapped.
- *
- * @param descriptor
- * @param namespaceMap
- * @param nsCount
- * @return
- */
- protected int mapNamespace(TypeDescriptor descriptor, List<TypeDescriptor> visitedDescriptors,
- Map<String, String> namespaceMap, int nsCount) {
- if (!visitedDescriptors.contains(descriptor)) {
- visitedDescriptors.add(descriptor);
- String namespace = descriptor.getNamespaceURI();
- if (namespace != null && namespace.length() > 0
- && !namespaceMap.containsKey(namespace)) {
- namespaceMap.put(namespace, "ns" + nsCount);
- nsCount++;
- }
-
- if (descriptor instanceof ArrayTypeDescriptor) {
- nsCount = mapNamespace(((ArrayTypeDescriptor) descriptor)
- .getElementType(),visitedDescriptors, namespaceMap, nsCount);
- } else if (descriptor instanceof ComplexTypeDescriptor) {
- List elements = ((ComplexTypeDescriptor) descriptor).getElements();
- for (Iterator iterator = elements.iterator(); iterator.hasNext();) {
- nsCount = mapNamespace((TypeDescriptor) iterator.next(),visitedDescriptors,
- namespaceMap, nsCount);
- }
- }
- }
- else {
- logger.error("The descriptor: "+descriptor+" is appears to be part of a cyclic schema. Bailing out of mapping namespace.");
- }
-
- return nsCount;
- }
-
- protected Element createElementNS(String namespace, String name) {
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- factory.setNamespaceAware(true);
- try {
- DocumentBuilder builder = factory.newDocumentBuilder();
- return builder.newDocument().createElementNS(namespace, name);
- } catch (ParserConfigurationException e) {
- return null;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/AbstractSOAPResponseParser.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/AbstractSOAPResponseParser.java b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/AbstractSOAPResponseParser.java
deleted file mode 100644
index 638c410..0000000
--- a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/AbstractSOAPResponseParser.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
-* 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.soap;
-
-import java.io.StringWriter;
-import javax.xml.transform.OutputKeys;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
-import org.w3c.dom.Node;
-
-/**
- * @author Dmitry Repchevsky
- */
-
-public abstract class AbstractSOAPResponseParser implements SOAPResponseParser{
-
- public String toString(Node node) throws TransformerException {
- TransformerFactory factory = TransformerFactory.newInstance();
- Transformer transformer = factory.newTransformer();
- StringWriter writer = new StringWriter();
- transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
- transformer.transform(new DOMSource(node), new StreamResult(writer));
-
- return writer.toString();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/BodyBuilder.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/BodyBuilder.java b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/BodyBuilder.java
deleted file mode 100644
index 89a2297..0000000
--- a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/BodyBuilder.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
-* 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.soap;
-
-import java.io.IOException;
-import java.util.Map;
-import javax.wsdl.WSDLException;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.soap.SOAPElement;
-import javax.xml.soap.SOAPException;
-import org.apache.taverna.wsdl.parser.UnknownOperationException;
-import org.xml.sax.SAXException;
-
-/**
- * Interface to a class that is responsible for creating the SOAP body elements from the provided inputs
- * for invoking a SOAP based Web-service.
- *
- * @author Stuart Owen
- */
-@SuppressWarnings("unchecked")
-public interface BodyBuilder {
-
- public SOAPElement build(Map inputMap)
- throws WSDLException, ParserConfigurationException, SOAPException,
- IOException, SAXException, UnknownOperationException;
-
-}
-
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/BodyBuilderFactory.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/BodyBuilderFactory.java b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/BodyBuilderFactory.java
deleted file mode 100644
index 64842ae..0000000
--- a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/BodyBuilderFactory.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
-* 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.soap;
-
-import java.util.List;
-
-import org.apache.taverna.wsdl.parser.TypeDescriptor;
-import org.apache.taverna.wsdl.parser.UnknownOperationException;
-import org.apache.taverna.wsdl.parser.WSDLParser;
-
-/**
- * Factory that creates an appropriate BodyBuilder according to the provided WSDLProcessors style and use.
- * @author Stuart Owen
- *
- */
-public class BodyBuilderFactory {
-
- private static BodyBuilderFactory instance = new BodyBuilderFactory();
-
- public static BodyBuilderFactory instance() {
- return instance;
- }
-
- public BodyBuilder create(WSDLParser parser, String operationName, List<TypeDescriptor> inputDescriptors) throws UnknownOperationException {
- String use = parser.getUse(operationName);
- String style = parser.getStyle(operationName);
- if (use.equals("encoded")) {
- return new EncodedBodyBuilder(style, parser,operationName, inputDescriptors);
- }
- else if (use.equals("literal")) {
- return new LiteralBodyBuilder(style,parser,operationName, inputDescriptors);
- }
- return new LiteralBodyBuilder(style,parser,operationName, inputDescriptors);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/CyclicReferenceException.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/CyclicReferenceException.java b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/CyclicReferenceException.java
deleted file mode 100644
index 7f2804e..0000000
--- a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/CyclicReferenceException.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
-* 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.soap;
-
-/**
- * Exception thrown when a MultiRef based xml document is found to have cyclic
- * references when transforming into a flat XML document, therefore meaning the
- * xml cannot be transformed.
- *
- * @author sowen
- *
- */
-
-public class CyclicReferenceException extends Exception {
-
- private static final long serialVersionUID = -4051406646273085676L;
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/EncodedBodyBuilder.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/EncodedBodyBuilder.java b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/EncodedBodyBuilder.java
deleted file mode 100644
index a88ca88..0000000
--- a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/EncodedBodyBuilder.java
+++ /dev/null
@@ -1,158 +0,0 @@
-/*
-* 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.soap;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import javax.wsdl.WSDLException;
-import javax.xml.XMLConstants;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.soap.SOAPConstants;
-import javax.xml.soap.SOAPElement;
-import javax.xml.soap.SOAPException;
-import javax.xml.soap.SOAPFactory;
-import org.apache.taverna.wsdl.parser.ArrayTypeDescriptor;
-import org.apache.taverna.wsdl.parser.BaseTypeDescriptor;
-import org.apache.taverna.wsdl.parser.TypeDescriptor;
-import org.apache.taverna.wsdl.parser.UnknownOperationException;
-import org.apache.taverna.wsdl.parser.WSDLParser;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.xml.sax.SAXException;
-
-@SuppressWarnings("unchecked")
-public class EncodedBodyBuilder extends AbstractBodyBuilder {
- public EncodedBodyBuilder(String style, WSDLParser parser, String operationName, List<TypeDescriptor> inputDescriptors) {
- super(style, parser,operationName,inputDescriptors);
- }
-
- @Override
- protected Use getUse() {
- return Use.ENCODED;
- }
-
- @Override
- public SOAPElement build(Map inputMap) throws WSDLException,
- ParserConfigurationException, SOAPException, IOException,
- SAXException, UnknownOperationException {
-
- SOAPElement result = super.build(inputMap);
-
- for (Iterator iterator = namespaceMappings.keySet().iterator(); iterator.hasNext();) {
- String namespaceURI = (String) iterator.next();
- String ns = namespaceMappings.get(namespaceURI);
- result.addNamespaceDeclaration(ns, namespaceURI);
- }
-
- result.setAttributeNS(SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE, "soapenv:encodingStyle", SOAPConstants.URI_NS_SOAP_ENCODING);
-
- return result;
- }
-
- @Override
- protected Element createSkeletonElementForSingleItem(
- Map<String, String> namespaceMappings, TypeDescriptor descriptor,
- String inputName, String typeName) {
-
- Element el = createElementNS(null, inputName);
-
- String ns = namespaceMappings.get(descriptor.getNamespaceURI());
- if (ns != null) {
- el.setAttributeNS(XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI, "xsi:type", ns + ":" + descriptor.getType());
- }
- return el;
- }
-
- @Override
- protected Element createElementForArrayType(
- Map<String, String> namespaceMappings, String inputName,
- Object dataValue, TypeDescriptor descriptor, String mimeType,
- String typeName) throws ParserConfigurationException, SAXException,
- IOException, UnknownOperationException {
- DocumentBuilderFactory builderFactory = DocumentBuilderFactory
- .newInstance();
- builderFactory.setNamespaceAware(true);
- DocumentBuilder docBuilder = builderFactory.newDocumentBuilder();
-
- ArrayTypeDescriptor arrayDescriptor = (ArrayTypeDescriptor) descriptor;
- TypeDescriptor elementType = arrayDescriptor.getElementType();
- int size = 0;
-
- Element el = createElementNS(null, inputName);
-
- if (dataValue instanceof List) {
- List dataValues = (List) dataValue;
- size = dataValues.size();
- populateElementWithList(mimeType, el, dataValues, elementType);
- } else {
- // if mime type is text/xml then the data is an array in xml form,
- // else its just a single primitive element
- if (mimeType.equals("'text/xml'")) {
-
- Document doc = docBuilder.parse(new ByteArrayInputStream(
- dataValue.toString().getBytes()));
- Node child = doc.getDocumentElement().getFirstChild();
-
- while (child != null) {
- size++;
- el.appendChild(el.getOwnerDocument()
- .importNode(child, true));
- child = child.getNextSibling();
- }
- } else {
- String tag = "item";
- if (elementType instanceof BaseTypeDescriptor) {
- tag = elementType.getType();
- } else {
- tag = elementType.getName();
- }
- Element item = el.getOwnerDocument().createElement(tag);
- populateElementWithObjectData(mimeType, item, dataValue, descriptor);
- el.appendChild(item);
- }
-
- }
-
- String ns = namespaceMappings.get(elementType.getNamespaceURI());
- if (ns != null) {
- String elementNS = ns + ":" + elementType.getType() + "[" + size + "]";
- el.setAttributeNS(SOAPConstants.URI_NS_SOAP_ENCODING, "soapenc:arrayType", elementNS);
- }
-
- el.setAttributeNS(XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI, "xsi:type", "soapenc:Array");
-
- return el;
- }
-
- @Override
- protected SOAPElement addElementToBody(String operationNamespace, SOAPElement body, Element el) throws SOAPException {
- SOAPElement child = SOAPFactory.newInstance().createElement(el);
- body.addChildElement(child);
- return body;
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/JaxWSInvoker.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/JaxWSInvoker.java b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/JaxWSInvoker.java
deleted file mode 100644
index 9f0ae88..0000000
--- a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/JaxWSInvoker.java
+++ /dev/null
@@ -1,235 +0,0 @@
-/*
-* 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.soap;
-
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import javax.xml.bind.DatatypeConverter;
-import javax.xml.namespace.QName;
-import javax.xml.soap.SOAPException;
-import javax.xml.soap.SOAPMessage;
-import javax.xml.soap.SOAPPart;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.ws.BindingProvider;
-import javax.xml.ws.Dispatch;
-import javax.xml.ws.Service;
-import javax.xml.ws.handler.Handler;
-import javax.xml.ws.handler.MessageContext;
-import javax.xml.ws.handler.soap.SOAPHandler;
-import javax.xml.ws.handler.soap.SOAPMessageContext;
-import javax.xml.ws.soap.SOAPBinding;
-import org.apache.taverna.wsdl.parser.WSDLParser;
-import org.apache.ws.security.WSConstants;
-import org.apache.ws.security.WSSecurityException;
-import org.apache.ws.security.message.WSSecHeader;
-import org.apache.ws.security.message.WSSecUsernameToken;
-import org.w3c.dom.Document;
-
-/**
- * JAX-WS based invoker. The invoker uses Apache WSS4j security library.
- *
- * @author Dmitry Repchevsky
- */
-
-public class JaxWSInvoker {
-
- private Dispatch<SOAPMessage> dispatch;
-
- private String username;
- private String password;
- private WSSTokenProfile token;
-
- public JaxWSInvoker(WSDLParser parser, String portName, String operationName) {
-
- QName port_qname = null;
- for (QName service_name : parser.getServices()) {
- loop:
- for (String port_name : parser.getPorts(service_name)) {
- if (portName == null) {
- for (String operation_name : parser.getOperations(port_name)) {
- if (operation_name.equals(operationName)) {
- port_qname = new QName(port_name);
- break loop;
- }
- }
- } else if (portName.equals(port_name)) {
- port_qname = new QName(portName);
- break;
- }
- }
-
- if (port_qname != null) {
- // found the port in this service
- Service service = Service.create(service_name);
- String endpoint = parser.getOperationEndpointLocation(port_qname.getLocalPart());
- service.addPort(port_qname, SOAPBinding.SOAP11HTTP_BINDING, endpoint); // TODO: SOAP version
- dispatch = service.createDispatch(port_qname, SOAPMessage.class, javax.xml.ws.Service.Mode.MESSAGE);
-
- List<Handler> chain = new ArrayList<Handler>();//Arrays.asList(new InvokerHandler());
- chain.add(new WSSHandler());
-
- dispatch.getBinding().setHandlerChain(chain);
-
- break;
- }
- }
-
- // assert(dispatch != null)
-
- if (operationName != null) {
- try {
- String soapAction = parser.getSOAPActionURI(operationName);
- if (soapAction != null) {
- Map<String, Object> rc = dispatch.getRequestContext();
- rc.put(BindingProvider.SOAPACTION_USE_PROPERTY, Boolean.TRUE);
- rc.put(BindingProvider.SOAPACTION_URI_PROPERTY, soapAction);
- }
- }
- catch(Exception ex) {}
- }
- }
-
- /**
- * Sets user credentials. If there is no WSS token profile is defined HTTP security is used
- *
- * @param username
- * @param password
- */
- public void setCredentials(String username, String password) {
- this.username = username;
- this.password = password;
- }
-
- /**
- * Specifies a token profile for WSS security
- *
- * @param token WSS security token to be used
- */
- public void setWSSSecurity(WSSTokenProfile token) {
- this.token = token;
- }
-
- /**
- * Sets up an http timeout.
- *
- * @param timeout
- */
- public void setTimeout(int timeout) {
- Map<String, Object> rc = dispatch.getRequestContext();
-
- // these parameters are SUN METRO JAX-WS implementation specific
- rc.put("com.sun.xml.internal.ws.request.timeout", timeout);
- rc.put("com.sun.xml.internal.ws.connect.timeout", timeout);
-
-// rc.put(BindingProviderProperties.REQUEST_TIMEOUT, timeout);
-// rc.put(BindingProviderProperties.CONNECT_TIMEOUT, timeout);
- }
-
- public SOAPMessage call(SOAPMessage message) throws Exception {
-
- Map<String, Object> rc = dispatch.getRequestContext();
-
- // if credentials are set, but no WS-Security token is defined
- // use Basic HTTP Authentication
- if (username != null && username.length() > 0 &&
- password != null && password.length() > 0 &&
- token == null) {
- rc.put(BindingProvider.USERNAME_PROPERTY, username);
- rc.put(BindingProvider.PASSWORD_PROPERTY, password);
- } else {
- if (rc.containsKey(BindingProvider.USERNAME_PROPERTY)) {
- rc.remove(BindingProvider.USERNAME_PROPERTY);
- }
- if (rc.containsKey(BindingProvider.PASSWORD_PROPERTY)) {
- rc.remove(BindingProvider.PASSWORD_PROPERTY);
- }
- }
-
- return dispatch.invoke(message);
- }
-
- class WSSHandler implements SOAPHandler<SOAPMessageContext> {
-
- @Override
- public Set getHeaders() {
- return Collections.EMPTY_SET;
- }
-
- @Override
- public void close(MessageContext context) {
-
- }
-
- @Override
- public boolean handleMessage(SOAPMessageContext context) {
-
- if (Boolean.TRUE == context.get(SOAPMessageContext.MESSAGE_OUTBOUND_PROPERTY)) {
- if (username != null && username.length() > 0 &&
- password != null && password.length() > 0 &&
- token != null) {
-
- SOAPMessage message = context.getMessage();
- SOAPPart part = message.getSOAPPart();
-
- try {
- switch(token) {
- case UsernameToken: {
- WSSecUsernameToken builder = new WSSecUsernameToken();
- builder.setPasswordType(WSConstants.PASSWORD_TEXT);
- builder.setUserInfo(username, password);
-
- WSSecHeader secHeader = new WSSecHeader();
- secHeader.insertSecurityHeader(part);
- Document signed = builder.build(part, secHeader);
- part.setContent(new DOMSource(signed));
- }
- case PasswordDigest: {
- WSSecUsernameToken builder = new WSSecUsernameToken();
- builder.setPasswordType(WSConstants.PASSWORD_TEXT);
- MessageDigest sha = MessageDigest.getInstance("MD5");
- sha.reset();
- sha.update(password.getBytes());
- String passwdDigest = DatatypeConverter.printBase64Binary(sha.digest());
- builder.setUserInfo(username, passwdDigest);
- WSSecHeader secHeader = new WSSecHeader();
- secHeader.insertSecurityHeader(part);
- Document signed = builder.build(part, secHeader);
- part.setContent(new DOMSource(signed));
- }
- }
- }
- catch (WSSecurityException | SOAPException | NoSuchAlgorithmException ex) {}
- }
- }
-
- return true;
- }
-
- @Override
- public boolean handleFault(SOAPMessageContext context) {
- return true;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/LiteralBodyBuilder.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/LiteralBodyBuilder.java b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/LiteralBodyBuilder.java
deleted file mode 100644
index 816837d..0000000
--- a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/LiteralBodyBuilder.java
+++ /dev/null
@@ -1,226 +0,0 @@
-/*
-* 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.soap;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import javax.wsdl.WSDLException;
-import javax.xml.XMLConstants;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.soap.SOAPElement;
-import javax.xml.soap.SOAPException;
-import javax.xml.soap.SOAPFactory;
-
-import org.apache.taverna.wsdl.parser.ArrayTypeDescriptor;
-import org.apache.taverna.wsdl.parser.BaseTypeDescriptor;
-import org.apache.taverna.wsdl.parser.TypeDescriptor;
-import org.apache.taverna.wsdl.parser.UnknownOperationException;
-import org.apache.taverna.wsdl.parser.WSDLParser;
-
-import org.apache.log4j.Logger;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-import org.xml.sax.SAXException;
-
-/**
- * An implementation of BodyBuilder that supports creating the SOAP body for
- * Webservices based upon a WSDL with Literal style.
- *
- * @author Stuart Owen
- * @author Stian Soiland-Reyes
- *
- */
-@SuppressWarnings("unchecked")
-public class LiteralBodyBuilder extends AbstractBodyBuilder {
-
- private static Logger logger = Logger.getLogger(LiteralBodyBuilder.class);
-
- private static final String TYPE = "type";
-
- public LiteralBodyBuilder(String style, WSDLParser parser, String operationName, List<TypeDescriptor> inputDescriptors) {
- super(style, parser, operationName,inputDescriptors);
- }
-
- @Override
- protected Use getUse() {
- return Use.LITERAL;
- }
-
- @Override
- public SOAPElement build(Map inputMap) throws WSDLException,
- ParserConfigurationException, SOAPException, IOException,
- SAXException, UnknownOperationException {
-
- SOAPElement body = super.build(inputMap);
-
- if (getStyle() == Style.DOCUMENT) {
- fixTypeAttributes(body);
- }
-
- return body;
- }
-
- @Override
- protected Element createSkeletonElementForSingleItem(
- Map<String, String> namespaceMappings, TypeDescriptor descriptor,
- String inputName, String typeName) {
- if (getStyle()==Style.DOCUMENT) {
- return createElementNS("", descriptor.getQname().getLocalPart());
-
- } else {
- return createElementNS("", inputName);
- }
- }
-
- private void fixTypeAttributes(Node parent) {
- if (parent.getNodeType() == Node.ELEMENT_NODE) {
- Element el = (Element) parent;
- if (parent.hasAttributes()) {
- NamedNodeMap attributes = parent.getAttributes();
- List<Node> attributeNodesForRemoval = new ArrayList<Node>();
- for (int i = 0; i < attributes.getLength(); i++) {
- Node node = attributes.item(i);
-
- if (XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI.equals(node.getNamespaceURI()) && TYPE.equals(node.getLocalName())) {
- // TAV-712 - don't just strip out xsi:type - let's fix the
- // name prefixes instead
-
- String xsiType = node.getTextContent();
- // Resolve prefix of xsi type
- String[] xsiTypeSplitted = xsiType.split(":", 2);
- String xsiTypePrefix = "";
- String xsiTypeName;
- if (xsiTypeSplitted.length == 1) {
- // No prefix
- xsiTypeName = xsiTypeSplitted[0];
- } else {
- xsiTypePrefix = xsiTypeSplitted[0];
- xsiTypeName = xsiTypeSplitted[1];
- }
-
- String xsiTypeNS;
- if (parent instanceof SOAPElement) {
- xsiTypeNS = ((SOAPElement)parent).getNamespaceURI(xsiTypePrefix);
- } else {
- xsiTypeNS = node
- .lookupNamespaceURI(xsiTypePrefix);
- }
- // Use global namespace prefixes
- String newPrefix = namespaceMappings.get(xsiTypeNS);
- if (newPrefix == null) {
- logger.warn("Can't find prefix for xsi:type namespace " + xsiTypeNS + " - keeping old " + xsiType);
- } else {
- String newXsiType = newPrefix + ":" + xsiTypeName;
- node.setTextContent(newXsiType);
- logger.info("Replacing " + xsiType + " with " + newXsiType);
- }
- }
- }
- for (Node node : attributeNodesForRemoval) {
- el.removeAttributeNS(node.getNamespaceURI(), node
- .getLocalName());
- }
- }
- }
- for (int i = 0; i < parent.getChildNodes().getLength(); i++) {
- fixTypeAttributes(parent.getChildNodes().item(i));
- }
- }
-
- @Override
- protected Element createElementForArrayType(
- Map<String, String> namespaceMappings, String inputName,
- Object dataValue, TypeDescriptor descriptor, String mimeType,
- String typeName) throws ParserConfigurationException, SAXException,
- IOException, UnknownOperationException {
-
- ArrayTypeDescriptor arrayDescriptor = (ArrayTypeDescriptor) descriptor;
- TypeDescriptor elementType = arrayDescriptor.getElementType();
- int size = 0;
-
- Element el = createElementNS("", inputName);
-
- if (dataValue instanceof List) {
- List dataValues = (List) dataValue;
- size = dataValues.size();
- populateElementWithList(mimeType, el, dataValues, elementType);
- } else {
-
- // if mime type is text/xml then the data is an array in xml form,
- // else its just a single primitive element
- if (mimeType.equals("'text/xml'")) {
- DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
- builderFactory.setNamespaceAware(true);
- DocumentBuilder docBuilder = builderFactory.newDocumentBuilder();
- Document doc = docBuilder.parse(new ByteArrayInputStream(
- dataValue.toString().getBytes()));
- Node child = doc.getDocumentElement().getFirstChild();
-
- while (child != null) {
- size++;
- el.appendChild(el.getOwnerDocument()
- .importNode(child, true));
- child = child.getNextSibling();
- }
- } else {
- String tag = "item";
- if (elementType instanceof BaseTypeDescriptor) {
- tag = elementType.getType();
- } else {
- tag = elementType.getName();
- }
- Element item = el.getOwnerDocument().createElement(tag);
- populateElementWithObjectData(mimeType, item, dataValue, descriptor);
- el.appendChild(item);
- }
-
- }
-
- return el;
- }
-
- @Override
- protected SOAPElement addElementToBody(String operationNamespace, SOAPElement body, Element el) throws SOAPException {
- SOAPElement element = SOAPFactory.newInstance().createElement(el);
-
- if (getStyle()==Style.DOCUMENT) {
- // el itself is a body
- Node node = el.getOwnerDocument().renameNode(el, operationNamespace, el.getLocalName());
- node.setPrefix(body.getPrefix()); // unnecessary, but to keep junits happy
-
- body = SOAPFactory.newInstance().createElement((Element)node);
-
- } else {
- body.addChildElement(element);
- }
- return body;
- }
-
-
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/ObjectConverter.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/ObjectConverter.java b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/ObjectConverter.java
deleted file mode 100644
index 3eadc9e..0000000
--- a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/ObjectConverter.java
+++ /dev/null
@@ -1,158 +0,0 @@
-/*
-* 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.soap;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
-/**
- * <p>
- * This class replicates the behaviour of data conversion when using DataThingFactory.bake in Taverna 1.
- * </p>
- * <p>
- * In particular it deals with the conversion of arrays to ArrayList
- * </p>
- * @author Stuart Owen
- *
- *
- */
-public class ObjectConverter {
-
- /**
- * Converts an Object into an appropriate type, in particular recursively converting [] arrays to List<?>'s.<br>
- *
- * This method is a copy of convertObject in DataThingFactory from Taverna 1
- * @param theObject
- * @return
- */
- public static Object convertObject(Object theObject) {
-
- if (theObject == null) {
- return null;
- }
- // If an array type...
- Class<?> theClass = theObject.getClass();
- if (theClass.isArray()) {
- // Special case for byte[]
- if (theObject instanceof byte[]) {
- // System.out.println("Found a byte[], returning it.");
- return theObject;
- } //extra primitive object checks for those fun edge cases!
- else if (theObject instanceof int[]){
- List<Object> l = new ArrayList<Object>();
- for (int i = 0; i<((int[])theObject).length;i++) {
- Object a = ((int[])theObject)[i];
- l.add(convertObject(a));
- }
- return l;
- } else if (theObject instanceof short[]){
- List<Object> l = new ArrayList<Object>();
- for (int i = 0; i<((short[])theObject).length;i++) {
- Object a = ((short[])theObject)[i];
- l.add(convertObject(a));
- }
- return l;
- } else if (theObject instanceof long[]){
- List<Object> l = new ArrayList<Object>();
- for (int i = 0; i<((long[])theObject).length;i++) {
- Object a = ((long[])theObject)[i];
- l.add(convertObject(a));
- }
- return l;
- } else if (theObject instanceof float[]){
- List<Object> l = new ArrayList<Object>();
- for (int i = 0; i<((float[])theObject).length;i++) {
- Object a = ((float[])theObject)[i];
- l.add(convertObject(a));
- }
- return l;
- } else if (theObject instanceof double[]){
- List<Object> l = new ArrayList<Object>();
- for (int i = 0; i<((double[])theObject).length;i++) {
- Object a = ((double[])theObject)[i];
- l.add(convertObject(a));
- }
- return l;
- } else if (theObject instanceof boolean[]){
- List<Object> l = new ArrayList<Object>();
- for (int i = 0; i<((boolean[])theObject).length;i++) {
- Object a = ((boolean[])theObject)[i];
- l.add(convertObject(a));
- }
- return l;
- } else if (theObject instanceof char[]){
- List<Object> l = new ArrayList<Object>();
- for (int i = 0; i<((char[])theObject).length;i++) {
- Object a = ((char[])theObject)[i];
- l.add(convertObject(a));
- }
- return l;
- } else {
- // For all other arrays, create a new
- // List and iterate over the array,
- // unpackaging the item and recursively
- // putting it into the new List after
- // conversion
-
- // System.out.println("Found an array length
- // "+theArray.length+", repacking as List...");
-
- List<Object> l = new ArrayList<Object>();
- Object[] theArray = (Object[]) theObject;
- for (int i = 0; i < theArray.length; i++) {
- l.add(convertObject(theArray[i]));
- }
- return l;
- }
- }
- // If a collection, iterate over it and copy
- if (theObject instanceof Collection) {
- if (theObject instanceof List) {
- // System.out.println("Re-packing a list...");
- List<Object> l = new ArrayList<Object>();
- for (Iterator<?> i = ((List<?>) theObject).iterator(); i.hasNext();) {
- l.add(convertObject(i.next()));
- }
- return l;
- } else if (theObject instanceof Set) {
- // System.out.println("Re-packing a set...");
- Set<Object> s = new HashSet<Object>();
- for (Iterator<?> i = ((Set<?>) theObject).iterator(); i.hasNext();) {
- s.add(convertObject(i.next()));
- }
- return s;
- }
- }
- // If a number then return the string representation for it
- if (theObject instanceof Number) {
- // System.out.println("Found a number, converting it to a
- // string...");
- return theObject.toString();
- }
- // Otherwise just return the object
- // System.out.println("Found a "+theObject.getClass().getName()+",
- // returning it");
- return theObject;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/SOAPResponseEncodedMultiRefParser.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/SOAPResponseEncodedMultiRefParser.java b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/SOAPResponseEncodedMultiRefParser.java
deleted file mode 100644
index ed15b10..0000000
--- a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/SOAPResponseEncodedMultiRefParser.java
+++ /dev/null
@@ -1,181 +0,0 @@
-/*
-* 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.soap;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import javax.xml.soap.SOAPElement;
-
-import org.apache.taverna.wsdl.parser.TypeDescriptor;
-
-import org.w3c.dom.Element;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-
-/**
- * A SOAPResponseParser responsible for responses that are fragmented into
- * seperate referenced blocks of XML - Multiref format. It trys to resolve each
- * reference to the corresponding multiref element, eventually generating a
- * single XML document. Cyclic references are not allows, and lead to a
- * CyclicReferenceException
- *
- * @author sowen
- *
- */
-@SuppressWarnings("unchecked")
-public class SOAPResponseEncodedMultiRefParser extends
- SOAPResponseEncodedParser {
-
- private List resolvedReferences = new ArrayList();
-
- private Map referenceMap;
-
- public SOAPResponseEncodedMultiRefParser(List<TypeDescriptor> outputDescriptors) {
- super(outputDescriptors);
- }
-
- /**
- * Expects a list of XML SOAPBodyElement fragements, with the first being
- * the root, and transforms this into a single XML document. Cyclic
- * references lead to a CyclicReferenceException being thrown. XML
- * namespaces are removed, leading to easier to read XML.
- *
- * @param response -
- * List of XML SOAPBodyElement fragments.
- */
- @Override
- public Map parse(List<SOAPElement> response) throws Exception, CyclicReferenceException {
- Map result = new HashMap();
- generateRefMap(response);
- expandRefMap();
- SOAPElement mainBody = response.get(0);
-
- for (TypeDescriptor descriptor : outputDescriptors) {
- String outputName = descriptor.getName();
-
- Node outputNode = getOutputNode(mainBody, outputName);
- if (outputNode != null) {
- expandNode(outputNode, new ArrayList());
- String xml;
- if (getStripAttributes()) {
- stripAttributes(outputNode);
- outputNode = removeNamespace(outputName, (Element) outputNode);
- }
- xml = toString(outputNode);
-
- result.put(outputName, xml);
- }
-
- }
-
- return result;
- }
-
- /**
- * Generates a map of each multiref element, mapped to its ID.
- *
- * @param response
- * @throws Exception
- */
- private void generateRefMap(List response) throws Exception {
- Map result = new HashMap();
-
- for (Iterator iterator = response.iterator(); iterator.hasNext();) {
- SOAPElement bodyElement = (SOAPElement) iterator.next();
- String id = bodyElement.getAttribute("id");
- if (id.length() > 0) {
- result.put("#" + id, bodyElement);
- }
- }
-
- referenceMap = result;
- }
-
- /**
- * Expands any references to other fragments within each multiref fragment,
- * resulting in all multiref fragments being fully expanded.
- *
- * @throws CyclicReferenceException
- */
- private void expandRefMap() throws CyclicReferenceException {
- for (Iterator iterator = referenceMap.keySet().iterator(); iterator
- .hasNext();) {
- String key = (String) iterator.next();
- if (!resolvedReferences.contains(key)) {
- expandMultirefElement(key, new ArrayList());
- }
- }
- }
-
- private void expandMultirefElement(String key, List parentKeys)
- throws CyclicReferenceException {
- if (parentKeys.contains(key))
- throw new CyclicReferenceException();
- parentKeys.add(key);
- Node node = (Node) referenceMap.get(key);
- expandNode(node, parentKeys);
- resolvedReferences.add(key);
- parentKeys.remove(key);
- }
-
- private void expandNode(Node node, List parentKeys)
- throws CyclicReferenceException {
- String href = getHrefForNode(node);
- if (href != null) {
- if (!resolvedReferences.contains(href)) {
- expandMultirefElement(href, parentKeys);
- }
- copyMultirefContentsToParent(node, href);
- }
- if (node.hasChildNodes()) {
- Node child = node.getFirstChild();
- while (child != null) {
- expandNode(child, parentKeys);
- child = child.getNextSibling();
- }
- }
- }
-
- private void copyMultirefContentsToParent(Node parent, String multirefKey) {
- Element multiRef = (Element) referenceMap.get(multirefKey);
- Node child = multiRef.getFirstChild();
- while (child != null) {
- parent.appendChild(parent.getOwnerDocument()
- .importNode(child, true));
- child = child.getNextSibling();
- }
- parent.getAttributes().removeNamedItem("href");
- }
-
- private String getHrefForNode(Node node) {
- String result = null;
- NamedNodeMap nodemap = node.getAttributes();
- if (nodemap != null) {
- Node attrNode = nodemap.getNamedItem("href");
- if (attrNode != null) {
- result = attrNode.getNodeValue();
- }
- }
- return result;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/SOAPResponseEncodedParser.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/SOAPResponseEncodedParser.java b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/SOAPResponseEncodedParser.java
deleted file mode 100644
index 9b9b3c9..0000000
--- a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/SOAPResponseEncodedParser.java
+++ /dev/null
@@ -1,174 +0,0 @@
-/*
-* 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.soap;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.soap.SOAPElement;
-
-import org.apache.taverna.wsdl.parser.TypeDescriptor;
-
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.xml.sax.SAXException;
-
-/**
- * SOAPResponseParser responsible for parsing SOAP responses from RPC/encoded
- * based service, but that are not fragmented to multiref documents.
- *
- * @author sowen
- *
- */
-@SuppressWarnings("unchecked")
-public class SOAPResponseEncodedParser extends AbstractSOAPResponseParser {
-
- protected List<TypeDescriptor> outputDescriptors;
-
- private boolean stripAttributes = false;
-
- public SOAPResponseEncodedParser(List<TypeDescriptor> outputDescriptors) {
- this.outputDescriptors = outputDescriptors;
- }
-
- /**
- * Parses the response into a single XML document, which is placed in the
- * outputMap together with the given output name. Namespaces and other
- * attributes are stripped out according to stripAttributes.
- *
- * @param List
- * @return Map
- */
- @Override
- public Map parse(List<SOAPElement> response) throws Exception {
-
- Map result = new HashMap();
- SOAPElement mainBody = response.get(0);
-
- for (TypeDescriptor descriptor : outputDescriptors) {
- String outputName = descriptor.getName();
-
- Node outputNode = getOutputNode(mainBody, outputName);
- if (outputNode != null) {
- if (stripAttributes) {
- stripAttributes(outputNode);
- outputNode = removeNamespace(outputName, (Element) outputNode);
- }
-
- String xml = toString(outputNode);
- result.put(outputName, xml);
- }
- }
-
- return result;
- }
-
- protected Node getOutputNode(Element mainBody, String outputName) {
- // first try using body namespace ...
- Node outputNode = mainBody.getElementsByTagNameNS(
- mainBody.getNamespaceURI(), outputName).item(0);
- // ... and if that doesn't work, try without namespace
- if (outputNode == null) {
- outputNode = mainBody.getElementsByTagName(outputName).item(
- 0);
- }
- if (outputNode == null) { // if still null, and there is only 1
- // output, take the first child
- if (outputDescriptors.size() == 1
- && mainBody.getChildNodes().getLength() == 1) {
- outputNode = mainBody.getFirstChild();
- }
- }
- return outputNode;
- }
-
- /**
- * Removes the namespace from the surrounding element that represents the
- * outputName. E.g. converts <ns1:element xmlns:ns1="http://someurl">...</ns1:element>
- * to <element>...</element>
- *
- * @param outputName
- * @param element
- * @return
- * @throws ParserConfigurationException
- * @throws IOException
- * @throws SAXException
- */
- protected Element removeNamespace(String outputName, Element element)
- throws ParserConfigurationException, SAXException, IOException {
-
- return (Element)element.getOwnerDocument().renameNode(element, null, element.getLocalName());
-
- // :-O
-// String xml;
-// String innerXML = XMLUtils.getInnerXMLString(element);
-// if (innerXML != null) {
-// xml = "<" + outputName + ">" + innerXML + "</" + outputName + ">";
-// } else {
-// xml = "<" + outputName + " />";
-// }
-// DocumentBuilder builder = DocumentBuilderFactory.newInstance()
-// .newDocumentBuilder();
-// Document doc = builder.parse(new ByteArrayInputStream(xml.getBytes()));
-// return doc.getDocumentElement();
- }
-
- protected void stripAttributes(Node node) {
- List names = new ArrayList();
- if (node.getAttributes() != null) {
- for (int i = 0; i < node.getAttributes().getLength(); i++) {
- names.add(node.getAttributes().item(i).getNodeName());
- }
- }
-
- for (Iterator iterator = names.iterator(); iterator.hasNext();) {
- node.getAttributes().removeNamedItem((String) iterator.next());
- }
-
- if (node.hasChildNodes()) {
- Node child = node.getFirstChild();
- while (child != null) {
- stripAttributes(child);
- child = child.getNextSibling();
- }
- }
-
- }
-
- /**
- * determines whether attributes in the resulting XML should be stripped
- * out, including namespace definitions, leading to XML that is much easier
- * to read.
- *
- * @param stripAttributes
- */
- public void setStripAttributes(boolean stripAttributes) {
- this.stripAttributes = stripAttributes;
- }
-
- public boolean getStripAttributes() {
- return this.stripAttributes;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/SOAPResponseLiteralParser.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/SOAPResponseLiteralParser.java b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/SOAPResponseLiteralParser.java
deleted file mode 100644
index 7f7c2c8..0000000
--- a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/SOAPResponseLiteralParser.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
-* 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.soap;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import javax.xml.soap.SOAPElement;
-
-import org.apache.taverna.wsdl.parser.TypeDescriptor;
-
-/**
- * Responsible for parsing the SOAP response from calling a Literal based
- * service.
- *
- * @author sowen
- *
- */
-@SuppressWarnings("unchecked")
-public class SOAPResponseLiteralParser extends AbstractSOAPResponseParser {
-
- List<TypeDescriptor>outputDescriptors;
-
- public SOAPResponseLiteralParser(List<TypeDescriptor> outputDescriptors) {
- this.outputDescriptors = outputDescriptors;
- }
-
- /**
- * Expects a list containing a single SOAPBodyElement, the contents of which
- * are transferred directly to the output, converted to a String, and placed
- * into the outputMaP which is returned
- *
- * @return Map of the outputs
- */
- @Override
- public Map parse(List response) throws Exception {
- Map result = new HashMap();
-
- if (response.size() > 0) {
- SOAPElement rpcElement = (SOAPElement) response.get(0);
-
- String outputName = getOutputName();
- String xml = toString(rpcElement);
-
- result.put(outputName, xml);
- }
-
- return result;
- }
-
- protected String getOutputName() {
- String result = "";
- for (TypeDescriptor descriptor : outputDescriptors) {
- String name=descriptor.getName();
- if (!name.equals("attachmentList")) {
- result = name;
- break;
- }
- }
- return result;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/SOAPResponseParser.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/SOAPResponseParser.java b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/SOAPResponseParser.java
deleted file mode 100644
index f919b87..0000000
--- a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/SOAPResponseParser.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
-* 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.soap;
-
-import java.util.List;
-import java.util.Map;
-import javax.xml.soap.SOAPElement;
-
-/**
- * Inteface that defines all parsers responsible for parsing SOAP responses from
- * calling SOAP based webservices.
- *
- * @author sowen
- *
- */
-@SuppressWarnings("unchecked")
-public interface SOAPResponseParser {
-
- /**
- * All SOAPResponseParsers take a list of SOAPBodyElement's, resulting from
- * invoking the service, and convert these into a suitable map of output
- * DataThings.
- *
- * @param response -
- * List of SOAPBodyElements
- * @return Map of output DataThing's mapped to their output name
- * @throws Exception
- */
- public Map parse(List<SOAPElement> response) throws Exception;
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/SOAPResponseParserFactory.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/SOAPResponseParserFactory.java b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/SOAPResponseParserFactory.java
deleted file mode 100644
index a092076..0000000
--- a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/SOAPResponseParserFactory.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
-* 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.soap;
-
-import java.util.List;
-
-import org.apache.taverna.wsdl.parser.TypeDescriptor;
-
-/**
- * A factory class that selects the correct type of SOAPResponseParser according
- * to the service type , the types output of that service, and the response from
- * invoking that service.
- *
- * @author sowen
- *
- */
-@SuppressWarnings("unchecked")
-public class SOAPResponseParserFactory {
-
- private static SOAPResponseParserFactory instance = new SOAPResponseParserFactory();
-
- public static SOAPResponseParserFactory instance() {
- return instance;
- }
-
- /**
- * returns an instance of the appropriate type of SOAPResponseParser
- *
- * @param response -
- * List of SOAPBodyElement's resulting from the service
- * invokation.
- * @param use -
- * the type of the service - 'literal' or 'encoded'
- * @param style -
- * the style of the service - 'document' or 'rpc'
- * @param outputDescriptors -
- * the List of {@link TypeDescriptor}'s describing the service outputs
- * @return
- * @see SOAPResponseParser
- */
- public SOAPResponseParser create(List response, String use, String style,
- List<TypeDescriptor> outputDescriptors) {
-
- SOAPResponseParser result = null;
-
- if (outputIsPrimitive(outputDescriptors)) {
- if (use.equalsIgnoreCase("literal")) {
- result = new SOAPResponsePrimitiveLiteralParser(outputDescriptors);
- }
- else {
- result = new SOAPResponsePrimitiveParser(outputDescriptors);
- }
- } else if (use.equals("literal")) {
- result = new SOAPResponseLiteralParser(outputDescriptors);
- } else {
- if (response.size() > 1) {
- result = new SOAPResponseEncodedMultiRefParser(outputDescriptors);
- } else {
- result = new SOAPResponseEncodedParser(outputDescriptors);
- }
- }
-
- return result;
- }
-
- private boolean outputIsPrimitive(List<TypeDescriptor> outputDescriptors) {
- boolean result = true;
- for (TypeDescriptor d : outputDescriptors) {
- if (d.getMimeType().equals("'text/xml'")) {
- result = false;
- break;
- }
- }
- return result;
- }
-
-}
[6/8] incubator-taverna-common-activities git commit: experimental
wsdl-generic based on XSD schema
Posted by re...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/WSDL11Parser.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/WSDL11Parser.java b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/WSDL11Parser.java
index 33c047d..5be79c6 100644
--- a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/WSDL11Parser.java
+++ b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/WSDL11Parser.java
@@ -20,6 +20,7 @@
package org.apache.taverna.wsdl.parser;
import java.io.IOException;
+import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -60,8 +61,8 @@ import javax.wsdl.factory.WSDLFactory;
import javax.wsdl.xml.WSDLReader;
import javax.xml.namespace.QName;
import org.apache.ws.commons.schema.XmlSchemaCollection;
-import org.apache.ws.commons.schema.XmlSchemaObject;
import org.apache.ws.commons.schema.utils.NamespaceMap;
+import org.apache.ws.commons.schema.utils.XmlSchemaNamed;
import org.w3c.dom.Element;
import org.xml.sax.InputSource;
@@ -228,7 +229,6 @@ public class WSDL11Parser implements GenericWSDLParser {
}
@Deprecated
- @Override
public String getOperationEndpointLocation(String operationName) throws UnknownOperationException {
return getSoapAddress(findPort(operationName));
}
@@ -258,7 +258,6 @@ public class WSDL11Parser implements GenericWSDLParser {
*
* @throws UnknownOperationException
*/
- @Override
public QName getRPCRequestMethodName(String portName, String operationName) throws UnknownOperationException {
if (portName == null) {
portName = findPort(operationName);
@@ -296,7 +295,6 @@ public class WSDL11Parser implements GenericWSDLParser {
*
* @throws UnknownOperationException
*/
- @Override
public QName getRPCResponseMethodName(String portName, String operationName) throws UnknownOperationException {
if (portName == null) {
portName = findPort(operationName);
@@ -357,13 +355,18 @@ public class WSDL11Parser implements GenericWSDLParser {
return null;
}
+ @Override
+ public XmlSchemaCollection getXmlSchemas() {
+ return schemas;
+ }
+
@Deprecated
- LinkedHashMap<String, XmlSchemaObject> getInputParameters(String operationName) throws UnknownOperationException {
+ LinkedHashMap<String, XmlSchemaNamed> getInputParameters(String operationName) throws UnknownOperationException {
return getInputParameters(null, operationName);
}
@Override
- public LinkedHashMap<String, XmlSchemaObject> getInputParameters(String portName, String operationName) throws UnknownOperationException {
+ public LinkedHashMap<String, XmlSchemaNamed> getInputParameters(String portName, String operationName) throws UnknownOperationException {
if (portName == null) {
portName = findPort(operationName);
}
@@ -373,12 +376,12 @@ public class WSDL11Parser implements GenericWSDLParser {
}
@Deprecated
- LinkedHashMap<String, XmlSchemaObject> getOutputParameters(String operationName) throws UnknownOperationException {
+ LinkedHashMap<String, XmlSchemaNamed> getOutputParameters(String operationName) throws UnknownOperationException {
return getOutputParameters(null, operationName);
}
@Override
- public LinkedHashMap<String, XmlSchemaObject> getOutputParameters(String portName, String operationName) throws UnknownOperationException {
+ public LinkedHashMap<String, XmlSchemaNamed> getOutputParameters(String portName, String operationName) throws UnknownOperationException {
if (portName == null) {
portName = findPort(operationName);
}
@@ -387,11 +390,11 @@ public class WSDL11Parser implements GenericWSDLParser {
return getParameters(parts);
}
- private LinkedHashMap<String, XmlSchemaObject> getParameters(List<Part> parts) {
- LinkedHashMap<String, XmlSchemaObject> parameters = new LinkedHashMap<String, XmlSchemaObject>();
+ private LinkedHashMap<String, XmlSchemaNamed> getParameters(List<Part> parts) {
+ LinkedHashMap<String, XmlSchemaNamed> parameters = new LinkedHashMap<String, XmlSchemaNamed>();
for (Part part : parts) {
- XmlSchemaObject parameter = getParameter(part);
+ XmlSchemaNamed parameter = getParameter(part);
if (parameter == null) {
logger.log(Level.WARNING, "can't find parameter type: {0}", part.getName());
@@ -480,8 +483,8 @@ public class WSDL11Parser implements GenericWSDLParser {
return parts;
}
- private XmlSchemaObject getParameter(Part part) {
- XmlSchemaObject parameter;
+ private XmlSchemaNamed getParameter(Part part) {
+ XmlSchemaNamed parameter;
QName elementName = part.getElementName();
if (elementName != null) {
@@ -809,7 +812,7 @@ public class WSDL11Parser implements GenericWSDLParser {
WSDLFactory factory = WSDLFactory.newInstance();
WSDLReader reader = factory.newWSDLReader();
reader.setFeature("javax.wsdl.verbose", false);
- Definition definition = reader.readWSDL(wsdlLocation);
+ Definition definition = reader.readWSDL(new WSDLLocatorImpl(new URL(wsdlLocation)));
parser = new WSDL11Parser(definition);
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/WSDL20Parser.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/WSDL20Parser.java b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/WSDL20Parser.java
index 4f2ee01..9fd0a12 100644
--- a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/WSDL20Parser.java
+++ b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/WSDL20Parser.java
@@ -45,6 +45,7 @@ import org.apache.woden.wsdl20.BindingOperation;
import org.apache.woden.wsdl20.Description;
import org.apache.woden.wsdl20.ElementDeclaration;
import org.apache.woden.wsdl20.Endpoint;
+import org.apache.woden.wsdl20.Interface;
import org.apache.woden.wsdl20.InterfaceMessageReference;
import org.apache.woden.wsdl20.InterfaceOperation;
import org.apache.woden.wsdl20.Service;
@@ -54,7 +55,7 @@ import org.apache.woden.wsdl20.extensions.soap.SOAPConstants;
import org.apache.woden.wsdl20.xml.DescriptionElement;
import org.apache.woden.wsdl20.xml.DocumentationElement;
import org.apache.ws.commons.schema.XmlSchemaCollection;
-import org.apache.ws.commons.schema.XmlSchemaObject;
+import org.apache.ws.commons.schema.utils.XmlSchemaNamed;
import org.w3c.dom.Element;
/**
@@ -82,7 +83,7 @@ public class WSDL20Parser implements GenericWSDLParser {
@Override
public List<QName> getServices() {
- List<QName> services = new ArrayList<QName>();
+ List<QName> services = new ArrayList();
for (Service service : description.getServices()) {
services.add(service.getName());
}
@@ -91,23 +92,16 @@ public class WSDL20Parser implements GenericWSDLParser {
@Override
public List<String> getPorts(QName serviceName) {
- List<String> ports = new ArrayList<String>();
-
- Service service = description.getService(serviceName);
- if (service != null) {
- for (Endpoint endpoint : service.getEndpoints()) {
- final NCName endpointName = endpoint.getName();
- if (endpointName != null) {
- ports.add(endpointName.toString());
- }
- }
+ List<String> interfaces = new ArrayList();
+ for (Interface _interface : description.getInterfaces()) {
+ interfaces.add(_interface.getName().getLocalPart());
}
- return ports;
+ return interfaces;
}
@Override
public List<String> getOperations(String portName) {
- List<String> operations = new ArrayList<String>();
+ List<String> operations = new ArrayList();
for (Service service : description.getServices()) {
for (Endpoint endpoint : service.getEndpoints()) {
@@ -150,8 +144,7 @@ public class WSDL20Parser implements GenericWSDLParser {
@Override
public QName getRPCRequestMethodName(String portName, String operationName) throws UnknownOperationException {
// NO RPC SUPPORT YET
- return new QName(operationName);
- }
+ return new QName(operationName); }
@Override
public QName getRPCResponseMethodName(String portName, String operationName) throws UnknownOperationException {
@@ -200,6 +193,7 @@ public class WSDL20Parser implements GenericWSDLParser {
}
}
return null;
+
}
@Override
@@ -221,32 +215,36 @@ public class WSDL20Parser implements GenericWSDLParser {
} catch (TransformerException ex) {}
}
}
- } catch (TransformerFactoryConfigurationError ex) {}
- catch (TransformerConfigurationException ex) {}
+ } catch (TransformerFactoryConfigurationError | TransformerConfigurationException ex) {}
return writer.toString();
}
@Override
- public LinkedHashMap<String, XmlSchemaObject> getInputParameters(String portName, String operationName) throws UnknownOperationException {
- LinkedHashMap<String, XmlSchemaObject> parameters = new LinkedHashMap<String, XmlSchemaObject>();
+ public XmlSchemaCollection getXmlSchemas() {
+ return schemas;
+ }
+
+ @Override
+ public LinkedHashMap<String, XmlSchemaNamed> getInputParameters(String portName, String operationName) throws UnknownOperationException {
+ LinkedHashMap<String, XmlSchemaNamed> parameters = new LinkedHashMap();
BindingOperation bindingOperation = getBindingOperation(portName, operationName);
InterfaceOperation interfaceOperation = bindingOperation.getInterfaceOperation();
-
+
// NOTE THAT THIS CODE IS NOT VALID FOR "RPC" STYLE
for (InterfaceMessageReference input : interfaceOperation.getInterfaceMessageReferences()) {
if (Direction.IN == input.getDirection()) {
ElementDeclaration element = input.getElementDeclaration();
- parameters.put(element.getName().getLocalPart(), (XmlSchemaObject)element.getContent());
+ parameters.put(element.getName().getLocalPart(), (XmlSchemaNamed)element.getContent());
}
}
return parameters;
}
@Override
- public LinkedHashMap<String, XmlSchemaObject> getOutputParameters(String portName, String operationName) throws UnknownOperationException {
- LinkedHashMap<String, XmlSchemaObject> parameters = new LinkedHashMap<String, XmlSchemaObject>();
+ public LinkedHashMap<String, XmlSchemaNamed> getOutputParameters(String portName, String operationName) throws UnknownOperationException {
+ LinkedHashMap<String, XmlSchemaNamed> parameters = new LinkedHashMap();
BindingOperation bindingOperation = getBindingOperation(portName, operationName);
InterfaceOperation interfaceOperation = bindingOperation.getInterfaceOperation();
@@ -254,8 +252,9 @@ public class WSDL20Parser implements GenericWSDLParser {
// NOTE THAT THIS CODE IS NOT VALID FOR "RPC" STYLE
for (InterfaceMessageReference output : interfaceOperation.getInterfaceMessageReferences()) {
if (Direction.OUT == output.getDirection()) {
+ // TODO!!!
ElementDeclaration element = output.getElementDeclaration();
- parameters.put(element.getName().getLocalPart(), (XmlSchemaObject)element.getContent());
+ parameters.put(element.getName().getLocalPart(), (XmlSchemaNamed)element.getContent());
}
}
return parameters;
@@ -298,12 +297,12 @@ public class WSDL20Parser implements GenericWSDLParser {
throw new UnknownOperationException("Unknown operation: " + operationName);
}
-
+
public static synchronized WSDL20Parser getWSDL20Parser(String wsdlLocation) throws Exception {
WSDL20Parser parser = null;
if (parsers == null) {
- parsers = new TreeMap<String, WSDL20Parser>();
+ parsers = new TreeMap();
} else {
parser = parsers.get(wsdlLocation);
}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/WSDLLocatorImpl.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/WSDLLocatorImpl.java b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/WSDLLocatorImpl.java
new file mode 100644
index 0000000..cc7053f
--- /dev/null
+++ b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/WSDLLocatorImpl.java
@@ -0,0 +1,95 @@
+/*
+* 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.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import javax.wsdl.xml.WSDLLocator;
+import org.xml.sax.InputSource;
+
+/**
+ * @author Dmitry Repchevsky
+ */
+
+public class WSDLLocatorImpl implements WSDLLocator {
+
+ private final URL baseURL;
+ private String latestImportURI;
+ private InputStream in;
+
+ public WSDLLocatorImpl(URL wsdlLocation) throws IOException {
+ baseURL = wsdlLocation;
+ latestImportURI = baseURL.toString();
+ }
+
+ @Override
+ public InputSource getBaseInputSource() {
+ try {
+ URLConnection connection = baseURL.openConnection();
+ in = connection.getInputStream();
+ InputSource source = new InputSource(in);
+ source.setSystemId(getBaseURI());
+ return source;
+ } catch (Exception ex) {
+ Logger.getLogger(WSDLLocatorImpl.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ return null;
+ }
+
+ @Override
+ public InputSource getImportInputSource(String parentLocation, String importLocation) {
+ try {
+ URL url = new URL(new URL(parentLocation), importLocation);
+ latestImportURI = url.toString();
+ URLConnection connection = url.openConnection();
+ InputSource source = new InputSource(connection.getInputStream());
+ source.setSystemId(latestImportURI);
+ return source;
+ } catch (Exception ex) {
+ Logger.getLogger(WSDLLocatorImpl.class.getName()).log(Level.SEVERE, null, ex);
+ }
+
+ return null;
+ }
+
+ @Override
+ public String getBaseURI() {
+ return baseURL.toString();
+ }
+
+ @Override
+ public String getLatestImportURI() {
+ return latestImportURI;
+ }
+
+ @Override
+ public void close() {
+ if (in != null) {
+ try {
+ in.close();
+ } catch (IOException ex) {
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/WSDLParser.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/WSDLParser.java b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/WSDLParser.java
index 6fef786..4cb0c53 100644
--- a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/WSDLParser.java
+++ b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/WSDLParser.java
@@ -24,11 +24,14 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
+import java.util.Map;
import javax.wsdl.WSDLException;
import javax.xml.namespace.QName;
import javax.xml.parsers.ParserConfigurationException;
+import org.apache.taverna.wsdl.parser.schema.XSModel;
import org.apache.ws.commons.schema.XmlSchemaElement;
-import org.apache.ws.commons.schema.XmlSchemaObject;
+import org.apache.ws.commons.schema.XmlSchemaType;
+import org.apache.ws.commons.schema.utils.XmlSchemaNamed;
import org.xml.sax.SAXException;
@@ -83,7 +86,7 @@ public class WSDLParser {
* @return a list of WSDLOperations for all operations for this service,
*/
public List<String> getOperations() {
- List<String> operations = new ArrayList<String>();
+ List<String> operations = new ArrayList();
for (QName serviceName : parser.getServices()) {
for (String portName : parser.getPorts(serviceName)) {
@@ -157,35 +160,58 @@ public class WSDLParser {
return parser.getOperationStyle(null, operationName);
}
+ public LinkedHashMap<String, XmlSchemaNamed> getInputParameters(String operationName) throws UnknownOperationException {
+ return parser.getInputParameters(null, operationName);
+ }
+
+ public LinkedHashMap<String, XmlSchemaNamed> getOutputParameters(String operationName) throws UnknownOperationException {
+ return parser.getOutputParameters(null, operationName);
+ }
/**
- * Returns a List of the TypeDescriptors representing the parameters for the
- * inputs to the service
+ * Returns a simple tree-based datatype model for the service input.
*
* @param operationName
- * @return List of TypeDescriptor
+ * @return input data model
* @throws UnknownOperationException if no operation matches the name
- * @throws IOException
*
*/
- public List<TypeDescriptor> getOperationInputParameters(String operationName)
- throws UnknownOperationException, IOException {
-
- return TypeDescriptors.getDescriptors(parser.getInputParameters(null, operationName));
+ public XSModel getInputDataModel(String operationName)
+ throws UnknownOperationException {
+
+ XSModel model = new XSModel(parser.getXmlSchemas());
+ LinkedHashMap<String, XmlSchemaNamed> input = parser.getInputParameters(null, operationName);
+ for (Map.Entry<String, XmlSchemaNamed> entry : input.entrySet()) {
+ XmlSchemaNamed o = entry.getValue();
+ if (o instanceof XmlSchemaElement) {
+ model.addGlobalElement(o.getQName());
+ } else if (o instanceof XmlSchemaType) {
+ model.addGlobalType(o.getQName(), new QName(entry.getKey()));
+ }
+ }
+ return model;
}
/**
- * Returns a List of the TypeDescriptors representing the parameters for the
- * outputs of the service
+ * Returns a simple tree-based datatype model for the service output.
*
* @param operationName
- * @return List of TypeDescriptor
+ * @return output data model
* @throws UnknownOperationException if no operation matches the name
- * @throws IOException
*/
- public List<TypeDescriptor> getOperationOutputParameters(
- String operationName) throws UnknownOperationException, IOException {
-
- return TypeDescriptors.getDescriptors(parser.getOutputParameters(null, operationName));
+ public XSModel getOutputDataModel(
+ String operationName) throws UnknownOperationException {
+
+ XSModel model = new XSModel(parser.getXmlSchemas());
+ LinkedHashMap<String, XmlSchemaNamed> output = parser.getOutputParameters(null, operationName);
+ for (Map.Entry<String, XmlSchemaNamed> entry : output.entrySet()) {
+ XmlSchemaNamed o = entry.getValue();
+ if (o instanceof XmlSchemaElement) {
+ model.addGlobalElement(o.getQName());
+ } else if (o instanceof XmlSchemaType) {
+ model.addGlobalType(o.getQName(), new QName(entry.getKey()));
+ }
+ }
+ return model;
}
/**
@@ -219,9 +245,9 @@ public class WSDLParser {
}
// all these things are odd... there is no any wrapper for the 'document' style
- LinkedHashMap<String, XmlSchemaObject> parameters = parser.getInputParameters(null, operationName);
+ LinkedHashMap<String, XmlSchemaNamed> parameters = parser.getInputParameters(null, operationName);
if (parameters.size() > 0) {
- XmlSchemaObject xmlSchemaObject = parameters.values().iterator().next();
+ XmlSchemaNamed xmlSchemaObject = parameters.values().iterator().next();
if (xmlSchemaObject instanceof XmlSchemaElement) {
XmlSchemaElement element = (XmlSchemaElement)xmlSchemaObject;
return element.getQName();
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/schema/XSAttribute.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/schema/XSAttribute.java b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/schema/XSAttribute.java
new file mode 100644
index 0000000..236bde2
--- /dev/null
+++ b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/schema/XSAttribute.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.schema;
+
+import javax.xml.bind.DatatypeConverter;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+import org.apache.ws.commons.schema.XmlSchema;
+import org.apache.ws.commons.schema.XmlSchemaAttribute;
+import org.apache.ws.commons.schema.XmlSchemaCollection;
+import org.apache.ws.commons.schema.XmlSchemaType;
+import org.apache.ws.commons.schema.XmlSchemaUse;
+
+/**
+ * @author Dmitry Repchevsky
+ */
+
+public class XSAttribute<T,V extends T> extends XSComponent<T, V, XmlSchemaAttribute> {
+
+ public XSAttribute(XmlSchemaAttribute attribute) {
+ this(attribute, null);
+ }
+
+ public XSAttribute(XmlSchemaAttribute attribute, Object object) {
+ super(attribute, object);
+ }
+
+ @Override
+ public XmlSchemaType getType() {
+ XmlSchemaType simpleType = component.getSchemaType();
+ if (simpleType == null) {
+ QName typeName = component.getSchemaTypeName();
+ XmlSchema schema = component.getParent();
+ XmlSchemaCollection schemaCollection = schema.getParent();
+ if (schemaCollection != null) {
+ simpleType = schemaCollection.getTypeByQName(typeName);
+ } else {
+ simpleType = schema.getTypeByName(typeName);
+ }
+ }
+ return simpleType;
+ }
+
+ @Override
+ public QName getName() {
+ return component.getWireName();
+ }
+
+ @Override
+ public Boolean validate() {
+ if (getUserObject() != null) {
+ return Boolean.TRUE;
+ }
+ return XmlSchemaUse.REQUIRED == component.getUse() ? Boolean.FALSE : null;
+ }
+
+ @Override
+ public void write(XMLStreamWriter stream) throws XMLStreamException {
+ QName type = getTypeName();
+ Object object = getUserObject();
+
+ if (object != null) {
+ if (object instanceof QName) {
+ object = DatatypeConverter.printQName((QName)object, stream.getNamespaceContext());
+ }
+
+ final QName name = getName();
+ final String localName = name.getLocalPart();
+ final String namespace = name.getNamespaceURI();
+
+ if (namespace != null && namespace.length() > 0) {
+ final String prefix = getPrefix(stream);
+ if (prefix != null) {
+ stream.writeAttribute(prefix, namespace, localName, object.toString());
+ } else {
+ stream.writeAttribute(namespace, localName, object.toString());
+ }
+ } else {
+ stream.writeAttribute(localName, object.toString());
+ }
+ } else if (XmlSchemaUse.REQUIRED == component.getUse()) {
+ throw new XMLStreamException("Required attribute missing: " + type.toString());
+ }
+ }
+
+ @Override
+ public String getXPath() {
+ final XSComponent parent = (XSComponent)getParent();
+ final StringBuilder xpath = new StringBuilder(parent.getXPath());
+ final QName qname = getName();
+ final String localpart = qname.getLocalPart();
+ final String namespace = qname.getNamespaceURI();
+ if (namespace.isEmpty()) {
+ xpath.append("/@").append(localpart);
+ } else {
+ xpath.append("/@[namespace-uri()='").append(namespace).append("' and local-name()='").append(localpart).append("']");
+ }
+ return xpath.toString();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/schema/XSComponent.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/schema/XSComponent.java b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/schema/XSComponent.java
new file mode 100644
index 0000000..393a8e8
--- /dev/null
+++ b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/schema/XSComponent.java
@@ -0,0 +1,113 @@
+/*
+* 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.schema;
+
+import javax.xml.XMLConstants;
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+import org.apache.ws.commons.schema.XmlSchema;
+import org.apache.ws.commons.schema.XmlSchemaObject;
+import org.apache.ws.commons.schema.XmlSchemaType;
+import org.apache.ws.commons.schema.utils.NamespacePrefixList;
+import org.apache.ws.commons.schema.utils.XmlSchemaNamed;
+
+/**
+ * An abstract implementation of XML Schema component tree node.
+ *
+ * @author Dmitry Repchevsky
+ */
+
+public abstract class XSComponent<T,V extends T, U extends XmlSchemaObject> extends XSNode<T,V> {
+ protected U component;
+
+ public XSComponent(U component) {
+ this(component, null);
+ }
+
+ public XSComponent(U component, Object value) {
+ this.component = component;
+ }
+
+ public U getXSComponent() {
+ return component;
+ }
+
+ public final QName getTypeName() {
+ XmlSchemaType type = getType();
+
+ // the type could be anonymouse
+ QName qname = type.getQName();
+
+ return qname != null ? new QName(qname.getNamespaceURI(), qname.getLocalPart()) : new QName("");
+ }
+
+ public abstract QName getName();
+ public abstract XmlSchemaType getType();
+
+ public abstract Boolean validate();
+ public abstract void write(XMLStreamWriter stream) throws XMLStreamException;
+ public abstract String getXPath();
+
+ protected String getPrefix(XMLStreamWriter stream) throws XMLStreamException {
+ final QName qname = getName();
+ final String namespace = qname.getNamespaceURI();
+
+ if (namespace.length() > 0) {
+ NamespaceContext ctx = stream.getNamespaceContext();
+ if (ctx == null) {
+ // warning !!!
+ } else {
+ String prefix = ctx.getPrefix(namespace);
+ if (prefix == null && component instanceof XmlSchemaNamed) {
+ XmlSchemaNamed named = (XmlSchemaNamed)component;
+ XmlSchema schema = named.getParent();
+
+ NamespacePrefixList namespaces = schema.getNamespaceContext();
+ if (namespaces != null) {
+ prefix = namespaces.getPrefix(namespace);
+ if (prefix != null) {
+ final String nmsp = ctx.getNamespaceURI(prefix);
+ if (nmsp != null && !nmsp.equals(namespace)) {
+ prefix = null; // prefix is already in use
+ }
+ }
+ }
+ }
+ if (prefix == null) {
+ prefix = "ns0";
+// JAVA BUG !!! getNamespaceURI() should never return null
+// for (int i = 1; !XMLConstants.NULL_NS_URI.equals(ctx.getNamespaceURI(prefix)); i++) {
+ for (int i = 1;; i++) {
+ final String nmsp = ctx.getNamespaceURI(prefix);
+ if (nmsp == null || XMLConstants.NULL_NS_URI.equals(nmsp)) {
+ break;
+ }
+ prefix = "ns" + i;
+ }
+ }
+ //stream.setPrefix(prefix, namespace);
+ return prefix;
+ }
+ }
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/schema/XSGlobalElement.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/schema/XSGlobalElement.java b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/schema/XSGlobalElement.java
new file mode 100644
index 0000000..6766506
--- /dev/null
+++ b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/schema/XSGlobalElement.java
@@ -0,0 +1,209 @@
+/*
+* 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.schema;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+import org.apache.ws.commons.schema.XmlSchema;
+import org.apache.ws.commons.schema.XmlSchemaCollection;
+import org.apache.ws.commons.schema.XmlSchemaComplexContent;
+import org.apache.ws.commons.schema.XmlSchemaComplexContentExtension;
+import org.apache.ws.commons.schema.XmlSchemaComplexContentRestriction;
+import org.apache.ws.commons.schema.XmlSchemaComplexType;
+import org.apache.ws.commons.schema.XmlSchemaContent;
+import org.apache.ws.commons.schema.XmlSchemaContentModel;
+import org.apache.ws.commons.schema.XmlSchemaElement;
+import org.apache.ws.commons.schema.XmlSchemaParticle;
+import org.apache.ws.commons.schema.XmlSchemaSimpleType;
+import org.apache.ws.commons.schema.XmlSchemaType;
+
+/**
+ * The node that represents a global XML Schema element tree node.
+ * This node should be an immediate child of XSModel node.
+ *
+ * @author Dmitry Repchevsky
+ */
+
+public class XSGlobalElement<T,V extends T> extends XSComponent<T,V, XmlSchemaElement> {
+
+ public XSGlobalElement(XmlSchemaElement element) {
+ super(element);
+ }
+
+ public XSGlobalElement(XmlSchemaElement element, Object value) {
+ super(element, value);
+ }
+
+ @Override
+ public XmlSchemaType getType() {
+ XmlSchemaElement element = XSParser.getElement(component);
+ XmlSchemaType type = element.getSchemaType();
+ if (type == null) {
+ QName typeName = element.getSchemaTypeName();
+ XmlSchema schema = element.getParent();
+ XmlSchemaCollection schemaCollection = schema.getParent();
+ if (schemaCollection != null) {
+ type = schemaCollection.getTypeByQName(typeName);
+ } else {
+ type = schema.getTypeByName(typeName);
+ }
+ }
+ return type;
+ }
+
+ @Override
+ public QName getName() {
+ return component.getQName();
+ }
+
+ @Override
+ public Boolean validate() {
+ final int n = getChildCount();
+
+ // if there is no child nodes in the node suppose it's ok.
+ if (n == 0) {
+ return Boolean.TRUE;
+ }
+
+ Boolean valid = null;
+
+ for (int i = 0; i < n; i++) {
+ XSComponent child = (XSComponent)getChildAt(i);
+ Boolean b = child.validate();
+ if (Boolean.FALSE.equals(b)) {
+ valid = Boolean.FALSE;
+ break;
+ }
+ if (valid == null) {
+ valid = b;
+ }
+ }
+
+ return valid == null ? (component.isNillable() ? null : Boolean.FALSE) : Boolean.TRUE;
+ }
+
+ @Override
+ public void write(XMLStreamWriter stream) throws XMLStreamException {
+ Boolean isValid = validate();
+ if (isValid != null && isValid) {
+ XmlSchemaType type = component.getSchemaType();
+ if (type instanceof XmlSchemaSimpleType) {
+ writeType(stream);
+ } else if (type instanceof XmlSchemaComplexType) {
+ XmlSchemaComplexType complexType = (XmlSchemaComplexType)type;
+ XmlSchemaParticle particle = complexType.getParticle();
+ if (particle == null) {
+ final XmlSchemaContentModel contentModel = complexType.getContentModel();
+ if (contentModel instanceof XmlSchemaComplexContent) {
+ XmlSchemaContent content = contentModel.getContent();
+ if (content instanceof XmlSchemaComplexContentExtension) {
+ XmlSchemaComplexContentExtension complexContentExtension = (XmlSchemaComplexContentExtension)content;
+ particle = complexContentExtension.getParticle();
+ } else if (content instanceof XmlSchemaComplexContentRestriction) {
+ XmlSchemaComplexContentRestriction complexContentRestriction = (XmlSchemaComplexContentRestriction)content;
+ particle = complexContentRestriction.getParticle();
+ }
+ }
+ }
+
+ if (particle != null && particle.getMaxOccurs() > 1) {
+ writeModelGroup(stream);
+ } else {
+ writeType(stream);
+ }
+ }
+ }
+ }
+
+ /**
+ * Write the element represented by this node to the stream.
+ *
+ * @param stream
+ * @throws XMLStreamException
+ */
+ private void writeType(XMLStreamWriter stream) throws XMLStreamException {
+
+ final QName qname = component.getQName();
+
+ final String localName = qname.getLocalPart();
+ final String namespace = qname.getNamespaceURI();
+
+ if (namespace != null && namespace.length() > 0) {
+ final String prefix = getPrefix(stream);
+ if (prefix != null) {
+ stream.writeStartElement(prefix, localName, namespace);
+ } else {
+ stream.writeStartElement(namespace, localName);
+ }
+ } else {
+ stream.writeStartElement(localName);
+ }
+
+ for (int i = 0, n = getChildCount(); i < n; i++) {
+ XSComponent child = (XSComponent)getChildAt(i);
+ child.write(stream);
+ }
+
+ Object object = getUserObject();
+ if (object != null) {
+ XmlSchemaSimpleType simpleType = XSModel.getSimpleType(this);
+ if (simpleType != null) {
+ stream.writeCharacters(object.toString());
+ }
+ }
+
+ stream.writeEndElement();
+ }
+
+ private void writeModelGroup(XMLStreamWriter stream) throws XMLStreamException {
+ final QName name = component.getQName();
+
+ final String localName = name.getLocalPart();
+ final String namespace = name.getNamespaceURI();
+
+ for (int i = 0, n = getChildCount(); i < n; i++) {
+ if (namespace != null && namespace.length() > 0) {
+ stream.writeStartElement(namespace, localName);
+ } else {
+ stream.writeStartElement(localName);
+ }
+
+ XSComponent child = (XSComponent)getChildAt(i);
+ child.write(stream);
+
+ stream.writeEndElement();
+ }
+ }
+
+ @Override
+ public String getXPath() {
+ final StringBuilder xpath = new StringBuilder("/");
+ final QName qname = getName();
+ final String localpart = qname.getLocalPart();
+ final String namespace = qname.getNamespaceURI();
+ if (namespace.isEmpty()) {
+ xpath.append(localpart);
+ } else {
+ xpath.append("*[namespace-uri()='").append(namespace).append("' and local-name()='").append(localpart).append("']");
+ }
+ return xpath.toString();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/schema/XSGlobalType.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/schema/XSGlobalType.java b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/schema/XSGlobalType.java
new file mode 100644
index 0000000..9ab86f6
--- /dev/null
+++ b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/schema/XSGlobalType.java
@@ -0,0 +1,50 @@
+/*
+* 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.schema;
+
+import javax.xml.namespace.QName;
+import org.apache.ws.commons.schema.XmlSchemaType;
+
+/**
+ * @author Dmitry Repchevsky
+ */
+
+public class XSGlobalType<T,V extends T> extends XSType<T,V> {
+
+ private QName name;
+
+ public XSGlobalType(XmlSchemaType type) {
+ this(type, null);
+ }
+
+ public XSGlobalType(XmlSchemaType type, Object value) {
+ this(type, value, null);
+ }
+
+ public XSGlobalType(XmlSchemaType type, Object value, QName name) {
+ super(type, value);
+ this.name = name;
+ }
+
+ @Override
+ public QName getName() {
+ return name != null ? name : super.getName();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/schema/XSMixedText.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/schema/XSMixedText.java b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/schema/XSMixedText.java
new file mode 100644
index 0000000..b30c96c
--- /dev/null
+++ b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/schema/XSMixedText.java
@@ -0,0 +1,66 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+
+package org.apache.taverna.wsdl.parser.schema;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+import org.apache.ws.commons.schema.XmlSchemaObject;
+import org.apache.ws.commons.schema.XmlSchemaType;
+
+/**
+ * @author Dmitry Repchevsky
+ */
+
+public class XSMixedText<T,V extends T> extends XSComponent<T,V, XmlSchemaObject> {
+
+ public XSMixedText() {
+ super(null);
+ }
+
+ @Override
+ public QName getName() {
+ return new QName("");
+ }
+
+ @Override
+ public XmlSchemaType getType() {
+ return null;
+ }
+
+ @Override
+ public Boolean validate() {
+ return null;
+ }
+
+ @Override
+ public void write(XMLStreamWriter stream) throws XMLStreamException {
+ Object object = getUserObject();
+ if (object != null) {
+ stream.writeCharacters(object.toString());
+ }
+ }
+
+ @Override
+ public String getXPath() {
+ XSComponent parentNode = (XSComponent)getParent();
+ return parentNode.getXPath() + "[" + parentNode.getIndex(this) + "]";
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/schema/XSModel.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/schema/XSModel.java b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/schema/XSModel.java
new file mode 100644
index 0000000..cd3e899
--- /dev/null
+++ b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/schema/XSModel.java
@@ -0,0 +1,474 @@
+/*
+* 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.schema;
+
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import javax.xml.bind.DatatypeConverter;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+import org.apache.ws.commons.schema.XmlSchema;
+import org.apache.ws.commons.schema.XmlSchemaAll;
+import org.apache.ws.commons.schema.XmlSchemaAttribute;
+import org.apache.ws.commons.schema.XmlSchemaChoice;
+import org.apache.ws.commons.schema.XmlSchemaCollection;
+import org.apache.ws.commons.schema.XmlSchemaComplexContentExtension;
+import org.apache.ws.commons.schema.XmlSchemaComplexContentRestriction;
+import org.apache.ws.commons.schema.XmlSchemaComplexType;
+import org.apache.ws.commons.schema.XmlSchemaContent;
+import org.apache.ws.commons.schema.XmlSchemaContentModel;
+import org.apache.ws.commons.schema.XmlSchemaElement;
+import org.apache.ws.commons.schema.XmlSchemaObject;
+import org.apache.ws.commons.schema.XmlSchemaParticle;
+import org.apache.ws.commons.schema.XmlSchemaSequence;
+import org.apache.ws.commons.schema.XmlSchemaSequenceMember;
+import org.apache.ws.commons.schema.XmlSchemaSimpleContentExtension;
+import org.apache.ws.commons.schema.XmlSchemaSimpleType;
+import org.apache.ws.commons.schema.XmlSchemaType;
+import org.apache.ws.commons.schema.constants.Constants;
+
+/**
+ * XML Schema model class that represent the root node and contains a set of auxiliary
+ * methods to manage the tree.
+ *
+ * @author Dmitry Repchevsky
+ */
+
+public class XSModel<T, V extends T> extends XSNode<T,V> {
+ private XmlSchemaCollection schemas;
+
+ public XSModel() {
+ schemas = new XmlSchemaCollection();
+ }
+
+ public XSModel(XmlSchemaCollection schemas) {
+ this.schemas = schemas;
+ }
+
+ /**
+ * Binds XML Schemas to the model. Execution of this method cleans the model (tree).
+ *
+ * @param schemas new XML Schemas this model is based on.
+ */
+ public void setSchemaCollection(XmlSchemaCollection schemas) {
+ removeAllChildren();
+ this.schemas = schemas;
+ }
+
+ /**
+ * Finds a node that corresponds to the provided XPath
+ *
+ * @param xpath XPath expression for the queried node
+ *
+ * @return the node in the model that corresponds to the XPath query
+ */
+ public XSNode<T,V> findNode(String xpath) {
+ return findComponent(this, xpath);
+ }
+
+ private XSComponent findComponent(XSNode<T,V> node, String xpath) {
+ if (node instanceof XSComponent) {
+ XSComponent component = (XSComponent)node;
+ if (xpath.equals(component.getXPath())) {
+ return component;
+ }
+ }
+
+ for (int i = 0, n = node.getChildCount(); i < n; i++) {
+ XSNode<T, V> childNode = (XSNode<T, V>)node.getChildAt(i);
+ XSComponent component = findComponent(childNode, xpath);
+ if (component != null) {
+ return component;
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Includes the element (with all its subelements obtained from the schema) to the model.
+ *
+ * @param element the element name to include into the model.
+ */
+ public void addGlobalElement(QName element) {
+ XSComponent node = (XSComponent)findElement(element);
+
+ if (node != null) {
+ parse(node);
+ insert((V)node, getChildCount());
+ }
+ }
+
+ /**
+ * Includes the type (with all its subelements obtained from the schema) to the model.<br/>
+ * Note that the model will serialize this global type as if it was the element of the given type.<br/>
+ *
+ * @param type a global type name to add to the model
+ * @param name the top level name to be serialized.
+ */
+ public void addGlobalType(QName type, QName name) {
+ XSGlobalType node = findType(type, name);
+ if (node != null) {
+ parse(node);
+ insert((V)node, getChildCount());
+ }
+ }
+
+ /**
+ * Validates the model tree against provided XML Schemas.
+ * Basically it validates whether all obligatory components have their values set.
+ *
+ * @return true if model is valid, false otherwise.
+ */
+ public boolean validate() {
+ Boolean valid = null;
+
+ for (int i = 0, n = getChildCount(); i < n; i++) {
+ XSComponent node = (XSComponent)getChildAt(i);
+
+ Boolean b = node.validate();
+ if (Boolean.FALSE.equals(b)) {
+ valid = Boolean.FALSE;
+ break;
+ }
+
+ if (valid == null) {
+ valid = b;
+ }
+ }
+ return valid != null && valid;
+ }
+
+ /**
+ * Constructs the model based on XML obtained from the provided stream
+ *
+ * @param stream The XML reader where the XML is read from
+ * @throws javax.xml.stream.XMLStreamException
+ */
+ public void read(XMLStreamReader stream) throws XMLStreamException {
+ removeAllChildren();
+
+ readElement(this, stream);
+ }
+
+ /**
+ * Constructs an XML based on the data provided by the model.
+ *
+ * @param stream XML writer to write generated XML
+ * @throws javax.xml.stream.XMLStreamException
+ */
+ public void write(XMLStreamWriter stream) throws XMLStreamException {
+ for (int i = 0, n = getChildCount(); i < n; i++) {
+ XSComponent node = (XSComponent)getChildAt(i);
+ node.write(stream);
+ }
+ }
+
+ protected XSParticle newParticle(XmlSchemaParticle particle) {
+ return new XSParticle(particle);
+ }
+
+ protected XSGlobalElement newGlobalElement(XmlSchemaElement element) {
+ return new XSGlobalElement(element);
+ }
+
+ protected XSGlobalType newGlobalType(XmlSchemaType type, QName name) {
+ return new XSGlobalType(type, name);
+ }
+
+ protected XSType newType(XmlSchemaType type) {
+ return new XSType(type);
+ }
+
+ protected XSAttribute newAttribute(XmlSchemaAttribute attribute) {
+ return new XSAttribute(attribute);
+ }
+
+ protected XSMixedText newMixedText() {
+ return new XSMixedText();
+ }
+ /**
+ * Builds the tree branch (child nodes) for the node.
+ */
+ private void parse(XSComponent node) {
+ XmlSchemaType type = node.getType();
+ if (type instanceof XmlSchemaComplexType) {
+ addComplexType(node, (XmlSchemaComplexType)type);
+ }
+ }
+
+ private void readElement(XSNode parent, XMLStreamReader reader) throws XMLStreamException {
+ StringBuilder text = new StringBuilder();
+
+ while (reader.hasNext()) {
+ int eventType = reader.next();
+ if (eventType == XMLStreamReader.END_ELEMENT) {
+ if (text.length() > 0 && parent instanceof XSComponent) {
+ XSComponent node = (XSComponent)parent;
+ if (XSModel.getSimpleType(node) != null) {
+ node.setUserObject(text.toString());
+ }
+ }
+ return;
+ } else if (eventType == XMLStreamReader.START_ELEMENT) {
+ QName elementName = reader.getName();
+
+ if (parent.getParent() == null) {
+ XSGlobalElement node = findElement(elementName);
+ if (node != null) {
+ parent.insert(node, parent.getChildCount());
+ readAttributes(node, reader);
+ readElement(node, reader);
+ }
+ } else {
+ if (parent instanceof XSParticle) {
+ XSParticle<XSNode, XSNode> node = (XSParticle)parent;
+ XmlSchemaParticle particle = node.getXSComponent();
+ if (particle.getMaxOccurs() > 1) {
+ if (elementName.equals(node.getName())) {
+ XSType typeNode = newType(node.getType());
+ node.insert(typeNode, node.getChildCount());
+ readAttributes(typeNode, reader);
+ readElement(typeNode, reader);
+ continue;
+ }
+
+ // we have reached a last element in a repeated sequence...
+ // move up to one level
+ parent = node.getParent();
+ }
+ }
+
+ XSComponent node = (XSComponent)parent;
+ XmlSchemaType type = node.getType();
+
+ if (type instanceof XmlSchemaComplexType) {
+ Map<QName, XmlSchemaElement> elements = getElements(node);
+ XmlSchemaElement element = elements.get(elementName);
+ if (element != null) {
+ XSParticle particleNode = newParticle(element);
+ node.insert(particleNode, node.getChildCount());
+
+ if (element.getMaxOccurs() > 1) {
+ XSType typeNode = newType(particleNode.getType());
+ particleNode.insert(typeNode, particleNode.getChildCount());
+ parent = particleNode;
+
+ readAttributes(typeNode, reader);
+ readElement(typeNode, reader);
+ } else {
+ readAttributes(particleNode, reader);
+ readElement(particleNode, reader);
+ }
+ }
+ } else {
+ throw new XMLStreamException("Simple type " + type.getQName() + " cannot have children! ");
+ }
+ }
+ } else if (parent.getParent() != null &&
+ (eventType == XMLStreamReader.CHARACTERS ||
+ eventType == XMLStreamReader.CDATA)) {
+ text.append(reader.getText()); //.append(LINE_SEPARATOR);
+
+ XSComponent node = (XSComponent)parent;
+ XmlSchemaType type = node.getType();
+
+ if (type instanceof XmlSchemaComplexType) {
+ XmlSchemaComplexType complexType = (XmlSchemaComplexType)type;
+ if (complexType.isMixed()) {
+ XSMixedText textNode = newMixedText();
+ parent.insert(textNode, parent.getChildCount());
+
+ textNode.setUserObject(text.toString());
+ text.setLength(0);
+ }
+ }
+ }
+ }
+ }
+
+ private void readAttributes(XSComponent node, XMLStreamReader reader) throws XMLStreamException {
+ Map<QName, XmlSchemaAttribute> attributes = getAttributes(node);
+
+ for (int i = 0, n = reader.getAttributeCount(); i < n; i++) {
+ QName attributeName = reader.getAttributeName(i);
+
+ XmlSchemaAttribute attribute = attributes.get(attributeName);
+ if (attribute != null) {
+ XSAttribute attributeNode = newAttribute(attribute);
+ node.insert(attributeNode, node.getChildCount());
+ String value = reader.getAttributeValue(i);
+ if (value != null && value.length() > 0) {
+ XmlSchemaSimpleType simpleType = XSModel.getSimpleType(attributeNode);
+ if (Constants.XSD_QNAME.equals(simpleType.getQName())) {
+ QName qname = DatatypeConverter.parseQName(value, reader.getNamespaceContext());
+ attributeNode.setUserObject(qname);
+ } else {
+ attributeNode.setUserObject(value);
+ }
+ }
+ }
+ }
+ }
+
+ private XSGlobalElement findElement(QName elementName) {
+ XmlSchemaElement element = schemas.getElementByQName(elementName);
+ if (element != null) {
+ return newGlobalElement(element);
+ }
+ return null;
+ }
+
+ private XSGlobalType findType(QName typeName, QName partName) {
+ XmlSchemaType type = schemas.getTypeByQName(typeName);
+ if (type != null) {
+ return newGlobalType(type, partName);
+ }
+ return null;
+ }
+
+ private void addComplexType(XSComponent component, XmlSchemaComplexType complexType) {
+ Map<QName, XmlSchemaAttribute> attributes = new LinkedHashMap<QName, XmlSchemaAttribute>();
+ XSParser.addAttributes(attributes, complexType.getAttributes());
+
+ XmlSchemaParticle particle = complexType.getParticle();
+ if (particle != null) {
+ addParticle(component, particle);
+ } else {
+ XmlSchemaContentModel contentModel = complexType.getContentModel();
+ if (contentModel != null) {
+ XmlSchemaContent content = contentModel.getContent();
+ if (content instanceof XmlSchemaComplexContentExtension) {
+ XmlSchemaComplexContentExtension complexContentExtension = (XmlSchemaComplexContentExtension)content;
+ XSParser.addAttributes(attributes, complexContentExtension.getAttributes());
+
+ final QName baseTypeName = complexContentExtension.getBaseTypeName();
+ final XmlSchemaType baseType;
+ final XmlSchema xmlSchema = complexType.getParent();
+ final XmlSchemaCollection xmlSchemaCollection = xmlSchema.getParent();
+ if (xmlSchemaCollection != null) {
+ baseType = xmlSchemaCollection.getTypeByQName(baseTypeName);
+ } else {
+ baseType = xmlSchema.getTypeByName(baseTypeName);
+ }
+ addComplexType(component, (XmlSchemaComplexType)baseType);
+
+ particle = complexContentExtension.getParticle();
+ addParticle(component, particle);
+ } else if (content instanceof XmlSchemaComplexContentRestriction) {
+ XmlSchemaComplexContentRestriction complexContentRestriction = (XmlSchemaComplexContentRestriction)content;
+ XSParser.addAttributes(attributes, complexContentRestriction.getAttributes());
+ particle = complexContentRestriction.getParticle();
+ addParticle(component, particle);
+ } else if (content instanceof XmlSchemaSimpleContentExtension) {
+ XmlSchemaSimpleContentExtension simpleContentExtension = (XmlSchemaSimpleContentExtension)content;
+ XSParser.addAttributes(attributes, simpleContentExtension.getAttributes());
+ }
+ }
+ }
+
+ for (XmlSchemaAttribute attribute : attributes.values()) {
+ XSAttribute child = newAttribute(attribute);
+ String value = attribute.getDefaultValue();
+ if (value != null) {
+ child.setUserObject(value);
+ }
+ component.insert((V)child, 0);
+ }
+ }
+
+ private Map<QName, XmlSchemaAttribute> getAttributes(XSComponent component) {
+ Map<QName, XmlSchemaAttribute> attributes = new LinkedHashMap<QName, XmlSchemaAttribute>();
+ XmlSchemaType type = component.getType();
+ if (type instanceof XmlSchemaComplexType) {
+ XSParser.addAttributes(attributes, (XmlSchemaComplexType)type);
+ }
+ return attributes;
+ }
+
+ private static Map<QName, XmlSchemaElement> getElements(XSComponent component) {
+ Map<QName, XmlSchemaElement> elements = new LinkedHashMap();
+ XmlSchemaType type = component.getType();
+ if (type instanceof XmlSchemaComplexType) {
+ XSParser.addElements(elements, (XmlSchemaComplexType)type);
+ }
+ return elements;
+ }
+
+ /**
+ * Returns closest simple type that corresponds to this node text content.
+ * In simple it returns a simple type if node is editable or null otherwise.
+ *
+ * @param component
+ *
+ * @return a simple type for the node content or null.
+ */
+ public final static XmlSchemaSimpleType getSimpleType(XSComponent component) {
+ final XmlSchemaType type = component.getType();
+ return type == null ? null : XSParser.getSimpleType(type);
+ }
+
+ public void addParticle(XSComponent component, XmlSchemaParticle particle) {
+ if (particle instanceof XmlSchemaElement) {
+ XSParticle node = newParticle(particle);
+ component.insert((V)node, component.getChildCount());
+
+ XmlSchemaElement element = (XmlSchemaElement)particle;
+ String value = element.getDefaultValue();
+ if (value != null) {
+ node.setUserObject(value);
+ }
+
+ if (element.getMaxOccurs() <= 1) {
+ parse(node);
+ } else {
+ XmlSchemaType type = node.getType();
+ XSType tNode = newType(type);
+ parse(tNode);
+ node.insert(tNode, node.getChildCount());
+// for (int i = 0, n = Math.max(1, (int)particle.getMinOccurs()); i < n; i++) {
+// XSTypeNode tNode = new XSTypeNode(type);
+// node.add(tNode);
+// }
+ }
+ } else if (particle instanceof XmlSchemaSequence) {
+ XmlSchemaSequence sequence = (XmlSchemaSequence)particle;
+ List<XmlSchemaSequenceMember> items = sequence.getItems();
+ for (XmlSchemaSequenceMember item : items) {
+ addParticle(component, (XmlSchemaParticle)item);
+ }
+ } else if (particle instanceof XmlSchemaAll) {
+ XmlSchemaAll all = (XmlSchemaAll)particle;
+ List<XmlSchemaElement> elements = all.getItems();
+ for (XmlSchemaElement element : elements) {
+ addParticle(component, element);
+ }
+ } else if (particle instanceof XmlSchemaChoice) {
+ XmlSchemaChoice xmlSchemaChoice = (XmlSchemaChoice)particle;
+ List<XmlSchemaObject> items = xmlSchemaChoice.getItems();
+
+ // for the choice add only one element
+ addParticle(component, (XmlSchemaParticle)items.get(0));
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/schema/XSNode.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/schema/XSNode.java b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/schema/XSNode.java
new file mode 100644
index 0000000..39912ad
--- /dev/null
+++ b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/schema/XSNode.java
@@ -0,0 +1,127 @@
+/*
+* 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.schema;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.List;
+
+/**
+ * Generic Tree Node implementation class that is compatible with MutableTreeNode
+ * Swing interface. The class is used as a replacement of DefaultMutableTreeNode to
+ * remove Swing references from the package. It may be used as an implementation though
+ * {@code
+ * MyMutableTreeNode extends XSNode<TreeNode, MutableTreeNode> implements MutableTreeNode
+ * }.
+ *
+ * @author Dmitry Repchevsky
+ */
+
+public class XSNode <T, V extends T> {
+
+ private V parent;
+ private Object userObject;
+ private final List<V> children;
+
+ public XSNode() {
+ children = new ArrayList();
+ }
+
+ public void insert(V child, int index) {
+ if (child instanceof XSNode) {
+ XSNode<XSNode,XSNode> node = (XSNode)child;
+ XSNode oldParent = node.getParent();
+ if (oldParent != null) {
+ oldParent.remove(node);
+ }
+ node.setParent(this);
+ }
+ children.add(index, child);
+ }
+
+ public void remove(int index) {
+ V child = children.remove(index);
+ if (child instanceof XSNode) {
+ XSNode<XSNode,XSNode> node = (XSNode)child;
+ node.setParent(null);
+ }
+ }
+
+ public void remove(V child) {
+ if (children.remove(child) && child instanceof XSNode) {
+ XSNode<XSNode,XSNode> node = (XSNode)child;
+ node.setParent(null);
+ }
+ }
+
+ public Object getUserObject() {
+ return userObject;
+ }
+
+ public void setUserObject(Object object) {
+ this.userObject = object;
+ }
+
+ public void removeFromParent() {
+ if (parent instanceof XSNode) {
+ XSNode<XSNode,XSNode> node = (XSNode)parent;
+ node.remove(this);
+ }
+ }
+
+ public void setParent(V newParent) {
+ this.parent = newParent;
+ }
+
+ public V getChildAt(int childIndex) {
+ return children.get(childIndex);
+ }
+
+ public int getChildCount() {
+ return children.size();
+ }
+
+ public V getParent() {
+ return parent;
+ }
+
+ public int getIndex(T node) {
+ return children.indexOf(node);
+ }
+
+ public boolean getAllowsChildren() {
+ return true;
+ }
+
+ public boolean isLeaf() {
+ return children.isEmpty();
+ }
+
+ public Enumeration children() {
+ return Collections.enumeration(children);
+ }
+
+ public void removeAllChildren() {
+ for (int i = getChildCount()-1; i >= 0; i--) {
+ remove(i);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/schema/XSParser.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/schema/XSParser.java b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/schema/XSParser.java
new file mode 100644
index 0000000..7266e61
--- /dev/null
+++ b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/schema/XSParser.java
@@ -0,0 +1,274 @@
+/*
+* 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.schema;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import javax.xml.namespace.QName;
+import org.apache.ws.commons.schema.XmlSchema;
+import org.apache.ws.commons.schema.XmlSchemaAttribute;
+import org.apache.ws.commons.schema.XmlSchemaAttributeGroup;
+import org.apache.ws.commons.schema.XmlSchemaAttributeGroupMember;
+import org.apache.ws.commons.schema.XmlSchemaAttributeGroupRef;
+import org.apache.ws.commons.schema.XmlSchemaAttributeOrGroupRef;
+import org.apache.ws.commons.schema.XmlSchemaChoice;
+import org.apache.ws.commons.schema.XmlSchemaCollection;
+import org.apache.ws.commons.schema.XmlSchemaComplexContentExtension;
+import org.apache.ws.commons.schema.XmlSchemaComplexContentRestriction;
+import org.apache.ws.commons.schema.XmlSchemaComplexType;
+import org.apache.ws.commons.schema.XmlSchemaContent;
+import org.apache.ws.commons.schema.XmlSchemaContentModel;
+import org.apache.ws.commons.schema.XmlSchemaElement;
+import org.apache.ws.commons.schema.XmlSchemaGroup;
+import org.apache.ws.commons.schema.XmlSchemaGroupParticle;
+import org.apache.ws.commons.schema.XmlSchemaGroupRef;
+import org.apache.ws.commons.schema.XmlSchemaParticle;
+import org.apache.ws.commons.schema.XmlSchemaSequence;
+import org.apache.ws.commons.schema.XmlSchemaSimpleContentExtension;
+import org.apache.ws.commons.schema.XmlSchemaSimpleType;
+import org.apache.ws.commons.schema.XmlSchemaType;
+import org.apache.ws.commons.schema.utils.XmlSchemaObjectBase;
+import org.apache.ws.commons.schema.utils.XmlSchemaRef;
+
+/**
+ * @author Dmitry Repchevsky
+ */
+
+public class XSParser {
+
+ public static void addElements(Map<QName, XmlSchemaElement> elements, XmlSchemaComplexType complexType) {
+ XmlSchemaParticle particle = complexType.getParticle();
+ if (particle != null) {
+ addElement(elements, Arrays.asList(particle));
+ } else {
+ XmlSchemaContentModel contentModel = complexType.getContentModel();
+ if (contentModel != null) {
+ XmlSchemaContent content = contentModel.getContent();
+ if (content instanceof XmlSchemaComplexContentExtension) {
+ XmlSchemaComplexContentExtension complexContentExtension = (XmlSchemaComplexContentExtension)content;
+ QName baseTypeName = complexContentExtension.getBaseTypeName();
+
+ XmlSchema schema = complexType.getParent();
+ XmlSchemaCollection schemaCollection = schema.getParent();
+
+ final XmlSchemaType baseType;
+ if (schemaCollection != null) {
+ baseType = schemaCollection.getTypeByQName(baseTypeName);
+ } else {
+ baseType = schema.getTypeByName(baseTypeName);
+ }
+
+ if (baseType instanceof XmlSchemaComplexType) {
+ addElements(elements, (XmlSchemaComplexType)baseType);
+ }
+
+ particle = complexContentExtension.getParticle();
+ if (particle != null) {
+ addElement(elements, Arrays.asList(particle));
+ }
+ } else if (content instanceof XmlSchemaComplexContentRestriction) {
+ XmlSchemaComplexContentRestriction complexContentRestriction = (XmlSchemaComplexContentRestriction)content;
+ particle = complexContentRestriction.getParticle();
+ if (particle != null) {
+ addElement(elements, Arrays.asList(particle));
+ }
+ }
+ }
+ }
+ }
+
+ private static void addElement(Map<QName, XmlSchemaElement> elements, List<? extends XmlSchemaObjectBase> items) {
+ for (XmlSchemaObjectBase item : items) {
+ if (item instanceof XmlSchemaElement) {
+ XmlSchemaElement element = (XmlSchemaElement)item;
+ elements.put(element.getWireName(), element); // getElement(element)
+ } else if(item instanceof XmlSchemaSequence) {
+ final XmlSchemaSequence sequence = (XmlSchemaSequence)item;
+ addElement(elements, sequence.getItems());
+ } else if (item instanceof XmlSchemaChoice) {
+ XmlSchemaChoice choice = (XmlSchemaChoice)item;
+ addElement(elements, choice.getItems());
+ } else if (item instanceof XmlSchemaGroup) {
+ XmlSchemaGroup group = (XmlSchemaGroup)item;
+ XmlSchemaGroupParticle groupParticle = group.getParticle();
+ addElement(elements, Arrays.asList(groupParticle));
+ } else if (item instanceof XmlSchemaGroupRef) {
+ XmlSchemaGroupRef groupRef = (XmlSchemaGroupRef)item;
+ XmlSchemaGroupParticle groupParticle = groupRef.getParticle();
+ addElement(elements, Arrays.asList(groupParticle));
+ }
+ }
+ }
+
+ public static XmlSchemaSimpleType getSimpleType(XmlSchemaType type) {
+ if (type instanceof XmlSchemaSimpleType) {
+ return (XmlSchemaSimpleType)type;
+ }
+
+ XmlSchemaComplexType complexType = (XmlSchemaComplexType)type;
+ return getSimpleType(complexType);
+ }
+
+ private static XmlSchemaSimpleType getSimpleType(XmlSchemaComplexType complexType) {
+ XmlSchemaContentModel contentModel = complexType.getContentModel();
+ if (contentModel == null) {
+ return null;
+ }
+
+ XmlSchemaContent content = contentModel.getContent();
+
+ QName baseTypeName;
+ if (content instanceof XmlSchemaComplexContentExtension) {
+ XmlSchemaComplexContentExtension complexContentExtension = (XmlSchemaComplexContentExtension)content;
+ baseTypeName = complexContentExtension.getBaseTypeName();
+ } else if (content instanceof XmlSchemaComplexContentRestriction) {
+ XmlSchemaComplexContentRestriction complexContentRestriction = (XmlSchemaComplexContentRestriction)content;
+ baseTypeName = complexContentRestriction.getBaseTypeName();
+ } else if (content instanceof XmlSchemaSimpleContentExtension) {
+ XmlSchemaSimpleContentExtension simpleContentExtension = (XmlSchemaSimpleContentExtension)content;
+ baseTypeName = simpleContentExtension.getBaseTypeName();
+ } else {
+ return null; // shouldn't happen
+ }
+
+ XmlSchemaType baseType;
+ XmlSchema schema = complexType.getParent();
+ XmlSchemaCollection schemaCollection = schema.getParent();
+ if (schemaCollection != null) {
+ baseType = schemaCollection.getTypeByQName(baseTypeName);
+ } else {
+ baseType = schema.getTypeByName(baseTypeName);
+ }
+
+ return getSimpleType(baseType);
+ }
+
+ public static void addAttributes(Map<QName, XmlSchemaAttribute> attributes, XmlSchemaComplexType complexType) {
+ addAttributes(attributes, complexType.getAttributes());
+
+ XmlSchemaContentModel contentModel = complexType.getContentModel();
+ if (contentModel != null) {
+ XmlSchemaContent content = contentModel.getContent();
+ if (content instanceof XmlSchemaComplexContentExtension) {
+ XmlSchemaComplexContentExtension complexContentExtension = (XmlSchemaComplexContentExtension)content;
+ addAttributes(attributes, complexContentExtension.getAttributes());
+
+ final QName baseTypeName = complexContentExtension.getBaseTypeName();
+ final XmlSchemaType baseType;
+ final XmlSchema xmlSchema = complexType.getParent();
+ final XmlSchemaCollection xmlSchemaCollection = xmlSchema.getParent();
+ if (xmlSchemaCollection != null) {
+ baseType = xmlSchemaCollection.getTypeByQName(baseTypeName);
+ } else {
+ baseType = xmlSchema.getTypeByName(baseTypeName);
+ }
+ addAttributes(attributes, (XmlSchemaComplexType) baseType);
+ } else if (content instanceof XmlSchemaComplexContentRestriction) {
+ XmlSchemaComplexContentRestriction complexContentRestriction = (XmlSchemaComplexContentRestriction)content;
+ addAttributes(attributes, complexContentRestriction.getAttributes());
+ } else if (content instanceof XmlSchemaSimpleContentExtension) {
+ XmlSchemaSimpleContentExtension simpleContentExtension = (XmlSchemaSimpleContentExtension)content;
+ addAttributes(attributes, simpleContentExtension.getAttributes());
+ }
+ }
+ }
+
+ static void addAttributes(Map<QName, XmlSchemaAttribute> attributes, List<XmlSchemaAttributeOrGroupRef> attributeOrGroupRefs) {
+ for (XmlSchemaAttributeOrGroupRef attributeOrGroupRef : attributeOrGroupRefs) {
+ addAttributes(attributes, (XmlSchemaAttributeGroupMember)attributeOrGroupRef);
+ }
+ }
+
+ private static void addAttributes(Map<QName, XmlSchemaAttribute> attributes, XmlSchemaAttributeGroupMember attributeGroupMember) {
+ if (attributeGroupMember instanceof XmlSchemaAttribute) {
+ XmlSchemaAttribute attribute = (XmlSchemaAttribute)attributeGroupMember; //getAttribute((XmlSchemaAttribute)attributeGroupMember);
+ attributes.put(attribute.getWireName(), attribute);
+ } else {
+ XmlSchemaAttributeGroup attributeGroup;
+ if (attributeGroupMember instanceof XmlSchemaAttributeGroup) {
+ attributeGroup = (XmlSchemaAttributeGroup)attributeGroupMember;
+ }
+ else {
+ XmlSchemaAttributeGroupRef attributeGroupRef = (XmlSchemaAttributeGroupRef)attributeGroupMember;
+ XmlSchemaRef<XmlSchemaAttributeGroup> ref = attributeGroupRef.getRef();
+ attributeGroup = ref.getTarget();
+ }
+
+ List<XmlSchemaAttributeGroupMember> attributeGroupMembers = attributeGroup.getAttributes();
+ for (XmlSchemaAttributeGroupMember xmlSchemaAttributeGroupMember : attributeGroupMembers) {
+ addAttributes(attributes, xmlSchemaAttributeGroupMember);
+ }
+ }
+ }
+
+ /**
+ * Finds the attribute declaration.
+ * <xs:attribute name="surname" type="xs:string" />
+ * ...
+ * <xs:attribute ref="surname"/>
+ *
+ *
+ * @param attribute the attribute for which is declaration is needed
+ *
+ * @return attribute declaration which is either a referred attribute or
+ * attribute itself.
+ */
+ private static XmlSchemaAttribute getAttribute(XmlSchemaAttribute attribute) {
+ if (attribute.isRef()) {
+ XmlSchemaRef<XmlSchemaAttribute> ref = attribute.getRef();
+ XmlSchemaAttribute refAttribute = ref.getTarget();
+ if (refAttribute != null) {
+ return refAttribute;
+ }
+ QName targetName = ref.getTargetQName();
+ XmlSchema schema = attribute.getParent();
+ XmlSchemaCollection schemaCollection = schema.getParent();
+ if (schemaCollection != null) {
+ attribute = schemaCollection.getAttributeByQName(targetName);
+ } else {
+ attribute = schema.getAttributeByName(targetName);
+ }
+ }
+ return attribute;
+ }
+
+ final static XmlSchemaElement getElement(XmlSchemaElement element) {
+ XmlSchemaRef<XmlSchemaElement> ref = element.getRef();
+ if (ref != null) {
+ XmlSchemaElement refElement = ref.getTarget();
+ if (refElement != null) {
+ return refElement;
+ }
+ QName targetName = ref.getTargetQName();
+ if (targetName != null) {
+ XmlSchema schema = element.getParent();
+ XmlSchemaCollection schemaCollection = schema.getParent();
+ if (schemaCollection != null) {
+ element = schemaCollection.getElementByQName(targetName);
+ } else {
+ element = schema.getElementByName(targetName);
+ }
+ }
+ }
+ return element;
+ }
+
+}
[7/8] incubator-taverna-common-activities git commit: experimental
wsdl-generic based on XSD schema
Posted by re...@apache.org.
experimental wsdl-generic based on XSD schema
Project: http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/commit/df390d97
Tree: http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/tree/df390d97
Diff: http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/diff/df390d97
Branch: refs/heads/wsdl-xsd-experimental
Commit: df390d97dd3cb29ee42b84fbd030797357b8bf10
Parents: 0574ac5
Author: redmitry <re...@84.88.50.62>
Authored: Fri Aug 21 11:27:53 2015 +0200
Committer: redmitry <re...@84.88.50.62>
Committed: Tue Sep 1 18:04:34 2015 +0200
----------------------------------------------------------------------
taverna-wsdl-generic/pom.xml | 51 +-
.../wsdl/invoker/AbstractSOAPInvoker.java | 71 +++
.../wsdl/invoker/CommandLineInvoker.java | 110 ++++
.../taverna/wsdl/invoker/JAXWSInvoker.java | 316 ++++++++++
.../taverna/wsdl/invoker/SOAPInvoker.java | 41 ++
.../wsdl/invoker/SOAPInvokerFactory.java | 47 ++
.../wsdl/invoker/SOAPInvokerFactoryImpl.java | 36 ++
.../taverna/wsdl/invoker/WSSTokenProfile.java | 39 ++
.../wsdl/parser/ArrayTypeDescriptor.java | 56 --
.../wsdl/parser/AttributeTypeDescriptor.java | 29 -
.../taverna/wsdl/parser/BaseTypeDescriptor.java | 31 -
.../wsdl/parser/ComplexTypeDescriptor.java | 71 ---
.../taverna/wsdl/parser/GenericWSDLParser.java | 10 +-
.../taverna/wsdl/parser/TypeDescriptor.java | 297 ---------
.../taverna/wsdl/parser/TypeDescriptors.java | 631 -------------------
.../taverna/wsdl/parser/WSDL11Parser.java | 31 +-
.../taverna/wsdl/parser/WSDL20Parser.java | 53 +-
.../taverna/wsdl/parser/WSDLLocatorImpl.java | 95 +++
.../apache/taverna/wsdl/parser/WSDLParser.java | 66 +-
.../taverna/wsdl/parser/schema/XSAttribute.java | 118 ++++
.../taverna/wsdl/parser/schema/XSComponent.java | 113 ++++
.../wsdl/parser/schema/XSGlobalElement.java | 209 ++++++
.../wsdl/parser/schema/XSGlobalType.java | 50 ++
.../taverna/wsdl/parser/schema/XSMixedText.java | 66 ++
.../taverna/wsdl/parser/schema/XSModel.java | 474 ++++++++++++++
.../taverna/wsdl/parser/schema/XSNode.java | 127 ++++
.../taverna/wsdl/parser/schema/XSParser.java | 274 ++++++++
.../taverna/wsdl/parser/schema/XSParticle.java | 193 ++++++
.../taverna/wsdl/parser/schema/XSType.java | 105 +++
.../wsdl/parser/schema/package-info.java | 6 +
.../taverna/wsdl/soap/AbstractBodyBuilder.java | 373 -----------
.../wsdl/soap/AbstractSOAPResponseParser.java | 46 --
.../apache/taverna/wsdl/soap/BodyBuilder.java | 45 --
.../taverna/wsdl/soap/BodyBuilderFactory.java | 52 --
.../wsdl/soap/CyclicReferenceException.java | 35 -
.../taverna/wsdl/soap/EncodedBodyBuilder.java | 158 -----
.../apache/taverna/wsdl/soap/JaxWSInvoker.java | 235 -------
.../taverna/wsdl/soap/LiteralBodyBuilder.java | 226 -------
.../taverna/wsdl/soap/ObjectConverter.java | 158 -----
.../soap/SOAPResponseEncodedMultiRefParser.java | 181 ------
.../wsdl/soap/SOAPResponseEncodedParser.java | 174 -----
.../wsdl/soap/SOAPResponseLiteralParser.java | 79 ---
.../taverna/wsdl/soap/SOAPResponseParser.java | 48 --
.../wsdl/soap/SOAPResponseParserFactory.java | 94 ---
.../SOAPResponsePrimitiveLiteralParser.java | 71 ---
.../wsdl/soap/SOAPResponsePrimitiveParser.java | 149 -----
.../taverna/wsdl/soap/WSDLSOAPInvoker.java | 288 ---------
.../taverna/wsdl/soap/WSSTokenProfile.java | 39 --
.../org/apache/taverna/wsdl/soap/package.html | 5 -
.../wsdl/xmlsplitter/XMLInputSplitter.java | 286 ---------
.../wsdl/xmlsplitter/XMLOutputSplitter.java | 198 ------
.../XMLSplitterExecutionException.java | 33 -
.../XMLSplitterSerialisationHelper.java | 341 ----------
...ache.taverna.wsdl.invoker.SOAPInvokerFactory | 1 +
.../wsdl/invoker/CommandLineInvokerTest.java | 50 ++
.../taverna/wsdl/parser/TypeDescriptorTest.java | 226 -------
.../taverna/wsdl/parser/WSDLParserTest.java | 313 ++++-----
.../parser/schema/test/ComplexType1Test.java | 180 ++++++
.../parser/schema/test/ComplexType2Test.java | 146 +++++
.../parser/schema/test/ComplexType3Test.java | 171 +++++
.../parser/schema/test/ComplexType4Test.java | 151 +++++
.../parser/schema/test/ComplexType5Test.java | 161 +++++
.../parser/schema/test/ComplexType6Test.java | 148 +++++
.../parser/schema/test/ComplexType7Test.java | 160 +++++
.../parser/schema/test/ComplexType8Test.java | 185 ++++++
.../parser/schema/test/SimpleType1Test.java | 122 ++++
.../parser/schema/test/SimpleType2Test.java | 121 ++++
.../parser/schema/test/TestSchemaTreeModel.java | 91 +++
.../parser/schema/test/XmlSchema001Test.java | 199 ++++++
.../wsdl/soap/EncodedBodyBuilderTest.java | 196 +++---
.../wsdl/soap/LiteralBodyBuilderTest.java | 214 +++----
.../wsdl/soap/SOAPResponseEncodedTest.java | 66 +-
.../wsdl/soap/SOAPResponseLiteralTest.java | 199 +++---
.../wsdl/soap/SOAPResponseMultiRefTest.java | 334 +++++-----
.../soap/SOAPResponseParserFactoryTest.java | 28 +-
.../taverna/wsdl/testutils/WSDLTestHelper.java | 5 +-
.../wsdl/xmlsplitter/XMLInputSplitterTest.java | 93 ---
.../wsdl/xmlsplitter/XMLOutputSplitterTest.java | 93 ---
.../XMLSplitterSerialisationHelperTest.java | 141 -----
.../wsdl/parser/schema/complex_type1.xml | 4 +
.../wsdl/parser/schema/complex_type1.xsd | 20 +
.../wsdl/parser/schema/complex_type2.xml | 4 +
.../wsdl/parser/schema/complex_type2.xsd | 18 +
.../wsdl/parser/schema/complex_type3.xml | 1 +
.../wsdl/parser/schema/complex_type3.xsd | 31 +
.../wsdl/parser/schema/complex_type4.xml | 4 +
.../wsdl/parser/schema/complex_type4.xsd | 19 +
.../wsdl/parser/schema/complex_type5.xml | 5 +
.../wsdl/parser/schema/complex_type5.xsd | 30 +
.../wsdl/parser/schema/complex_type6.xml | 1 +
.../wsdl/parser/schema/complex_type6.xsd | 29 +
.../wsdl/parser/schema/complex_type7.xml | 6 +
.../wsdl/parser/schema/complex_type7.xsd | 28 +
.../wsdl/parser/schema/complex_type8.xml | 4 +
.../wsdl/parser/schema/complex_type8.xsd | 31 +
.../taverna/wsdl/parser/schema/simple_type1.xml | 1 +
.../taverna/wsdl/parser/schema/simple_type1.xsd | 15 +
.../taverna/wsdl/parser/schema/simple_type2.xml | 1 +
.../taverna/wsdl/parser/schema/simple_type2.xsd | 15 +
.../parser/schema/xml-schema-example-001.xml | 9 +
.../parser/schema/xml-schema-example-001.xsd | 28 +
101 files changed, 5496 insertions(+), 5732 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/pom.xml
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/pom.xml b/taverna-wsdl-generic/pom.xml
index 2f95e3b..98d3987 100644
--- a/taverna-wsdl-generic/pom.xml
+++ b/taverna-wsdl-generic/pom.xml
@@ -9,12 +9,11 @@
</parent>
<artifactId>taverna-wsdl-generic</artifactId>
- <!--
- <version>2.1.1-incubating-SNAPSHOT</version>
- -->
+ <version>3.0.0-incubating-SNAPSHOT</version>
+
<packaging>bundle</packaging>
<name>Apache Taverna WSDL-generic Library</name>
- <description>WSDL 1.1/2.0 generic parsing library</description>
+ <description>WSDL 1.1/2.0 handling classes bundled for Taverna 3 OSGi</description>
<build>
<plugins>
@@ -23,6 +22,30 @@
<artifactId>maven-bundle-plugin</artifactId>
<version>2.3.7</version>
<extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Bundle-RequiredExecutionEnvironment>JavaSE-1.7</Bundle-RequiredExecutionEnvironment>
+ <Main-Class>org.apache.taverna.wsdl.invoker.CommandLineInvoker</Main-Class>
+ <Import-Package>
+ javax.activation;version="0.0.0",
+ javax.xml.bind;version="0.0.0",
+ javax.xml.namespace;version="0.0.0",
+ javax.xml.parsers;version="0.0.0",
+ javax.xml.soap;version="0.0.0",
+ javax.xml.transform;version="0.0.0",
+ javax.xml.transform.dom;version="0.0.0",
+ javax.xml.transform.stream;version="0.0.0",
+ javax.xml.ws;version="0.0.0",
+ javax.xml.ws.handler;version="0.0.0",
+ javax.xml.ws.handler.soap;version="0.0.0",
+ org.w3c.dom;version="0.0.0",
+ org.w3c.dom.ls;version="0.0.0",
+ org.xml.sax;version="0.0.0",
+ *
+ </Import-Package>
+ </instructions>
+ </configuration>
+
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
@@ -50,11 +73,19 @@
</execution>
</executions>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.3.2</version>
+ <configuration>
+ <source>1.7</source>
+ <target>1.7</target>
+ </configuration>
+ </plugin>
</plugins>
</build>
<dependencies>
-
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
@@ -76,16 +107,16 @@
<version>${javax.wsdl.version}</version>
</dependency>
<dependency>
- <groupId>org.apache.woden</groupId>
- <artifactId>woden-api</artifactId>
- <version>1.0M9</version>
- </dependency>
- <dependency>
<groupId>org.apache.ws.xmlschema</groupId>
<artifactId>xmlschema-core</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
+ <groupId>org.apache.woden</groupId>
+ <artifactId>woden</artifactId>
+ <version>1.0M9</version>
+ </dependency>
+ <dependency>
<groupId>org.apache.ws.security</groupId>
<artifactId>wss4j</artifactId>
<version>1.6.18</version>
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/invoker/AbstractSOAPInvoker.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/invoker/AbstractSOAPInvoker.java b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/invoker/AbstractSOAPInvoker.java
new file mode 100644
index 0000000..b923a50
--- /dev/null
+++ b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/invoker/AbstractSOAPInvoker.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.invoker;
+
+import java.util.Map;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+import org.apache.taverna.wsdl.parser.UnknownOperationException;
+import org.apache.taverna.wsdl.parser.WSDLParser;
+import org.apache.taverna.wsdl.parser.schema.XSComponent;
+import org.apache.taverna.wsdl.parser.schema.XSModel;
+import org.apache.taverna.wsdl.parser.schema.XSNode;
+
+/**
+ * @author Dmitry Repchevsky
+ */
+
+public abstract class AbstractSOAPInvoker implements SOAPInvoker {
+ private final XSModel<XSComponent, XSComponent> input, output;
+
+ public AbstractSOAPInvoker(WSDLParser parser, String port, String operationXPointer) throws UnknownOperationException {
+ input = parser.getInputDataModel(operationXPointer);
+ output = parser.getInputDataModel(operationXPointer);
+ }
+
+
+ protected void writeInputs(XMLStreamWriter writer, Map<String, Object> inputs) throws XMLStreamException {
+ for (Map.Entry<String, Object> entry : inputs.entrySet()) {
+ XSNode node = input.findNode(entry.getKey());
+ if (node != null) {
+ node.setUserObject(entry.getValue());
+ }
+ }
+
+ input.write(writer);
+ }
+
+ protected void readOutputs(XMLStreamReader reader, Map<String, Object> outputs) throws XMLStreamException {
+ output.read(reader);
+ addOutputs(output, outputs);
+ }
+
+ private void addOutputs(XSNode<XSComponent, XSComponent> node, Map<String, Object> outputs) {
+ for (int i = 0, n = node.getChildCount(); i < n; i++) {
+ XSComponent component = node.getChildAt(i);
+ Object value = component.getUserObject();
+ if (value != null && value.toString().length() > 0) {
+ outputs.put(component.getXPath(), value);
+ }
+ addOutputs(component, outputs);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/invoker/CommandLineInvoker.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/invoker/CommandLineInvoker.java b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/invoker/CommandLineInvoker.java
new file mode 100644
index 0000000..bc90787
--- /dev/null
+++ b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/invoker/CommandLineInvoker.java
@@ -0,0 +1,110 @@
+/*
+* 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.invoker;
+
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.nio.file.StandardOpenOption;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.taverna.wsdl.parser.WSDLParser;
+
+/**
+ * @author Dmitry Repchevsky
+ */
+
+public class CommandLineInvoker {
+
+ public static void main(String[] args) {
+
+ String wsdlLocation = null;
+ String operation = null;
+ String xpath = null;
+
+ String username = null;
+ String password = null;
+
+ final Map<String, Object> inputs = new HashMap();
+ final Map<String, Object> files = new HashMap();
+ final Map<String, Object> outputs = new HashMap();
+
+ Map<String, Object> parameters = null;
+
+ for (String arg : args) {
+ switch(arg) {
+ case "-u" : xpath = null; username = ""; break;
+ case "-p" : xpath = null; password = ""; break;
+ case "-wsdl" : xpath = null; wsdlLocation = ""; break;
+ case "-operation" : xpath = null; operation = ""; break;
+ case "-in" : xpath = null; parameters = inputs; break;
+ case "-file" : xpath = null; parameters = files; break;
+ case "-out" : xpath = null; parameters = outputs; break;
+ default : if (username != null && username.isEmpty()) {
+ username = arg.isEmpty() ? null : arg;
+ } else if (password != null && password.isEmpty()) {
+ password = arg.isEmpty() ? null : arg;
+ } else if (wsdlLocation != null && wsdlLocation.isEmpty()) {
+ wsdlLocation = arg;
+ } else if (operation != null && operation.isEmpty()) {
+ operation = arg;
+ } else if (xpath == null){
+ xpath = arg;
+ } else if (parameters != null) {
+ parameters.put(xpath, arg);
+ } else {
+ throw new IllegalArgumentException();
+ }
+ }
+ }
+
+ if (wsdlLocation == null || wsdlLocation.isEmpty()) {
+ throw new IllegalArgumentException("no wsdl location specified");
+ }
+
+ try {
+ WSDLParser parser = new WSDLParser(wsdlLocation);
+
+ for(Map.Entry<String, Object> entry : files.entrySet()) {
+ final String path = entry.getValue().toString();
+ byte[] file = Files.readAllBytes(Paths.get(path));
+ inputs.put(entry.getKey(), new String(file));
+ }
+
+ SOAPInvokerFactory factory = SOAPInvokerFactory.newInstance();
+ SOAPInvoker invoker = factory.newSOAPInvoker(parser, null, operation);
+
+ if (username != null && password != null) {
+ invoker.setCredentials(username, password);
+ }
+
+ Map<String, Object> result = invoker.invoke(inputs);
+
+ for(Map.Entry<String, Object> entry : outputs.entrySet()) {
+ final String key = entry.getKey();
+ final String path = entry.getValue().toString();
+
+ String value = result.get(key).toString();
+ Files.write(Paths.get(path), value.getBytes(), StandardOpenOption.CREATE);
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/invoker/JAXWSInvoker.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/invoker/JAXWSInvoker.java b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/invoker/JAXWSInvoker.java
new file mode 100644
index 0000000..aa76a31
--- /dev/null
+++ b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/invoker/JAXWSInvoker.java
@@ -0,0 +1,316 @@
+/*
+* 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.invoker;
+
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import javax.xml.bind.DatatypeConverter;
+import javax.xml.namespace.QName;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.soap.MessageFactory;
+import javax.xml.soap.SAAJResult;
+import javax.xml.soap.SOAPBody;
+import javax.xml.soap.SOAPConstants;
+import javax.xml.soap.SOAPException;
+import javax.xml.soap.SOAPMessage;
+import javax.xml.soap.SOAPPart;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.ws.BindingProvider;
+import javax.xml.ws.Dispatch;
+import javax.xml.ws.Service;
+import javax.xml.ws.handler.Handler;
+import javax.xml.ws.handler.MessageContext;
+import javax.xml.ws.handler.soap.SOAPHandler;
+import javax.xml.ws.handler.soap.SOAPMessageContext;
+import javax.xml.ws.soap.SOAPBinding;
+import org.apache.taverna.wsdl.parser.UnknownOperationException;
+import org.apache.taverna.wsdl.parser.WSDLParser;
+import org.apache.ws.security.WSConstants;
+import org.apache.ws.security.WSSecurityException;
+import org.apache.ws.security.message.WSSecHeader;
+import org.apache.ws.security.message.WSSecUsernameToken;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+
+/**
+ * JAX-WS based invoker. The invoker uses Apache WSS4j security library.
+ *
+ * @author Dmitry Repchevsky
+ */
+
+public class JAXWSInvoker extends AbstractSOAPInvoker {
+
+ private Dispatch<SOAPMessage> dispatch;
+
+ private String username;
+ private String password;
+ private WSSTokenProfile token;
+
+ public JAXWSInvoker(WSDLParser parser, String portName, String operationName) throws UnknownOperationException {
+ super(parser, portName, operationName);
+
+ QName port_qname = null;
+ for (QName service_name : parser.getServices()) {
+ loop:
+ for (String port_name : parser.getPorts(service_name)) {
+ if (portName == null) {
+ for (String operation_name : parser.getOperations(port_name)) {
+ if (operation_name.equals(operationName)) {
+ port_qname = new QName(port_name);
+ break loop;
+ }
+ }
+ } else if (portName.equals(port_name)) {
+ port_qname = new QName(portName);
+ break;
+ }
+ }
+
+ if (port_qname != null) {
+ // found the port in this service
+ Service service = Service.create(service_name);
+ String endpoint = parser.getOperationEndpointLocation(port_qname.getLocalPart());
+ service.addPort(port_qname, SOAPBinding.SOAP11HTTP_BINDING, endpoint); // TODO: SOAP version
+
+ dispatch = service.createDispatch(port_qname, SOAPMessage.class, javax.xml.ws.Service.Mode.MESSAGE);
+
+ List<Handler> chain = new ArrayList();//Arrays.asList(new InvokerHandler());
+ chain.add(new WSSHandler());
+
+ dispatch.getBinding().setHandlerChain(chain);
+
+ break;
+ }
+ }
+
+ // assert(dispatch != null)
+
+ if (operationName != null) {
+ try {
+ String soapAction = parser.getSOAPActionURI(operationName);
+ if (soapAction != null) {
+ Map<String, Object> rc = dispatch.getRequestContext();
+ rc.put(BindingProvider.SOAPACTION_USE_PROPERTY, Boolean.TRUE);
+ rc.put(BindingProvider.SOAPACTION_URI_PROPERTY, soapAction);
+ }
+ }
+ catch(Exception ex) {}
+ }
+ }
+
+ /**
+ * Sets user credentials. If there is no WSS token profile is defined HTTP security is used
+ *
+ * @param username
+ * @param password
+ */
+ @Override
+ public void setCredentials(String username, String password) {
+ this.username = username;
+ this.password = password;
+ }
+
+ /**
+ * Specifies a token profile for WSS security
+ *
+ * @param token WSS security token to be used
+ */
+ public void setWSSSecurity(WSSTokenProfile token) {
+ this.token = token;
+ }
+
+ /**
+ * Sets up an http timeout.
+ *
+ * @param timeout
+ */
+ @Override
+ public void setTimeout(int timeout) {
+ Map<String, Object> rc = dispatch.getRequestContext();
+
+ // these parameters are SUN METRO JAX-WS implementation specific
+ rc.put("com.sun.xml.internal.ws.request.timeout", timeout);
+ rc.put("com.sun.xml.internal.ws.connect.timeout", timeout);
+
+// rc.put(BindingProviderProperties.REQUEST_TIMEOUT, timeout);
+// rc.put(BindingProviderProperties.CONNECT_TIMEOUT, timeout);
+ }
+
+ @Override
+ public Map<String, Object> invoke(Map<String, Object> inputs) throws Exception {
+ MessageFactory factory = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL); // TODO: SOAP version
+ SOAPMessage message = factory.createMessage();
+
+ createSoapBody(message, inputs);
+
+ SOAPMessage response = call(message);
+
+ return parseSoapBody(response);
+ }
+
+ /**
+ * Prepares the soap message body filling it with provided input data
+ *
+ * @param message the message for which the body is being constructed.
+ * @param inputs message parameters map with xpath keys.
+ *
+ * @throws SOAPException
+ * @throws ParserConfigurationException
+ * @throws XMLStreamException
+ */
+ private void createSoapBody(SOAPMessage message, Map<String, Object> inputs)
+ throws XMLStreamException, TransformerConfigurationException, TransformerException, SOAPException {
+
+ StringWriter w = new StringWriter();
+ XMLOutputFactory streamFactory = XMLOutputFactory.newInstance();
+ streamFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
+ XMLStreamWriter writer = streamFactory.createXMLStreamWriter(w);
+
+ writeInputs(writer, inputs); // generate SOAP Body document
+
+ TransformerFactory transformerFactory = TransformerFactory.newInstance();
+ Transformer transformer = transformerFactory.newTransformer();
+ transformer.transform(new StreamSource(new StringReader(w.toString())), new SAAJResult(message.getSOAPBody()));
+ }
+
+ private Map<String, Object> parseSoapBody(SOAPMessage message) throws SOAPException, XMLStreamException, TransformerConfigurationException, TransformerException {
+ SOAPBody body = message.getSOAPBody();
+ Node node = body.getFirstChild();
+
+ StringWriter w = new StringWriter();
+
+ TransformerFactory transformerFactory = TransformerFactory.newInstance();
+ Transformer transformer = transformerFactory.newTransformer();
+ transformer.transform(new DOMSource(node), new StreamResult(w));
+
+ XMLInputFactory streamFactory = XMLInputFactory.newInstance();
+ XMLStreamReader reader = streamFactory.createXMLStreamReader(new StringReader(w.toString()));
+
+ Map<String, Object> outputs = new HashMap();
+ readOutputs(reader, outputs);
+ return outputs;
+ }
+
+ private SOAPMessage call(SOAPMessage message) throws Exception {
+
+ Map<String, Object> rc = dispatch.getRequestContext();
+
+ // if credentials are set, but no WS-Security token is defined
+ // use Basic HTTP Authentication
+ if (username != null && username.length() > 0 &&
+ password != null && password.length() > 0 &&
+ token == null) {
+ rc.put(BindingProvider.USERNAME_PROPERTY, username);
+ rc.put(BindingProvider.PASSWORD_PROPERTY, password);
+ } else {
+ if (rc.containsKey(BindingProvider.USERNAME_PROPERTY)) {
+ rc.remove(BindingProvider.USERNAME_PROPERTY);
+ }
+ if (rc.containsKey(BindingProvider.PASSWORD_PROPERTY)) {
+ rc.remove(BindingProvider.PASSWORD_PROPERTY);
+ }
+ }
+
+ return dispatch.invoke(message);
+ }
+
+ class WSSHandler implements SOAPHandler<SOAPMessageContext> {
+
+ @Override
+ public Set getHeaders() {
+ return Collections.EMPTY_SET;
+ }
+
+ @Override
+ public void close(MessageContext context) {
+
+ }
+
+ @Override
+ public boolean handleMessage(SOAPMessageContext context) {
+
+ if (Boolean.TRUE == context.get(SOAPMessageContext.MESSAGE_OUTBOUND_PROPERTY)) {
+ if (username != null && username.length() > 0 &&
+ password != null && password.length() > 0 &&
+ token != null) {
+
+ SOAPMessage message = context.getMessage();
+ SOAPPart part = message.getSOAPPart();
+
+ try {
+ switch(token) {
+ case UsernameToken: {
+ WSSecUsernameToken builder = new WSSecUsernameToken();
+ builder.setPasswordType(WSConstants.PASSWORD_TEXT);
+ builder.setUserInfo(username, password);
+
+ WSSecHeader secHeader = new WSSecHeader();
+ secHeader.insertSecurityHeader(part);
+ Document signed = builder.build(part, secHeader);
+ part.setContent(new DOMSource(signed));
+ }
+ case PasswordDigest: {
+ WSSecUsernameToken builder = new WSSecUsernameToken();
+ builder.setPasswordType(WSConstants.PASSWORD_TEXT);
+ MessageDigest sha = MessageDigest.getInstance("MD5");
+ sha.reset();
+ sha.update(password.getBytes());
+ String passwdDigest = DatatypeConverter.printBase64Binary(sha.digest());
+ builder.setUserInfo(username, passwdDigest);
+ WSSecHeader secHeader = new WSSecHeader();
+ secHeader.insertSecurityHeader(part);
+ Document signed = builder.build(part, secHeader);
+ part.setContent(new DOMSource(signed));
+ }
+ }
+ }
+ catch (WSSecurityException | SOAPException | NoSuchAlgorithmException ex) {}
+ }
+ }
+
+ return true;
+ }
+
+ @Override
+ public boolean handleFault(SOAPMessageContext context) {
+ return true;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/invoker/SOAPInvoker.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/invoker/SOAPInvoker.java b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/invoker/SOAPInvoker.java
new file mode 100644
index 0000000..82a070c
--- /dev/null
+++ b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/invoker/SOAPInvoker.java
@@ -0,0 +1,41 @@
+/*
+* 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.invoker;
+
+import java.util.Map;
+
+/**
+ * @author Dmitry Repchevsky
+ */
+
+public interface SOAPInvoker {
+ void setTimeout(int timeout);
+ void setCredentials(String username, String password);
+
+ /**
+ * Calls the service with provided input parameters.
+ *
+ * @param inputs
+ * @return
+ *
+ * @throws Exception
+ */
+ Map<String, Object> invoke(Map<String, Object> inputs) throws Exception;
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/invoker/SOAPInvokerFactory.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/invoker/SOAPInvokerFactory.java b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/invoker/SOAPInvokerFactory.java
new file mode 100644
index 0000000..4b86aba
--- /dev/null
+++ b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/invoker/SOAPInvokerFactory.java
@@ -0,0 +1,47 @@
+/*
+* 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.invoker;
+
+import java.util.Iterator;
+import java.util.ServiceLoader;
+import org.apache.taverna.wsdl.parser.UnknownOperationException;
+import org.apache.taverna.wsdl.parser.WSDLParser;
+
+/**
+ * @author Dmitry Repchevsky
+ */
+
+public abstract class SOAPInvokerFactory {
+
+ public abstract SOAPInvoker newSOAPInvoker(WSDLParser parser, String portName, String operationXPointer)
+ throws UnknownOperationException;
+
+ public static SOAPInvokerFactory newInstance() {
+ ServiceLoader<SOAPInvokerFactory> loader = ServiceLoader.load(SOAPInvokerFactory.class, SOAPInvokerFactory.class.getClassLoader());
+ Iterator<SOAPInvokerFactory> iterator = loader.iterator();
+
+ if (iterator.hasNext()) {
+ return iterator.next();
+ }
+
+ throw new RuntimeException("implementation not found");
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/invoker/SOAPInvokerFactoryImpl.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/invoker/SOAPInvokerFactoryImpl.java b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/invoker/SOAPInvokerFactoryImpl.java
new file mode 100644
index 0000000..90a14e8
--- /dev/null
+++ b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/invoker/SOAPInvokerFactoryImpl.java
@@ -0,0 +1,36 @@
+/*
+* 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.invoker;
+
+import org.apache.taverna.wsdl.parser.UnknownOperationException;
+import org.apache.taverna.wsdl.parser.WSDLParser;
+
+/**
+ * @author Dmitry Repchevsky
+ */
+
+public class SOAPInvokerFactoryImpl extends SOAPInvokerFactory {
+
+ @Override
+ public SOAPInvoker newSOAPInvoker(WSDLParser parser, String portName, String operationXPointer) throws UnknownOperationException {
+ return new JAXWSInvoker(parser, portName, operationXPointer);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/invoker/WSSTokenProfile.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/invoker/WSSTokenProfile.java b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/invoker/WSSTokenProfile.java
new file mode 100644
index 0000000..880dab0
--- /dev/null
+++ b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/invoker/WSSTokenProfile.java
@@ -0,0 +1,39 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+
+package org.apache.taverna.wsdl.invoker;
+
+/**
+ * @author Dmitry Repchevsky
+ */
+
+public enum WSSTokenProfile {
+
+ PasswordDigest("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest"),
+ PasswordText("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText"),
+ UsernameToken("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#UsernameToken"),
+ Base64Binary("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soapmessage-security-1.0#Base64Binary"),
+ X509v3("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3");
+
+ public final String TOKEN;
+
+ private WSSTokenProfile(String token) {
+ TOKEN = token;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/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
deleted file mode 100644
index 32364ee..0000000
--- a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/ArrayTypeDescriptor.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
-* 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/df390d97/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
deleted file mode 100644
index ff80b01..0000000
--- a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/AttributeTypeDescriptor.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
-* 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/df390d97/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
deleted file mode 100644
index deed212..0000000
--- a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/BaseTypeDescriptor.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
-* 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/df390d97/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
deleted file mode 100644
index e428277..0000000
--- a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/ComplexTypeDescriptor.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
-* 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/df390d97/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
index 73c22aa..d061358 100644
--- 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
@@ -22,7 +22,8 @@ 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;
+import org.apache.ws.commons.schema.XmlSchemaCollection;
+import org.apache.ws.commons.schema.utils.XmlSchemaNamed;
/**
* @author Dmitry Repchevsky
@@ -35,7 +36,7 @@ public interface GenericWSDLParser {
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;
@@ -47,6 +48,7 @@ public interface GenericWSDLParser {
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;
+ XmlSchemaCollection getXmlSchemas();
+ LinkedHashMap<String, XmlSchemaNamed> getInputParameters(String portName, String operationName) throws UnknownOperationException;
+ LinkedHashMap<String, XmlSchemaNamed> getOutputParameters(String portName, String operationName) throws UnknownOperationException;
}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/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
deleted file mode 100644
index f7bcbcf..0000000
--- a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/TypeDescriptor.java
+++ /dev/null
@@ -1,297 +0,0 @@
-/*
-* 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;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/TypeDescriptors.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/TypeDescriptors.java b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/TypeDescriptors.java
deleted file mode 100644
index cffc320..0000000
--- a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/parser/TypeDescriptors.java
+++ /dev/null
@@ -1,631 +0,0 @@
-/*
-* 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.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.util.ArrayList;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import javax.xml.XMLConstants;
-import javax.xml.namespace.QName;
-import javax.xml.soap.SOAPConstants;
-import org.apache.ws.commons.schema.*;
-import org.apache.ws.commons.schema.utils.XmlSchemaObjectBase;
-import org.apache.ws.commons.schema.utils.XmlSchemaRef;
-import org.w3c.dom.Attr;
-import org.xml.sax.InputSource;
-
-/**
- * An utility class to construct WSDL type descriptors based on XML Schema.
- *
- * @author Dmitry Repchevsky
- */
-
-public class TypeDescriptors
-{
- private final XmlSchemaCollection schemas;
-
- /**
- * Constructor that takes a collection of XML Schemas.
- *
- * @param schemas XML Schemas that this class uses to build type descriptors
- */
- public TypeDescriptors(XmlSchemaCollection schemas) {
- this.schemas = schemas;
-
- if (schemas.schemaForNamespace(SOAPConstants.URI_NS_SOAP_ENCODING) == null) {
- // get soapEncoding datatypes
- try {
- InputStream soapEncodingStream = TypeDescriptors.class.getClassLoader().getResourceAsStream("META-INF/soap-encoding.xsd");
- try {
- schemas.read(new InputSource(soapEncodingStream));
- }
- finally {
- soapEncodingStream.close();
- }
-
-// URL soapEncodingURL = new URL(SOAPConstants.URI_NS_SOAP_ENCODING);
-// InputStream soapEncodingStream = soapEncodingURL.openStream();
-// try {
-// schemas.read(new InputSource(soapEncodingStream));
-// }
-// finally {
-// soapEncodingStream.close();
-// }
- }
- catch(MalformedURLException ex) {}
- catch(IOException ex) {}
- }
- }
-
- public static List<TypeDescriptor> getDescriptors(LinkedHashMap<String, XmlSchemaObject> map) {
-
- List<TypeDescriptor> result = new ArrayList<TypeDescriptor>();
-
- for (Map.Entry<String, XmlSchemaObject> parameter : map.entrySet()) {
-
- TypeDescriptor typeDescriptor;
-
- String partName = parameter.getKey();
- XmlSchemaObject xmlSchemaObject = parameter.getValue();
-
- if (xmlSchemaObject instanceof XmlSchemaElement) {
- typeDescriptor = getDescriptor((XmlSchemaElement)xmlSchemaObject);
- } else if (xmlSchemaObject instanceof XmlSchemaType) {
- typeDescriptor = getDescriptor((XmlSchemaType)xmlSchemaObject);
- } else {
- throw new IllegalArgumentException("wrong XmlSchemaObject. Mast be either xs:element or xs:type");
- }
-
- typeDescriptor.setName(partName);
-
- result.add(typeDescriptor);
- }
-
- return result;
- }
-
- public static TypeDescriptor getDescriptor(XmlSchemaElement element) {
- XmlSchema xmlSchema = element.getParent();
-
- XmlSchemaCollection schemas = xmlSchema.getParent();
- if (schemas == null) {
- schemas = new XmlSchemaCollection();
- // TODO: put somehow schema inside
- }
-
- TypeDescriptors descriptors = new TypeDescriptors(schemas);
- return descriptors.getElementDescriptor(element);
- }
-
- public static TypeDescriptor getDescriptor(XmlSchemaType type) {
- XmlSchema xmlSchema = type.getParent();
-
- XmlSchemaCollection schemas = xmlSchema.getParent();
- if (schemas == null) {
- schemas = new XmlSchemaCollection();
- }
-
- TypeDescriptors descriptors = new TypeDescriptors(schemas);
- return descriptors.getTypeDescriptor(type.getQName());
- }
-
- /**
- * Builds a type descriptor for a "Literal" parameter.
- *
- * @param elementName an XML element name of the parameter.
- * @return a Type Descriptor for the parameter.
- */
- public TypeDescriptor getElementDescriptor(QName elementName) {
- XmlSchemaElement element = schemas.getElementByQName(elementName);
- if (element == null) {
- return null;
- }
- return getElementDescriptor(element);
- }
-
- /**
- * Builds a type descriptor for a "RPC" parameter.
- *
- * @param typeName an XML type name of the parameter.
- * @return a Type Descriptor for the parameter.
- */
- public TypeDescriptor getTypeDescriptor(QName typeName) {
- XmlSchemaType xmlSchemaType = schemas.getTypeByQName(typeName);
-
- if (xmlSchemaType == null) {
- return null;
- }
-
- TypeDescriptor typeDesc;
- if (SOAPConstants.URI_NS_SOAP_ENCODING.equals(typeName.getNamespaceURI()) &&
- "Array".equals(typeName.getLocalPart())) {
- typeDesc = new ArrayTypeDescriptor();
- } else {
- typeDesc = getTypeDescriptor(xmlSchemaType);
- }
-
- typeDesc.setType(typeName.getLocalPart());
-
- return typeDesc;
- }
-
- private TypeDescriptor getElementDescriptor(XmlSchemaElement element) {
- TypeDescriptor elementDescriptor;
- TypeDescriptor typeDesc;
-
- QName typeName;
- if (element.isRef()) {
- XmlSchemaRef<XmlSchemaElement> ref = element.getRef();
-
- XmlSchemaElement target = ref.getTarget();
- if (target == null) {
- QName targetName = ref.getTargetQName();
- if (targetName != null) {
- target = schemas.getElementByQName(targetName);
- }
- }
- if (target != null) {
- typeName = target.getSchemaTypeName();
- if (typeName != null) {
- typeDesc = getTypeDescriptor(typeName);
- } else {
- XmlSchemaType xmlSchemaType = target.getSchemaType();
- typeDesc = getTypeDescriptor(xmlSchemaType);
- }
- } else {
- return null; // invalid XML Schema...
- }
- } else {
- typeName = element.getSchemaTypeName();
- if (typeName != null) {
- typeDesc = getTypeDescriptor(typeName);
- } else {
- XmlSchemaType xmlSchemaType = element.getSchemaType();
- typeDesc = getTypeDescriptor(xmlSchemaType);
- }
- }
-
- if (element.getMaxOccurs() > 1) {
- ArrayTypeDescriptor arrayElementDescriptor = new ArrayTypeDescriptor();
- arrayElementDescriptor.setElementType(typeDesc);
-
- elementDescriptor = arrayElementDescriptor;
- }
- else if (typeDesc instanceof ComplexTypeDescriptor) {
- ComplexTypeDescriptor complexElementDescr = (ComplexTypeDescriptor)typeDesc;
- ComplexTypeDescriptor complexTypeDesc = new ComplexTypeDescriptor();
-
- complexTypeDesc.getElements().addAll(complexElementDescr.getElements());
- complexTypeDesc.getAttributes().addAll(complexElementDescr.getAttributes());
-
- elementDescriptor = complexTypeDesc;
- } else {
- elementDescriptor = new BaseTypeDescriptor();
- }
- elementDescriptor.setType(typeName == null ? "" : typeName.getLocalPart());
-
- elementDescriptor.setName(element.isRef() ? element.getWireName().getLocalPart() : element.getName());
- elementDescriptor.setQname(element.getWireName());
- elementDescriptor.setOptional(element.getMinOccurs() == 0);
- elementDescriptor.setUnbounded(Long.MAX_VALUE == element.getMaxOccurs());
- elementDescriptor.setNillable(element.isNillable());
-
- return elementDescriptor;
- }
-
- private TypeDescriptor getTypeDescriptor(XmlSchemaType xmlSchemaType) {
- TypeDescriptor typeDesc;
-
- if (xmlSchemaType instanceof XmlSchemaSimpleType) {
- typeDesc = getSimpleTypeDescriptor((XmlSchemaSimpleType)xmlSchemaType);
- } else {
- typeDesc = getComplexTypeDescriptor((XmlSchemaComplexType)xmlSchemaType);
- }
-
- if (!xmlSchemaType.isAnonymous()) {
- typeDesc.setName(xmlSchemaType.getName());
- }
-
- typeDesc.setQname(xmlSchemaType.getQName());
-
- return typeDesc;
- }
-
- private TypeDescriptor getComplexTypeDescriptor(XmlSchemaComplexType xmlSchemaComplexType) {
- ComplexTypeDescriptor typeDesc = new ComplexTypeDescriptor();
-
- List<XmlSchemaAttributeOrGroupRef> attributes = xmlSchemaComplexType.getAttributes();
- for (XmlSchemaAttributeOrGroupRef attribute : attributes) {
- // all XmlSchemaAttributeOrGroupRef descendants are XmlSchemaAttributeGroupMember
- addAttributeTypeDescriptors(typeDesc.getAttributes(), (XmlSchemaAttributeGroupMember)attribute);
- }
-
- XmlSchemaContentModel xmlSchemaContentModel = xmlSchemaComplexType.getContentModel();
- if (xmlSchemaContentModel != null) {
- XmlSchemaContent content = xmlSchemaContentModel.getContent();
-
- if (content instanceof XmlSchemaComplexContentExtension) {
- XmlSchemaComplexContentExtension complexContentExtension = (XmlSchemaComplexContentExtension)content;
-
- attributes = complexContentExtension.getAttributes();
-
- XmlSchemaParticle particle = complexContentExtension.getParticle();
- addElementTypeDescriptors(typeDesc.getElements(), particle);
-
- QName baseTypeName = complexContentExtension.getBaseTypeName();
- if (baseTypeName != null) {
- TypeDescriptor baseTypeDesc = getTypeDescriptor(baseTypeName);
- if (baseTypeDesc instanceof ComplexTypeDescriptor) {
- ComplexTypeDescriptor base = (ComplexTypeDescriptor)baseTypeDesc;
- typeDesc.getElements().addAll(base.getElements());
- }
- }
- } else if (content instanceof XmlSchemaComplexContentRestriction) {
- XmlSchemaComplexContentRestriction complexContentRestriction = (XmlSchemaComplexContentRestriction)content;
-
- attributes = complexContentRestriction.getAttributes();
-
- // check for "SOAP Encoding"
- QName baseTypeName = complexContentRestriction.getBaseTypeName();
- if (baseTypeName != null) {
- TypeDescriptor baseTypeDesc = getTypeDescriptor(baseTypeName);
- if (baseTypeDesc instanceof ArrayTypeDescriptor) {
- ArrayTypeDescriptor arrayDesc = (ArrayTypeDescriptor)baseTypeDesc;
- TypeDescriptor arrayTypeDesc = getArrayType(attributes);
- arrayDesc.setElementType(arrayTypeDesc);
- return arrayDesc;
- }
- }
-
- XmlSchemaParticle particle = complexContentRestriction.getParticle();
- addElementTypeDescriptors(typeDesc.getElements(), particle);
- } else if (content instanceof XmlSchemaSimpleContentExtension) {
- XmlSchemaSimpleContentExtension xmlSchemaSimpleContentExtension = (XmlSchemaSimpleContentExtension)content;
-
- attributes = xmlSchemaSimpleContentExtension.getAttributes();
-
- QName baseTypeName = xmlSchemaSimpleContentExtension.getBaseTypeName();
- if (baseTypeName != null) {
- TypeDescriptor baseTypeDesc = getTypeDescriptor(baseTypeName);
- typeDesc.setType(baseTypeDesc.getType());
- }
- } else if (content instanceof XmlSchemaSimpleContentRestriction){
- XmlSchemaSimpleContentRestriction xmlSchemaSimpleContentRestriction = (XmlSchemaSimpleContentRestriction)content;
-
- attributes = xmlSchemaSimpleContentRestriction.getAttributes();
-
- QName baseTypeName = xmlSchemaSimpleContentRestriction.getBaseTypeName();
- if (baseTypeName == null) {
- XmlSchemaSimpleType simpleType = xmlSchemaSimpleContentRestriction.getBaseType();
- baseTypeName = simpleType.getQName();
- }
-
- TypeDescriptor baseTypeDesc = getTypeDescriptor(baseTypeName);
- typeDesc.setType(baseTypeDesc.getType());
- }
-
- for (XmlSchemaAttributeOrGroupRef attribute : attributes) {
- addAttributeTypeDescriptors(typeDesc.getAttributes(), (XmlSchemaAttributeGroupMember)attribute);
- }
- } else {
- XmlSchemaParticle particle = xmlSchemaComplexType.getParticle();
- addElementTypeDescriptors(typeDesc.getElements(), particle);
- }
-
- return typeDesc;
- }
-
- /*
- * Adds all elements found in the "particle" to the "elements" list
- */
- private void addElementTypeDescriptors(List<TypeDescriptor> elements, XmlSchemaParticle particle)
- {
- if (particle instanceof XmlSchemaElement){
- XmlSchemaElement element = (XmlSchemaElement)particle;
- TypeDescriptor elementTypeDescriptor = getElementDescriptor(element);
- elements.add(elementTypeDescriptor);
- }
- else if (particle instanceof XmlSchemaAll) {
- addElementTypeDescriptors(elements, (XmlSchemaAll)particle);
- }
- else if (particle instanceof XmlSchemaSequence) {
- addElementTypeDescriptors(elements, (XmlSchemaSequence)particle);
- }
- else if (particle instanceof XmlSchemaChoice) {
- addElementTypeDescriptors(elements, (XmlSchemaChoice)particle);
- }
- }
-
- /*
- * Adds all elements found in a sequence to the list of elements
- */
- private void addElementTypeDescriptors(List<TypeDescriptor> elements, XmlSchemaSequence sequence) {
- List<XmlSchemaSequenceMember> items = sequence.getItems();
- addElementTypeDescriptors(elements, items);
- }
-
- /*
- * Adds all elements found in a "all" particle to the list of elements
- */
- private void addElementTypeDescriptors(List<TypeDescriptor> elements, XmlSchemaAll all) {
- for (XmlSchemaElement element : all.getItems()) {
- TypeDescriptor elementTypeDescriptor = getElementDescriptor(element);
- elements.add(elementTypeDescriptor);
- }
- }
-
- /*
- * Adds all elements found in a "choice" particle to the list of elements
- */
-
- private void addElementTypeDescriptors(List<TypeDescriptor> elements, XmlSchemaChoice choice) {
- List<XmlSchemaObject> items = choice.getItems();
- addElementTypeDescriptors(elements, items);
- }
-
- private void addElementTypeDescriptors(List<TypeDescriptor> elements, List<? extends XmlSchemaObjectBase> items) {
- for (XmlSchemaObjectBase item : items) {
- if (item instanceof XmlSchemaElement) {
- addElementTypeDescriptors(elements, (XmlSchemaElement)item);
- } else if(item instanceof XmlSchemaSequence) {
- addElementTypeDescriptors(elements, (XmlSchemaSequence)item);
- } else if (item instanceof XmlSchemaChoice) {
- addElementTypeDescriptors(elements, (XmlSchemaChoice)item);
- } else if (item instanceof XmlSchemaGroup) {
- XmlSchemaGroup group = (XmlSchemaGroup)item;
- XmlSchemaGroupParticle groupParticle = group.getParticle();
- addElementTypeDescriptors(elements, groupParticle);
- } else if (item instanceof XmlSchemaGroupRef) {
- XmlSchemaGroupRef groupRef = (XmlSchemaGroupRef)item;
- XmlSchemaGroupParticle groupParticle = groupRef.getParticle();
- addElementTypeDescriptors(elements, groupParticle);
- }
- }
- }
-
- /*
- * Builds a BaseTypeDescriptor from a simpleType definition.
- * Method processes simpleType restrictions to find an appropriate XML primitive type
- */
- private BaseTypeDescriptor getSimpleTypeDescriptor(XmlSchemaSimpleType xmlSchemaSimpleType) {
- BaseTypeDescriptor typeDesc = new BaseTypeDescriptor();
-
- QName typeName = xmlSchemaSimpleType.getQName();
- if (typeName != null && XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(typeName.getNamespaceURI())) {
- typeDesc.setType(typeName.getLocalPart());
- } else {
- XmlSchemaSimpleTypeContent simpleTypeContent = xmlSchemaSimpleType.getContent();
- if (simpleTypeContent instanceof XmlSchemaSimpleTypeRestriction) {
- XmlSchemaSimpleTypeRestriction simpleTypeRestriction = (XmlSchemaSimpleTypeRestriction)simpleTypeContent;
-
- QName baseTypeName = simpleTypeRestriction.getBaseTypeName();
- if (baseTypeName == null) {
- XmlSchemaSimpleType baseType = simpleTypeRestriction.getBaseType();
- baseTypeName = baseType.getQName();
- }
-
- TypeDescriptor baseTypeDesc = getTypeDescriptor(baseTypeName);
- typeDesc.setType(baseTypeDesc.getType());
- }
- else if (simpleTypeContent instanceof XmlSchemaSimpleTypeList) {
- XmlSchemaSimpleTypeList simpleTypeList = (XmlSchemaSimpleTypeList)simpleTypeContent;
-
- QName itemTypeName = simpleTypeList.getItemTypeName();
- if (itemTypeName == null) {
- XmlSchemaSimpleType itemType = simpleTypeList.getItemType();
- itemTypeName = itemType.getQName();
- }
-
- if (XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(itemTypeName.getNamespaceURI())) {
- typeDesc.setType(itemTypeName.getLocalPart());
- }
- else {
- TypeDescriptor baseTypeDesc = getTypeDescriptor(itemTypeName);
- typeDesc.setType(baseTypeDesc.getType());
- }
- }
- else if (simpleTypeContent instanceof XmlSchemaSimpleTypeUnion) {
- XmlSchemaSimpleTypeUnion typeUnion = (XmlSchemaSimpleTypeUnion)simpleTypeContent;
-
- // TODO
- }
- }
-
- return typeDesc;
- }
-
- /*
- * Inserts attribute descriptions specified by the attribute (may be a group of attributes) into the attributes list
- */
- private void addAttributeTypeDescriptors(List<TypeDescriptor> attributes, XmlSchemaAttributeGroupMember attribute) {
- AttributeTypeDescriptor typeDesc = new AttributeTypeDescriptor();
-
- if (attribute instanceof XmlSchemaAttribute) {
- XmlSchemaAttribute xmlSchemaAttribute = (XmlSchemaAttribute)attribute;
-
- QName attrName;
- if (xmlSchemaAttribute.isRef()) {
- XmlSchemaRef<XmlSchemaAttribute> xmlSchemaRef = xmlSchemaAttribute.getRef();
-
- attrName = xmlSchemaRef.getTargetQName();
- if (attrName == null) {
- XmlSchemaAttribute xmlSchemaRefAttribute = xmlSchemaRef.getTarget();
- attrName = xmlSchemaRefAttribute.getWireName();
- }
- } else {
- attrName = xmlSchemaAttribute.getWireName();
- }
-
- typeDesc.setName(attrName.getLocalPart());
- typeDesc.setQname(attrName);
-
- TypeDescriptor attrTypeDesc;
-
- QName attrTypeName = xmlSchemaAttribute.getSchemaTypeName();
- if (attrTypeName != null) {
- attrTypeDesc = getTypeDescriptor(attrTypeName);
- } else {
- XmlSchemaSimpleType xmlSchemaSimpleType = xmlSchemaAttribute.getSchemaType();
- if (xmlSchemaSimpleType == null) {
- attrTypeDesc = new BaseTypeDescriptor();
- attrTypeDesc.setType("anySimpleType");
- } else {
- attrTypeDesc = getTypeDescriptor(xmlSchemaSimpleType);
- }
- }
-
- typeDesc.setType(attrTypeDesc.getType());
-
- typeDesc.setOptional(XmlSchemaUse.OPTIONAL == xmlSchemaAttribute.getUse());
- attributes.add(typeDesc);
- }
- else {
- XmlSchemaAttributeGroup xmlSchemaAttributeGroup;
- if (attribute instanceof XmlSchemaAttributeGroup) {
- xmlSchemaAttributeGroup = (XmlSchemaAttributeGroup)attribute;
- }
- else {
- XmlSchemaAttributeGroupRef xmlSchemaAttributeGroupRef = (XmlSchemaAttributeGroupRef)attribute;
- XmlSchemaRef<XmlSchemaAttributeGroup> xmlSchemaRef = xmlSchemaAttributeGroupRef.getRef();
- xmlSchemaAttributeGroup = xmlSchemaRef.getTarget();
- }
-
- List<XmlSchemaAttributeGroupMember> xmlSchemaAttributeGroupMembers = xmlSchemaAttributeGroup.getAttributes();
- for (XmlSchemaAttributeGroupMember xmlSchemaAttributeGroupMember : xmlSchemaAttributeGroupMembers) {
- addAttributeTypeDescriptors(attributes, xmlSchemaAttributeGroupMember);
- }
- }
- }
-
- /*
- * Looking for "SOAP-ENC:arrayType" attribute in attributes list
- */
- private TypeDescriptor getArrayType(List<XmlSchemaAttributeOrGroupRef> attributes) {
- for (XmlSchemaAttributeOrGroupRef attribute : attributes) {
- TypeDescriptor arrayTypeDesc = getArrayType((XmlSchemaAttributeGroupMember)attribute);
- if (arrayTypeDesc != null) {
- return arrayTypeDesc;
- }
- }
- return null;
- }
-
- /*
- * Getting a TypeDescriptor for the attribute ("SOAP-ENC:arrayType")
- */
- private TypeDescriptor getArrayType(XmlSchemaAttributeGroupMember attribute) {
- if (attribute instanceof XmlSchemaAttribute) {
- XmlSchemaAttribute xmlSchemaAttribute = (XmlSchemaAttribute)attribute;
- QName attrName;
- if (xmlSchemaAttribute.isRef()) {
- XmlSchemaRef<XmlSchemaAttribute> xmlSchemaRef = xmlSchemaAttribute.getRef();
-
- attrName = xmlSchemaRef.getTargetQName();
- if (attrName == null) {
- XmlSchemaAttribute xmlSchemaRefAttribute = xmlSchemaRef.getTarget();
- attrName = xmlSchemaRefAttribute.getWireName();
- }
- } else {
- attrName = xmlSchemaAttribute.getWireName();
- }
-
- if (SOAPConstants.URI_NS_SOAP_ENCODING.equals(attrName.getNamespaceURI()) &&
- "arrayType".equals(attrName.getLocalPart())) {
-
- Attr[] unhandled = xmlSchemaAttribute.getUnhandledAttributes();
-
- String arrayType = null;
- for (Attr attr : unhandled) {
- if ("arrayType".equals(attr.getLocalName())) {
- if (SOAPConstants.URI_NS_SOAP_ENCODING.equals(attr.getNamespaceURI())) {
- arrayType = attr.getValue();
- break;
- }
- if ("http://schemas.xmlsoap.org/wsdl/".equals(attr.getNamespaceURI())) {
- arrayType = attr.getValue();
- }
- }
- }
-
- if (arrayType != null) {
- QName arrayTypeQName = getArrayTypeQName(arrayType);
-
- if (arrayTypeQName.getNamespaceURI() == null || arrayTypeQName.getNamespaceURI().isEmpty())
- {
- String namespace = xmlSchemaAttribute.getParent().getNamespaceContext().getNamespaceURI(XMLConstants.DEFAULT_NS_PREFIX);
- arrayTypeQName = new QName(namespace, arrayTypeQName.getLocalPart());
- }
- return getTypeDescriptor(arrayTypeQName);
- }
- }
- }
- else {
- XmlSchemaAttributeGroup xmlSchemaAttributeGroup;
- if (attribute instanceof XmlSchemaAttributeGroup) {
- xmlSchemaAttributeGroup = (XmlSchemaAttributeGroup)attribute;
- }
- else {
- XmlSchemaAttributeGroupRef xmlSchemaAttributeGroupRef = (XmlSchemaAttributeGroupRef)attribute;
- XmlSchemaRef<XmlSchemaAttributeGroup> xmlSchemaRef = xmlSchemaAttributeGroupRef.getRef();
- xmlSchemaAttributeGroup = xmlSchemaRef.getTarget();
- }
-
- List<XmlSchemaAttributeGroupMember> xmlSchemaAttributeGroupMembers = xmlSchemaAttributeGroup.getAttributes();
- for (XmlSchemaAttributeGroupMember xmlSchemaAttributeGroupMember : xmlSchemaAttributeGroupMembers) {
- TypeDescriptor arrayTypeDesc = getArrayType(xmlSchemaAttributeGroupMember);
- if (arrayTypeDesc != null) {
- return arrayTypeDesc;
- }
- }
- }
-
- return null;
- }
-
- /*
- * Parsing an arrayTypeValue to get its name.
- *
- * arrayTypeValue = atype asize
- * atype = QName *( rank )
- * rank = "[" *( "," ) "]"
- * asize = "[" #length "]"
- * length = 1*DIGIT
- */
- private QName getArrayTypeQName(String arrayType) {
- final int prefixIdx = arrayType.indexOf(':');
- final int rankIdx = arrayType.indexOf('[');
-
- if (prefixIdx < 0) {
- String localName = arrayType.substring(0, rankIdx);
- return new QName(localName);
- }
-
- String localName = arrayType.substring(prefixIdx + 1, rankIdx);
-
- String prefix = arrayType.substring(0, prefixIdx);
- String namespace = schemas.getNamespaceContext().getNamespaceURI(prefix);
-
- return new QName(namespace, localName, prefix);
- }
-}
[4/8] incubator-taverna-common-activities git commit: experimental
wsdl-generic based on XSD schema
Posted by re...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/SOAPResponsePrimitiveLiteralParser.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/SOAPResponsePrimitiveLiteralParser.java b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/SOAPResponsePrimitiveLiteralParser.java
deleted file mode 100644
index f65c46d..0000000
--- a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/SOAPResponsePrimitiveLiteralParser.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
-* 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.soap;
-
-import java.io.ByteArrayInputStream;
-import java.util.List;
-import java.util.Map;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-
-import org.apache.taverna.wsdl.parser.TypeDescriptor;
-
-import org.w3c.dom.Document;
-import org.w3c.dom.Node;
-
-/**
- * A response parser specifically for literal use services that return primative types.
- * It extends the SOAPReponseLiteralParser, but unwraps the result from the enclosing XML
- * to expose the primitive result.
- *
- * This is specially designed for unwrapped/literal type services, and RPC/literal services (untested).
- * @author Stuart
- *
- */
-@SuppressWarnings("unchecked")
-public class SOAPResponsePrimitiveLiteralParser extends
- SOAPResponseLiteralParser {
-
- public SOAPResponsePrimitiveLiteralParser(List<TypeDescriptor> outputDescriptors) {
- super(outputDescriptors);
- }
-
- @Override
- public Map parse(List response) throws Exception {
- Map result = super.parse(response);
- Object dataValue = result.get(getOutputName());
- if (dataValue!=null) {
- String xml = dataValue.toString();
-
- DocumentBuilder builder = DocumentBuilderFactory.newInstance()
- .newDocumentBuilder();
- Document doc = builder.parse(new ByteArrayInputStream(xml.getBytes()));
-
- Node node = doc.getFirstChild();
- result.put(getOutputName(), node.getFirstChild().getNodeValue());
- }
- return result;
- }
-
-
-}
-
-
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/SOAPResponsePrimitiveParser.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/SOAPResponsePrimitiveParser.java b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/SOAPResponsePrimitiveParser.java
deleted file mode 100644
index f9af843..0000000
--- a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/SOAPResponsePrimitiveParser.java
+++ /dev/null
@@ -1,149 +0,0 @@
-/*
-* 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.soap;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.TreeMap;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import javax.xml.XMLConstants;
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBException;
-import javax.xml.bind.Unmarshaller;
-import javax.xml.namespace.QName;
-import javax.xml.soap.SOAPElement;
-import org.apache.taverna.wsdl.parser.ArrayTypeDescriptor;
-import org.apache.taverna.wsdl.parser.BaseTypeDescriptor;
-import org.apache.taverna.wsdl.parser.TypeDescriptor;
-import org.apache.taverna.wsdl.parser.WSDL11Parser;
-import org.w3c.dom.Attr;
-import org.w3c.dom.Element;
-
-
-/**
- * SOAPResponseParser responsible for parsing soap responses that map to outputs
- * that can be directly represented with Primitive types (i.e. int, String,
- * String[]).
- *
- * @author sowen
- *
- */
-@SuppressWarnings("unchecked")
-public class SOAPResponsePrimitiveParser implements SOAPResponseParser {
-
- private Unmarshaller u;
- private Map<String, TypeDescriptor> descriptors;
-
- private static final Logger logger = Logger.getLogger(WSDL11Parser.class.getName());
-
- public SOAPResponsePrimitiveParser(List<TypeDescriptor> outputDescriptors) {
-
- descriptors = new TreeMap<String, TypeDescriptor>();
-
- for (TypeDescriptor desc : outputDescriptors) {
- descriptors.put(desc.getName(), desc);
- }
-
- try {
- u = JAXBContext.newInstance().createUnmarshaller();
- }
- catch(JAXBException ex) {}
- }
-
- /**
- * Parses each SOAPBodyElement for the primitive type, and places it in the
- * output Map
- */
- @Override
- public Map parse(List<SOAPElement> response) throws Exception {
- Map result = new HashMap();
-
- SOAPElement responseElement = response.get(0);
-
- for (Iterator<SOAPElement> paramIterator = responseElement.getChildElements(); paramIterator.hasNext();) {
- SOAPElement param = paramIterator.next();
-
- TypeDescriptor typeDesc = descriptors.get(param.getLocalName());
- if (typeDesc != null) {
- if (typeDesc instanceof ArrayTypeDescriptor) {
- ArrayTypeDescriptor arrayDesc = (ArrayTypeDescriptor)typeDesc;
- typeDesc = arrayDesc.getElementType(); // do we need to know a type here?
- List elements = new ArrayList();
- for (Iterator<Element> iter = param.getChildElements(); iter.hasNext();) {
- Element element = iter.next();
- Object value = getNodeObject(element, typeDesc.getQname());
- elements.add(value);
- }
-
- result.put(param.getElementName().getLocalName(), ObjectConverter.convertObject(elements));
- }
- else if (typeDesc instanceof BaseTypeDescriptor) {
- Object value = getNodeObject(param, typeDesc.getQname());
- result.put(param.getElementName().getLocalName(), ObjectConverter.convertObject(value));
- }
- }
- }
-
- return result;
- }
-
- private Object getNodeObject(Element element, QName type) throws JAXBException {
- Attr attr = (Attr)element.getAttributes().getNamedItemNS(XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI, "type");
- if (attr != null) {
- String xsiType = attr.getValue();
- int idx = xsiType.indexOf(':');
- if (idx > 0) {
- String prefix = xsiType.substring(0, idx);
- String namespace = element.lookupNamespaceURI(prefix);
- if (namespace != null) {
- String localName = xsiType.substring(idx + 1);
- QName typeName = new QName(namespace, localName);
- if (typeName.equals(type)) {
- return u.unmarshal(element, Object.class).getValue();
- }
- logger.log(Level.WARNING, "different types in parameter {0}defined: {1}, expected: {2}", new Object[]{element.getLocalName(), typeName, type});
- } else {
- logger.log(Level.WARNING, "no xsi:type namespace found: {0}", xsiType);
- }
- } else {
- logger.log(Level.WARNING, "missing parameter xsi:type namespace {0} xsi:type='{1}'", new Object[]{element.getLocalName(), xsiType});
- }
- }
-
- // this is a safeguard code where there is no xsi:type specified, so using provided type
- attr = element.getOwnerDocument().createAttributeNS(XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI, "type");
-
- String prefix = element.lookupPrefix(type.getNamespaceURI());
- if (prefix == null) {
- // it is supposed that elements are of primitive types...
- element.setAttribute(XMLConstants.XML_NS_PREFIX + ":xsd", type.getNamespaceURI());
- prefix = "xsd";
- }
- attr.setValue(prefix + ":" + type.getLocalPart());
-
- element.getAttributes().setNamedItemNS(attr);
-
- return u.unmarshal(element, Object.class).getValue();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/WSDLSOAPInvoker.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/WSDLSOAPInvoker.java b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/WSDLSOAPInvoker.java
deleted file mode 100644
index 319cc70..0000000
--- a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/WSDLSOAPInvoker.java
+++ /dev/null
@@ -1,288 +0,0 @@
-/*
-* 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.soap;
-
-import java.io.BufferedInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import javax.activation.DataHandler;
-import javax.wsdl.WSDLException;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.soap.AttachmentPart;
-import javax.xml.soap.MessageFactory;
-import javax.xml.soap.SOAPConstants;
-import javax.xml.soap.SOAPElement;
-import javax.xml.soap.SOAPEnvelope;
-import javax.xml.soap.SOAPException;
-import javax.xml.soap.SOAPMessage;
-import org.apache.taverna.wsdl.parser.UnknownOperationException;
-import org.apache.taverna.wsdl.parser.WSDLParser;
-import org.apache.log4j.Logger;
-import org.xml.sax.SAXException;
-
-/**
- * Invoke SOAP based webservices
- *
- * @author Stuart Owen
- *
- */
-@SuppressWarnings("unchecked")
-public class WSDLSOAPInvoker {
-
- private static final String ATTACHMENT_LIST = "attachmentList";
-
- private static Logger logger = Logger.getLogger(WSDLSOAPInvoker.class);
-
- private BodyBuilderFactory bodyBuilderFactory = BodyBuilderFactory.instance();
- private WSDLParser parser;
- private String operationName;
- private List<String> outputNames;
-
- private JaxWSInvoker invoker;
-
- public WSDLSOAPInvoker(WSDLParser parser, String operationName,
- List<String> outputNames) {
- this.parser = parser;
- this.operationName = operationName;
- this.outputNames = outputNames;
-
- invoker = new JaxWSInvoker(parser, null, operationName);
- invoker.setTimeout(getTimeout());
- }
-
- public void setCredentials(String username, String password) {
- invoker.setCredentials(username, password);
- }
-
- public void setWSSSecurity(WSSTokenProfile token) {
- invoker.setWSSSecurity(token);
- }
-
- protected String getOperationName() {
- return operationName;
- }
-
- protected WSDLParser getParser() {
- return parser;
- }
-
- protected List<String> getOutputNames() {
- return outputNames;
- }
-
-
- /**
- * Invokes the webservice with the supplied input Map, and returns a Map
- * containing the outputs, mapped against their output names.
- *
- * @param inputMap
- * @return
- * @throws Exception
- */
- public Map<String, Object> invoke(Map inputMap) throws Exception {
-
- SOAPMessage message = makeRequestEnvelope(inputMap);
-
- return invoke(message);
- }
-
- public SOAPMessage call(SOAPMessage message) throws Exception
- {
- return invoker.call(message);
-
-// String endpoint = parser.getOperationEndpointLocations(operationName).get(0);
-// URL endpointURL = new URL(endpoint);
-//
-// String soapAction = parser.getSOAPActionURI(operationName);
-// if (soapAction != null) {
-// MimeHeaders headers = message.getMimeHeaders();
-// headers.setHeader("SOAPAction", soapAction);
-// }
-//
-// logger.info("Invoking service with SOAP envelope:\n" + message.getSOAPPart().getEnvelope());
-//
-// SOAPConnectionFactory factory = SOAPConnectionFactory.newInstance();
-// SOAPConnection connection = factory.createConnection();
-//
-//// call.setTimeout(getTimeout());
-// return connection.call(message, endpointURL);
- }
-
- /**
- * Invokes the webservice with the supplied input Map and preconfigured axis call,
- * and returns a Map containing the outputs, mapped against their output names.
- */
- public Map<String, Object> invoke(SOAPMessage message)
- throws Exception {
-
- SOAPMessage response = call(message);
-
- List<SOAPElement> responseElements = new ArrayList();
- for (Iterator<SOAPElement> iter = response.getSOAPBody().getChildElements(); iter.hasNext();)
- {
- responseElements.add(iter.next());
- }
- logger.info("Received SOAP response:\n"+response);
-
- Map<String, Object> result;
- if (responseElements.isEmpty()) {
- if (outputNames.size() == 1
- && outputNames.get(0).equals(ATTACHMENT_LIST)) {
- // Could be axis 2 service with no output (TAV-617)
- result = new HashMap<String, Object>();
- } else {
- throw new IllegalStateException(
- "Missing expected outputs from service");
- }
- } else {
- logger.info("SOAP response was:" + response);
- SOAPResponseParser responseParser =
- SOAPResponseParserFactory.instance().create(responseElements,
- getUse(),
- getStyle(),
- parser.getOperationOutputParameters(operationName));
- result = responseParser.parse(responseElements);
- }
-
- result.put(ATTACHMENT_LIST, extractAttachments(message));
-
- return result;
- }
-
- protected SOAPMessage makeRequestEnvelope(Map inputMap)
- throws UnknownOperationException, IOException, WSDLException,
- ParserConfigurationException, SOAPException, SAXException {
-
- MessageFactory factory = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL); // TODO: SOAP version
- SOAPMessage message = factory.createMessage();
-//
-// String soapAction = parser.getSOAPActionURI(operationName);
-// if (soapAction != null) {
-// MimeHeaders headers = message.getMimeHeaders();
-// headers.addHeader("SOAPAction", soapAction);
-// }
-//
-// if (username != null && username.length() > 0 &&
-// password != null && password.length() > 0) {
-// String authorization = DatatypeConverter.printBase64Binary((username+":"+password).getBytes());
-// MimeHeaders headers = message.getMimeHeaders();
-// headers.addHeader("Authorization", "Basic " + authorization);
-// }
-
- SOAPEnvelope requestEnv = message.getSOAPPart().getEnvelope();
-
- addSoapHeader(requestEnv);
-
- requestEnv.getBody().addChildElement(makeSoapBody(inputMap));
-
- return message;
- }
-
- protected void addSoapHeader(SOAPEnvelope envelope) throws SOAPException
- {
- }
-
- protected SOAPElement makeSoapBody(Map inputMap)
- throws UnknownOperationException, IOException, WSDLException,
- ParserConfigurationException, SOAPException, SAXException {
-
- BodyBuilder builder =
- bodyBuilderFactory.create(parser, operationName, parser.getOperationInputParameters(operationName));
-
- return builder.build(inputMap);
- }
-
- /**
- * Reads the property taverna.wsdl.timeout, default to 5 minutes if missing.
- *
- * @return
- */
- protected Integer getTimeout() {
- int result = 300000;
- String minutesStr = System.getProperty("taverna.wsdl.timeout");
-
- if (minutesStr == null) {
- // using default of 5 minutes
- return result;
- }
- try {
- int minutes = Integer.parseInt(minutesStr.trim());
- result = minutes * 1000 * 60;
- } catch (NumberFormatException e) {
- logger.error("Non-integer timeout", e);
- return result;
- }
- return result;
- }
-
- protected String getStyle() throws UnknownOperationException {
- return parser.getStyle(operationName);
- }
-
- protected String getUse() throws UnknownOperationException {
- return parser.getUse(operationName);
- }
-
- /**
- * Exctracts any attachments that result from invoking the service, and
- * returns them as a List wrapped within a DataThing
- *
- * @param message
- * @return
- * @throws SOAPException
- * @throws IOException
- */
- protected List extractAttachments(SOAPMessage message)
- throws SOAPException, IOException {
- List attachmentList = new ArrayList();
- if (message.countAttachments() > 0) {
- for (Iterator i = message.getAttachments(); i
- .hasNext();) {
- AttachmentPart ap = (AttachmentPart) i.next();
- DataHandler dh = ap.getDataHandler();
- BufferedInputStream bis = new BufferedInputStream(dh
- .getInputStream());
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- int c;
- while ((c = bis.read()) != -1) {
- bos.write(c);
- }
- bis.close();
- bos.close();
- String mimeType = dh.getContentType();
- if (mimeType.matches(".*image.*")
- || mimeType.matches(".*octet.*")
- || mimeType.matches(".*audio.*")
- || mimeType.matches(".*application/zip.*")) {
- attachmentList.add(bos.toByteArray());
- } else {
- attachmentList.add(new String(bos.toByteArray()));
- }
- }
- }
-
- return attachmentList;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/WSSTokenProfile.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/WSSTokenProfile.java b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/WSSTokenProfile.java
deleted file mode 100644
index 90f675d..0000000
--- a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/WSSTokenProfile.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
-* 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.soap;
-
-/**
- * @author Dmitry Repchevsky
- */
-
-public enum WSSTokenProfile {
-
- PasswordDigest("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest"),
- PasswordText("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText"),
- UsernameToken("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#UsernameToken"),
- Base64Binary("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soapmessage-security-1.0#Base64Binary"),
- X509v3("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3");
-
- public final String TOKEN;
-
- private WSSTokenProfile(String token) {
- TOKEN = token;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/package.html
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/package.html b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/package.html
deleted file mode 100644
index 5fd36e5..0000000
--- a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/package.html
+++ /dev/null
@@ -1,5 +0,0 @@
-<body>
-Contains classes required to invoke an endpoint for a SOAP based web-service described by a WSDL.<br>
-These classes are derived heavily from the original parsing classes from the Taverna 1 WSDLBasedProcessor and have been refactored<br>
-to remove references to to Taverna 1
-</body>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/xmlsplitter/XMLInputSplitter.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/xmlsplitter/XMLInputSplitter.java b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/xmlsplitter/XMLInputSplitter.java
deleted file mode 100644
index 5f93f9d..0000000
--- a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/xmlsplitter/XMLInputSplitter.java
+++ /dev/null
@@ -1,286 +0,0 @@
-/*
-* 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.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 javax.xml.bind.DatatypeConverter;
-import org.apache.taverna.wsdl.parser.ArrayTypeDescriptor;
-import org.apache.taverna.wsdl.parser.BaseTypeDescriptor;
-import org.apache.taverna.wsdl.parser.ComplexTypeDescriptor;
-import org.apache.taverna.wsdl.parser.TypeDescriptor;
-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.getQname().getPrefix(), 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 = DatatypeConverter.printBase64Binary((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/df390d97/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/xmlsplitter/XMLOutputSplitter.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/xmlsplitter/XMLOutputSplitter.java b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/xmlsplitter/XMLOutputSplitter.java
deleted file mode 100644
index fdb8cc1..0000000
--- a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/xmlsplitter/XMLOutputSplitter.java
+++ /dev/null
@@ -1,198 +0,0 @@
-/*
-* 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.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 org.apache.taverna.wsdl.parser.ArrayTypeDescriptor;
-import org.apache.taverna.wsdl.parser.BaseTypeDescriptor;
-import org.apache.taverna.wsdl.parser.ComplexTypeDescriptor;
-import org.apache.taverna.wsdl.parser.TypeDescriptor;
-
-import javax.xml.bind.DatatypeConverter;
-
-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 = DatatypeConverter.parseBase64Binary(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/df390d97/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/xmlsplitter/XMLSplitterExecutionException.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/xmlsplitter/XMLSplitterExecutionException.java b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/xmlsplitter/XMLSplitterExecutionException.java
deleted file mode 100644
index 18c19d1..0000000
--- a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/xmlsplitter/XMLSplitterExecutionException.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
-* 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.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/df390d97/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/xmlsplitter/XMLSplitterSerialisationHelper.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/xmlsplitter/XMLSplitterSerialisationHelper.java b/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/xmlsplitter/XMLSplitterSerialisationHelper.java
deleted file mode 100644
index 4c5e5bc..0000000
--- a/taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/xmlsplitter/XMLSplitterSerialisationHelper.java
+++ /dev/null
@@ -1,341 +0,0 @@
-/*
-* 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.xmlsplitter;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-
-import org.apache.taverna.wsdl.parser.ArrayTypeDescriptor;
-import org.apache.taverna.wsdl.parser.AttributeTypeDescriptor;
-import org.apache.taverna.wsdl.parser.BaseTypeDescriptor;
-import org.apache.taverna.wsdl.parser.ComplexTypeDescriptor;
-import org.apache.taverna.wsdl.parser.TypeDescriptor;
-
-import org.apache.log4j.Logger;
-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);
- }
- }
-
- 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/df390d97/taverna-wsdl-generic/src/main/resources/META-INF/services/org.apache.taverna.wsdl.invoker.SOAPInvokerFactory
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/main/resources/META-INF/services/org.apache.taverna.wsdl.invoker.SOAPInvokerFactory b/taverna-wsdl-generic/src/main/resources/META-INF/services/org.apache.taverna.wsdl.invoker.SOAPInvokerFactory
new file mode 100644
index 0000000..d03297f
--- /dev/null
+++ b/taverna-wsdl-generic/src/main/resources/META-INF/services/org.apache.taverna.wsdl.invoker.SOAPInvokerFactory
@@ -0,0 +1 @@
+org.apache.taverna.wsdl.invoker.SOAPInvokerFactoryImpl # Invoker factory for the standard java JAX-WS implementation
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/invoker/CommandLineInvokerTest.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/invoker/CommandLineInvokerTest.java b/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/invoker/CommandLineInvokerTest.java
new file mode 100644
index 0000000..73f84a8
--- /dev/null
+++ b/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/invoker/CommandLineInvokerTest.java
@@ -0,0 +1,50 @@
+/*
+* 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.invoker;
+
+import org.junit.Test;
+
+
+/**
+ * @author Dmitry Repchevsky
+ */
+public class CommandLineInvokerTest {
+
+ private final static String[] PARAME = {
+ "-wsdl",
+ "http://inb.bsc.es/service/NCBIBlastp?wsdl",
+ "-operation",
+ "runNCBIBlastp",
+ "-in",
+ "/*[namespace-uri()='http://inb.bsc.es' and local-name()='request']/sequence/sequence",
+ "MKELNDLEKKYNAHIGVYALDTKSGKEVKFNSDKRFAYA",
+ "-out",
+ "/*[namespace-uri()='http://inb.bsc.es' and local-name()='response']/report/blast_text",
+ "blast.txt"};
+
+ public CommandLineInvokerTest() {
+
+ }
+
+ @Test
+ public void test1() {
+ //CommandLineInvoker.main(PARAME);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/parser/TypeDescriptorTest.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/parser/TypeDescriptorTest.java b/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/parser/TypeDescriptorTest.java
deleted file mode 100644
index 64b0e36..0000000
--- a/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/parser/TypeDescriptorTest.java
+++ /dev/null
@@ -1,226 +0,0 @@
-/*
-* 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;
-
-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/df390d97/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/parser/WSDLParserTest.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/parser/WSDLParserTest.java b/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/parser/WSDLParserTest.java
index c2f91ee..aa5a280 100644
--- a/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/parser/WSDLParserTest.java
+++ b/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/parser/WSDLParserTest.java
@@ -19,21 +19,32 @@
package org.apache.taverna.wsdl.parser;
+import org.apache.taverna.wsdl.parser.WSDLParser;
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.LinkedHashMap;
import java.util.List;
+import javax.wsdl.WSDLException;
import javax.xml.namespace.QName;
import org.apache.taverna.wsdl.testutils.WSDLTestHelper;
+import org.apache.ws.commons.schema.XmlSchemaElement;
+import org.apache.ws.commons.schema.XmlSchemaObject;
+import org.apache.ws.commons.schema.utils.XmlSchemaNamed;
import org.junit.Test;
public class WSDLParserTest {
+ @Test
+ public void getWSDL11fromSSLTest() throws Exception {
+ WSDL11Parser.getWSDL11Parser("https://transplantdb.bsc.es/registry/rest/service/94259BD285E07E855382DD197BC61D62");
+ }
+
@Test
public void testGetOperations() throws Exception {
WSDLParser parser = new WSDLParser(wsdlResourcePath("eutils/eutils_lite.wsdl"));
@@ -59,101 +70,103 @@ public class WSDLParserTest {
@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());
+// WSDLParser parser = new WSDLParser(wsdlResourcePath("eutils/eutils_lite.wsdl"));
+//
+// LinkedHashMap<String,XmlSchemaNamed> inputs = parser
+// .getInputParameters("run_eInfo");
+// LinkedHashMap<String,XmlSchemaNamed> outputs = parser
+// .getOutputParameters("run_eInfo");
+//
+// assertEquals("wrong number of inputs", 1, inputs.size());
+// assertEquals("wrong number of outputs", 1, outputs.size());
+//
+// XmlSchemaNamed input = inputs.values().iterator().next();
+// assertTrue("input should be complex", input instanceof XmlSchemaElement);
+//
+// XmlSchemaElement element = (XmlSchemaElement) input;
+// assertEquals("wrong name", "parameters", element.getName());
+// assertEquals("wrong number of elements", 3, element.
+// .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());
+// 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
@@ -165,73 +178,73 @@ public class WSDLParserTest {
@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());
+// 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());
+// 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());
+// 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
[2/8] incubator-taverna-common-activities git commit: experimental
wsdl-generic based on XSD schema
Posted by re...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/soap/EncodedBodyBuilderTest.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/soap/EncodedBodyBuilderTest.java b/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/soap/EncodedBodyBuilderTest.java
index 5235626..10165e3 100644
--- a/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/soap/EncodedBodyBuilderTest.java
+++ b/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/soap/EncodedBodyBuilderTest.java
@@ -44,111 +44,111 @@ public class EncodedBodyBuilderTest implements LocationConstants {
@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");
- SOAPElement body = builder.build(inputMap);
-
- Iterator<SOAPElement> children = body.getChildElements();
-
- assertTrue("empty body content", children.hasNext());
-
- SOAPElement child = children.next();
-
- assertTrue("wrong body content (must be '{}str')", "str".equals(child.getLocalName()) && child.getNamespaceURI() == null);
-
- String type = child.getAttributeNS(XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI, "type");
- assertNotNull("missing xsi:type", type);
- assertTrue("wrong xsi:type", "xsd:string".equals(type));
- assertTrue("wrong text value", "Roger Ramjet".equals(child.getTextContent()));
+// 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");
+// SOAPElement body = builder.build(inputMap);
+//
+// Iterator<SOAPElement> children = body.getChildElements();
+//
+// assertTrue("empty body content", children.hasNext());
+//
+// SOAPElement child = children.next();
+//
+// assertTrue("wrong body content (must be '{}str')", "str".equals(child.getLocalName()) && child.getNamespaceURI() == null);
+//
+// String type = child.getAttributeNS(XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI, "type");
+// assertNotNull("missing xsi:type", type);
+// assertTrue("wrong xsi:type", "xsd:string".equals(type));
+// assertTrue("wrong text value", "Roger Ramjet".equals(child.getTextContent()));
}
@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);
- SOAPElement body = builder.build(inputMap);
-
- Iterator<SOAPElement> children = body.getChildElements();
- assertTrue("missing body element", children.hasNext());
- SOAPElement child = children.next();
- assertTrue("wrong body element (must be '{}array')", "array".equals(child.getLocalName()) && child.getNamespaceURI() == null);
- String type = child.getAttributeNS(XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI, "type");
- assertNotNull("missing xsi:type", type);
- assertTrue("wrong xsi:type", "soapenc:Array".equals(type));
-
- Iterator<Element> elements = child.getChildElements();
- for (int i = 0, n = array.size(); i < n; i++) {
- assertTrue("missing array element", elements.hasNext());
- Element element = elements.next();
- assertTrue("wrong array element (must be '{}string')", "string".equals(element.getLocalName()) && element.getNamespaceURI() == null);
- assertTrue("wrong array text content", array.get(i).equals(element.getTextContent()));
- }
+// 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);
+// SOAPElement body = builder.build(inputMap);
+//
+// Iterator<SOAPElement> children = body.getChildElements();
+// assertTrue("missing body element", children.hasNext());
+// SOAPElement child = children.next();
+// assertTrue("wrong body element (must be '{}array')", "array".equals(child.getLocalName()) && child.getNamespaceURI() == null);
+// String type = child.getAttributeNS(XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI, "type");
+// assertNotNull("missing xsi:type", type);
+// assertTrue("wrong xsi:type", "soapenc:Array".equals(type));
+//
+// Iterator<Element> elements = child.getChildElements();
+// for (int i = 0, n = array.size(); i < n; i++) {
+// assertTrue("missing array element", elements.hasNext());
+// Element element = elements.next();
+// assertTrue("wrong array element (must be '{}string')", "string".equals(element.getLocalName()) && element.getNamespaceURI() == null);
+// assertTrue("wrong array text content", array.get(i).equals(element.getTextContent()));
+// }
}
@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);
- SOAPElement body = builder.build(inputMap);
-
- Iterator<SOAPElement> persons = body.getChildElements(new QName("", "p"));
-
- assertTrue("'Person' tag is missing", persons.hasNext());
- SOAPElement person = persons.next();
- assertFalse("more than one 'Person' tag found", persons.hasNext());
-
- String personType = person.getAttributeNS(XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI, "type");
- assertNotNull("type definition of Person is missing", personType);
- assertTrue("wrong xsi:type for the 'Person' tag", "ns1:Person".equals(personType));
-
- assertTrue("wrong type definition for Person", "ns1:Person".equals(personType));
-
- Iterator<SOAPElement> names = person.getChildElements(new QName("", "name"));
-
- assertTrue("'name' tag is missing", names.hasNext());
- SOAPElement name = names.next();
- assertFalse("More than one 'name' tag found", names.hasNext());
-
- String nameType = name.getAttributeNS(XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI, "type");
- assertNotNull("type definition of name is missing", nameType);
- assertTrue("wrong name's xsi:type", "xsd:string".equals(nameType));
- assertTrue("wrong 'name' tag value (must be 'bob')", "bob".equals(name.getTextContent()));
-
- Iterator<SOAPElement> ages = person.getChildElements(new QName("", "age"));
-
- assertTrue("'age' tag is missing", ages.hasNext());
- SOAPElement age = ages.next();
- assertFalse("more than one 'age' tag found", ages.hasNext());
-
- String ageType = age.getAttributeNS(XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI, "type");
- assertNotNull("missing type definition for the 'age' tag", ageType);
- assertTrue("wrong xsi:type for 'age' tag", "xsd:int".equals(ageType));
- assertTrue("wrong 'age' tag value (must be 12)", "12".equals(age.getTextContent()));
- }
-
- protected BodyBuilder createBuilder(String wsdl, String operation) throws Exception {
- WSDLParser parser = new WSDLParser(wsdl);
-
- return BodyBuilderFactory.instance().create(parser, operation, parser.getOperationInputParameters(operation));
+// 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);
+// SOAPElement body = builder.build(inputMap);
+//
+// Iterator<SOAPElement> persons = body.getChildElements(new QName("", "p"));
+//
+// assertTrue("'Person' tag is missing", persons.hasNext());
+// SOAPElement person = persons.next();
+// assertFalse("more than one 'Person' tag found", persons.hasNext());
+//
+// String personType = person.getAttributeNS(XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI, "type");
+// assertNotNull("type definition of Person is missing", personType);
+// assertTrue("wrong xsi:type for the 'Person' tag", "ns1:Person".equals(personType));
+//
+// assertTrue("wrong type definition for Person", "ns1:Person".equals(personType));
+//
+// Iterator<SOAPElement> names = person.getChildElements(new QName("", "name"));
+//
+// assertTrue("'name' tag is missing", names.hasNext());
+// SOAPElement name = names.next();
+// assertFalse("More than one 'name' tag found", names.hasNext());
+//
+// String nameType = name.getAttributeNS(XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI, "type");
+// assertNotNull("type definition of name is missing", nameType);
+// assertTrue("wrong name's xsi:type", "xsd:string".equals(nameType));
+// assertTrue("wrong 'name' tag value (must be 'bob')", "bob".equals(name.getTextContent()));
+//
+// Iterator<SOAPElement> ages = person.getChildElements(new QName("", "age"));
+//
+// assertTrue("'age' tag is missing", ages.hasNext());
+// SOAPElement age = ages.next();
+// assertFalse("more than one 'age' tag found", ages.hasNext());
+//
+// String ageType = age.getAttributeNS(XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI, "type");
+// assertNotNull("missing type definition for the 'age' tag", ageType);
+// assertTrue("wrong xsi:type for 'age' tag", "xsd:int".equals(ageType));
+// assertTrue("wrong 'age' tag value (must be 12)", "12".equals(age.getTextContent()));
}
+//
+// 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/df390d97/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/soap/LiteralBodyBuilderTest.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/soap/LiteralBodyBuilderTest.java b/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/soap/LiteralBodyBuilderTest.java
index b3d16ae..80b15b7 100644
--- a/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/soap/LiteralBodyBuilderTest.java
+++ b/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/soap/LiteralBodyBuilderTest.java
@@ -45,137 +45,137 @@ public class LiteralBodyBuilderTest implements LocationConstants{
@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);
-
- SOAPElement body = builder.build(inputMap);
-
- assertTrue("Wrong wrapping element name", "queryPmid".equals(body.getLocalName()) && "http://www.ebi.ac.uk/webservices/whatizit/ws".equals(body.getNamespaceURI()));
-
- Iterator<Node> pipelineNames = body.getChildElements(new QName("","pipelineName"));
-
- assertTrue("No pipelineName defined", pipelineNames.hasNext());
- assertTrue("Wrong pipelineName value (must be 'swissProt')", "swissProt".equals(pipelineNames.next().getTextContent()));
-
- Iterator<Node> pmids = body.getChildElements(new QName("","pmid"));
-
- assertTrue("No pmid defined", pmids.hasNext());
- assertTrue("Wrong pmid value (must be '1234')", "1234".equals(pmids.next().getTextContent()));
+// 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);
+//
+// SOAPElement body = builder.build(inputMap);
+//
+// assertTrue("Wrong wrapping element name", "queryPmid".equals(body.getLocalName()) && "http://www.ebi.ac.uk/webservices/whatizit/ws".equals(body.getNamespaceURI()));
+//
+// Iterator<Node> pipelineNames = body.getChildElements(new QName("","pipelineName"));
+//
+// assertTrue("No pipelineName defined", pipelineNames.hasNext());
+// assertTrue("Wrong pipelineName value (must be 'swissProt')", "swissProt".equals(pipelineNames.next().getTextContent()));
+//
+// Iterator<Node> pmids = body.getChildElements(new QName("","pmid"));
+//
+// assertTrue("No pmid defined", pmids.hasNext());
+// assertTrue("Wrong pmid value (must be '1234')", "1234".equals(pmids.next().getTextContent()));
}
@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");
-
- SOAPElement body = builder.build(inputMap);
-
- assertEquals("Wrong localName","str", body.getLocalName());
- assertEquals("XML should containe qualifed namespace for str","http://testing.org", body.getNamespaceURI());
+// 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");
+//
+// SOAPElement body = builder.build(inputMap);
+//
+// assertEquals("Wrong localName","str", body.getLocalName());
+// assertEquals("XML should containe qualifed namespace for str","http://testing.org", body.getNamespaceURI());
}
@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");
-
- SOAPElement body = builder.build(inputMap);
-
- assertTrue("Input element should be named {http://testing.org}str ", "str".equals(body.getLocalName()) && "http://testing.org".equals(body.getNamespaceURI()));
-
- assertEquals("Value should be 12345:","12345",body.getFirstChild().getNodeValue());
+// 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");
+//
+// SOAPElement body = builder.build(inputMap);
+//
+// assertTrue("Input element should be named {http://testing.org}str ", "str".equals(body.getLocalName()) && "http://testing.org".equals(body.getNamespaceURI()));
+//
+// assertEquals("Value should be 12345:","12345",body.getFirstChild().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>");
-
- SOAPElement body = builder.build(inputMap);
-
- assertTrue("Outer element should be named {http://testing.org}array ", "array".equals(body.getLocalName()) && "http://testing.org".equals(body.getNamespaceURI()));
-
- assertTrue("There must be three child nodes in array", body.getChildNodes().getLength() == 3);
-
- Iterator<Node> items = body.getChildElements(new QName("", "item"));
- assertTrue("Array element should be named item", items.hasNext());
-
- assertTrue("First Array element should have the value '1'", "1".equals(items.next().getTextContent()));
+// 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>");
+//
+// SOAPElement body = builder.build(inputMap);
+//
+// assertTrue("Outer element should be named {http://testing.org}array ", "array".equals(body.getLocalName()) && "http://testing.org".equals(body.getNamespaceURI()));
+//
+// assertTrue("There must be three child nodes in array", body.getChildNodes().getLength() == 3);
+//
+// Iterator<Node> items = body.getChildElements(new QName("", "item"));
+// assertTrue("Array element should be named item", items.hasNext());
+//
+// assertTrue("First Array element should have the value '1'", "1".equals(items.next().getTextContent()));
}
@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>");
- SOAPElement 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.getElementQName());
+// 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>");
+// SOAPElement 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.getElementQName());
}
@Test
public void testOperationElementNameTAV744() throws Exception {
- URL tav744Url = getClass().getResource(
- "/org/apache/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
- SOAPElement 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.getElementQName());
+// 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
+// SOAPElement 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.getElementQName());
}
@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");
-
- SOAPElement body = builder.build(inputMap);
-
- assertTrue("Outer element should be named {http://testing.org}countString","countString".equals(body.getLocalName()) && "http://testing.org".equals(body.getNamespaceURI()));
-
- Node strNode = body.getFirstChild();
- assertEquals("Inner element should be called 'str'","str",strNode.getNodeName());
- assertEquals("str content should be abcdef","abcdef",strNode.getFirstChild().getNodeValue());
+// 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");
+//
+// SOAPElement body = builder.build(inputMap);
+//
+// assertTrue("Outer element should be named {http://testing.org}countString","countString".equals(body.getLocalName()) && "http://testing.org".equals(body.getNamespaceURI()));
+//
+// Node strNode = body.getFirstChild();
+// assertEquals("Inner element should be called 'str'","str",strNode.getNodeName());
+// assertEquals("str content should be abcdef","abcdef",strNode.getFirstChild().getNodeValue());
}
- protected BodyBuilder createBuilder(String wsdl, String operation) throws Exception {
- WSDLParser parser = new WSDLParser(wsdl);
- return BodyBuilderFactory.instance().create(parser, operation, parser.getOperationInputParameters(operation));
- }
+// 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/df390d97/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/soap/SOAPResponseEncodedTest.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/soap/SOAPResponseEncodedTest.java b/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/soap/SOAPResponseEncodedTest.java
index d7ddd93..ae3903f 100644
--- a/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/soap/SOAPResponseEncodedTest.java
+++ b/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/soap/SOAPResponseEncodedTest.java
@@ -45,38 +45,38 @@ public class SOAPResponseEncodedTest implements LocationConstants {
@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<SOAPElement> response = new ArrayList<SOAPElement>();
-
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- factory.setNamespaceAware(true);
- DocumentBuilder builder = factory.newDocumentBuilder();
- Document doc = builder.parse(new InputSource(new StringReader(xml1)));
- response.add(SOAPFactory.newInstance().createElement(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());
+// 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<SOAPElement> response = new ArrayList<SOAPElement>();
+//
+// DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+// factory.setNamespaceAware(true);
+// DocumentBuilder builder = factory.newDocumentBuilder();
+// Document doc = builder.parse(new InputSource(new StringReader(xml1)));
+// response.add(SOAPFactory.newInstance().createElement(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/df390d97/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/soap/SOAPResponseLiteralTest.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/soap/SOAPResponseLiteralTest.java b/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/soap/SOAPResponseLiteralTest.java
index 2e714ce..2a5bc21 100644
--- a/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/soap/SOAPResponseLiteralTest.java
+++ b/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/soap/SOAPResponseLiteralTest.java
@@ -27,9 +27,6 @@ import java.util.Map;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.soap.SOAPFactory;
-import org.apache.taverna.wsdl.parser.BaseTypeDescriptor;
-import org.apache.taverna.wsdl.parser.ComplexTypeDescriptor;
-import org.apache.taverna.wsdl.parser.TypeDescriptor;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import org.junit.Test;
@@ -41,119 +38,119 @@ public class SOAPResponseLiteralTest{
@SuppressWarnings("unchecked")
@Test
public void testLiteralParserResultInTextBlock() 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>";
-
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- factory.setNamespaceAware(true);
- DocumentBuilder builder = factory.newDocumentBuilder();
- Document doc = builder.parse(new InputSource(new StringReader(xml)));
-
- response.add(SOAPFactory.newInstance().createElement(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());
+// List response = new ArrayList();
+// String xml = "<testResponse><out><data name="a">some data</data><data name="b">some more data</data></out></testResponse>";
+//
+// DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+// factory.setNamespaceAware(true);
+// DocumentBuilder builder = factory.newDocumentBuilder();
+// Document doc = builder.parse(new InputSource(new StringReader(xml)));
+//
+// response.add(SOAPFactory.newInstance().createElement(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 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>";
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- factory.setNamespaceAware(true);
- DocumentBuilder builder = factory.newDocumentBuilder();
- Document doc = builder.parse(new InputSource(new StringReader(xml)));
- response.add(SOAPFactory.newInstance().createElement(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());
+// List response = new ArrayList();
+// String xml = "<testResponse><out><data name=\"a\">some data</data><data name=\"b\">some more data</data></out></testResponse>";
+// DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+// factory.setNamespaceAware(true);
+// DocumentBuilder builder = factory.newDocumentBuilder();
+// Document doc = builder.parse(new InputSource(new StringReader(xml)));
+// response.add(SOAPFactory.newInstance().createElement(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>";
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- factory.setNamespaceAware(true);
- DocumentBuilder builder = factory.newDocumentBuilder();
- Document doc = builder.parse(new InputSource(new StringReader(xml)));
-
- response.add(SOAPFactory.newInstance().createElement(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());
+// List response = new ArrayList();
+//
+// String xml = "<getStringReturn xmlns=\"http://testing.org\">a string</getStringReturn>";
+// DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+// factory.setNamespaceAware(true);
+// DocumentBuilder builder = factory.newDocumentBuilder();
+// Document doc = builder.parse(new InputSource(new StringReader(xml)));
+//
+// response.add(SOAPFactory.newInstance().createElement(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());
+// 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());
}
}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/soap/SOAPResponseMultiRefTest.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/soap/SOAPResponseMultiRefTest.java b/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/soap/SOAPResponseMultiRefTest.java
index dde12c4..2b7696e 100644
--- a/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/soap/SOAPResponseMultiRefTest.java
+++ b/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/soap/SOAPResponseMultiRefTest.java
@@ -33,8 +33,6 @@ import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.soap.SOAPFactory;
-import org.apache.taverna.wsdl.parser.ComplexTypeDescriptor;
-import org.apache.taverna.wsdl.parser.TypeDescriptor;
import org.apache.taverna.wsdl.parser.WSDLParser;
import org.apache.taverna.wsdl.testutils.LocationConstants;
import org.apache.taverna.wsdl.testutils.WSDLTestHelper;
@@ -52,187 +50,187 @@ public class SOAPResponseMultiRefTest implements LocationConstants {
@SuppressWarnings("unchecked")
@Test
public void testMultiRef() throws Exception {
- WSDLParser wsdlParser = new WSDLParser(wsdlResourcePath("TestServices-rpcencoded.wsdl"));
-
- List response = new ArrayList();
-
- String xml1 = "<ns1:getPersonResponse soapenv:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:ns1=\"urn:testing\" xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"><getPersonReturn href=\"#id0\"/></ns1:getPersonResponse>";
- String xml2 = "<multiRef id=\"id0\" soapenc:root=\"0\" soapenv:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><age xsi:type=\"soapenc:string\">5</age><name xsi:type=\"soapenc:string\">bob</name></multiRef>";
-
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- factory.setNamespaceAware(true);
- DocumentBuilder builder = factory.newDocumentBuilder();
- Document doc = builder.parse(new InputSource(new StringReader(xml1)));
-
- response.add(SOAPFactory.newInstance().createElement(doc.getDocumentElement()));
-
- doc = builder.parse(new InputSource(new StringReader(xml2)));
- response.add(SOAPFactory.newInstance().createElement(doc.getDocumentElement()));
-
- SOAPResponseEncodedMultiRefParser parser = new SOAPResponseEncodedMultiRefParser(
- wsdlParser.getOperationOutputParameters("getPerson"));
- parser.setStripAttributes(true);
- Map outputMap = parser.parse(response);
-
- assertNotNull("no output map returned", outputMap);
-
- assertEquals("map should contain 1 element", 1, outputMap.size());
-
- Object getPersonReturn = outputMap
- .get("getPersonReturn");
-
- assertNotNull(
- "output map should have contained entry for 'getPersonReturn'",
- getPersonReturn);
-
- assertEquals("output data should be a string", String.class,
- getPersonReturn.getClass());
-
- assertEquals(
- "unexpected xml content in output",
- "<getPersonReturn><age>5</age><name>bob</name></getPersonReturn>",
- getPersonReturn.toString());
-
+// WSDLParser wsdlParser = new WSDLParser(wsdlResourcePath("TestServices-rpcencoded.wsdl"));
+//
+// List response = new ArrayList();
+//
+// String xml1 = "<ns1:getPersonResponse soapenv:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:ns1=\"urn:testing\" xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"><getPersonReturn href=\"#id0\"/></ns1:getPersonResponse>";
+// String xml2 = "<multiRef id=\"id0\" soapenc:root=\"0\" soapenv:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><age xsi:type=\"soapenc:string\">5</age><name xsi:type=\"soapenc:string\">bob</name></multiRef>";
+//
+// DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+// factory.setNamespaceAware(true);
+// DocumentBuilder builder = factory.newDocumentBuilder();
+// Document doc = builder.parse(new InputSource(new StringReader(xml1)));
+//
+// response.add(SOAPFactory.newInstance().createElement(doc.getDocumentElement()));
+//
+// doc = builder.parse(new InputSource(new StringReader(xml2)));
+// response.add(SOAPFactory.newInstance().createElement(doc.getDocumentElement()));
+//
+// SOAPResponseEncodedMultiRefParser parser = new SOAPResponseEncodedMultiRefParser(
+// wsdlParser.getOperationOutputParameters("getPerson"));
+// parser.setStripAttributes(true);
+// Map outputMap = parser.parse(response);
+//
+// assertNotNull("no output map returned", outputMap);
+//
+// assertEquals("map should contain 1 element", 1, outputMap.size());
+//
+// Object getPersonReturn = outputMap
+// .get("getPersonReturn");
+//
+// assertNotNull(
+// "output map should have contained entry for 'getPersonReturn'",
+// getPersonReturn);
+//
+// assertEquals("output data should be a string", String.class,
+// getPersonReturn.getClass());
+//
+// assertEquals(
+// "unexpected xml content in output",
+// "<getPersonReturn><age>5</age><name>bob</name></getPersonReturn>",
+// getPersonReturn.toString());
+//
}
@SuppressWarnings("unchecked")
@Test
public void testMultiRefReturnNamespaced() throws Exception {
- WSDLParser wsdlParser = new WSDLParser(wsdlResourcePath("TestServices-rpcencoded.wsdl"));
-
- List response = new ArrayList();
-
- String xml1 = "<ns1:getPersonResponse soapenv:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:ns1=\"urn:testing\" xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"><ns1:getPersonReturn xmlns:ns1=\"urn:testing\" href=\"#id0\"/></ns1:getPersonResponse>";
- String xml2 = "<multiRef id=\"id0\" soapenc:root=\"0\" soapenv:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><age xsi:type=\"soapenc:string\">5</age><name xsi:type=\"soapenc:string\">bob</name></multiRef>";
-
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- factory.setNamespaceAware(true);
- DocumentBuilder builder = factory.newDocumentBuilder();
- Document doc = builder.parse(new InputSource(new StringReader(xml1)));
-
- response.add(SOAPFactory.newInstance().createElement(doc.getDocumentElement()));
-
- doc = builder.parse(new InputSource(new StringReader(xml2)));
- response.add(SOAPFactory.newInstance().createElement(doc.getDocumentElement()));
-
- SOAPResponseEncodedMultiRefParser parser = new SOAPResponseEncodedMultiRefParser(
- wsdlParser.getOperationOutputParameters("getPerson"));
- parser.setStripAttributes(true);
- Map outputMap = parser.parse(response);
-
- assertNotNull("no output map returned", outputMap);
-
- assertEquals("map should contain 1 element", 1, outputMap.size());
-
- Object getPersonReturn = outputMap
- .get("getPersonReturn");
-
- assertNotNull(
- "output map should have contained entry for 'getPersonReturn'",
- getPersonReturn);
-
- assertEquals("output data should be a string", String.class,
- getPersonReturn.getClass());
-
- assertEquals(
- "unexpected xml content in output",
- "<getPersonReturn><age>5</age><name>bob</name></getPersonReturn>",
- getPersonReturn.toString());
+// WSDLParser wsdlParser = new WSDLParser(wsdlResourcePath("TestServices-rpcencoded.wsdl"));
+//
+// List response = new ArrayList();
+//
+// String xml1 = "<ns1:getPersonResponse soapenv:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:ns1=\"urn:testing\" xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"><ns1:getPersonReturn xmlns:ns1=\"urn:testing\" href=\"#id0\"/></ns1:getPersonResponse>";
+// String xml2 = "<multiRef id=\"id0\" soapenc:root=\"0\" soapenv:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><age xsi:type=\"soapenc:string\">5</age><name xsi:type=\"soapenc:string\">bob</name></multiRef>";
+//
+// DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+// factory.setNamespaceAware(true);
+// DocumentBuilder builder = factory.newDocumentBuilder();
+// Document doc = builder.parse(new InputSource(new StringReader(xml1)));
+//
+// response.add(SOAPFactory.newInstance().createElement(doc.getDocumentElement()));
+//
+// doc = builder.parse(new InputSource(new StringReader(xml2)));
+// response.add(SOAPFactory.newInstance().createElement(doc.getDocumentElement()));
+//
+// SOAPResponseEncodedMultiRefParser parser = new SOAPResponseEncodedMultiRefParser(
+// wsdlParser.getOperationOutputParameters("getPerson"));
+// parser.setStripAttributes(true);
+// Map outputMap = parser.parse(response);
+//
+// assertNotNull("no output map returned", outputMap);
+//
+// assertEquals("map should contain 1 element", 1, outputMap.size());
+//
+// Object getPersonReturn = outputMap
+// .get("getPersonReturn");
+//
+// assertNotNull(
+// "output map should have contained entry for 'getPersonReturn'",
+// getPersonReturn);
+//
+// assertEquals("output data should be a string", String.class,
+// getPersonReturn.getClass());
+//
+// assertEquals(
+// "unexpected xml content in output",
+// "<getPersonReturn><age>5</age><name>bob</name></getPersonReturn>",
+// getPersonReturn.toString());
}
@SuppressWarnings("unchecked")
@Test
public void testNestedReferences() throws Exception {
-
- //only the name is important.
- TypeDescriptor descriptor = new ComplexTypeDescriptor();
- descriptor.setName("result");
- SOAPResponseEncodedMultiRefParser parser = new SOAPResponseEncodedMultiRefParser(
- Collections.singletonList(descriptor));
-
-
- String xml1 = "<response><result><creatures href=\"#id0\"/></result></response>";
- String xml2 = "<multiref id=\"id0\"><item href=\"#id1\"/><item href=\"#id2\"/></multiref>";
- String xml3 = "<multiref id=\"id1\"><creature>monkey</creature></multiref>";
- String xml4 = "<multiref id=\"id2\"><creature>frog</creature></multiref>";
-
- List response = new ArrayList();
-
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- factory.setNamespaceAware(true);
- DocumentBuilder builder = factory.newDocumentBuilder();
- Document doc = builder.parse(new InputSource(new StringReader(xml1)));
-
- response.add(SOAPFactory.newInstance().createElement(doc.getDocumentElement()));
-
- doc = builder.parse(new InputSource(new StringReader(xml2)));
- response.add(SOAPFactory.newInstance().createElement(doc.getDocumentElement()));
-
- doc = builder.parse(new InputSource(new StringReader(xml3)));
- response.add(SOAPFactory.newInstance().createElement(doc.getDocumentElement()));
-
- doc = builder.parse(new InputSource(new StringReader(xml4)));
- response.add(SOAPFactory.newInstance().createElement(doc.getDocumentElement()));
-
-
- 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("result");
-
- assertNotNull("output map should have contained entry for 'result'",
- result);
-
- assertEquals("output data should be a string", String.class, result
- .getClass());
-
- assertEquals(
- "incorrect xml content in output",
- "<result><creatures><item><creature>monkey</creature></item><item><creature>frog</creature></item></creatures></result>",
- result.toString());
-
+//
+// //only the name is important.
+// TypeDescriptor descriptor = new ComplexTypeDescriptor();
+// descriptor.setName("result");
+// SOAPResponseEncodedMultiRefParser parser = new SOAPResponseEncodedMultiRefParser(
+// Collections.singletonList(descriptor));
+//
+//
+// String xml1 = "<response><result><creatures href=\"#id0\"/></result></response>";
+// String xml2 = "<multiref id=\"id0\"><item href=\"#id1\"/><item href=\"#id2\"/></multiref>";
+// String xml3 = "<multiref id=\"id1\"><creature>monkey</creature></multiref>";
+// String xml4 = "<multiref id=\"id2\"><creature>frog</creature></multiref>";
+//
+// List response = new ArrayList();
+//
+// DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+// factory.setNamespaceAware(true);
+// DocumentBuilder builder = factory.newDocumentBuilder();
+// Document doc = builder.parse(new InputSource(new StringReader(xml1)));
+//
+// response.add(SOAPFactory.newInstance().createElement(doc.getDocumentElement()));
+//
+// doc = builder.parse(new InputSource(new StringReader(xml2)));
+// response.add(SOAPFactory.newInstance().createElement(doc.getDocumentElement()));
+//
+// doc = builder.parse(new InputSource(new StringReader(xml3)));
+// response.add(SOAPFactory.newInstance().createElement(doc.getDocumentElement()));
+//
+// doc = builder.parse(new InputSource(new StringReader(xml4)));
+// response.add(SOAPFactory.newInstance().createElement(doc.getDocumentElement()));
+//
+//
+// 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("result");
+//
+// assertNotNull("output map should have contained entry for 'result'",
+// result);
+//
+// assertEquals("output data should be a string", String.class, result
+// .getClass());
+//
+// assertEquals(
+// "incorrect xml content in output",
+// "<result><creatures><item><creature>monkey</creature></item><item><creature>frog</creature></item></creatures></result>",
+// result.toString());
+//
}
@SuppressWarnings("unchecked")
@Test
public void testFailOnCyclic() throws Exception {
- List outputNames = new ArrayList();
- outputNames.add("attachmentList");
- outputNames.add("result");
-
- String xml1 = "<response><result><item href=\"#id0\"/></result></response>";
- String xml2 = "<multiref id=\"id0\"><item href=\"#id1\"/></multiref>";
- String xml3 = "<multiref id=\"id1\"><item href=\"#id0\"/></multiref>";
-
- List response = new ArrayList();
-
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- factory.setNamespaceAware(true);
- DocumentBuilder builder = factory.newDocumentBuilder();
- Document doc = builder.parse(new InputSource(new StringReader(xml1)));
- response.add(SOAPFactory.newInstance().createElement(doc.getDocumentElement()));
-
- doc = builder.parse(new InputSource(new StringReader(xml2)));
- response.add(SOAPFactory.newInstance().createElement(doc.getDocumentElement()));
-
- doc = builder.parse(new InputSource(new StringReader(xml3)));
- response.add(SOAPFactory.newInstance().createElement(doc.getDocumentElement()));
-
- SOAPResponseEncodedMultiRefParser parser = new SOAPResponseEncodedMultiRefParser(
- outputNames);
- parser.setStripAttributes(true);
-
- try {
- parser.parse(response);
- fail("CyclicReferenceException should have been thrown");
- } catch (CyclicReferenceException e) {
-
- }
+// List outputNames = new ArrayList();
+// outputNames.add("attachmentList");
+// outputNames.add("result");
+//
+// String xml1 = "<response><result><item href=\"#id0\"/></result></response>";
+// String xml2 = "<multiref id=\"id0\"><item href=\"#id1\"/></multiref>";
+// String xml3 = "<multiref id=\"id1\"><item href=\"#id0\"/></multiref>";
+//
+// List response = new ArrayList();
+//
+// DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+// factory.setNamespaceAware(true);
+// DocumentBuilder builder = factory.newDocumentBuilder();
+// Document doc = builder.parse(new InputSource(new StringReader(xml1)));
+// response.add(SOAPFactory.newInstance().createElement(doc.getDocumentElement()));
+//
+// doc = builder.parse(new InputSource(new StringReader(xml2)));
+// response.add(SOAPFactory.newInstance().createElement(doc.getDocumentElement()));
+//
+// doc = builder.parse(new InputSource(new StringReader(xml3)));
+// response.add(SOAPFactory.newInstance().createElement(doc.getDocumentElement()));
+//
+// SOAPResponseEncodedMultiRefParser parser = new SOAPResponseEncodedMultiRefParser(
+// outputNames);
+// parser.setStripAttributes(true);
+//
+// try {
+// parser.parse(response);
+// fail("CyclicReferenceException should have been thrown");
+// } catch (CyclicReferenceException e) {
+//
+// }
}
}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/soap/SOAPResponseParserFactoryTest.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/soap/SOAPResponseParserFactoryTest.java b/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/soap/SOAPResponseParserFactoryTest.java
index c3794c6..94ba0b2 100644
--- a/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/soap/SOAPResponseParserFactoryTest.java
+++ b/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/soap/SOAPResponseParserFactoryTest.java
@@ -40,24 +40,24 @@ public class SOAPResponseParserFactoryTest implements LocationConstants {
//output mime type, if the use is set to 'literal' (unwrapped/literal)
@Test
public void testLiteralUnwrappedParserForNonXMLOutput() throws Exception {
- SOAPResponseParserFactory factory = SOAPResponseParserFactory.instance();
- List<String> response = new ArrayList<String>();
- WSDLParser wsdlParser = new WSDLParser(wsdlResourcePath("TestServices-unwrapped.wsdl"));
-
- SOAPResponseParser parser = factory.create(response, "literal", "document", wsdlParser.getOperationOutputParameters("getString"));
-
- assertTrue("The parser is the wrong type, it was:"+parser.getClass().getSimpleName(),parser instanceof SOAPResponsePrimitiveLiteralParser);
+// SOAPResponseParserFactory factory = SOAPResponseParserFactory.instance();
+// List<String> response = new ArrayList<String>();
+// WSDLParser wsdlParser = new WSDLParser(wsdlResourcePath("TestServices-unwrapped.wsdl"));
+//
+// SOAPResponseParser parser = factory.create(response, "literal", "document", wsdlParser.getOperationOutputParameters("getString"));
+//
+// assertTrue("The parser is the wrong type, it was:"+parser.getClass().getSimpleName(),parser instanceof SOAPResponsePrimitiveLiteralParser);
}
//an additional test using another unwrapped/literal wsdl that returns a primative type
@Test
public void testLiteralUnwrappedAlternativeWSDL() throws Exception {
- SOAPResponseParserFactory factory = SOAPResponseParserFactory.instance();
- List<String> response = new ArrayList<String>();
- WSDLParser wsdlParser = new WSDLParser(wsdlResourcePath("prodoric.wsdl"));
-
- SOAPResponseParser parser = factory.create(response, "literal", "document", wsdlParser.getOperationOutputParameters("hello"));
-
- assertTrue("The parser is the wrong type, it was:"+parser.getClass().getSimpleName(),parser instanceof SOAPResponsePrimitiveLiteralParser);
+// SOAPResponseParserFactory factory = SOAPResponseParserFactory.instance();
+// List<String> response = new ArrayList<String>();
+// WSDLParser wsdlParser = new WSDLParser(wsdlResourcePath("prodoric.wsdl"));
+//
+// SOAPResponseParser parser = factory.create(response, "literal", "document", wsdlParser.getOperationOutputParameters("hello"));
+//
+// assertTrue("The parser is the wrong type, it was:"+parser.getClass().getSimpleName(),parser instanceof SOAPResponsePrimitiveLiteralParser);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/testutils/WSDLTestHelper.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/testutils/WSDLTestHelper.java b/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/testutils/WSDLTestHelper.java
index 58c039e..c63f56e 100644
--- a/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/testutils/WSDLTestHelper.java
+++ b/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/testutils/WSDLTestHelper.java
@@ -43,8 +43,5 @@ public class WSDLTestHelper implements LocationConstants {
return content;
- }
-
-
-
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/xmlsplitter/XMLInputSplitterTest.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/xmlsplitter/XMLInputSplitterTest.java b/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/xmlsplitter/XMLInputSplitterTest.java
deleted file mode 100644
index 4d856eb..0000000
--- a/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/xmlsplitter/XMLInputSplitterTest.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
-* 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.xmlsplitter;
-
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.taverna.wsdl.parser.TypeDescriptor;
-import org.apache.taverna.wsdl.parser.WSDLParser;
-import org.apache.taverna.wsdl.testutils.LocationConstants;
-import org.apache.taverna.wsdl.testutils.WSDLTestHelper;
-
-import org.junit.Test;
-
-public class XMLInputSplitterTest implements LocationConstants {
-
- @Test
- public void testExecute() throws Exception {
- WSDLParser parser = new WSDLParser(WSDLTestHelper.wsdlResourcePath("eutils/eutils_lite.wsdl"));
- TypeDescriptor descriptor = parser.getOperationInputParameters("run_eInfo").get(0);
- XMLInputSplitter splitter = new XMLInputSplitter(descriptor,new String[]{"db","tool","email"},new String[]{"text/plain","text/plain","text/plain"},new String[]{"output"});
- Map<String,Object> inputMap = new HashMap<String, Object>();
- inputMap.put("db", "pubmed");
- inputMap.put("email", "bob.monkhouse@itv.com");
- Map<String,String> outputMap = splitter.execute(inputMap);
- assertNotNull("there should be an output named 'output'",outputMap.containsKey("output"));
- String xml = outputMap.get("output");
- assertTrue(xml.startsWith("<parameters xmlns=\"http://www.ncbi.nlm.nih.gov/soap/eutils/einfo\">"));
- assertTrue(xml.contains("<db>pubmed</db>"));
- assertTrue(! xml.contains("<tool"));
- assertTrue(xml.contains("<email>bob.monkhouse@itv.com</email>"));
- }
-
-
- @Test
- public void testOptional() throws Exception {
- WSDLParser parser = new WSDLParser(WSDLTestHelper.wsdlResourcePath("VSOi.wsdl"));
- TypeDescriptor descriptor = parser.getOperationInputParameters("Query").get(0);
- XMLInputSplitter splitter = new XMLInputSplitter(descriptor,new String[]{"version","block"},new String[]{"text/plain","text/plain"},new String[]{"output"});
- Map<String,Object> inputMap = new HashMap<String, Object>();
- // connect none of the inputs
- Map<String,String> outputMap = splitter.execute(inputMap);
- assertNotNull("there should be an output named 'output'",outputMap.containsKey("output"));
- String xml = outputMap.get("output");
- // empty string as <block> as it is not nillable
- assertTrue(xml.contains("<block xmlns=\"\"></block>"));
- // minOccurs=0 - so it should not be there
- assertTrue(! xml.contains("<version>"));
- }
-
-
- @Test
- public void testNillable() throws Exception {
- WSDLParser parser = new WSDLParser(WSDLTestHelper.wsdlResourcePath("VSOi.wsdl"));
- TypeDescriptor descriptor = parser.getOperationInputParameters("Query").get(0);
- XMLInputSplitter splitter = new XMLInputSplitter(descriptor,new String[]{"version","block"},new String[]{"text/plain","text/plain"},new String[]{"output"});
- Map<String,Object> inputMap = new HashMap<String, Object>();
- // Magic string meaning insert xsi:nil=true
- inputMap.put("version", "xsi:nil");
- Map<String,String> outputMap = splitter.execute(inputMap);
- assertNotNull("there should be an output named 'output'",outputMap.containsKey("output"));
- String xml = outputMap.get("output");
- System.out.println(xml);
- // empty string as <block> as it is not nillable
- assertTrue(xml.contains("<block xmlns=\"\"></block>"));
- // FIXME: Should not really allow nil=true here, as version is not nillable!
- assertTrue(xml.contains("<version xmlns=\"\" " +
- "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " +
- "xsi:nil=\"true\" />"));
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/xmlsplitter/XMLOutputSplitterTest.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/xmlsplitter/XMLOutputSplitterTest.java b/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/xmlsplitter/XMLOutputSplitterTest.java
deleted file mode 100644
index 9c3c483..0000000
--- a/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/xmlsplitter/XMLOutputSplitterTest.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
-* 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.xmlsplitter;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import org.apache.taverna.wsdl.parser.TypeDescriptor;
-import org.apache.taverna.wsdl.parser.WSDLParser;
-import org.apache.taverna.wsdl.testutils.WSDLTestHelper;
-import org.junit.Test;
-import static org.junit.Assert.*;
-
-/**
- *
- * @author sowen
- */
-public class XMLOutputSplitterTest extends WSDLTestHelper {
-
- @Test
- public void testRPCComplexWithInternalList() throws Exception {
-
- WSDLParser parser = new WSDLParser(WSDLTestHelper.wsdlResourcePath("menagerie-complex-rpc.wsdl"));
- TypeDescriptor descriptor = parser.getOperationOutputParameters("getComplexWithInternalList").get(0);
- XMLOutputSplitter splitter = new XMLOutputSplitter(descriptor, new String [] {"length","innerArray","innerList"}, new String [] {"text/plain","l('text/plain')","l('text/plain')"}, new String[] {"input"});
- String inputXML=getResourceContentsString("getComplexWithInternalListResponse.xml");
- Map<String,String> inputMap = new HashMap<String,String>();
- inputMap.put("input", inputXML);
- Map<String,Object> outputMap = splitter.execute(inputMap);
- assertNotNull(outputMap.get("length"));
- assertNotNull(outputMap.get("innerList"));
- assertNotNull(outputMap.get("innerArray"));
-
- assertEquals("4",outputMap.get("length"));
-
- List<String> array = ( List<String> )outputMap.get("innerArray");
- assertEquals(4,array.size());
- assertEquals("String A",array.get(0));
- assertEquals("String B",array.get(1));
- assertEquals("String C",array.get(2));
- assertEquals("String D",array.get(3));
-
- array = ( List<String> )outputMap.get("innerList");
- assertEquals(4,array.size());
- assertEquals("String A",array.get(0));
- assertEquals("String B",array.get(1));
- assertEquals("String C",array.get(2));
- assertEquals("String D",array.get(3));
- }
-
- @Test
- public void testWrappedArrayDefinedWithRestriction() throws Exception {
- WSDLParser parser = new WSDLParser(WSDLTestHelper.wsdlResourcePath("jws-online.wsdl"));
- TypeDescriptor descriptor = parser.getOperationOutputParameters("getSteadyStateTable").get(0);
- XMLOutputSplitter splitter = new XMLOutputSplitter(descriptor, new String [] {"model","fluxNames","fluxVals"}, new String [] {"text/plain","l('text/plain')","l('text/plain')"}, new String[] {"input"});
- String inputXML=getResourceContentsString("jws-splitter-input.xml");
-
- Map<String,String> inputMap = new HashMap<String,String>();
- inputMap.put("input", inputXML);
- Map<String,Object> outputMap = splitter.execute(inputMap);
-
- assertNotNull(outputMap.get("model"));
- assertNotNull(outputMap.get("fluxNames"));
- assertNotNull(outputMap.get("fluxVals"));
-
- assertEquals("teusink",outputMap.get("model"));
- List<String> array = ( List<String> )outputMap.get("fluxNames");
- assertEquals(17,array.size());
- assert(array.contains("v[G3PDH]"));
-
- array = ( List<String> )outputMap.get("fluxVals");
- assertEquals(17,array.size());
- assert(array.contains("88.15049285974906"));
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/xmlsplitter/XMLSplitterSerialisationHelperTest.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/xmlsplitter/XMLSplitterSerialisationHelperTest.java b/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/xmlsplitter/XMLSplitterSerialisationHelperTest.java
deleted file mode 100644
index 7c63297..0000000
--- a/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/xmlsplitter/XMLSplitterSerialisationHelperTest.java
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
-* 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.xmlsplitter;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import java.io.StringReader;
-import java.util.List;
-
-import org.apache.taverna.wsdl.parser.ComplexTypeDescriptor;
-import org.apache.taverna.wsdl.parser.TypeDescriptor;
-
-//import org.embl.ebi.escience.scufl.XScufl;
-import org.jdom.Element;
-import org.jdom.input.SAXBuilder;
-import org.jdom.output.XMLOutputter;
-import org.junit.Test;
-
-public class XMLSplitterSerialisationHelperTest {
-
-// @Test
-// public void testScuflNS() throws Exception {
-// assertEquals("namespace should be equal",XScufl.XScuflNS,XMLSplitterSerialisationHelper.XScuflNS);
-// }
-
- @Test
- public void testCyclicToElement() throws Exception {
- ComplexTypeDescriptor a = new ComplexTypeDescriptor();
- a.setName("a");
- a.setType("typename");
- a.setQnameFromString("{namespace}typename");
-
- ComplexTypeDescriptor b = new ComplexTypeDescriptor();
- b.setName("b");
- b.setType("typename2");
- b.setQnameFromString("{namespace}typename2");
-
- a.getElements().add(b);
-
- b.getElements().add(a);
-
- Element el = XMLSplitterSerialisationHelper
- .typeDescriptorToExtensionXML(a);
-
- String xml = new XMLOutputter().outputString(el);
-
- assertEquals(
- "unexpected xml",
- "<s:extensions xmlns:s=\"http://org.embl.ebi.escience/xscufl/0.1alpha\"><s:complextype optional=\"false\" unbounded=\"false\" typename=\"typename\" name=\"a\" qname=\"{namespace}typename\"><s:elements><s:complextype optional=\"false\" unbounded=\"false\" typename=\"typename2\" name=\"b\" qname=\"{namespace}typename2\"><s:elements><s:complextype id=\"{namespace}typename\" optional=\"false\" unbounded=\"false\" typename=\"typename\" name=\"a\" /></s:elements></s:complextype></s:elements></s:complextype></s:extensions>",
- xml);
-
- }
-
- @Test
- public void testCyclicToElement2() throws Exception {
- ComplexTypeDescriptor a = new ComplexTypeDescriptor();
- a.setName("a");
- a.setType("typename");
- a.setQnameFromString("{namespace}typename");
-
- a.getElements().add(a);
-
- Element el = XMLSplitterSerialisationHelper
- .typeDescriptorToExtensionXML(a);
-
- String xml = new XMLOutputter().outputString(el);
-
- assertEquals(
- "unexpected xml",
- "<s:extensions xmlns:s=\"http://org.embl.ebi.escience/xscufl/0.1alpha\"><s:complextype optional=\"false\" unbounded=\"false\" typename=\"typename\" name=\"a\" qname=\"{namespace}typename\"><s:elements><s:complextype id=\"{namespace}typename\" optional=\"false\" unbounded=\"false\" typename=\"typename\" name=\"a\" /></s:elements></s:complextype></s:extensions>",
- xml);
- }
-
- @Test
- public void testCyclicFromElement() throws Exception {
- String xml = "<s:extensions xmlns:s=\"http://org.embl.ebi.escience/xscufl/0.1alpha\"><s:complextype optional=\"false\" unbounded=\"false\" typename=\"typename\" name=\"a\" qname=\"{namespace}typename\"><s:elements><s:complextype id=\"{namespace}typename\" /></s:elements></s:complextype></s:extensions>";
- Element el = new SAXBuilder().build(new StringReader(xml))
- .getRootElement();
-
- TypeDescriptor a = XMLSplitterSerialisationHelper
- .extensionXMLToTypeDescriptor(el);
-
- assertTrue("wrong type", a instanceof ComplexTypeDescriptor);
- assertEquals("wrong name", "a", a.getName());
-
- List<TypeDescriptor> a_elements = ((ComplexTypeDescriptor) a).getElements();
-
- assertEquals("should be only 1 element", 1, a_elements.size());
-
- TypeDescriptor b = a_elements.get(0);
-
- assertTrue("wrong type", b instanceof ComplexTypeDescriptor);
-
- List<TypeDescriptor> b_elements = ((ComplexTypeDescriptor) b).getElements();
-
- assertEquals("should be only 1 element", 1, b_elements.size());
-
- assertEquals("b should contain a reference to a", a.toString(),
- b_elements.get(0).toString());
- }
-
- /**
- * Tests the QName is constructed with the correct URI and LocalPart
- *
- * @throws Exception
- */
- @Test
- public void testCorrectQName() throws Exception {
- TypeDescriptor desc = XMLSplitterSerialisationHelper
- .extensionXMLToTypeDescriptor(new SAXBuilder().build(
- new StringReader(eInfoXML())).getRootElement());
- assertEquals("NamespaceURI is incorrect",
- "http://www.ncbi.nlm.nih.gov/soap/eutils/espell", desc
- .getQname().getNamespaceURI());
- assertEquals("Localpart is incorrect", "eSpellRequest", desc.getQname()
- .getLocalPart());
- }
-
- private String eInfoXML() {
- return "<s:extensions xmlns:s=\"http://org.embl.ebi.escience/xscufl/0.1alpha\"><s:complextype optional=\"false\" unbounded=\"false\" typename=\"eSpellRequest\" name=\"parameters\" qname=\"{http://www.ncbi.nlm.nih.gov/soap/eutils/espell}eSpellRequest\"><s:elements><s:basetype optional=\"true\" unbounded=\"false\" typename=\"string\" name=\"db\" qname=\"{http://www.w3.org/2001/XMLSchema}string\" /><s:basetype optional=\"true\" unbounded=\"false\" typename=\"string\" name=\"term\" qname=\"{http://www.w3.org/2001/XMLSchema}string\" /><s:basetype optional=\"true\" unbounded=\"false\" typename=\"string\" name=\"tool\" qname=\"{http://www.w3.org/2001/XMLSchema}string\" /><s:basetype optional=\"true\" unbounded=\"false\" typename=\"string\" name=\"email\" qname=\"{http://www.w3.org/2001/XMLSchema}string\" /></s:elements></s:complextype></s:extensions>";
-
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/complex_type1.xml
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/complex_type1.xml b/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/complex_type1.xml
new file mode 100644
index 0000000..a5754dd
--- /dev/null
+++ b/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/complex_type1.xml
@@ -0,0 +1,4 @@
+<person xmlns="http://example.com">
+ <name>Napoleon</name>
+ <surname>Bonaparte</surname>
+</person>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/complex_type1.xsd
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/complex_type1.xsd b/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/complex_type1.xsd
new file mode 100644
index 0000000..a6aa8f7
--- /dev/null
+++ b/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/complex_type1.xsd
@@ -0,0 +1,20 @@
+<!--
+-->
+<xs:schema
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://example.com"
+ targetNamespace="http://example.com"
+ attributeFormDefault="unqualified"
+ elementFormDefault="qualified"
+ version="1.0">
+
+ <xs:element name="person" type="tns:person"/>
+
+ <xs:complexType name="person">
+ <xs:sequence>
+ <xs:element name="name" type="xs:string"/>
+ <xs:element name="surname" type="xs:string"/>
+ </xs:sequence>
+ </xs:complexType>
+
+</xs:schema>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/complex_type2.xml
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/complex_type2.xml b/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/complex_type2.xml
new file mode 100644
index 0000000..4fa43a7
--- /dev/null
+++ b/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/complex_type2.xml
@@ -0,0 +1,4 @@
+<campaign xmlns="http://example.com">
+ <title>Campagne de Russie</title>
+ <date>1812-06-24</date>
+</campaign>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/complex_type2.xsd
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/complex_type2.xsd b/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/complex_type2.xsd
new file mode 100644
index 0000000..3ff0f2a
--- /dev/null
+++ b/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/complex_type2.xsd
@@ -0,0 +1,18 @@
+<xs:schema
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://example.com"
+ targetNamespace="http://example.com"
+ attributeFormDefault="unqualified"
+ elementFormDefault="qualified"
+ version="1.0">
+
+ <xs:element name="campaign">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element name="title" type="xs:string"/>
+ <xs:element name="date" type="xs:date"/>
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+
+</xs:schema>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/complex_type3.xml
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/complex_type3.xml b/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/complex_type3.xml
new file mode 100644
index 0000000..c17ad09
--- /dev/null
+++ b/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/complex_type3.xml
@@ -0,0 +1 @@
+<person xmlns="http://example.com" birthday="1769-08-15">Napoleon</person>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/complex_type3.xsd
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/complex_type3.xsd b/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/complex_type3.xsd
new file mode 100644
index 0000000..865365f
--- /dev/null
+++ b/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/complex_type3.xsd
@@ -0,0 +1,31 @@
+<!--
+ The test checks a complex element with simple content that contains a attribute.
+ To make things more complicated an additional level of inheritance is introduced.
+ The final xml should look like:
+ <person xmlns="http://example.com" birthday="1769-08-15">Napoleon</person>
+-->
+<xs:schema
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://example.com"
+ targetNamespace="http://example.com"
+ attributeFormDefault="unqualified"
+ elementFormDefault="qualified"
+ version="1.0">
+
+ <xs:element name="person" type="tns:person"/>
+
+ <xs:complexType name="person">
+ <xs:complexContent>
+ <xs:extension base="tns:human"/>
+ </xs:complexContent>
+ </xs:complexType>
+
+ <xs:complexType name="human">
+ <xs:simpleContent>
+ <xs:extension base="xs:string">
+ <xs:attribute name="birthday" type="xs:date" />
+ </xs:extension>
+ </xs:simpleContent>
+ </xs:complexType>
+
+</xs:schema>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/complex_type4.xml
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/complex_type4.xml b/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/complex_type4.xml
new file mode 100644
index 0000000..4a942e4
--- /dev/null
+++ b/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/complex_type4.xml
@@ -0,0 +1,4 @@
+<person xmlns="http://example.com">
+ <hobby>war</hobby>
+ <hobby>archeology</hobby>
+</person>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/complex_type4.xsd
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/complex_type4.xsd b/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/complex_type4.xsd
new file mode 100644
index 0000000..c3ff2b9
--- /dev/null
+++ b/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/complex_type4.xsd
@@ -0,0 +1,19 @@
+<!--
+-->
+<xs:schema
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://example.com"
+ targetNamespace="http://example.com"
+ attributeFormDefault="unqualified"
+ elementFormDefault="qualified"
+ version="1.0">
+
+ <xs:element name="person" type="tns:person"/>
+
+ <xs:complexType name="person">
+ <xs:sequence>
+ <xs:element name="hobby" type="xs:string" minOccurs="2" maxOccurs="unbounded" />
+ </xs:sequence>
+ </xs:complexType>
+
+</xs:schema>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/complex_type5.xml
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/complex_type5.xml b/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/complex_type5.xml
new file mode 100644
index 0000000..4f65716
--- /dev/null
+++ b/taverna-wsdl-generic/src/test/resources/org/apache/taverna/wsdl/parser/schema/complex_type5.xml
@@ -0,0 +1,5 @@
+<person xmlns="http://example.com">
+ <name>Napoleon</name>
+ <surname>Bonaparte</surname>
+ <hobby>war</hobby>
+</person>
\ No newline at end of file
[8/8] incubator-taverna-common-activities git commit:
Posted by re...@apache.org.
Project: http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/commit/979e6155
Tree: http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/tree/979e6155
Diff: http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/diff/979e6155
Branch: refs/heads/wsdl-xsd-experimental
Commit: 979e6155230a4e27f153370c21aff0d190d0e8b6
Parents: df390d9
Author: redmitry <re...@84.88.50.62>
Authored: Mon Sep 14 12:46:48 2015 +0200
Committer: redmitry <re...@84.88.50.62>
Committed: Mon Sep 14 12:46:48 2015 +0200
----------------------------------------------------------------------
.../java/org/apache/taverna/wsdl/parser/WSDLParserTest.java | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/979e6155/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/parser/WSDLParserTest.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/parser/WSDLParserTest.java b/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/parser/WSDLParserTest.java
index aa5a280..e857d3a 100644
--- a/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/parser/WSDLParserTest.java
+++ b/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/parser/WSDLParserTest.java
@@ -42,7 +42,7 @@ public class WSDLParserTest {
@Test
public void getWSDL11fromSSLTest() throws Exception {
- WSDL11Parser.getWSDL11Parser("https://transplantdb.bsc.es/registry/rest/service/94259BD285E07E855382DD197BC61D62");
+ WSDL11Parser.getWSDL11Parser("https://transplantdb.bsc.es/registry/rest/service/6E36427B278738C5AB51D0FEFB08A0BB");
}
@Test
@@ -50,8 +50,7 @@ public class WSDLParserTest {
WSDLParser parser = new WSDLParser(wsdlResourcePath("eutils/eutils_lite.wsdl"));
List<String> operations = parser.getOperations("eUtilsServiceSoap");
- assertEquals(
- "wrong number of operations found (wsdl may have changed)", 12,
+ assertEquals("wrong number of operations found (wsdl may have changed)", 12,
operations.size());
assertEquals("wrong name for first operation", "run_eGquery", operations.get(0));
assertEquals("wrong style", "document", parser.getStyle());
[3/8] incubator-taverna-common-activities git commit: experimental
wsdl-generic based on XSD schema
Posted by re...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/parser/schema/test/ComplexType1Test.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/parser/schema/test/ComplexType1Test.java b/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/parser/schema/test/ComplexType1Test.java
new file mode 100644
index 0000000..65438c7
--- /dev/null
+++ b/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/parser/schema/test/ComplexType1Test.java
@@ -0,0 +1,180 @@
+/*
+* 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.schema.test;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathExpressionException;
+import javax.xml.xpath.XPathFactory;
+import org.apache.taverna.wsdl.parser.schema.XSGlobalElement;
+import org.apache.taverna.wsdl.parser.schema.XSNode;
+import org.apache.taverna.wsdl.parser.schema.XSParticle;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+/**
+ * @author Dmitry Repchevsky
+ */
+
+public class ComplexType1Test extends TestSchemaTreeModel {
+
+ private final static String XML_FILE = "org/apache/taverna/wsdl/parser/schema/complex_type1.xml";
+ private final static String XSD_FILE = "org/apache/taverna/wsdl/parser/schema/complex_type1.xsd";
+
+ @Before
+ public void loadModel() {
+ loadModel(XSD_FILE);
+ }
+
+ @Test
+ public void complexTypeReadTest() {
+ fillModel(XML_FILE);
+ testModel();
+ }
+
+ @Test
+ public void complexTypeWriteTest() {
+ fillModel();
+ testModel();
+ }
+
+ @Test
+ public void XPathTest() throws ParserConfigurationException, SAXException, IOException, XPathExpressionException {
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ dbf.setNamespaceAware(true);
+ DocumentBuilder db = dbf.newDocumentBuilder();
+
+ InputStream in = ComplexType1Test.class.getClassLoader().getResourceAsStream(XML_FILE);
+ Document doc;
+ try {
+ doc = db.parse(in);
+ } finally {
+ in.close();
+ }
+
+ XPath xpath = XPathFactory.newInstance().newXPath();
+
+ fillModel(XML_FILE);
+
+ XSGlobalElement element = (XSGlobalElement)model.getChildAt(0);
+
+ XSParticle particle1 = (XSParticle)element.getChildAt(0);
+ Object name_value = xpath.evaluate(particle1.getXPath(), doc, XPathConstants.STRING);
+ Assert.assertEquals("wrong text value for the 'name' element", particle1.getUserObject(), name_value);
+
+ XSParticle particle2 = (XSParticle)element.getChildAt(1);
+ Object surname_value = xpath.evaluate(particle2.getXPath(), doc, XPathConstants.STRING);
+ Assert.assertEquals("wrong text value for the 'surname' element", particle2.getUserObject(), surname_value);
+ }
+
+ private void fillModel() {
+ model.addGlobalElement(new QName("http://example.com","person"));
+
+ Assert.assertTrue("the root node must have one child node", model.getChildCount() == 1);
+
+ XSNode<XSNode, XSNode> node = model.getChildAt(0);
+ Assert.assertEquals("the node 'person' should have two child nodes", 2, node.getChildCount());
+ Assert.assertTrue("the node 'person' must be represented by an element node", node instanceof XSGlobalElement);
+
+ XSNode node1 = node.getChildAt(0);
+ Assert.assertTrue("the node 'name' must be represented by a particle node", node1 instanceof XSParticle);
+
+ XSParticle particle1 = (XSParticle)node1;
+ particle1.setUserObject("Napoleon");
+
+ XSNode node2 = node.getChildAt(1);
+ Assert.assertTrue("the node 'surname' must be represented by a particle node", node2 instanceof XSParticle);
+
+ XSParticle particle2 = (XSParticle)node2;
+ particle2.setUserObject("Bonaparte");
+ }
+
+ private void testModel() {
+ XMLOutputFactory f = XMLOutputFactory.newInstance();
+ f.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+ try {
+ XMLStreamWriter writer = f.createXMLStreamWriter(out);
+ try {
+ model.write(writer);
+ } finally {
+ writer.close();
+ }
+ } catch(XMLStreamException ex) {
+ Assert.fail(ex.getMessage());
+ }
+
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ dbf.setNamespaceAware(true);
+ DocumentBuilder db = null;
+ try {
+ db = dbf.newDocumentBuilder();
+ } catch(ParserConfigurationException ex) {
+ Assert.fail(ex.getMessage());
+ }
+
+ try {
+ Document doc = db.parse(new ByteArrayInputStream(out.toByteArray()));
+
+ Element root = doc.getDocumentElement();
+ Assert.assertNotNull("missed root ('person') element", root);
+
+ NodeList children = root.getChildNodes();
+ Assert.assertEquals("the element '<person>' should have two child nodes", 2, children.getLength());
+
+ Node node1 = children.item(0);
+ Assert.assertEquals("wrong first child node type", Node.ELEMENT_NODE, node1.getNodeType());
+ Assert.assertEquals("wrong first child element name", "name", node1.getLocalName());
+ Assert.assertEquals("wrong 'name' element namespace", "http://example.com", node1.getNamespaceURI());
+ Assert.assertEquals("wrong '{http://example.com}name' text content", "Napoleon", node1.getTextContent());
+
+ Node node2 = children.item(1);
+ Assert.assertEquals("wrong second child node type", Node.ELEMENT_NODE, node2.getNodeType());
+ Assert.assertEquals("wrong second child element name", "surname", node2.getLocalName());
+ Assert.assertEquals("wrong 'surname' element namespace", "http://example.com", node2.getNamespaceURI());
+ Assert.assertEquals("wrong '{http://example.com}surname' element text content", "Bonaparte", node2.getTextContent());
+
+ } catch(SAXException ex) {
+ Assert.fail(ex.getMessage());
+ } catch(IOException ex) {
+ Assert.fail(ex.getMessage());
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/parser/schema/test/ComplexType2Test.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/parser/schema/test/ComplexType2Test.java b/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/parser/schema/test/ComplexType2Test.java
new file mode 100644
index 0000000..821abb3
--- /dev/null
+++ b/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/parser/schema/test/ComplexType2Test.java
@@ -0,0 +1,146 @@
+/*
+* 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.schema.test;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+import org.apache.taverna.wsdl.parser.schema.XSGlobalElement;
+import org.apache.taverna.wsdl.parser.schema.XSNode;
+import org.apache.taverna.wsdl.parser.schema.XSParticle;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+/**
+ * @author Dmitry Repchevsky
+ */
+
+public class ComplexType2Test extends TestSchemaTreeModel {
+
+ private final static String XML_FILE = "org/apache/taverna/wsdl/parser/schema/complex_type2.xml";
+ private final static String XSD_FILE = "org/apache/taverna/wsdl/parser/schema/complex_type2.xsd";
+
+ @Before
+ public void loadModel() {
+ loadModel(XSD_FILE);
+ }
+
+ @Test
+ public void complexTypeReadTest() {
+ fillModel(XML_FILE);
+ testModel();
+ }
+
+ @Test
+ public void complexTypeWriteTest() {
+ fillModel();
+ testModel();
+ }
+
+ private void fillModel() {
+ model.addGlobalElement(new QName("http://example.com", "campaign"));
+
+ Assert.assertTrue("the root node must have one child node", model.getChildCount() == 1);
+
+ XSNode<XSNode, XSNode> node = model.getChildAt(0);
+ Assert.assertTrue("the node 'campaign' must be the represented by an element node", node instanceof XSGlobalElement);
+ Assert.assertEquals("the node 'campaign' should have two child nodes", 2, node.getChildCount());
+
+ XSNode node1 = node.getChildAt(0);
+ Assert.assertTrue("the node 'title' must be the represented by a particle node", node1 instanceof XSParticle);
+
+ XSParticle particle1 = (XSParticle)node1;
+ particle1.setUserObject("Campagne de Russie");
+
+ XSNode node2 = node.getChildAt(1);
+ Assert.assertTrue("the node 'date' must be the represented by a particle node", node2 instanceof XSParticle);
+
+ XSParticle particle2 = (XSParticle)node2;
+ particle2.setUserObject("1812-06-24");
+ }
+
+ private void testModel() {
+ XMLOutputFactory f = XMLOutputFactory.newInstance();
+ f.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+ try {
+ XMLStreamWriter writer = f.createXMLStreamWriter(out);
+ try {
+ model.write(writer);
+ } finally {
+ writer.close();
+ }
+ } catch(XMLStreamException ex) {
+ Assert.fail(ex.getMessage());
+ }
+
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ dbf.setNamespaceAware(true);
+ DocumentBuilder db = null;
+ try {
+ db = dbf.newDocumentBuilder();
+ } catch(ParserConfigurationException ex) {
+ Assert.fail(ex.getMessage());
+ }
+
+ try {
+ Document doc = db.parse(new ByteArrayInputStream(out.toByteArray()));
+
+ Element root = doc.getDocumentElement();
+ Assert.assertNotNull("missed root ('campaign') element", root);
+
+ NodeList children = root.getChildNodes();
+
+ Assert.assertEquals("'campaign' should have two child elements", 2, children.getLength());
+
+ Node node1 = children.item(0);
+ Assert.assertEquals("wrong first child node type", Node.ELEMENT_NODE, node1.getNodeType());
+ Assert.assertEquals("wrong first child element name", "title", node1.getLocalName());
+ Assert.assertEquals("wrong 'title' element namespace", "http://example.com", node1.getNamespaceURI());
+ Assert.assertEquals("wrong '{http://example.com}title' element text content", "Campagne de Russie", node1.getTextContent());
+
+ Node node2 = children.item(1);
+ Assert.assertEquals("wrong second child node type", Node.ELEMENT_NODE, node2.getNodeType());
+ Assert.assertEquals("wrong second child element name", "date", node2.getLocalName());
+ Assert.assertEquals("wrong 'date' element namespace", "http://example.com", node2.getNamespaceURI());
+ Assert.assertEquals("wrong '{http://example.com}date' element text content:", "1812-06-24", node2.getTextContent());
+
+ } catch(SAXException ex) {
+ Assert.fail(ex.getMessage());
+ } catch(IOException ex) {
+ Assert.fail(ex.getMessage());
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/parser/schema/test/ComplexType3Test.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/parser/schema/test/ComplexType3Test.java b/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/parser/schema/test/ComplexType3Test.java
new file mode 100644
index 0000000..a0dcc41
--- /dev/null
+++ b/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/parser/schema/test/ComplexType3Test.java
@@ -0,0 +1,171 @@
+/*
+* 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.schema.test;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathExpressionException;
+import javax.xml.xpath.XPathFactory;
+import org.apache.taverna.wsdl.parser.schema.XSAttribute;
+import org.apache.taverna.wsdl.parser.schema.XSGlobalElement;
+import org.apache.taverna.wsdl.parser.schema.XSNode;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+/**
+ * @author Dmitry Repchevsky
+ */
+
+public class ComplexType3Test extends TestSchemaTreeModel {
+
+ private final static String XML_FILE = "org/apache/taverna/wsdl/parser/schema/complex_type3.xml";
+ private final static String XSD_FILE = "org/apache/taverna/wsdl/parser/schema/complex_type3.xsd";
+
+ @Before
+ public void loadModel() {
+ loadModel(XSD_FILE);
+ }
+
+ @Test
+ public void complexTypeReadTest() {
+ fillModel(XML_FILE);
+ testModel();
+ }
+
+ @Test
+ public void complexTypeWriteTest() {
+ fillModel();
+ testModel();
+ }
+
+ @Test
+ public void XPathTest() throws ParserConfigurationException, SAXException, IOException, XPathExpressionException {
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ dbf.setNamespaceAware(true);
+ DocumentBuilder db = dbf.newDocumentBuilder();
+
+ InputStream in = ComplexType1Test.class.getClassLoader().getResourceAsStream(XML_FILE);
+ Document doc;
+ try {
+ doc = db.parse(in);
+ } finally {
+ in.close();
+ }
+ XPath xpath = XPathFactory.newInstance().newXPath();
+
+ fillModel(XML_FILE);
+
+ XSGlobalElement<XSNode, XSNode> element = (XSGlobalElement)model.getChildAt(0);
+ Object person_value = xpath.evaluate(element.getXPath(), doc, XPathConstants.STRING);
+ Assert.assertEquals("wrong text value for the 'person' element", element.getUserObject(), person_value);
+
+ XSNode node1 = element.getChildAt(0);
+ XSAttribute attribute = (XSAttribute)node1;
+ Object birthday_value = xpath.evaluate(attribute.getXPath(), doc, XPathConstants.STRING);
+ Assert.assertEquals("wrong text value for the 'birthday' attribute", attribute.getUserObject(), birthday_value);
+ }
+
+ private void fillModel() {
+ model.addGlobalElement(new QName("http://example.com", "person"));
+
+ Assert.assertTrue("the root node must have one child node", model.getChildCount() == 1);
+
+ XSNode<XSNode, XSNode> node = model.getChildAt(0);
+ Assert.assertEquals("the node 'person' should have one child nodes", 1, node.getChildCount());
+ Assert.assertTrue("the 'person' node must be the represented by an element node", node instanceof XSGlobalElement);
+
+ XSGlobalElement elementNode = (XSGlobalElement)node;
+ elementNode.setUserObject("Napoleon");
+
+ XSNode child = node.getChildAt(0);
+ Assert.assertTrue("the 'child' node must be the represented by an attribute node", child instanceof XSAttribute);
+
+ XSAttribute attribute = (XSAttribute)child;
+ attribute.setUserObject("1769-08-15");
+ }
+
+ private void testModel() {
+ XMLOutputFactory f = XMLOutputFactory.newInstance();
+ f.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+ try {
+ XMLStreamWriter writer = f.createXMLStreamWriter(out);
+ try {
+ model.write(writer);
+ } finally {
+ writer.close();
+ }
+ } catch(XMLStreamException ex) {
+ Assert.fail(ex.getMessage());
+ }
+
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ dbf.setNamespaceAware(true);
+ DocumentBuilder db = null;
+ try {
+ db = dbf.newDocumentBuilder();
+ } catch(ParserConfigurationException ex) {
+ Assert.fail(ex.getMessage());
+ }
+
+ try {
+ Document doc = db.parse(new ByteArrayInputStream(out.toByteArray()));
+
+ Element root = doc.getDocumentElement();
+
+ Assert.assertNotNull("missed root ('person') element", root);
+ Assert.assertEquals("wrong 'person' element type", Node.ELEMENT_NODE, root.getNodeType());
+ Assert.assertEquals("wrong 'person' element name", "person", root.getLocalName());
+ Assert.assertEquals("wrong 'person' element namespace", "http://example.com", root.getNamespaceURI());
+
+ final NodeList children = root.getChildNodes();
+ Assert.assertEquals("'person' element should have one child node", 1, children.getLength());
+ Assert.assertEquals("wrong 'person' element text content", "Napoleon", root.getTextContent());
+
+ final Attr attribute = root.getAttributeNode("birthday");
+ Assert.assertNotNull("'birthday' attribute is missed in the 'person' element", attribute);
+ Assert.assertEquals("wrong 'person' element text content", "1769-08-15", attribute.getValue());
+ } catch(SAXException ex) {
+ Assert.fail(ex.getMessage());
+ } catch(IOException ex) {
+ Assert.fail(ex.getMessage());
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/parser/schema/test/ComplexType4Test.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/parser/schema/test/ComplexType4Test.java b/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/parser/schema/test/ComplexType4Test.java
new file mode 100644
index 0000000..0028556
--- /dev/null
+++ b/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/parser/schema/test/ComplexType4Test.java
@@ -0,0 +1,151 @@
+/*
+* 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.schema.test;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+import org.apache.taverna.wsdl.parser.schema.XSGlobalElement;
+import org.apache.taverna.wsdl.parser.schema.XSNode;
+import org.apache.taverna.wsdl.parser.schema.XSParticle;
+import org.apache.taverna.wsdl.parser.schema.XSType;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+/**
+ * @author Dmitry Repchevsky
+ */
+
+public class ComplexType4Test extends TestSchemaTreeModel {
+
+ private final static String XML_FILE = "org/apache/taverna/wsdl/parser/schema/complex_type4.xml";
+ private final static String XSD_FILE = "org/apache/taverna/wsdl/parser/schema/complex_type4.xsd";
+
+ @Before
+ public void loadModel() {
+ loadModel(XSD_FILE);
+ }
+
+ @Test
+ public void complexTypeReadTest() {
+ fillModel(XML_FILE);
+ testModel();
+ }
+
+ @Test
+ public void complexTypeWriteTest() {
+ fillModel();
+ testModel();
+ }
+
+ private void fillModel() {
+
+ //Adding the element to the model automatically constructs the tree structure
+ model.addGlobalElement(new QName("http://example.com", "person"));
+
+ Assert.assertTrue("the root node must have one child node", model.getChildCount() == 1);
+
+ XSNode<XSNode, XSNode> node = model.getChildAt(0);
+ Assert.assertTrue("the node 'person' must be the represented by an element node", node instanceof XSGlobalElement);
+ Assert.assertEquals("the node 'person' should have one child node", 1, node.getChildCount());
+
+ XSNode<XSNode, XSNode> particleNode = node.getChildAt(0);
+ Assert.assertTrue("the sequence node must be the represented by a particle node", particleNode instanceof XSParticle);
+ Assert.assertEquals("the sequence node should have one child node", 1, particleNode.getChildCount());
+
+ XSNode node1 = particleNode.getChildAt(0);
+ Assert.assertTrue("the 'hobby' node must be the represented by a particle node", node1 instanceof XSType);
+
+ XSType<XSNode, XSNode> hobby1 = (XSType)node1;
+ hobby1.setUserObject("war");
+
+ XSType hobby2 = new XSType(hobby1.getXSComponent());
+ hobby2.setUserObject("archeology");
+ ((XSParticle)particleNode).insert(hobby2,particleNode.getChildCount());
+
+ }
+
+ private void testModel() {
+ XMLOutputFactory f = XMLOutputFactory.newInstance();
+ f.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+ try {
+ XMLStreamWriter writer = f.createXMLStreamWriter(out);
+ try {
+ model.write(writer);
+ } finally {
+ writer.close();
+ }
+ } catch(XMLStreamException ex) {
+ Assert.fail(ex.getMessage());
+ }
+
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ dbf.setNamespaceAware(true);
+ DocumentBuilder db = null;
+ try {
+ db = dbf.newDocumentBuilder();
+ } catch(ParserConfigurationException ex) {
+ Assert.fail(ex.getMessage());
+ }
+
+ try {
+ Document doc = db.parse(new ByteArrayInputStream(out.toByteArray()));
+
+ Element root = doc.getDocumentElement();
+ Assert.assertNotNull("missed root ('person') element", root);
+
+ NodeList children = root.getChildNodes();
+ Assert.assertEquals("the element 'person' should have two child elements", 2, children.getLength());
+
+ Node node1 = children.item(0);
+ Assert.assertEquals("wrong first child element type", Node.ELEMENT_NODE, node1.getNodeType());
+ Assert.assertEquals("wrong first child element name", "hobby", node1.getLocalName());
+ Assert.assertEquals("wrong first child element namespace", "http://example.com", node1.getNamespaceURI());
+ Assert.assertEquals("wrong first child element text content", "war", node1.getTextContent());
+
+ Node node2 = children.item(1);
+ Assert.assertEquals("wrong second child element type", Node.ELEMENT_NODE, node2.getNodeType());
+ Assert.assertEquals("wrong second child element name", "hobby", node2.getLocalName());
+ Assert.assertEquals("wrong second child element namespace", "http://example.com", node2.getNamespaceURI());
+ Assert.assertEquals("wrong second child element text content", "archeology", node2.getTextContent());
+
+ } catch(SAXException ex) {
+ Assert.fail(ex.getMessage());
+ } catch(IOException ex) {
+ Assert.fail(ex.getMessage());
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/parser/schema/test/ComplexType5Test.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/parser/schema/test/ComplexType5Test.java b/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/parser/schema/test/ComplexType5Test.java
new file mode 100644
index 0000000..1ad306d
--- /dev/null
+++ b/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/parser/schema/test/ComplexType5Test.java
@@ -0,0 +1,161 @@
+/*
+* 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.schema.test;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+import org.apache.taverna.wsdl.parser.schema.XSGlobalElement;
+import org.apache.taverna.wsdl.parser.schema.XSNode;
+import org.apache.taverna.wsdl.parser.schema.XSParticle;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+/**
+ * @author Dmitry Repchevsky
+ */
+
+public class ComplexType5Test extends TestSchemaTreeModel {
+
+ private final static String XML_FILE = "org/apache/taverna/wsdl/parser/schema/complex_type5.xml";
+ private final static String XSD_FILE = "org/apache/taverna/wsdl/parser/schema/complex_type5.xsd";
+
+ @Before
+ public void loadModel() {
+ loadModel(XSD_FILE);
+ }
+
+ @Test
+ public void complexTypeReadTest() {
+ fillModel(XML_FILE);
+ testModel();
+ }
+
+ @Test
+ public void complexTypeWriteTest() {
+ fillModel();
+ testModel();
+ }
+
+ private void fillModel() {
+ model.addGlobalElement(new QName("http://example.com","person"));
+
+ Assert.assertTrue("the root node must have one child node", model.getChildCount() == 1);
+
+ XSNode<XSNode, XSNode> node = model.getChildAt(0);
+ Assert.assertTrue("the 'person' node must be the represented by an element node", node instanceof XSGlobalElement);
+ Assert.assertEquals("the node `person' should have three child nodes", 3, node.getChildCount());
+
+ for (int i = 0, n = node.getChildCount(); i <n; i++) {
+ XSNode child = node.getChildAt(i);
+ Assert.assertTrue("the 'child' node must be the represented by a particle node", child instanceof XSParticle);
+
+ final XSParticle particleNode = (XSParticle)child;
+ final QName qname = particleNode.getName();
+
+ final String namespaceURI = qname.getNamespaceURI();
+ Assert.assertEquals("wrong element namespace", "http://example.com", namespaceURI);
+
+ final String localPart = qname.getLocalPart();
+ switch(localPart) {
+ case "name": particleNode.setUserObject("Napoleon");break;
+ case "surname": particleNode.setUserObject("Bonaparte");break;
+ case "hobby": particleNode.setUserObject("war");break;
+ default: Assert.fail("unknown element node found");
+ }
+ }
+ }
+
+ private void testModel() {
+ XMLOutputFactory f = XMLOutputFactory.newInstance();
+ f.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+ try {
+ XMLStreamWriter writer = f.createXMLStreamWriter(out);
+ try {
+ model.write(writer);
+ } finally {
+ writer.close();
+ }
+ } catch(XMLStreamException ex) {
+ Assert.fail(ex.getMessage());
+ }
+
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ dbf.setNamespaceAware(true);
+ DocumentBuilder db = null;
+ try {
+ db = dbf.newDocumentBuilder();
+ } catch(ParserConfigurationException ex) {
+ Assert.fail(ex.getMessage());
+ }
+
+ try {
+ Document doc = db.parse(new ByteArrayInputStream(out.toByteArray()));
+
+ Element root = doc.getDocumentElement();
+ Assert.assertNotNull("missed root ('person') element", root);
+
+ NodeList children = root.getChildNodes();
+ Assert.assertEquals("'person' should have three child elements", 3, children.getLength());
+
+ Node node1 = children.item(0);
+
+ Assert.assertEquals("wrong first child element type", Node.ELEMENT_NODE, node1.getNodeType());
+ Assert.assertEquals("wrong first child element name", "name", node1.getLocalName());
+ Assert.assertEquals("wrong first child element namespace", "http://example.com", node1.getNamespaceURI());
+ Assert.assertEquals("wrong first element text content", "Napoleon", node1.getTextContent());
+
+ Node node2 = children.item(1);
+
+ Assert.assertEquals("wrong second node type", Node.ELEMENT_NODE, node2.getNodeType());
+ Assert.assertEquals("wrong second element name", "surname", node2.getLocalName());
+ Assert.assertEquals("wrong second element namespace", "http://example.com", node2.getNamespaceURI());
+ Assert.assertEquals("wrong second element text content", "Bonaparte", node2.getTextContent());
+
+ Node node3 = children.item(2);
+
+ Assert.assertEquals("wrong third node type", Node.ELEMENT_NODE, node3.getNodeType());
+ Assert.assertEquals("wrong third element name", "hobby", node3.getLocalName());
+ Assert.assertEquals("wrong third element namespace", "http://example.com", node3.getNamespaceURI());
+ Assert.assertEquals("wrong third element text content", "war", node3.getTextContent());
+
+ } catch(SAXException ex) {
+ Assert.fail(ex.getMessage());
+ } catch(IOException ex) {
+ Assert.fail(ex.getMessage());
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/parser/schema/test/ComplexType6Test.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/parser/schema/test/ComplexType6Test.java b/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/parser/schema/test/ComplexType6Test.java
new file mode 100644
index 0000000..9392073
--- /dev/null
+++ b/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/parser/schema/test/ComplexType6Test.java
@@ -0,0 +1,148 @@
+/*
+* 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.schema.test;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+import org.apache.taverna.wsdl.parser.schema.XSAttribute;
+import org.apache.taverna.wsdl.parser.schema.XSGlobalElement;
+import org.apache.taverna.wsdl.parser.schema.XSNode;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+/**
+ * @author Dmitry Repchevsky
+ */
+
+public class ComplexType6Test extends TestSchemaTreeModel {
+
+ private final static String XML_FILE = "org/apache/taverna/wsdl/parser/schema/complex_type6.xml";
+ private final static String XSD_FILE = "org/apache/taverna/wsdl/parser/schema/complex_type6.xsd";
+
+ @Before
+ public void loadModel() {
+ loadModel(XSD_FILE);
+ }
+
+ @Test
+ public void complexTypeReadTest() {
+ fillModel(XML_FILE);
+ testModel();
+ }
+
+ @Test
+ public void complexTypeWriteTest() {
+ fillModel();
+ testModel();
+ }
+
+ private void fillModel() {
+ model.addGlobalElement(new QName("http://example.com", "person"));
+
+ Assert.assertTrue("the root node must have one child node", model.getChildCount() == 1);
+
+ XSNode<XSNode, XSNode> node = model.getChildAt(0);
+ Assert.assertTrue("the node 'person' must be the represented by an element node", node instanceof XSGlobalElement);
+ Assert.assertEquals("the node 'person' should have three child nodes", 3, node.getChildCount());
+
+ for (int i = 0, n = node.getChildCount(); i <n; i++) {
+ XSNode child = node.getChildAt(i);
+ Assert.assertTrue("the child node must be the represented by an attribute node", child instanceof XSAttribute);
+
+ final XSAttribute attributeNode = (XSAttribute)child;
+ final QName qname = attributeNode.getName();
+
+ final String namespaceURI = qname.getNamespaceURI();
+ Assert.assertEquals("wrong attribute namespace", "", namespaceURI);
+
+ final String localPart = qname.getLocalPart();
+ switch(localPart) {
+ case "name": attributeNode.setUserObject("Napoleon");break;
+ case "surname": attributeNode.setUserObject("Bonaparte");break;
+ case "hobby": attributeNode.setUserObject("war");break;
+ default: Assert.fail("unknown attribute node found");
+ }
+ }
+ }
+
+ private void testModel() {
+ XMLOutputFactory f = XMLOutputFactory.newInstance();
+ f.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+ try {
+ XMLStreamWriter writer = f.createXMLStreamWriter(out);
+ try {
+ model.write(writer);
+ } finally {
+ writer.close();
+ }
+ } catch(XMLStreamException ex) {
+ Assert.fail(ex.getMessage());
+ }
+
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ dbf.setNamespaceAware(true);
+ DocumentBuilder db = null;
+ try {
+ db = dbf.newDocumentBuilder();
+ } catch(ParserConfigurationException ex) {
+ Assert.fail(ex.getMessage());
+ }
+
+ try {
+ Document doc = db.parse(new ByteArrayInputStream(out.toByteArray()));
+
+ Element root = doc.getDocumentElement();
+ Assert.assertNotNull("missed root ('person') element", root);
+ Assert.assertEquals("wrong 'person' element type", Node.ELEMENT_NODE, root.getNodeType());
+ Assert.assertEquals("wrong 'person' element name", "person", root.getLocalName());
+ Assert.assertEquals("wrong 'person' element namespace", "http://example.com", root.getNamespaceURI());
+
+ final NodeList children = root.getChildNodes();
+ Assert.assertEquals("there shouldn't be any child nodes in the 'person' element", 0, children.getLength());
+
+ final Attr attribute = root.getAttributeNode("name");
+ Assert.assertNotNull("'name' attribute is missed in 'person' element", attribute);
+ Assert.assertEquals("wrong 'name' attribute text content", "Napoleon", attribute.getValue());
+
+ } catch(SAXException ex) {
+ Assert.fail(ex.getMessage());
+ } catch(IOException ex) {
+ Assert.fail(ex.getMessage());
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/parser/schema/test/ComplexType7Test.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/parser/schema/test/ComplexType7Test.java b/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/parser/schema/test/ComplexType7Test.java
new file mode 100644
index 0000000..c663d23
--- /dev/null
+++ b/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/parser/schema/test/ComplexType7Test.java
@@ -0,0 +1,160 @@
+/*
+* 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.schema.test;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+import org.apache.taverna.wsdl.parser.schema.XSGlobalElement;
+import org.apache.taverna.wsdl.parser.schema.XSNode;
+import org.apache.taverna.wsdl.parser.schema.XSParticle;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+/**
+ * @author Dmitry Repchevsky
+ */
+
+public class ComplexType7Test extends TestSchemaTreeModel {
+
+ private final static String XML_FILE = "org/apache/taverna/wsdl/parser/schema/complex_type7.xml";
+ private final static String XSD_FILE = "org/apache/taverna/wsdl/parser/schema/complex_type7.xsd";
+
+ @Before
+ public void loadModel() {
+ loadModel(XSD_FILE);
+ }
+
+ @Test
+ public void complexTypeReadTest() {
+ fillModel(XML_FILE);
+ testModel();
+ }
+
+ @Test
+ public void complexTypeWriteTest() {
+ fillModel();
+ testModel();
+ }
+
+ private void fillModel() {
+ model.addGlobalElement(new QName("http://example.com","person"));
+
+ Assert.assertTrue("root node must have one child node", model.getChildCount() == 1);
+
+ XSNode<XSNode, XSNode> node = model.getChildAt(0);
+ Assert.assertTrue("node 'person' must be the represented by an element node", node instanceof XSGlobalElement);
+ Assert.assertEquals("node 'person' should have one child node", 1, node.getChildCount());
+
+ XSNode<XSNode, XSNode> particle = node.getChildAt(0);
+ Assert.assertTrue("the node 'fullname' must be the represented by a particle node", particle instanceof XSParticle);
+ Assert.assertEquals("node 'fullname' should have two child nodes", 2, particle.getChildCount());
+
+ XSNode node1 = particle.getChildAt(0);
+ Assert.assertTrue("the node 'name' must be the represented by a particle node", node1 instanceof XSParticle);
+
+ XSParticle particle1 = (XSParticle)node1;
+ particle1.setUserObject("Napoleon");
+
+ XSNode node2 = particle.getChildAt(1);
+ Assert.assertTrue("the 'surname' node must be the represented by a particle node", node2 instanceof XSParticle);
+
+ XSParticle particle2 = (XSParticle)node2;
+ particle2.setUserObject("Bonaparte");
+ }
+
+ private void testModel() {
+ XMLOutputFactory f = XMLOutputFactory.newInstance();
+ f.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+ try {
+ XMLStreamWriter writer = f.createXMLStreamWriter(out);
+ try {
+ model.write(writer);
+ } finally {
+ writer.close();
+ }
+ } catch(XMLStreamException ex) {
+ Assert.fail(ex.getMessage());
+ }
+
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ dbf.setNamespaceAware(true);
+ DocumentBuilder db = null;
+ try {
+ db = dbf.newDocumentBuilder();
+ } catch(ParserConfigurationException ex) {
+ Assert.fail(ex.getMessage());
+ }
+
+ try {
+ Document doc = db.parse(new ByteArrayInputStream(out.toByteArray()));
+
+ Element root = doc.getDocumentElement();
+ Assert.assertNotNull("root element 'person' is missed", root);
+ Assert.assertEquals("wrong root element name", "person", root.getLocalName());
+ Assert.assertEquals("wrong root element namespace", "http://example.com", root.getNamespaceURI());
+ Assert.assertEquals("the element 'person' should have one child node", 1, root.getChildNodes().getLength());
+
+ Node node = root.getFirstChild();
+
+ Assert.assertEquals("wrong child element type", Node.ELEMENT_NODE, node.getNodeType());
+ Assert.assertEquals("wrong child element name", "fullname", node.getLocalName());
+ Assert.assertEquals("wrong child element namespace", "http://example.com", node.getNamespaceURI());
+
+ NodeList children = node.getChildNodes();
+ Assert.assertEquals("element 'fullname' should have two child elements", 2, children.getLength());
+
+ Node node1 = children.item(0);
+
+ Assert.assertEquals("wrong first child element type", Node.ELEMENT_NODE, node1.getNodeType());
+ Assert.assertEquals("wrong first child element name", "name", node1.getLocalName());
+ Assert.assertEquals("wrong first child element namespace", "http://example.com", node1.getNamespaceURI());
+ Assert.assertEquals("wrong first element text content", "Napoleon", node1.getTextContent());
+
+ Node node2 = children.item(1);
+
+ Assert.assertEquals("wrong second node type", Node.ELEMENT_NODE, node2.getNodeType());
+ Assert.assertEquals("wrong second element name", "surname", node2.getLocalName());
+ Assert.assertEquals("wrong second element namespace", "http://example.com", node2.getNamespaceURI());
+ Assert.assertEquals("wrong second element text content", "Bonaparte", node2.getTextContent());
+
+ } catch(SAXException ex) {
+ Assert.fail(ex.getMessage());
+ } catch(IOException ex) {
+ Assert.fail(ex.getMessage());
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/parser/schema/test/ComplexType8Test.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/parser/schema/test/ComplexType8Test.java b/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/parser/schema/test/ComplexType8Test.java
new file mode 100644
index 0000000..4bf0775
--- /dev/null
+++ b/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/parser/schema/test/ComplexType8Test.java
@@ -0,0 +1,185 @@
+/*
+* 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.schema.test;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathExpressionException;
+import javax.xml.xpath.XPathFactory;
+import org.apache.taverna.wsdl.parser.schema.XSGlobalElement;
+import org.apache.taverna.wsdl.parser.schema.XSNode;
+import org.apache.taverna.wsdl.parser.schema.XSParticle;
+import org.apache.taverna.wsdl.parser.schema.XSType;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+/**
+ * @author Dmitry Repchevsky
+ */
+
+public class ComplexType8Test extends TestSchemaTreeModel {
+
+ private final static String XML_FILE = "org/apache/taverna/wsdl/parser/schema/complex_type8.xml";
+ private final static String XSD_FILE = "org/apache/taverna/wsdl/parser/schema/complex_type8.xsd";
+
+ @Before
+ public void loadModel() {
+ loadModel(XSD_FILE);
+ }
+
+ @Test
+ public void complexTypeReadTest() {
+ fillModel(XML_FILE);
+ testModel();
+ }
+
+ @Test
+ public void complexTypeWriteTest() {
+ fillModel();
+ testModel();
+ }
+
+ @Test
+ public void XPathTest() throws ParserConfigurationException, SAXException, IOException, XPathExpressionException {
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ dbf.setNamespaceAware(true);
+ DocumentBuilder db = dbf.newDocumentBuilder();
+
+ InputStream in = ComplexType1Test.class.getClassLoader().getResourceAsStream(XML_FILE);
+ Document doc;
+ try {
+ doc = db.parse(in);
+ } finally {
+ in.close();
+ }
+ XPath xpath = XPathFactory.newInstance().newXPath();
+
+ fillModel(XML_FILE);
+
+ XSGlobalElement element = (XSGlobalElement)model.getChildAt(0);
+ XSParticle particleNode = (XSParticle)element.getChildAt(0);
+
+ XSType hobby1 = (XSType)particleNode.getChildAt(0);
+ Object hobby1_value = xpath.evaluate(hobby1.getXPath(), doc, XPathConstants.STRING);
+ Assert.assertEquals("wrong text value for the first 'hobby' element", hobby1.getUserObject(), hobby1_value);
+
+ XSType hobby2 = (XSType)particleNode.getChildAt(1);
+ Object hobby2_value = xpath.evaluate(hobby2.getXPath(), doc, XPathConstants.STRING);
+ Assert.assertEquals("wrong text value for the second 'hobby' element", hobby2.getUserObject(), hobby2_value);
+ }
+
+ private void fillModel() {
+ model.addGlobalElement(new QName("http://example.com","person"));
+
+ Assert.assertTrue("the root node must have one child node", model.getChildCount() == 1);
+
+ XSNode<XSNode, XSNode> node = model.getChildAt(0);
+ Assert.assertTrue("the 'person' node must be the represented by an element node", node instanceof XSGlobalElement);
+ Assert.assertEquals("the node 'person' should have one child node", 1, node.getChildCount());
+
+ XSNode<XSNode, XSNode> particleNode = node.getChildAt(0);
+ Assert.assertTrue("the sequence node must be represented by a particle node", particleNode instanceof XSParticle);
+
+ // one empty node should have been created by the model.
+ Assert.assertEquals("the sequence node should have one child node", 1, particleNode.getChildCount());
+
+ XSNode node1 = particleNode.getChildAt(0);
+ Assert.assertTrue("the child node must be represented by a type node", node1 instanceof XSType);
+
+ XSType<XSNode, XSNode> hobby1 = (XSType)node1;
+ hobby1.setUserObject("war");
+
+ XSType hobby2 = new XSType(hobby1.getXSComponent());
+ hobby2.setUserObject("archeology");
+ ((XSParticle)particleNode).insert(hobby2, particleNode.getChildCount());
+ }
+
+ private void testModel() {
+ XMLOutputFactory f = XMLOutputFactory.newInstance();
+ f.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+ try {
+ XMLStreamWriter writer = f.createXMLStreamWriter(out);
+ try {
+ model.write(writer);
+ } finally {
+ writer.close();
+ }
+ } catch(XMLStreamException ex) {
+ Assert.fail(ex.getMessage());
+ }
+
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ dbf.setNamespaceAware(true);
+ DocumentBuilder db = null;
+ try {
+ db = dbf.newDocumentBuilder();
+ } catch(ParserConfigurationException ex) {
+ Assert.fail(ex.getMessage());
+ }
+
+ try {
+ Document doc = db.parse(new ByteArrayInputStream(out.toByteArray()));
+
+ Element root = doc.getDocumentElement();
+ Assert.assertNotNull("'person' element is missed", root);
+
+ NodeList children = root.getChildNodes();
+ Assert.assertEquals("'person' should have two child elements", 2, children.getLength());
+
+ Node node1 = children.item(0);
+ Assert.assertEquals("wrong first node type", Node.ELEMENT_NODE, node1.getNodeType());
+ Assert.assertEquals("wrong first element name", "hobby", node1.getLocalName());
+ Assert.assertEquals("wrong first element namespace", "http://example.com", node1.getNamespaceURI());
+ Assert.assertEquals("wrong third element text content", "war", node1.getTextContent());
+
+ Node node2 = children.item(1);
+ Assert.assertEquals("wrong second node type", Node.ELEMENT_NODE, node2.getNodeType());
+ Assert.assertEquals("wrong second element name", "hobby", node2.getLocalName());
+ Assert.assertEquals("wrong second element namespace", "http://example.com", node2.getNamespaceURI());
+ Assert.assertEquals("wrong second element text content", "archeology", node2.getTextContent());
+
+
+ } catch(SAXException ex) {
+ Assert.fail(ex.getMessage());
+ } catch(IOException ex) {
+ Assert.fail(ex.getMessage());
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/parser/schema/test/SimpleType1Test.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/parser/schema/test/SimpleType1Test.java b/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/parser/schema/test/SimpleType1Test.java
new file mode 100644
index 0000000..8de10ca
--- /dev/null
+++ b/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/parser/schema/test/SimpleType1Test.java
@@ -0,0 +1,122 @@
+/*
+* 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.schema.test;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+import org.apache.taverna.wsdl.parser.schema.XSGlobalElement;
+import org.apache.taverna.wsdl.parser.schema.XSNode;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.xml.sax.SAXException;
+
+/**
+ * @author Dmitry Repchevsky
+ */
+
+public class SimpleType1Test extends TestSchemaTreeModel {
+
+ private final static String XML_FILE = "org/apache/taverna/wsdl/parser/schema/simple_type1.xml";
+ private final static String XSD_FILE = "org/apache/taverna/wsdl/parser/schema/simple_type1.xsd";
+
+ @Before
+ public void loadModel() {
+ loadModel(XSD_FILE);
+ }
+
+ @Test
+ public void simpleTypeReadTest() {
+ fillModel(XML_FILE);
+ testModel();
+ }
+
+ @Test
+ public void simpleTypeWriteTest() {
+ fillModel();
+ testModel();
+ }
+
+ private void fillModel() {
+ model.addGlobalElement(new QName("http://example.com","name"));
+
+ Assert.assertTrue("there must be ONE simple elements in the model", model.getChildCount() == 1);
+
+ XSNode node = model.getChildAt(0);
+
+ Assert.assertTrue("the 'name' must be the represented by an element node", node instanceof XSGlobalElement);
+
+ XSGlobalElement element = (XSGlobalElement)node;
+ element.setUserObject("Napoleon");
+ }
+
+ private void testModel() {
+ XMLOutputFactory of = XMLOutputFactory.newInstance();
+ of.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+ try {
+ XMLStreamWriter writer = of.createXMLStreamWriter(out);
+ try {
+ model.write(writer);
+ } finally {
+ writer.close();
+ }
+ } catch(XMLStreamException ex) {
+ Assert.fail(ex.getMessage());
+ }
+
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ dbf.setNamespaceAware(true);
+ DocumentBuilder db = null;
+ try {
+ db = dbf.newDocumentBuilder();
+ } catch(ParserConfigurationException ex) {
+ Assert.fail(ex.getMessage());
+ }
+
+ try {
+ Document doc = db.parse(new ByteArrayInputStream(out.toByteArray()));
+
+ Element node = doc.getDocumentElement();
+
+ Assert.assertEquals("wrong element type", Node.ELEMENT_NODE, node.getNodeType());
+ Assert.assertEquals("wrong element name", "name", node.getLocalName());
+ Assert.assertEquals("wrong 'name' element namespace", "http://example.com", node.getNamespaceURI());
+ Assert.assertEquals("wrong '{http://example.com}name' element text content", "Napoleon", node.getTextContent());
+ } catch(SAXException ex) {
+ Assert.fail(ex.getMessage());
+ } catch(IOException ex) {
+ Assert.fail(ex.getMessage());
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/parser/schema/test/SimpleType2Test.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/parser/schema/test/SimpleType2Test.java b/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/parser/schema/test/SimpleType2Test.java
new file mode 100644
index 0000000..d4e27ff
--- /dev/null
+++ b/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/parser/schema/test/SimpleType2Test.java
@@ -0,0 +1,121 @@
+/*
+* 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.schema.test;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+import org.apache.taverna.wsdl.parser.schema.XSGlobalElement;
+import org.apache.taverna.wsdl.parser.schema.XSNode;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.xml.sax.SAXException;
+
+/**
+ * @author Dmitry Repchevsky
+ */
+
+public class SimpleType2Test extends TestSchemaTreeModel {
+
+ private final static String XML_FILE = "org/apache/taverna/wsdl/parser/schema/simple_type2.xml";
+ private final static String XSD_FILE = "org/apache/taverna/wsdl/parser/schema/simple_type2.xsd";
+
+ @Before
+ public void loadModel() {
+ loadModel(XSD_FILE);
+ }
+
+ @Test
+ public void simpleTypeReadTest() {
+ fillModel(XML_FILE);
+ testModel();
+ }
+
+ @Test
+ public void simpleTypeWriteTest() {
+ fillModel();
+ testModel();
+ }
+
+ private void fillModel() {
+ model.addGlobalElement(new QName("http://example.com","surname"));
+
+ Assert.assertTrue("there must be ONE simple elements in the model", model.getChildCount() == 1);
+
+ XSNode node = model.getChildAt(0);
+ Assert.assertTrue("the 'surename' must be the represented by an element node", node instanceof XSGlobalElement);
+
+ XSGlobalElement element = (XSGlobalElement)node;
+ element.setUserObject("Bonaparte");
+ }
+
+ private void testModel() {
+ XMLOutputFactory of = XMLOutputFactory.newInstance();
+ of.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+ try {
+ XMLStreamWriter writer = of.createXMLStreamWriter(out);
+ try {
+ model.write(writer);
+ } finally {
+ writer.close();
+ }
+ } catch(XMLStreamException ex) {
+ Assert.fail(ex.getMessage());
+ }
+
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ dbf.setNamespaceAware(true);
+ DocumentBuilder db = null;
+ try {
+ db = dbf.newDocumentBuilder();
+ } catch(ParserConfigurationException ex) {
+ Assert.fail(ex.getMessage());
+ }
+
+ try {
+ final Document doc = db.parse(new ByteArrayInputStream(out.toByteArray()));
+
+ final Element node = doc.getDocumentElement();
+ Assert.assertNotNull("'surname' element is missed", node);
+ Assert.assertEquals("wrong element type", Node.ELEMENT_NODE, node.getNodeType());
+ Assert.assertEquals("wrong element name", "surname", node.getLocalName());
+ Assert.assertEquals("wrong 'surname' element namespace", "http://example.com", node.getNamespaceURI());
+ Assert.assertEquals("wrong '{http://example.com}surname' element text content", "Bonaparte", node.getTextContent());
+ } catch(SAXException ex) {
+ Assert.fail(ex.getMessage());
+ } catch(IOException ex) {
+ Assert.fail(ex.getMessage());
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/parser/schema/test/TestSchemaTreeModel.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/parser/schema/test/TestSchemaTreeModel.java b/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/parser/schema/test/TestSchemaTreeModel.java
new file mode 100644
index 0000000..2865cbe
--- /dev/null
+++ b/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/parser/schema/test/TestSchemaTreeModel.java
@@ -0,0 +1,91 @@
+/*
+* 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.schema.test;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import org.apache.taverna.wsdl.parser.schema.XSModel;
+import org.apache.taverna.wsdl.parser.schema.XSNode;
+import org.apache.ws.commons.schema.XmlSchemaCollection;
+import org.junit.Assert;
+import org.junit.Before;
+
+/**
+ * @author Dmitry Repchevsky
+ */
+
+public abstract class TestSchemaTreeModel {
+
+ XSModel<XSNode, XSNode> model;
+
+ @Before
+ public void init() {
+ model = new XSModel();
+ }
+
+ /**
+ * Loads the model from provided XML Schema file
+ *
+ * @param xsd XML Schema URI location
+ */
+ void loadModel(final String xsd) {
+ XmlSchemaCollection schemas = new XmlSchemaCollection();
+
+ try {
+ InputStream in = TestSchemaTreeModel.class.getClassLoader().getResourceAsStream(xsd);
+ try {
+ schemas.read(new InputStreamReader(in));
+ } finally {
+ in.close();
+ }
+ } catch(IOException ex) {
+ Assert.fail(ex.getMessage());
+ }
+
+ model.setSchemaCollection(schemas);
+ }
+
+ /**
+ * Fills the model with provided XML file
+ *
+ * @param xml XML document URI location
+ */
+ void fillModel(final String xml) {
+ try {
+ InputStream in = TestSchemaTreeModel.class.getClassLoader().getResourceAsStream(xml);
+
+ try {
+ XMLInputFactory f = XMLInputFactory.newInstance();
+ XMLStreamReader reader = f.createXMLStreamReader(in);
+ model.read(reader);
+ } catch(XMLStreamException ex) {
+ Assert.fail(ex.getMessage());
+ } finally {
+ in.close();
+ }
+ } catch(IOException ex) {
+ Assert.fail(ex.getMessage());
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/df390d97/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/parser/schema/test/XmlSchema001Test.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/parser/schema/test/XmlSchema001Test.java b/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/parser/schema/test/XmlSchema001Test.java
new file mode 100644
index 0000000..5f5f105
--- /dev/null
+++ b/taverna-wsdl-generic/src/test/java/org/apache/taverna/wsdl/parser/schema/test/XmlSchema001Test.java
@@ -0,0 +1,199 @@
+/*
+* 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.schema.test;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathExpressionException;
+import javax.xml.xpath.XPathFactory;
+import org.apache.taverna.wsdl.parser.schema.XSAttribute;
+import org.apache.taverna.wsdl.parser.schema.XSGlobalElement;
+import org.apache.taverna.wsdl.parser.schema.XSNode;
+import org.apache.taverna.wsdl.parser.schema.XSParticle;
+import org.apache.taverna.wsdl.parser.schema.XSType;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.xml.sax.SAXException;
+
+/**
+ * @author Dmitry Repchevsky
+ */
+
+public class XmlSchema001Test extends TestSchemaTreeModel {
+
+ private final static String XML_FILE = "org/apache/taverna/wsdl/parser/schema/xml-schema-example-001.xml";
+ private final static String XSD_FILE = "org/apache/taverna/wsdl/parser/schema/xml-schema-example-001.xsd";
+
+ @Before
+ public void loadModel() {
+ loadModel(XSD_FILE);
+ }
+
+ @Test
+ public void complexTypeReadTest() {
+ fillModel(XML_FILE);
+ testModel();
+ }
+
+ @Test
+ public void complexTypeWriteTest() {
+ fillModel();
+ testModel();
+ }
+
+ @Test
+ public void XPathTest() throws ParserConfigurationException, SAXException, IOException, XPathExpressionException {
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ dbf.setNamespaceAware(true);
+ DocumentBuilder db = dbf.newDocumentBuilder();
+
+ InputStream in = ComplexType1Test.class.getClassLoader().getResourceAsStream(XML_FILE);
+ Document doc;
+ try {
+ doc = db.parse(in);
+ } finally {
+ in.close();
+ }
+
+ XPath xpath = XPathFactory.newInstance().newXPath();
+
+ fillModel(XML_FILE);
+
+ XSGlobalElement element = (XSGlobalElement)model.getChildAt(0);
+
+ //...
+ }
+
+ private void fillModel() {
+ model.addGlobalElement(new QName("publication"));
+
+ Assert.assertTrue("the root node must have one child node", model.getChildCount() == 1);
+
+ XSNode<XSNode, XSNode> element = model.getChildAt(0);
+ Assert.assertTrue("the node 'publication' must be the represented by an element node", element instanceof XSGlobalElement);
+ Assert.assertEquals("the node 'publication' should have four child nodes", 4, element.getChildCount());
+
+ XSNode node0 = element.getChildAt(0);
+ Assert.assertTrue("the node 'doi' must be the represented by an attribute node", node0 instanceof XSAttribute);
+ Assert.assertEquals("the node 'doi' should have no child nodes", 0, node0.getChildCount());
+
+ XSAttribute doi = (XSAttribute)node0;
+ doi.setUserObject("0.1371/journal.pone.0107889");
+
+ XSNode node1 = element.getChildAt(1);
+ Assert.assertTrue("the node 'title' must be the represented by a particle node", node1 instanceof XSParticle);
+ Assert.assertEquals("the node 'doi' should have no child nodes", 0, node1.getChildCount());
+
+ XSParticle title = (XSParticle)node1;
+ title.setUserObject("BioSWR - Semantic Web Services Registry for Bioinformatics.");
+
+ XSNode node2 = element.getChildAt(2);
+ Assert.assertTrue("the node 'journal' must be the represented by a particle node", node2 instanceof XSParticle);
+ Assert.assertEquals("the node 'journal' should have no child nodes", 0, node2.getChildCount());
+
+ XSParticle journal = (XSParticle)node2;
+ journal.setUserObject("PLoS ONE");
+
+ XSNode<XSNode, XSNode> node3 = element.getChildAt(3);
+ Assert.assertTrue("the node 'author' must be the represented by a particle node", node3 instanceof XSParticle);
+ Assert.assertEquals("the node 'author' should have one child node", 1, node3.getChildCount());
+
+ XSNode<XSNode, XSNode> type0 = node3.getChildAt(0);
+ Assert.assertTrue("the 'author' type node must be the represented by a type node", type0 instanceof XSType);
+ Assert.assertEquals("the 'author' type node should have three child nodes", 3, type0.getChildCount());
+
+ XSNode particle0 = type0.getChildAt(0);
+ Assert.assertTrue("the node 'first_name' must be the represented by a particle node", particle0 instanceof XSParticle);
+ Assert.assertEquals("the node 'first_name' should have no child nodes", 0, particle0.getChildCount());
+
+ XSParticle firstName = (XSParticle)particle0;
+ firstName.setUserObject("Dmitry");
+
+ XSNode particle1 = type0.getChildAt(1);
+ Assert.assertTrue("the node 'last_name' must be the represented by a particle node", particle1 instanceof XSParticle);
+ Assert.assertEquals("the node 'last_name' should have no child nodes", 0, particle1.getChildCount());
+
+ XSParticle lastName = (XSParticle)particle1;
+ lastName.setUserObject("Repchevsky");
+
+ XSNode<XSNode, XSNode> particle2 = type0.getChildAt(2);
+ Assert.assertTrue("the node 'affiliation' must be the represented by a particle node", particle2 instanceof XSParticle);
+ Assert.assertEquals("the node 'affiliation' should have one child node", 1, particle2.getChildCount());
+
+ XSNode type = particle2.getChildAt(0);
+ Assert.assertTrue("the 'affiliation' type node must be the represented by a type node", type instanceof XSType);
+ Assert.assertEquals("the 'affiliation' type node should have no child nodes", 0, type.getChildCount());
+
+ XSType affiliation = (XSType)type;
+ affiliation.setUserObject("Barcelona Supercomputing Center");
+ }
+
+ private void testModel() {
+ XMLOutputFactory f = XMLOutputFactory.newInstance();
+ f.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+ try {
+ XMLStreamWriter writer = f.createXMLStreamWriter(out);
+ try {
+ model.write(writer);
+ } finally {
+ writer.close();
+ }
+ } catch(XMLStreamException ex) {
+ Assert.fail(ex.getMessage());
+ }
+
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ dbf.setNamespaceAware(true);
+ DocumentBuilder db = null;
+ try {
+ db = dbf.newDocumentBuilder();
+ } catch(ParserConfigurationException ex) {
+ Assert.fail(ex.getMessage());
+ }
+
+ try {
+ Document doc = db.parse(new ByteArrayInputStream(out.toByteArray()));
+
+ Element root = doc.getDocumentElement();
+
+ //...
+ } catch(SAXException ex) {
+ Assert.fail(ex.getMessage());
+ } catch(IOException ex) {
+ Assert.fail(ex.getMessage());
+ }
+ }
+}