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:25 UTC
[7/8] incubator-taverna-common-activities git commit: experimental
wsdl-generic based on XSD schema
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);
- }
-}