TUSCANY-3859: Update "no namespace" type references in xs:extension schema elements

git-svn-id: https://svn.apache.org/repos/asf/tuscany/sca-java-1.x/trunk@1091732 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/itest/wsdlgen-verify/src/main/java/wsdlgen/verify/BaseClass.java b/itest/wsdlgen-verify/src/main/java/wsdlgen/verify/BaseClass.java
new file mode 100644
index 0000000..b9b7d6e
--- /dev/null
+++ b/itest/wsdlgen-verify/src/main/java/wsdlgen/verify/BaseClass.java
@@ -0,0 +1,46 @@
+/*

+ * 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 wsdlgen.verify;

+

+import java.io.Serializable;

+

+public class BaseClass implements Serializable {

+    private static final long serialVersionUID = -4086312879555658070L;

+

+    private long id;

+

+    private String commentair;

+    

+    public long getId() {

+        return id;

+    }

+

+    public void setId(long id) {

+        this.id = id;

+    }

+

+    public String getCommentair() {

+        return commentair;

+    }

+

+    public void setCommentair(String commentair) {

+        this.commentair = commentair;

+    }

+}

diff --git a/itest/wsdlgen-verify/src/main/java/wsdlgen/verify/DataTypes.java b/itest/wsdlgen-verify/src/main/java/wsdlgen/verify/DataTypes.java
index 68b87d3..5715b24 100644
--- a/itest/wsdlgen-verify/src/main/java/wsdlgen/verify/DataTypes.java
+++ b/itest/wsdlgen-verify/src/main/java/wsdlgen/verify/DataTypes.java
@@ -50,6 +50,8 @@
 

     void testByteArray(byte[] byteArray);

 

+    void testBaseExtension(ExtClass ext);

+

     void testException() throws Exception;

 

     DataObject testDynamicSDO();

diff --git a/itest/wsdlgen-verify/src/main/java/wsdlgen/verify/ExtClass.java b/itest/wsdlgen-verify/src/main/java/wsdlgen/verify/ExtClass.java
new file mode 100644
index 0000000..fe6f6fe
--- /dev/null
+++ b/itest/wsdlgen-verify/src/main/java/wsdlgen/verify/ExtClass.java
@@ -0,0 +1,34 @@
+/*

+ * 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 wsdlgen.verify;

+

+public class ExtClass extends BaseClass {

+    private static final long serialVersionUID = 7076974968473202208L;

+

+    private String name;

+

+    public String getName() {

+        return name;

+    }

+

+    public void setName(String name) {

+        this.name = name;

+    }

+}

diff --git a/itest/wsdlgen-verify/src/main/java/wsdlgen/verify/impl/DataTypesImpl.java b/itest/wsdlgen-verify/src/main/java/wsdlgen/verify/impl/DataTypesImpl.java
index 55e5994..9d9cf8c 100644
--- a/itest/wsdlgen-verify/src/main/java/wsdlgen/verify/impl/DataTypesImpl.java
+++ b/itest/wsdlgen-verify/src/main/java/wsdlgen/verify/impl/DataTypesImpl.java
@@ -23,8 +23,10 @@
 import javax.jws.WebParam;

 import javax.jws.soap.SOAPBinding;

 import commonj.sdo.DataObject;

+import wsdlgen.verify.BaseClass;

 import wsdlgen.verify.ComplexNumber;

 import wsdlgen.verify.DataTypes;

+import wsdlgen.verify.ExtClass;

 

 public class DataTypesImpl implements DataTypes {

 

@@ -62,6 +64,9 @@
     public void testByteArray(byte[] byteArray) {

     }

 

+    public void testBaseExtension(ExtClass ext) {

+    }

+

     public void testException() throws Exception {

     }

 

diff --git a/itest/wsdlgen-verify/src/test/java/wsdlgen/verify/BaseFramework.java b/itest/wsdlgen-verify/src/test/java/wsdlgen/verify/BaseFramework.java
index 06b6bb7..e8abc95 100644
--- a/itest/wsdlgen-verify/src/test/java/wsdlgen/verify/BaseFramework.java
+++ b/itest/wsdlgen-verify/src/test/java/wsdlgen/verify/BaseFramework.java
@@ -199,6 +199,16 @@
         return (Element)childNodes.item(0);

     }

 

+    protected Element extensionElement(Element complexType) {

+        // find xs:complexContent child element

+        NodeList childNodes = complexType.getElementsByTagNameNS(SCHEMA_NS, "complexContent");

+        Element complexContent = (Element)childNodes.item(0);

+

+        // find first xs:extension child element

+        childNodes = complexContent.getElementsByTagNameNS(SCHEMA_NS, "extension");

+        return (Element)childNodes.item(0);

+    }

+

     private static void readWSDL(String serviceName) throws Exception {

         WSDLReader wsdlReader = WSDLFactory.newInstance().newWSDLReader();

         wsdlReader.setFeature("javax.wsdl.verbose",false);

diff --git a/itest/wsdlgen-verify/src/test/java/wsdlgen/verify/DataTypesTestCase.java b/itest/wsdlgen-verify/src/test/java/wsdlgen/verify/DataTypesTestCase.java
index 9071edb..b6dbeec 100644
--- a/itest/wsdlgen-verify/src/test/java/wsdlgen/verify/DataTypesTestCase.java
+++ b/itest/wsdlgen-verify/src/test/java/wsdlgen/verify/DataTypesTestCase.java
@@ -107,6 +107,13 @@
     }

 

     @Test

+    public void testBaseExtension() throws Exception {

+        String paramType = parameterType("testBaseExtension");

+        assertEquals("tns:extClass", paramType);

+        assertEquals("tns:baseClass", extensionElement(typeDefinition(paramType)).getAttribute("base"));

+    }

+

+    @Test

     public void testException() throws Exception {

         assertEquals("xs:string", faultType("testException", "Exception"));

     }

diff --git a/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/Interface2WSDLGenerator.java b/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/Interface2WSDLGenerator.java
index 00a767c..ecd11dd 100644
--- a/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/Interface2WSDLGenerator.java
+++ b/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/Interface2WSDLGenerator.java
@@ -728,41 +728,56 @@
 	                _import.getParentNode().removeChild(_import);
 	            }
 	
-	            // look for any type attributes that refer to the 
-	            // node being merged
-	            NodeList elements = refSchema.getElementsByTagNameNS("http://www.w3.org/2001/XMLSchema","element");
-	            for (int k = 0; k < elements.getLength(); k++){
-	                Element element = (Element) elements.item(k);
-	                if (element != null && element.getAttributes() != null) {
-	                    Node type = element.getAttributes().getNamedItem("type");
-	                    
-	                    if (type != null &&
-	                        type.getNodeValue().equals(typeName)){
-	                        if (xsDef.getNamespace().equals(defaultNamespace)){
-	                            // double check that there is a "tns" namespace shortname specified
-	                            String tnsNamespace = refSchema.getDocumentElement().getAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:tns");
-	                            
-	                            if (tnsNamespace == null || tnsNamespace.length() == 0) {
-	                                refSchema.getDocumentElement().setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:tns", defaultNamespace);
-	                            }
-	                            
-	                            // just add "tns" in front of the type name as
-	                            // we have merged the type into this schema
-	                            type.setNodeValue("tns:" + type.getNodeValue());
-	                        } else {
-	                            // add a namespace 
-	                            refSchema.getDocumentElement().setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:__nnns", defaultNamespace);
-	
-	                            // prefix the type name with the namespace
-	                            type.setNodeValue("__nnns:" + type.getNodeValue());
-	                        }
-	                    }
-	                }
-	            }
+	            // TUSCANY-3859: Look for any attributes that refer to the node being merged
+                fixUpNoNamespaceAttributes("element", "type", xsDef, typeName, defaultNamespace);
+                fixUpNoNamespaceAttributes("extension", "base", xsDef, typeName, defaultNamespace);
         	}
         }
     }
 
+    /**
+     * TUSCANY-3859 
+     * Correct any schema attributes that used to point to types in the no namespace schema
+     * 
+     * @param elementName
+     * @param attributeName
+     * @param xsDef
+     * @param defaultNamespace
+     */  
+    private void fixUpNoNamespaceAttributes(String elementName, String attributeName,
+                                            XSDefinition xsDef, String typeName, String defaultNamespace) {
+        Document refSchema = xsDef.getDocument();
+        NodeList elements = refSchema.getElementsByTagNameNS("http://www.w3.org/2001/XMLSchema", elementName);
+        for (int k = 0; k < elements.getLength(); k++){
+            Element element = (Element) elements.item(k);
+            if (element != null && element.getAttributes() != null) {
+                Node type = element.getAttributes().getNamedItem(attributeName);
+                
+                if (type != null &&
+                    type.getNodeValue().equals(typeName)){
+                    if (xsDef.getNamespace().equals(defaultNamespace)){
+                        // double check that there is a "tns" namespace shortname specified
+                        String tnsNamespace = refSchema.getDocumentElement().getAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:tns");
+                        
+                        if (tnsNamespace == null || tnsNamespace.length() == 0) {
+                            refSchema.getDocumentElement().setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:tns", defaultNamespace);
+                        }
+                        
+                        // just add "tns" in front of the type name as
+                        // we have merged the type into this schema
+                        type.setNodeValue("tns:" + type.getNodeValue());
+                    } else {
+                        // add a namespace 
+                        refSchema.getDocumentElement().setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:__nnns", defaultNamespace);
+    
+                        // prefix the type name with the namespace
+                        type.setNodeValue("__nnns:" + type.getNodeValue());
+                    }
+                }
+            }
+        }
+    }
+
     /*
      * Just used when debugging DOM problems
      */