You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by rf...@apache.org on 2006/08/30 03:00:59 UTC
svn commit: r438318 - in /incubator/tuscany/java/sca/idl/wsdl/src:
main/java/org/apache/tuscany/idl/wsdl/ test/java/org/apache/tuscany/idl/wsdl/
test/resources/org/apache/tuscany/idl/wsdl/
Author: rfeng
Date: Tue Aug 29 18:00:58 2006
New Revision: 438318
URL: http://svn.apache.org/viewvc?rev=438318&view=rev
Log:
Add InterfaceWSDLIntrospector to introspect WSDL portTypes to create WSDLServiceContracts
Added:
incubator/tuscany/java/sca/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/InterfaceWSDLIntrospector.java (with props)
incubator/tuscany/java/sca/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/InterfaceWSDLIntrospectorImpl.java (with props)
incubator/tuscany/java/sca/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/NotSupportedWSDLException.java (with props)
incubator/tuscany/java/sca/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/InterfaceWSDLIntrospectorImplTestCase.java (with props)
incubator/tuscany/java/sca/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/stockquote.wsdl
Added: incubator/tuscany/java/sca/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/InterfaceWSDLIntrospector.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/InterfaceWSDLIntrospector.java?rev=438318&view=auto
==============================================================================
--- incubator/tuscany/java/sca/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/InterfaceWSDLIntrospector.java (added)
+++ incubator/tuscany/java/sca/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/InterfaceWSDLIntrospector.java Tue Aug 29 18:00:58 2006
@@ -0,0 +1,48 @@
+/*
+ * 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.tuscany.idl.wsdl;
+
+import javax.wsdl.PortType;
+
+import org.apache.tuscany.spi.idl.InvalidServiceContractException;
+
+/**
+ * Introspector for creating WSDLServiceContract definitions from WSDL PortTypes.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface InterfaceWSDLIntrospector {
+
+ /**
+ * Introspect a WSDL portType and return a service contract definition.
+ *
+ * @param type the portType to inspect
+ * @return a WSDLServiceContract corresponding to the WSDL portType
+ */
+ WSDLServiceContract introspect(PortType portType) throws InvalidServiceContractException;
+
+ /**
+ * Introspect a WSDL portType and return a service contract definition.
+ *
+ * @param type the portType to inspect
+ * @param callback the callback portType to inspec
+ * @return a WSDLServiceContract corresponding to the WSDL portType
+ */
+ WSDLServiceContract introspect(PortType type, PortType callback) throws InvalidServiceContractException;
+}
Propchange: incubator/tuscany/java/sca/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/InterfaceWSDLIntrospector.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/InterfaceWSDLIntrospector.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/InterfaceWSDLIntrospectorImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/InterfaceWSDLIntrospectorImpl.java?rev=438318&view=auto
==============================================================================
--- incubator/tuscany/java/sca/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/InterfaceWSDLIntrospectorImpl.java (added)
+++ incubator/tuscany/java/sca/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/InterfaceWSDLIntrospectorImpl.java Tue Aug 29 18:00:58 2006
@@ -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.tuscany.idl.wsdl;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.wsdl.Fault;
+import javax.wsdl.Input;
+import javax.wsdl.Message;
+import javax.wsdl.Operation;
+import javax.wsdl.Output;
+import javax.wsdl.Part;
+import javax.wsdl.PortType;
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.spi.idl.InvalidServiceContractException;
+import org.apache.tuscany.spi.model.DataType;
+
+/**
+ * Introspector for creating WSDLServiceContract definitions from WSDL PortTypes.
+ */
+public class InterfaceWSDLIntrospectorImpl implements InterfaceWSDLIntrospector {
+
+ // FIXME: Do we want to deal with document-literal wrapped style based on the JAX-WS spec?
+ protected Map<String, org.apache.tuscany.spi.model.Operation<QName>> introspectOperations(PortType portType)
+ throws NotSupportedWSDLException {
+ Map<String, org.apache.tuscany.spi.model.Operation<QName>> operations =
+ new HashMap<String, org.apache.tuscany.spi.model.Operation<QName>>();
+ for (Object op : portType.getOperations()) {
+ Operation wsdlOp = (Operation) op;
+ String name = wsdlOp.getName();
+
+ Input input = wsdlOp.getInput();
+ Message inputMsg = (input == null) ? null : input.getMessage();
+ List<DataType<QName>> parameterTypes = introspectTypes(inputMsg);
+
+ Message outputMsg = null;
+ Output output = wsdlOp.getOutput();
+ outputMsg = (output == null) ? null : output.getMessage();
+
+ List outputParts = (outputMsg == null) ? null : outputMsg.getOrderedParts(null);
+ DataType<QName> returnType = null;
+ if (outputParts != null || outputParts.size() > 0) {
+ if (outputParts.size() > 1) {
+ // We don't support output with multiple parts
+ throw new NotSupportedWSDLException("Multi-part output is not supported");
+ }
+ Part part = (Part) outputParts.get(0);
+ returnType = introspectType(part);
+ }
+
+ Collection faults = wsdlOp.getFaults().values();
+ List<DataType<QName>> faultTypes = new ArrayList<DataType<QName>>();
+ for (Object f : faults) {
+ Fault fault = (Fault) f;
+ Message faultMsg = fault.getMessage();
+ List faultParts = faultMsg.getOrderedParts(null);
+ if (faultParts.size() != 1) {
+ throw new NotSupportedWSDLException("The fault message MUST have a single part");
+ }
+ Part part = (Part) faultParts.get(0);
+ // A fault is typed by a message
+ DataType<QName> dataType = introspectType(part);
+ faultTypes.add(dataType);
+ }
+
+ // FIXME: [rfeng] How to figure the nonBlocking and dataBinding?
+ org.apache.tuscany.spi.model.Operation<QName> operation =
+ new org.apache.tuscany.spi.model.Operation<QName>(name, returnType, parameterTypes, faultTypes,
+ true, null);
+ operations.put(name, operation);
+ }
+ return operations;
+ }
+
+ protected List<DataType<QName>> introspectTypes(Message message) {
+ List<DataType<QName>> dataTypes = new ArrayList<DataType<QName>>();
+ if (message != null) {
+ List parts = message.getOrderedParts(null);
+ for (Object p : parts) {
+ Part part = (Part) p;
+ DataType<QName> dataType = introspectType(part);
+ dataTypes.add(dataType);
+ }
+ }
+ return dataTypes;
+ }
+
+ protected DataType<QName> introspectType(Part part) {
+ QName partTypeName = part.getElementName();
+ // FIXME: How can we get the corresponing type name for the element? We need the XSD model
+ if (partTypeName == null) {
+ partTypeName = part.getTypeName();
+ }
+ // FIXME: What java class is it? Should we try to see if there's a generated one?
+ return new DataType<QName>(Object.class, partTypeName);
+ }
+
+ /**
+ * @see org.apache.tuscany.idl.wsdl.InterfaceWSDLIntrospector#introspect(javax.wsdl.PortType)
+ */
+ public WSDLServiceContract introspect(PortType portType) throws InvalidServiceContractException {
+ WSDLServiceContract contract = new WSDLServiceContract();
+ contract.setPortType(portType);
+ contract.setInterfaceName(portType.getQName().getLocalPart());
+ contract.getOperations().putAll(introspectOperations(portType));
+ return contract;
+ }
+
+ /**
+ * @see org.apache.tuscany.idl.wsdl.InterfaceWSDLIntrospector#introspect(javax.wsdl.PortType, javax.wsdl.PortType)
+ */
+ public WSDLServiceContract introspect(PortType portType, PortType callbackPortType)
+ throws InvalidServiceContractException {
+ WSDLServiceContract contract = new WSDLServiceContract();
+ contract.setPortType(portType);
+ contract.setInterfaceName(portType.getQName().getLocalPart());
+ contract.getOperations().putAll(introspectOperations(portType));
+ contract.setCallbackPortType(callbackPortType);
+ contract.setCallbackName(callbackPortType.getQName().getLocalPart());
+ contract.getCallbacksOperations().putAll(introspectOperations(callbackPortType));
+ return contract;
+ }
+
+}
Propchange: incubator/tuscany/java/sca/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/InterfaceWSDLIntrospectorImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/InterfaceWSDLIntrospectorImpl.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/NotSupportedWSDLException.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/NotSupportedWSDLException.java?rev=438318&view=auto
==============================================================================
--- incubator/tuscany/java/sca/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/NotSupportedWSDLException.java (added)
+++ incubator/tuscany/java/sca/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/NotSupportedWSDLException.java Tue Aug 29 18:00:58 2006
@@ -0,0 +1,57 @@
+/*
+ * 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.tuscany.idl.wsdl;
+
+import org.apache.tuscany.spi.idl.InvalidServiceContractException;
+
+/**
+ * An exception to indicate some WSDL styles that we don't support
+ */
+public class NotSupportedWSDLException extends InvalidServiceContractException {
+
+ /**
+ *
+ */
+ public NotSupportedWSDLException() {
+ }
+
+ /**
+ * @param message
+ */
+ public NotSupportedWSDLException(String message) {
+ super(message);
+ }
+
+ /**
+ * @param message
+ * @param cause
+ */
+ public NotSupportedWSDLException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ /**
+ * @param cause
+ */
+ public NotSupportedWSDLException(Throwable cause) {
+ super(cause);
+ }
+
+}
Propchange: incubator/tuscany/java/sca/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/NotSupportedWSDLException.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/NotSupportedWSDLException.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/InterfaceWSDLIntrospectorImplTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/InterfaceWSDLIntrospectorImplTestCase.java?rev=438318&view=auto
==============================================================================
--- incubator/tuscany/java/sca/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/InterfaceWSDLIntrospectorImplTestCase.java (added)
+++ incubator/tuscany/java/sca/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/InterfaceWSDLIntrospectorImplTestCase.java Tue Aug 29 18:00:58 2006
@@ -0,0 +1,82 @@
+/*
+ * 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.tuscany.idl.wsdl;
+
+import java.net.URL;
+import java.util.List;
+import java.util.Map;
+
+import javax.wsdl.Definition;
+import javax.wsdl.PortType;
+import javax.wsdl.factory.WSDLFactory;
+import javax.wsdl.xml.WSDLReader;
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.spi.idl.InvalidServiceContractException;
+import org.apache.tuscany.spi.model.DataType;
+import org.apache.tuscany.spi.model.Operation;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+/**
+ *
+ */
+public class InterfaceWSDLIntrospectorImplTestCase extends TestCase {
+ private static final QName PORTTYPE_NAME = new QName("http://example.com/stockquote.wsdl", "StockQuotePortType");
+
+ private PortType portType;
+
+ /**
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ WSDLFactory factory = WSDLFactory.newInstance();
+ URL url = getClass().getResource("stockquote.wsdl");
+ WSDLReader reader = factory.newWSDLReader();
+ reader.setFeature("javax.wsdl.verbose", false);
+ Definition definition = reader.readWSDL(url.toExternalForm());
+ portType = definition.getPortType(PORTTYPE_NAME);
+ }
+
+ public final void testIntrospectPortType() throws InvalidServiceContractException {
+ InterfaceWSDLIntrospector introspector = new InterfaceWSDLIntrospectorImpl();
+ WSDLServiceContract contract = introspector.introspect(portType);
+ Assert.assertEquals(contract.getInterfaceName(), "StockQuotePortType");
+ Map<String, Operation<QName>> operations = contract.getOperations();
+ Assert.assertEquals(1, operations.size());
+ Operation<QName> operation = operations.get("getLastTradePrice");
+ Assert.assertNotNull(operation);
+ List<DataType<QName>> inputTypes = operation.getParameterTypes();
+ Assert.assertEquals(1, inputTypes.size());
+ DataType<QName> returnType = operation.getReturnType();
+ Assert.assertNotNull(returnType);
+ Assert.assertEquals(0, operation.getFaultTypes().size());
+ }
+
+ public final void testIntrospectPortTypePortType() throws InvalidServiceContractException {
+ InterfaceWSDLIntrospector introspector = new InterfaceWSDLIntrospectorImpl();
+ WSDLServiceContract contract = introspector.introspect(portType, portType);
+ Assert.assertEquals("StockQuotePortType", contract.getInterfaceName());
+ Assert.assertEquals("StockQuotePortType", contract.getCallbackName());
+ }
+
+}
Propchange: incubator/tuscany/java/sca/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/InterfaceWSDLIntrospectorImplTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/InterfaceWSDLIntrospectorImplTestCase.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/stockquote.wsdl
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/stockquote.wsdl?rev=438318&view=auto
==============================================================================
--- incubator/tuscany/java/sca/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/stockquote.wsdl (added)
+++ incubator/tuscany/java/sca/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/stockquote.wsdl Tue Aug 29 18:00:58 2006
@@ -0,0 +1,40 @@
+<?xml version="1.0"?>
+<definitions name="StockQuote" targetNamespace="http://example.com/stockquote.wsdl"
+ xmlns:tns="http://example.com/stockquote.wsdl" xmlns:xsd1="http://example.com/stockquote.xsd"
+ xmlns="http://schemas.xmlsoap.org/wsdl/">
+
+ <types>
+ <schema targetNamespace="http://example.com/stockquote.xsd" xmlns="http://www.w3.org/2001/XMLSchema">
+ <element name="getLastTradePrice">
+ <complexType>
+ <sequence>
+ <element name="tickerSymbol" type="string" />
+ </sequence>
+ </complexType>
+ </element>
+ <element name="getLastTradePriceResponse">
+ <complexType>
+ <sequence>
+ <element name="price" type="float" />
+ </sequence>
+ </complexType>
+ </element>
+ </schema>
+ </types>
+
+ <message name="GetLastTradePriceInput">
+ <part name="body" element="xsd1:getLastTradePrice" />
+ </message>
+
+ <message name="GetLastTradePriceOutput">
+ <part name="body" element="xsd1:getLastTradePriceResponse" />
+ </message>
+
+ <portType name="StockQuotePortType">
+ <operation name="getLastTradePrice">
+ <input message="tns:GetLastTradePriceInput" />
+ <output message="tns:GetLastTradePriceOutput" />
+ </operation>
+ </portType>
+
+</definitions>
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org