diff options
16 files changed, 473 insertions, 53 deletions
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 b4e3387d84..86c18378b8 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 @@ -25,8 +25,10 @@ import java.security.AccessController; import java.security.PrivilegedActionException; import java.security.PrivilegedExceptionAction; import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; import java.util.HashSet; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.logging.Level; @@ -50,6 +52,12 @@ import javax.xml.bind.annotation.XmlSeeAlso; import javax.xml.namespace.QName; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.Result; +import javax.xml.transform.Source; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; import org.apache.tuscany.sca.databinding.DataBinding; @@ -77,8 +85,16 @@ import org.apache.tuscany.sca.xsd.XSDFactory; import org.apache.tuscany.sca.xsd.XSDefinition; import org.apache.ws.commons.schema.XmlSchema; import org.apache.ws.commons.schema.XmlSchemaCollection; +import org.apache.ws.commons.schema.XmlSchemaComplexType; +import org.apache.ws.commons.schema.XmlSchemaElement; import org.apache.ws.commons.schema.XmlSchemaException; +import org.apache.ws.commons.schema.XmlSchemaGroupBase; +import org.apache.ws.commons.schema.XmlSchemaImport; +import org.apache.ws.commons.schema.XmlSchemaObject; +import org.apache.ws.commons.schema.XmlSchemaObjectCollection; +import org.apache.ws.commons.schema.XmlSchemaSerializer.XmlSchemaSerializerException; import org.apache.ws.commons.schema.utils.NamespaceMap; +import org.oasisopen.sca.ServiceRuntimeException; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; @@ -199,11 +215,17 @@ public class Interface2WSDLGenerator { } private boolean outputTypeCompatible(DataType wrapperType, DataType outputType, Map<String, XMLTypeHelper> helpers) { + // TUSCANY-3283 - use same algorithm as input types as we now support + // multiple output values so the real output types will + // be wrapped in an "idl:output" data type + /* if (getTypeHelper(outputType, helpers) != getTypeHelper(wrapperType, helpers)) { return false; } else { return true; } + */ + return inputTypesCompatible(wrapperType, outputType, helpers); } private void addDataType(Map<XMLTypeHelper, List<DataType>> map, DataType type, Map<String, XMLTypeHelper> helpers) { @@ -349,19 +371,26 @@ public class Interface2WSDLGenerator { wsdlDefinition.setBinding(binding); // call each helper in turn to populate the wsdl.types element - XmlSchemaCollection schemaCollection = new XmlSchemaCollection(); + XmlSchemaCollection schemaCollection = new XmlSchemaCollection(); - for (Map.Entry<XMLTypeHelper, List<DataType>> en: getDataTypes(interfaze, false, helpers).entrySet()) { + // TUSCANY-3283 - "true" here means also generate the include the wrapper types for xsd generation using JAXB + Map<XMLTypeHelper, List<DataType>> dataTypes = getDataTypes(interfaze, true, helpers); + for (Map.Entry<XMLTypeHelper, List<DataType>> en: dataTypes.entrySet()) { XMLTypeHelper helper = en.getKey(); if (helper == null) { continue; } List<XSDefinition> xsDefinitions = helper.getSchemaDefinitions(xsdFactory, resolver, en.getValue()); + + // TUSCANY-3283 - move the nonamespace types into the namespace of the interface + // as per JAXWS + mergeNoNamespaceSchema(namespaceURI, xsDefinitions); + for (XSDefinition xsDef: xsDefinitions) { addSchemaExtension(xsDef, schemaCollection, wsdlDefinition, definition); } } - + // remove global wrapper elements with schema definitions from generation list for (QName wrapperName: new HashSet<QName>(wrappers.keySet())) { if (wsdlDefinition.getXmlSchemaElement(wrapperName) != null) { @@ -370,6 +399,8 @@ public class Interface2WSDLGenerator { } // generate schema elements for wrappers that aren't defined in the schemas + // TUSCANY-3283 - as we're generating wrappers with JAXB it won't + // go through here for all wrappers??? if (wrappers.size() > 0) { int i = 0; int index = 0; @@ -384,25 +415,44 @@ public class Interface2WSDLGenerator { schemaDoc = xsDef.getDocument(); schema = schemaDoc.getDocumentElement(); } else { - schemaDoc = createDocument(); - schema = schemaDoc.createElementNS(SCHEMA_NS, "xs:schema"); - // The elementFormDefault should be set to unqualified, see TUSCANY-2388 - schema.setAttribute("elementFormDefault", "unqualified"); - schema.setAttribute("attributeFormDefault", "qualified"); - schema.setAttribute("targetNamespace", targetNS); - schema.setAttributeNS(XMLNS_NS, "xmlns:xs", SCHEMA_NS); - schemaDoc.appendChild(schema); - Schema schemaExt = createSchemaExt(definition); - schemaExt.setElement(schema); - prefixMaps.put(schema, new HashMap<String, String>()); - xsDef = xsdFactory.createXSDefinition(); - xsDef.setUnresolved(true); - xsDef.setNamespace(targetNS); - xsDef.setDocument(schemaDoc); - // TUSCANY-2465: Set the system id to avoid schema conflict - xsDef.setLocation(URI.create("xsd_" + index + ".xsd")); - index++; - wrapperXSDs.put(targetNS, xsDef); + // TUSCANY-3283 - if we have to generate a new check to see if the + // WSDL doc already has a schema in this namespace +// xsDef = wsdlDefinition.getSchema(targetNS); +// if (xsDef != null) { +// schemaDoc = xsDef.getDocument(); +// schema = schemaDoc.getDocumentElement(); +// wrapperXSDs.put(targetNS, xsDef); +// Map<String, String> prefixMap = prefixMaps.get(schema); +// if (prefixMap == null){ +// prefixMap = new HashMap<String, String>(); +// prefixMaps.put(schema, prefixMap); +// String [] prefixes = xsDef.getSchema().getNamespaceContext().getDeclaredPrefixes(); +// for (int j = 0; j < prefixes.length; j++){ +// prefixMap.put(xsDef.getSchema().getNamespaceContext().getNamespaceURI(prefixes[j]), +// prefixes[j]); +// } +// } +// } else { + schemaDoc = createDocument(); + schema = schemaDoc.createElementNS(SCHEMA_NS, "xs:schema"); + // The elementFormDefault should be set to unqualified, see TUSCANY-2388 + schema.setAttribute("elementFormDefault", "unqualified"); + schema.setAttribute("attributeFormDefault", "qualified"); + schema.setAttribute("targetNamespace", targetNS); + schema.setAttributeNS(XMLNS_NS, "xmlns:xs", SCHEMA_NS); + schemaDoc.appendChild(schema); + Schema schemaExt = createSchemaExt(definition); + schemaExt.setElement(schema); + prefixMaps.put(schema, new HashMap<String, String>()); + xsDef = xsdFactory.createXSDefinition(); + xsDef.setUnresolved(true); + xsDef.setNamespace(targetNS); + xsDef.setDocument(schemaDoc); + // TUSCANY-2465: Set the system id to avoid schema conflict + xsDef.setLocation(URI.create("xsd_" + index + ".xsd")); + index++; + wrapperXSDs.put(targetNS, xsDef); +// } } Element wrapper = schemaDoc.createElementNS(SCHEMA_NS, "xs:element"); schema.appendChild(wrapper); @@ -483,6 +533,178 @@ public class Interface2WSDLGenerator { return definition; } + + // TUSCANY-3283 - merge the nonamespace schema into the default namespace schema + private void mergeNoNamespaceSchema(String toNamespace, List<XSDefinition> xsDefinitions){ + String fromNamespace = ""; + Document fromDoc = null; + XSDefinition fromXsDef = null; + Document toDoc = null; + List<Document> relatedDocs = new ArrayList<Document>(); + + for (XSDefinition xsDef: xsDefinitions) { + if(xsDef.getNamespace().equals("")){ + fromXsDef = xsDef; + fromDoc = xsDef.getDocument(); + } else if(xsDef.getNamespace().equals(toNamespace)){ + toDoc = xsDef.getDocument(); + } else { + relatedDocs.add(xsDef.getDocument()); + } + } + + if (fromDoc != null && toDoc != null){ + try { + List<XmlSchema> resultingDocs = mergeSchema(fromNamespace, fromDoc, toNamespace, toDoc, relatedDocs); + + for (XmlSchema schema : resultingDocs){ + for (XSDefinition xsDef: xsDefinitions) { + if (xsDef.getNamespace().equals(schema.getTargetNamespace())){ + Document doc = schema.getSchemaDocument(); + // just for debugging + //printDOM(doc); + xsDef.setDocument(doc); + //xsDef.setSchema(schema); + } + } + } + + xsDefinitions.remove(fromXsDef); + } catch (XmlSchemaSerializerException ex){ + throw new WSDLGenerationException(ex); + } + } + } + + // TUSCANY-3283 - merge the nonamespace schema into the default namespace schema + private List<XmlSchema> mergeSchema(String fromNamespace, + Document fromDoc, + String toNamespace, + Document toDoc, + List<Document> relatedDocs) throws XmlSchemaSerializerException{ + // Read all the input DOMs into a schema collection so we can manipulate them + XmlSchemaCollection schemaCollection = new XmlSchemaCollection(); + schemaCollection.read(fromDoc.getDocumentElement()); + schemaCollection.read(toDoc.getDocumentElement()); + + for(Document doc : relatedDocs){ + schemaCollection.read(doc.getDocumentElement()); + } + + XmlSchema fromSchema = null; + XmlSchema toSchema = null; + List<XmlSchema> resultSchema = new ArrayList<XmlSchema>(); + XmlSchema schemas[] = schemaCollection.getXmlSchemas(); + for (int i=0; i < schemas.length; i++){ + XmlSchema schema = schemas[i]; + + if (schema.getTargetNamespace() == null){ + fromSchema = schema; + } else if (schema.getTargetNamespace().equals(toNamespace)){ + toSchema = schema; + resultSchema.add(schema); + } else if (schema.getTargetNamespace().equals("http://www.w3.org/2001/XMLSchema")){ + // do nothing as we're not going to print out the + // schema schema + } else { + resultSchema.add(schema); + } + } + + if (fromSchema == null || toSchema == null){ + return resultSchema; + } + + // copy all the FROM items to the TO schema + XmlSchemaObjectCollection fromItems = fromSchema.getItems(); + XmlSchemaObjectCollection toItems = toSchema.getItems(); + + Iterator<XmlSchemaObject> iter = fromItems.getIterator(); + while(iter.hasNext()){ + // don't copy import for TO namespace + XmlSchemaObject obj = iter.next(); + if (obj instanceof XmlSchemaImport && + ((XmlSchemaImport)obj).getNamespace().equals(toNamespace)){ + // do nothing + } else { + toItems.add(obj); + // correct any references to the item just moved + fixUpMovedTypeReferences(fromNamespace, toNamespace, obj, resultSchema); + } + } + + return resultSchema; + } + + // TUSCANY-3283 - fix up any references to types moved to the default namespace schema + public void fixUpMovedTypeReferences(String fromNamespace, String toNamespace, XmlSchemaObject fixUpObj, List<org.apache.ws.commons.schema.XmlSchema> relatedSchema){ + + if (!(fixUpObj instanceof XmlSchemaComplexType)){ + return; + } + + for (XmlSchema schema : relatedSchema){ + int importRemoveIndex = -1; + for (int i = 0; i < schema.getItems().getCount(); i++){ + XmlSchemaObject obj = schema.getItems().getItem(i); + + // if this is not the TO schema then fix up all references + // to items moved to the TO schema + if(!schema.getTargetNamespace().equals(toNamespace)){ + processXMLSchemaObject(toNamespace, obj, fixUpObj); + } + + // remove FROM imports + if (obj instanceof XmlSchemaImport && + ((XmlSchemaImport)obj).getNamespace().equals(fromNamespace)){ + importRemoveIndex = i; + } + } + + if (importRemoveIndex >= 0){ + schema.getItems().removeAt(importRemoveIndex); + } + } + } + + // TUSCANY-3283 - iterate down the schema tree looking for references to the item being moved + public void processXMLSchemaObject(String toNamespace, XmlSchemaObject obj, XmlSchemaObject fixUpObj){ + if (obj instanceof XmlSchemaComplexType){ + processXMLSchemaObject(toNamespace, ((XmlSchemaComplexType)obj).getParticle(), fixUpObj); + } else if (obj instanceof XmlSchemaElement){ + XmlSchemaElement element = (XmlSchemaElement)obj; + if(element.getSchemaType() == fixUpObj){ + QName name = element.getSchemaTypeName(); + QName newName = new QName(toNamespace, name.getLocalPart()); + element.setSchemaTypeName(newName); + } + ((XmlSchemaElement)obj).getSchemaType(); + } else if (obj instanceof XmlSchemaGroupBase){ + XmlSchemaObjectCollection items = ((XmlSchemaGroupBase)obj).getItems(); + Iterator<XmlSchemaObject> iter = items.getIterator(); + while(iter.hasNext()){ + processXMLSchemaObject(toNamespace, iter.next(), fixUpObj); + } + } + // TODO - what other structure items will be generated by JAXB? + } + + /* + * TUSCANY-3283 - Just used when debugging DOM problems + */ + private void printDOM(Document document){ + try { + Transformer transformer = TransformerFactory.newInstance().newTransformer(); + Source source = new DOMSource(document); + Result result = new StreamResult(System.out); + transformer.transform(source, result); + System.out.println("\n"); + System.out.flush(); + } catch (Exception ex){ + ex.toString(); + } + } + private static void addSchemaImport(Element schema, String nsURI, Document schemaDoc) { Element imp = schemaDoc.createElementNS(SCHEMA_NS, "xs:import"); diff --git a/sca-java-2.x/trunk/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/wsdlgen/BindingWSDLGeneratorTestCase.java b/sca-java-2.x/trunk/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/wsdlgen/BindingWSDLGeneratorTestCase.java index f905c10bf7..b3bf5c20d3 100644 --- a/sca-java-2.x/trunk/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/wsdlgen/BindingWSDLGeneratorTestCase.java +++ b/sca-java-2.x/trunk/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/wsdlgen/BindingWSDLGeneratorTestCase.java @@ -74,6 +74,7 @@ public class BindingWSDLGeneratorTestCase extends TestCase { new JAXWSJavaInterfaceProcessor(registry).visitInterface(iface2); new DataBindingJavaInterfaceProcessor(registry).visitInterface(iface2); javaIC2.setInterface(iface2); + BindingWSDLGenerator.printWSDL = true; WSDLInterfaceContract wsdlIC2 = BindingWSDLGenerator.createWSDLInterfaceContract(javaIC2, false, new XSDModelResolver(null, null), dataBindings, wsdlFactory, xsdFactory, documentBuilderFactory, null); assertNotNull(wsdlIC2); } diff --git a/sca-java-2.x/trunk/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Output2OutputTransformer.java b/sca-java-2.x/trunk/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Output2OutputTransformer.java index f2e1eb7742..f59666127d 100644 --- a/sca-java-2.x/trunk/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Output2OutputTransformer.java +++ b/sca-java-2.x/trunk/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Output2OutputTransformer.java @@ -138,6 +138,18 @@ public class Output2OutputTransformer extends BaseTransformer<Object, Object> im for (int i = 0; i < list1.size(); i++) { String n1 = list1.get(i).getQName().getLocalPart(); String n2 = list2.get(i).getQName().getLocalPart(); + + // TUSCANY-3283 - strip off any leading "_" characters for this comparison. + // Now we generate wrappers with JAXB it names the response + // wrapper's child as "_return" + if (n1.startsWith("_")){ + n1 = n1.substring(1); + } + + if (n2.startsWith("_")){ + n2 = n2.substring(1); + } + if (!n1.equals(n2)) { return false; } diff --git a/sca-java-2.x/trunk/modules/databinding-axiom/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer b/sca-java-2.x/trunk/modules/databinding-axiom/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer index 70318b3930..685b76000c 100644 --- a/sca-java-2.x/trunk/modules/databinding-axiom/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer +++ b/sca-java-2.x/trunk/modules/databinding-axiom/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer @@ -19,7 +19,9 @@ # org.apache.tuscany.sca.databinding.axiom.CallableReference2OMElement;source=org.oasisopen.sca.CallableReference,target=org.apache.axiom.om.OMElement,weight=10
# org.apache.tuscany.sca.databinding.axiom.OMElement2CallableReference;source=org.apache.axiom.om.OMElement,target=org.oasisopen.sca.CallableReference,weight=10
org.apache.tuscany.sca.databinding.axiom.Externalizable2OMElement;source=java.io.Externalizable,target=org.apache.axiom.om.OMElement,weight=10
+org.apache.tuscany.sca.databinding.axiom.Externalizable2OMElement;source=org.oasisopen.sca.ServiceReference,target=org.apache.axiom.om.OMElement,weight=10
org.apache.tuscany.sca.databinding.axiom.OMElement2Externalizable;source=org.apache.axiom.om.OMElement,target=java.io.Externalizable,weight=10
+org.apache.tuscany.sca.databinding.axiom.OMElement2Externalizable;source=org.apache.axiom.om.OMElement,target=org.oasisopen.sca.ServiceReference,weight=10
org.apache.tuscany.sca.databinding.axiom.Exception2OMElement;source=java:exception,target=org.apache.axiom.om.OMElement,weight=10
org.apache.tuscany.sca.databinding.axiom.OMElement2Exception;source=org.apache.axiom.om.OMElement,target=java:exception,weight=10
# org.apache.tuscany.sca.databinding.axiom.Object2OMElement;source=java:simpleType,target=org.apache.axiom.om.OMElement,weight=80000
diff --git a/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/servicereference/ServiceReferenceDataBinding.java b/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/servicereference/ServiceReferenceDataBinding.java new file mode 100644 index 0000000000..2117d2c3cf --- /dev/null +++ b/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/servicereference/ServiceReferenceDataBinding.java @@ -0,0 +1,42 @@ +/*
+ * 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.databinding.servicereference;
+
+import org.apache.tuscany.sca.databinding.BaseDataBinding;
+import org.apache.tuscany.sca.databinding.XMLTypeHelper;
+import org.oasisopen.sca.ServiceReference;
+
+public class ServiceReferenceDataBinding extends BaseDataBinding {
+
+ public static final String NAME = ServiceReference.class.getName();
+
+ private ServiceReferenceTypeHelper xmlTypeHelper;
+
+ public ServiceReferenceDataBinding() {
+ super(NAME, ServiceReference.class);
+ this.xmlTypeHelper = new ServiceReferenceTypeHelper();
+ }
+
+ @Override
+ public XMLTypeHelper getXMLTypeHelper() {
+ return xmlTypeHelper;
+ }
+
+}
diff --git a/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/servicereference/ServiceReferenceTypeHelper.java b/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/servicereference/ServiceReferenceTypeHelper.java new file mode 100644 index 0000000000..57da596d24 --- /dev/null +++ b/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/servicereference/ServiceReferenceTypeHelper.java @@ -0,0 +1,74 @@ +/* + * 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.databinding.servicereference; + +import java.beans.Introspector; +import java.util.ArrayList; +import java.util.List; +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.databinding.XMLTypeHelper; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.Interface; +import org.apache.tuscany.sca.interfacedef.util.JavaXMLMapper; +import org.apache.tuscany.sca.interfacedef.util.TypeInfo; +import org.apache.tuscany.sca.interfacedef.util.XMLType; +import org.apache.tuscany.sca.xsd.XSDFactory; +import org.apache.tuscany.sca.xsd.XSDefinition; + +/** + * Maps ServiceReference interfaces to AnyType + */ +public class ServiceReferenceTypeHelper implements XMLTypeHelper { + private static final String SCHEMA_NS = "http://www.w3.org/2001/XMLSchema"; + private static final String ANYTYPE_NAME = "anyType"; + private static final QName ANYTYPE_QNAME = new QName(SCHEMA_NS, ANYTYPE_NAME); + + public ServiceReferenceTypeHelper() { + super(); + } + + public TypeInfo getTypeInfo(Class javaType, Object logical) { + QName xmlType = JavaXMLMapper.getXMLType(javaType); + if (xmlType != null) { + return new TypeInfo(xmlType, true, null); + } else if (javaType.isInterface()) { + return new TypeInfo(ANYTYPE_QNAME, true, null); + } else { + if (logical instanceof XMLType) { + xmlType = ((XMLType)logical).getTypeName(); + } + if (xmlType == null) { + xmlType = new QName(Introspector.decapitalize(javaType.getSimpleName())); + } + return new TypeInfo(xmlType, false, null); + } + } + + public List<XSDefinition> getSchemaDefinitions(XSDFactory factory, ModelResolver resolver, Interface intf) { + return new ArrayList<XSDefinition>(); + } + + public List<XSDefinition> getSchemaDefinitions(XSDFactory factory, ModelResolver resolver, List<DataType> dataTypes) { + return new ArrayList<XSDefinition>(); + } + +} diff --git a/sca-java-2.x/trunk/modules/databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.DataBinding b/sca-java-2.x/trunk/modules/databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.DataBinding index ef8a825d68..3c0dce0492 100644 --- a/sca-java-2.x/trunk/modules/databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.DataBinding +++ b/sca-java-2.x/trunk/modules/databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.DataBinding @@ -23,4 +23,5 @@ org.apache.tuscany.sca.databinding.javabeans.JavaBeansDataBinding;name=java:comp org.apache.tuscany.sca.databinding.javabeans.SimpleJavaDataBinding;name=java:simpleType
org.apache.tuscany.sca.databinding.javabeans.JavaExceptionDataBinding;name=java:exception
org.apache.tuscany.sca.databinding.externalizable.ExternalizableDataBinding;name=java.io.Externalizable
+org.apache.tuscany.sca.databinding.servicereference.ServiceReferenceDataBinding;name=org.oasisopen.sca.ServiceReference
diff --git a/sca-java-2.x/trunk/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/BaseBeanGenerator.java b/sca-java-2.x/trunk/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/BaseBeanGenerator.java index 05a5dc89de..ca39ec0e62 100644 --- a/sca-java-2.x/trunk/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/BaseBeanGenerator.java +++ b/sca-java-2.x/trunk/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/BaseBeanGenerator.java @@ -48,6 +48,7 @@ import org.objectweb.asm.Opcodes; public abstract class BaseBeanGenerator implements Opcodes { private static final Map<String, String> COLLECTION_CLASSES = new HashMap<String, String>(); + static { COLLECTION_CLASSES.put("Ljava/util/Collection;", "java/util/ArrayList"); COLLECTION_CLASSES.put("Ljava/util/List;", "java/util/ArrayList"); @@ -55,7 +56,11 @@ public abstract class BaseBeanGenerator implements Opcodes { COLLECTION_CLASSES.put("Ljava/util/Queue;", "java/util/LinkedList"); } private final static Class[] KNOWN_JAXB_ANNOTATIONS = - {XmlAttachmentRef.class, XmlMimeType.class, XmlJavaTypeAdapter.class, XmlList.class}; + {XmlAttachmentRef.class, + XmlMimeType.class, + XmlJavaTypeAdapter.class, + XmlList.class}; + private static final Map<String, String> JAVA_KEYWORDS = new HashMap<String, String>(); static { @@ -140,7 +145,7 @@ public abstract class BaseBeanGenerator implements Opcodes { // Annotate the class annotateClass(cw, name, namespace, propOrder); - // Decalre the default constructor + // Declare the default constructor declareConstructor(cw, classSignature); if (properties != null) { for (BeanProperty p : properties) { @@ -228,8 +233,11 @@ public abstract class BaseBeanGenerator implements Opcodes { av0 = fv.visitAnnotation("Ljavax/xml/bind/annotation/XmlElement;", true); av0.visit("name", propName); av0.visit("namespace", ""); + // TUSCANY-3283 - force not nillable if it isn't if (isNillable) { av0.visit("nillable", Boolean.TRUE); + } else { + av0.visit("nillable", Boolean.FALSE); } // FIXME: // av0.visit("required", Boolean.FALSE); diff --git a/sca-java-2.x/trunk/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/FaultBeanGenerator.java b/sca-java-2.x/trunk/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/FaultBeanGenerator.java index 117253cebb..2e82428f7e 100644 --- a/sca-java-2.x/trunk/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/FaultBeanGenerator.java +++ b/sca-java-2.x/trunk/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/FaultBeanGenerator.java @@ -34,6 +34,8 @@ import java.util.List; import javax.xml.namespace.QName; import javax.xml.ws.WebFault; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; import org.apache.tuscany.sca.interfacedef.java.impl.JavaInterfaceUtil; import org.objectweb.asm.ClassWriter; @@ -72,9 +74,7 @@ public class FaultBeanGenerator extends BaseBeanGenerator { return props.toArray(new BeanProperty[0]); } - public byte[] generate(Class<? extends Throwable> exceptionClass) { - String className = getFaultBeanName(exceptionClass); - + public byte[] generate(Class<? extends Throwable> exceptionClass, Operation operation) { // The reflection code here allows for toleration of older versions of ASM. ClassWriter cw; try { @@ -91,35 +91,52 @@ public class FaultBeanGenerator extends BaseBeanGenerator { } - - + // TUSCANY-3283 - all generated classes (including exception) should go in the namespace + // of the interface not the namespace of the originating exception. + // consequently we need to create a matching package name for the schema + QName element = getElementName(exceptionClass, operation); + String name = element.getLocalPart(); + String namespace = element.getNamespaceURI(); + + String className = getFaultBeanName(exceptionClass, operation); String classDescriptor = className.replace('.', '/'); String classSignature = "L" + classDescriptor + ";"; - QName element = getElementName(exceptionClass); - String namespace = element.getNamespaceURI(); - String name = element.getLocalPart(); + return defineClass(cw, classDescriptor, classSignature, namespace, name, getProperties(exceptionClass)); } - public Class<?> generate(Class<? extends Throwable> exceptionClass, GeneratedClassLoader cl) { + public Class<?> generate(Class<? extends Throwable> exceptionClass, GeneratedClassLoader cl, Operation operation) { synchronized (exceptionClass) { - Class<?> faultBeanClass = generatedClasses.get(exceptionClass); + QName element = getElementName(exceptionClass, operation); + Class<?> faultBeanClass = generatedClasses.get(element); if (faultBeanClass == null) { - String className = getFaultBeanName(exceptionClass); + + // TUSCANY-3283 - all generated classes (including exception) should go in the namespace + // of the interface not the namespace of the originating exception. + // consequently we need to create a matching package name for the schema + String name = element.getLocalPart(); + String namespace = element.getNamespaceURI(); + + String className = getFaultBeanName(exceptionClass, operation); String classDescriptor = className.replace('.', '/'); String classSignature = "L" + classDescriptor + ";"; - QName element = getElementName(exceptionClass); - String namespace = element.getNamespaceURI(); - String name = element.getLocalPart(); - faultBeanClass = - generate(classDescriptor, classSignature, namespace, name, getProperties(exceptionClass), cl); - generatedClasses.put(exceptionClass, faultBeanClass); + + faultBeanClass = generate(classDescriptor, classSignature, namespace, name, getProperties(exceptionClass), cl); + generatedClasses.put(element, faultBeanClass); } return faultBeanClass; } } - private static String getFaultBeanName(Class<?> exceptionClass) { + private static String getFaultBeanName(Class<?> exceptionClass, Operation operation) { + // TUSCANY-3283 - all generated classes (including exception) should go in the namespace + // of the interface not the namespace of the originating exception. + // consequently we need to create a matching package name for the schema + String interfacePkg = null; + if (operation != null && operation.getInterface() instanceof JavaInterface){ + interfacePkg = ((JavaInterface)operation.getInterface()).getJavaClass().getPackage().getName(); + } + String faultBeanName = null; WebFault webFault = exceptionClass.getAnnotation(WebFault.class); if (webFault != null) { @@ -131,7 +148,12 @@ public class FaultBeanGenerator extends BaseBeanGenerator { String name = exceptionClass.getName(); int index = name.lastIndexOf('.'); - String pkg = name.substring(0, index); + String pkg = null; + if (interfacePkg != null){ + pkg = interfacePkg; + } else { + pkg = name.substring(0, index); + } String clsName = name.substring(index + 1); // FIXME: [rfeng] This is a workaround to avoid "Prohibited package name: java.lang.jaxws" @@ -142,9 +164,17 @@ public class FaultBeanGenerator extends BaseBeanGenerator { return faultBeanName; } - public static QName getElementName(Class<? extends Throwable> exceptionClass) { + public static QName getElementName(Class<? extends Throwable> exceptionClass, Operation operation) { WebFault webFault = exceptionClass.getAnnotation(WebFault.class); + + // TUSCANY-3283 - all generated classes (including exception) should go in the namespace + // of the interface not the namespace of the originating exception. + // consequently we need to create a matching package name for the schema String namespace = null; + if (operation != null && operation.getInterface() instanceof JavaInterface){ + namespace = ((JavaInterface)operation.getInterface()).getQName().getNamespaceURI(); + } + String name = null; if (webFault != null) { namespace = webFault.targetNamespace(); @@ -162,6 +192,6 @@ public class FaultBeanGenerator extends BaseBeanGenerator { public static Class<?> generateFaultBeanClass(Class<? extends Throwable> exceptionClass) { FaultBeanGenerator generator = new FaultBeanGenerator(); GeneratedClassLoader cl = new GeneratedClassLoader(exceptionClass.getClassLoader()); - return generator.generate(exceptionClass, cl); + return generator.generate(exceptionClass, cl, null); } } diff --git a/sca-java-2.x/trunk/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/GeneratedDataTypeImpl.java b/sca-java-2.x/trunk/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/GeneratedDataTypeImpl.java index c3f568ef48..2fbf374ac9 100644 --- a/sca-java-2.x/trunk/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/GeneratedDataTypeImpl.java +++ b/sca-java-2.x/trunk/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/GeneratedDataTypeImpl.java @@ -29,6 +29,8 @@ import javax.xml.namespace.QName; import org.apache.tuscany.sca.databinding.jaxb.JAXBDataBinding; import org.apache.tuscany.sca.databinding.jaxb.XMLAdapterExtensionPoint; import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; import org.apache.tuscany.sca.interfacedef.util.XMLType; /** @@ -48,16 +50,21 @@ public class GeneratedDataTypeImpl implements DataType<XMLType> { private String wrapperName; private boolean request; private GeneratedClassLoader classLoader; + private Operation operation; private Class<? extends Throwable> exceptionClass; - public GeneratedDataTypeImpl(XMLAdapterExtensionPoint xmlAdapters, Class<? extends Throwable> exceptionClass, GeneratedClassLoader cl) { + public GeneratedDataTypeImpl(XMLAdapterExtensionPoint xmlAdapters, + Class<? extends Throwable> exceptionClass, + GeneratedClassLoader cl, + Operation operation) { super(); this.exceptionClass = exceptionClass; this.classLoader = cl; - QName name = FaultBeanGenerator.getElementName(exceptionClass); + QName name = FaultBeanGenerator.getElementName(exceptionClass, operation); this.logical = new XMLType(name, name); this.xmlAdapters = xmlAdapters; + this.operation = operation; } public GeneratedDataTypeImpl(XMLAdapterExtensionPoint xmlAdapters, @@ -103,7 +110,7 @@ public class GeneratedDataTypeImpl implements DataType<XMLType> { } else if (exceptionClass != null) { FaultBeanGenerator faultBeanGenerator = new FaultBeanGenerator(); faultBeanGenerator.setXmlAdapters(xmlAdapters); - physical = faultBeanGenerator.generate(exceptionClass, classLoader); + physical = faultBeanGenerator.generate(exceptionClass, classLoader, operation); } } return physical; diff --git a/sca-java-2.x/trunk/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/JAXWSFaultExceptionMapper.java b/sca-java-2.x/trunk/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/JAXWSFaultExceptionMapper.java index fcf7006f16..166f1d6b6d 100644 --- a/sca-java-2.x/trunk/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/JAXWSFaultExceptionMapper.java +++ b/sca-java-2.x/trunk/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/JAXWSFaultExceptionMapper.java @@ -290,7 +290,7 @@ public class JAXWSFaultExceptionMapper implements FaultExceptionMapper { @SuppressWarnings("unchecked") public boolean introspectFaultDataType(DataType<DataType> exceptionType, final Operation operation, final boolean generatingFaultBean) { - QName faultName = null; + boolean result = false; final Class<?> cls = exceptionType.getPhysical(); @@ -298,6 +298,7 @@ public class JAXWSFaultExceptionMapper implements FaultExceptionMapper { return true; } DataType faultType = (DataType)exceptionType.getLogical(); + QName faultName = ((XMLType)faultType.getLogical()).getElementName(); Class<?> faultBean = null; final WebFault fault = cls.getAnnotation(WebFault.class); if (fault != null) { @@ -346,7 +347,7 @@ public class JAXWSFaultExceptionMapper implements FaultExceptionMapper { operation == null ? t.getClassLoader() : ((JavaInterface)operation.getInterface()) .getJavaClass().getClassLoader(); GeneratedClassLoader cl = new GeneratedClassLoader(parent); - GeneratedDataTypeImpl dt = new GeneratedDataTypeImpl(xmlAdapterExtensionPoint, t, cl); + GeneratedDataTypeImpl dt = new GeneratedDataTypeImpl(xmlAdapterExtensionPoint, t, cl, operation); return dt; } else { return new DataTypeImpl<XMLType>(cls, new XMLType(qname, qname)); diff --git a/sca-java-2.x/trunk/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/WrapperBeanGenerator.java b/sca-java-2.x/trunk/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/WrapperBeanGenerator.java index 6a664b366e..42151464a4 100644 --- a/sca-java-2.x/trunk/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/WrapperBeanGenerator.java +++ b/sca-java-2.x/trunk/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/WrapperBeanGenerator.java @@ -205,7 +205,9 @@ public class WrapperBeanGenerator extends BaseBeanGenerator { Type genericReturnType = asyncMethod? returnType : m.getGenericReturnType(); BeanProperty prop = new BeanProperty(propNS, propName, returnType, genericReturnType, true); prop.getJaxbAnnotaions().addAll(jaxb); - properties.add(prop); + // TUSCANY-3283 - As per JAXWS spec () the "return" value should come first in the + // list when there are holders. + properties.add(0, prop); } wrapperClass = generate(wrapperClassDescriptor, wrapperClassSignature, wrapperNamespace, wrapperName, properties diff --git a/sca-java-2.x/trunk/modules/interface-java-jaxws/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxws/FaultBeanGeneratorTestCase.java b/sca-java-2.x/trunk/modules/interface-java-jaxws/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxws/FaultBeanGeneratorTestCase.java index 3ea1427494..ce0adb076b 100644 --- a/sca-java-2.x/trunk/modules/interface-java-jaxws/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxws/FaultBeanGeneratorTestCase.java +++ b/sca-java-2.x/trunk/modules/interface-java-jaxws/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxws/FaultBeanGeneratorTestCase.java @@ -40,7 +40,7 @@ public class FaultBeanGeneratorTestCase { @Test public void testGenerate() throws IOException { - byte[] content = new FaultBeanGenerator().generate(MyException.class); + byte[] content = new FaultBeanGenerator().generate(MyException.class, null); ClassReader cr = new ClassReader(content); PrintWriter pw = new PrintWriter(System.out); CheckClassAdapter.verify(cr, false, pw); diff --git a/sca-java-2.x/trunk/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/WSDLDefinition.java b/sca-java-2.x/trunk/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/WSDLDefinition.java index 9fd4313af0..1fbbae970d 100644 --- a/sca-java-2.x/trunk/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/WSDLDefinition.java +++ b/sca-java-2.x/trunk/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/WSDLDefinition.java @@ -185,6 +185,14 @@ public interface WSDLDefinition extends Base { * Gets the wsdli:location attribute namespace mappings * @return a Map with key being namespace and value the location */ - Map<String, String> getWsdliLocations(); + Map<String, String> getWsdliLocations(); + + /** + * Find the schema definition for the provided namespace + * + * @param namespace + * @return the schema definition relating to the provided namespace or null if not found + */ + XSDefinition getSchema(String namespace); } diff --git a/sca-java-2.x/trunk/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/impl/WSDLDefinitionImpl.java b/sca-java-2.x/trunk/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/impl/WSDLDefinitionImpl.java index dc3afaa641..a0ff4723bf 100644 --- a/sca-java-2.x/trunk/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/impl/WSDLDefinitionImpl.java +++ b/sca-java-2.x/trunk/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/impl/WSDLDefinitionImpl.java @@ -361,4 +361,13 @@ public class WSDLDefinitionImpl implements WSDLDefinition { public Map<String, String> getWsdliLocations() { return wsdliLocations ; } + + public XSDefinition getSchema(String namespace){ + for (XSDefinition xsDef : schemas){ + if (xsDef.getNamespace().equals(namespace)){ + return xsDef; + } + } + return null; + } } diff --git a/sca-java-2.x/trunk/testing/itest/ws/pom.xml b/sca-java-2.x/trunk/testing/itest/ws/pom.xml index a6265984ae..adb471939e 100644 --- a/sca-java-2.x/trunk/testing/itest/ws/pom.xml +++ b/sca-java-2.x/trunk/testing/itest/ws/pom.xml @@ -61,6 +61,7 @@ <module>external-client</module> <module>external-service</module> <module>launcher-axis2</module> + <module>wsdlgen</module> </modules> </project> |