diff options
Diffstat (limited to 'sca-java-2.x/trunk/modules/binding-ws-wsdlgen/src/main/java')
3 files changed, 156 insertions, 19 deletions
diff --git a/sca-java-2.x/trunk/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/BindingWSDLGenerator.java b/sca-java-2.x/trunk/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/BindingWSDLGenerator.java index ef70b5f5c0..516a62a556 100644 --- a/sca-java-2.x/trunk/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/BindingWSDLGenerator.java +++ b/sca-java-2.x/trunk/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/BindingWSDLGenerator.java @@ -266,27 +266,64 @@ public class BindingWSDLGenerator { /** * Create a WSDLInterfaceContract from a JavaInterfaceContract */ - protected static WSDLInterfaceContract createWSDLInterfaceContract(JavaInterfaceContract contract, - boolean requiresSOAP12, - ModelResolver resolver, - DataBindingExtensionPoint dataBindings, - WSDLFactory wsdlFactory, - XSDFactory xsdFactory, - DocumentBuilderFactory documentBuilderFactory, - Monitor monitor) { + public static WSDLInterfaceContract createWSDLInterfaceContract(JavaInterfaceContract contract, + boolean requiresSOAP12, + ModelResolver resolver, + DataBindingExtensionPoint dataBindings, + WSDLFactory wsdlFactory, + XSDFactory xsdFactory, + DocumentBuilderFactory documentBuilderFactory, + Monitor monitor) { WSDLInterfaceContract wsdlContract = wsdlFactory.createWSDLInterfaceContract(); - WSDLInterface wsdlInterface = wsdlFactory.createWSDLInterface(); - wsdlContract.setInterface(wsdlInterface); + + if (contract.getInterface() != null){ + WSDLInterface wsdlInterface = createWSDLInterface((JavaInterface)contract.getInterface(), + requiresSOAP12, + resolver, + dataBindings, + wsdlFactory, + xsdFactory, + documentBuilderFactory, + monitor); + wsdlContract.setInterface(wsdlInterface); + } + + if (contract.getCallbackInterface() != null){ + WSDLInterface wsdlInterface = createWSDLInterface((JavaInterface)contract.getCallbackInterface(), + requiresSOAP12, + resolver, + dataBindings, + wsdlFactory, + xsdFactory, + documentBuilderFactory, + monitor); + wsdlContract.setCallbackInterface(wsdlInterface); + } + return wsdlContract; + } + + /** + * Create a WSDLInterface from a JavaInterface + */ + public static WSDLInterface createWSDLInterface(JavaInterface javaInterface, + boolean requiresSOAP12, + ModelResolver resolver, + DataBindingExtensionPoint dataBindings, + WSDLFactory wsdlFactory, + XSDFactory xsdFactory, + DocumentBuilderFactory documentBuilderFactory, + Monitor monitor) { + + WSDLInterface wsdlInterface = wsdlFactory.createWSDLInterface(); WSDLDefinition wsdlDefinition = wsdlFactory.createWSDLDefinition(); - JavaInterface iface = (JavaInterface)contract.getInterface(); Definition def = null; try { Interface2WSDLGenerator wsdlGenerator = new Interface2WSDLGenerator(requiresSOAP12, resolver, dataBindings, xsdFactory, documentBuilderFactory, monitor); - def = wsdlGenerator.generate(iface, wsdlDefinition); + def = wsdlGenerator.generate(javaInterface, wsdlDefinition); } catch (WSDLException e) { throw new WSDLGenerationException(e); } @@ -294,7 +331,7 @@ public class BindingWSDLGenerator { // for debugging if (printWSDL) { try { - System.out.println("Generated WSDL for Java interface " + iface.getName() + " class " + iface.getJavaClass().getName()); + System.out.println("Generated WSDL for Java interface " + javaInterface.getName() + " class " + javaInterface.getJavaClass().getName()); WSDLWriter writer = javax.wsdl.factory.WSDLFactory.newInstance().newWSDLWriter(); writer.writeWSDL(def, System.out); } catch (WSDLException e) { @@ -316,7 +353,7 @@ public class BindingWSDLGenerator { throw new WSDLGenerationException(e); } - return wsdlContract; - } + return wsdlInterface; + } } diff --git a/sca-java-2.x/trunk/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/Interface2WSDLGenerator.java b/sca-java-2.x/trunk/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/Interface2WSDLGenerator.java index 7509f2ab57..a072b31322 100644 --- a/sca-java-2.x/trunk/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/Interface2WSDLGenerator.java +++ b/sca-java-2.x/trunk/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/Interface2WSDLGenerator.java @@ -797,10 +797,20 @@ public class Interface2WSDLGenerator { } helpers.put(db, helper); } - TypeInfo typeInfo = helper.getTypeInfo(javaType.isArray() ? javaType.getComponentType() : javaType, - dataType.getLogical()); - ElementInfo element = new ElementInfo(name, typeInfo); - element.setMany(byte[].class != javaType && javaType.isArray()); + // TUSCANY-3616 - don't revert a byte[] to a byte type but retain the mapping to base64Binary + // which is carried in the dataType and the original javaType + TypeInfo typeInfo = null; + ElementInfo element = null; + if (byte[].class == javaType){ + typeInfo = helper.getTypeInfo(javaType, dataType.getLogical()); + element = new ElementInfo(name, typeInfo); + element.setMany(false); + } else { + typeInfo = helper.getTypeInfo(javaType.isArray() ? javaType.getComponentType() : javaType, dataType.getLogical()); + element = new ElementInfo(name, typeInfo); + element.setMany(javaType.isArray()); + } + element.setNillable(!javaType.isPrimitive()); return element; } diff --git a/sca-java-2.x/trunk/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/WSDLContractBuilder.java b/sca-java-2.x/trunk/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/WSDLContractBuilder.java new file mode 100644 index 0000000000..25a566bd24 --- /dev/null +++ b/sca-java-2.x/trunk/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/WSDLContractBuilder.java @@ -0,0 +1,90 @@ +/*
+ * 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.sca.binding.ws.wsdlgen;
+
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.Contract;
+import org.apache.tuscany.sca.assembly.Endpoint;
+import org.apache.tuscany.sca.assembly.EndpointReference;
+import org.apache.tuscany.sca.assembly.builder.BindingBuilder;
+import org.apache.tuscany.sca.assembly.builder.BuilderContext;
+import org.apache.tuscany.sca.assembly.builder.ContractBuilder;
+import org.apache.tuscany.sca.binding.ws.WebServiceBinding;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.resolver.ResolverExtension;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.FactoryExtensionPoint;
+import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract;
+import org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory;
+import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterfaceContract;
+import org.apache.tuscany.sca.runtime.RuntimeEndpoint;
+import org.apache.tuscany.sca.runtime.RuntimeEndpointReference;
+import org.apache.tuscany.sca.xsd.XSDFactory;
+
+/**
+ * Created WSDL contracts for Endpoints or EndpointReferences for use during
+ * interface contract mapping. The assmebly spec defines WSDL as the lowest
+ * common denominator for contract mapping.
+ */
+public class WSDLContractBuilder implements ContractBuilder {
+
+ private ExtensionPointRegistry extensionPoints;
+ private FactoryExtensionPoint modelFactories;
+ private DataBindingExtensionPoint dataBindings;
+ private WSDLFactory wsdlFactory;
+ private XSDFactory xsdFactory;
+ private DocumentBuilderFactory documentBuilderFactory;
+
+ public WSDLContractBuilder(ExtensionPointRegistry extensionPoints) {
+ this.extensionPoints = extensionPoints;
+
+ modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class);
+ dataBindings = extensionPoints.getExtensionPoint(DataBindingExtensionPoint.class);
+ wsdlFactory = modelFactories.getFactory(WSDLFactory.class);
+ xsdFactory = modelFactories.getFactory(XSDFactory.class);
+ documentBuilderFactory = modelFactories.getFactory(DocumentBuilderFactory.class);
+
+ }
+
+ public boolean build(InterfaceContract interfaceContract, BuilderContext context){
+// Uncomment the printWSDL = lines to see the WSDL that is generated
+// for interface matching purposes
+// BindingWSDLGenerator.printWSDL = true;
+ JavaInterfaceContract javaContract = (JavaInterfaceContract)interfaceContract;
+ WSDLInterfaceContract wsdlContract =
+ BindingWSDLGenerator.createWSDLInterfaceContract(javaContract,
+ false,
+ null,
+ dataBindings,
+ wsdlFactory,
+ xsdFactory,
+ documentBuilderFactory,
+ null);
+ javaContract.setNormailizedWSDLContract(wsdlContract);
+// BindingWSDLGenerator.printWSDL = false;
+ return true;
+ }
+
+}
|