You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by am...@apache.org on 2007/05/11 14:35:59 UTC

svn commit: r537181 - in /webservices/axis2/branches/java/1_2/modules/adb-codegen: ./ src/org/apache/axis2/schema/template/ test-resources/testsuite/ test/org/apache/axis2/schema/defaultnamespaces/

Author: amilas
Date: Fri May 11 05:35:58 2007
New Revision: 537181

URL: http://svn.apache.org/viewvc?view=rev&rev=537181
Log:
fixed some namespace handling bugs

Added:
    webservices/axis2/branches/java/1_2/modules/adb-codegen/test-resources/testsuite/default_namespaces.xsd
    webservices/axis2/branches/java/1_2/modules/adb-codegen/test/org/apache/axis2/schema/defaultnamespaces/
    webservices/axis2/branches/java/1_2/modules/adb-codegen/test/org/apache/axis2/schema/defaultnamespaces/DefaultNamespacesTest.java
Modified:
    webservices/axis2/branches/java/1_2/modules/adb-codegen/maven.xml
    webservices/axis2/branches/java/1_2/modules/adb-codegen/pom.xml
    webservices/axis2/branches/java/1_2/modules/adb-codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate.xsl

Modified: webservices/axis2/branches/java/1_2/modules/adb-codegen/maven.xml
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_2/modules/adb-codegen/maven.xml?view=diff&rev=537181&r1=537180&r2=537181
==============================================================================
--- webservices/axis2/branches/java/1_2/modules/adb-codegen/maven.xml (original)
+++ webservices/axis2/branches/java/1_2/modules/adb-codegen/maven.xml Fri May 11 05:35:58 2007
@@ -294,6 +294,18 @@
             <arg file="${schema.generated.src.dir}"/>
         </java>
 
+
+        <!-- ################################################################### -->
+        <!-- All simple derived types xsd -->
+        <ant:echo>Compiling default_namespaces.xsd</ant:echo>
+        <java classname="org.apache.axis2.schema.XSD2Java" fork="true">
+            <jvmarg line="${maven.junit.jvmargs}"/>
+            <classpath refid="maven.dependency.classpath"/>
+            <classpath location="${compiled.classes.dir}"/>
+            <arg file="${testsuite.source.dir}/default_namespaces.xsd"/>
+            <arg file="${schema.generated.src.dir}"/>
+        </java>
+
         <!-- ################################################################### -->
         <!-- Compile the generated classes -->
         <javac destdir="${schema.generated.classes.dir}" srcdir="${schema.generated.src.dir}">

Modified: webservices/axis2/branches/java/1_2/modules/adb-codegen/pom.xml
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_2/modules/adb-codegen/pom.xml?view=diff&rev=537181&r1=537180&r2=537181
==============================================================================
--- webservices/axis2/branches/java/1_2/modules/adb-codegen/pom.xml (original)
+++ webservices/axis2/branches/java/1_2/modules/adb-codegen/pom.xml Fri May 11 05:35:58 2007
@@ -338,31 +338,43 @@
 									<arg file="${testsuite.source.dir}/boolean.xsd"/>
 									<arg file="${schema.generated.src.dir}"/>
 								</java>
-                                                                <!-- ################################################################### -->
-        <!-- All simple derived types xsd -->
-        <ant:echo>Compiling particalMaxOccures.xsd</ant:echo>
-        <java classname="org.apache.axis2.schema.XSD2Java" fork="true">
-            <jvmarg line="${maven.junit.jvmargs}"/>
-            <classpath refid="maven.dependency.classpath"/>
-            <classpath location="${compiled.classes.dir}"/>
-            <arg file="${testsuite.source.dir}/particalMaxOccures.xsd"/>
-            <arg file="${schema.generated.src.dir}"/>
-        </java>
 
-        <!-- ################################################################### -->
-        <!-- All simple derived types xsd -->
-        <ant:echo>Compiling innerParticles.xsd</ant:echo>
-        <java classname="org.apache.axis2.schema.XSD2Java" fork="true">
-            <jvmarg line="${maven.junit.jvmargs}"/>
-            <classpath refid="maven.dependency.classpath"/>
-            <classpath location="${compiled.classes.dir}"/>
-            <arg file="${testsuite.source.dir}/innerParticles.xsd"/>
-            <arg file="${schema.generated.src.dir}"/>
-        </java>
+                                <!-- ################################################################### -->
+                                <!-- All simple derived types xsd -->
+                                <ant:echo>Compiling particalMaxOccures.xsd</ant:echo>
+                                <java classname="org.apache.axis2.schema.XSD2Java" fork="true">
+                                    <jvmarg line="${maven.junit.jvmargs}"/>
+                                    <classpath refid="maven.dependency.classpath"/>
+                                    <classpath location="${compiled.classes.dir}"/>
+                                    <arg file="${testsuite.source.dir}/particalMaxOccures.xsd"/>
+                                    <arg file="${schema.generated.src.dir}"/>
+                                </java>
+
+                                <!-- ################################################################### -->
+                                <!-- All simple derived types xsd -->
+                                <ant:echo>Compiling innerParticles.xsd</ant:echo>
+                                <java classname="org.apache.axis2.schema.XSD2Java" fork="true">
+                                    <jvmarg line="${maven.junit.jvmargs}"/>
+                                    <classpath refid="maven.dependency.classpath"/>
+                                    <classpath location="${compiled.classes.dir}"/>
+                                    <arg file="${testsuite.source.dir}/innerParticles.xsd"/>
+                                    <arg file="${schema.generated.src.dir}"/>
+                                </java>
+
+                                <!-- ################################################################### -->
+                                <!-- All simple derived types xsd -->
+                                <ant:echo>Compiling default_namespaces.xsd</ant:echo>
+                                <java classname="org.apache.axis2.schema.XSD2Java" fork="true">
+                                    <jvmarg line="${maven.junit.jvmargs}"/>
+                                    <classpath refid="maven.dependency.classpath"/>
+                                    <classpath location="${compiled.classes.dir}"/>
+                                    <arg file="${testsuite.source.dir}/default_namespaces.xsd"/>
+                                    <arg file="${schema.generated.src.dir}"/>
+                                </java>
 					                       
 
 
-							</tasks>
+                            </tasks>
 						</configuration>
 						<goals>
 							<goal>run</goal>

Modified: webservices/axis2/branches/java/1_2/modules/adb-codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate.xsl
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_2/modules/adb-codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate.xsl?view=diff&rev=537181&r1=537180&r2=537181
==============================================================================
--- webservices/axis2/branches/java/1_2/modules/adb-codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate.xsl (original)
+++ webservices/axis2/branches/java/1_2/modules/adb-codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate.xsl Fri May 11 05:35:58 2007
@@ -739,9 +739,17 @@
                 <xsl:for-each select="memberType">
                       <xsl:if test="position() > 1">} else </xsl:if>
                       if (localObject instanceof <xsl:value-of select="@type"/>){
-                            writeAttribute("xsi","http://www.w3.org/2001/XMLSchema-instance","type",
-                               registerPrefix(xmlWriter,"<xsl:value-of select="@nsuri"/>")+":<xsl:value-of select="@originalName"/>",
-                               xmlWriter);
+                           java.lang.String namespacePrefix = registerPrefix(xmlWriter,"<xsl:value-of select="@nsuri"/>");
+                           if ((namespacePrefix != null) &amp;&amp; (namespacePrefix.trim().length() > 0)){
+                               writeAttribute("xsi","http://www.w3.org/2001/XMLSchema-instance","type",
+                                   namespacePrefix+":<xsl:value-of select="@originalName"/>",
+                                   xmlWriter);
+                           } else {
+                               writeAttribute("xsi","http://www.w3.org/2001/XMLSchema-instance","type",
+                                   "<xsl:value-of select="@originalName"/>",
+                                   xmlWriter);
+                           }
+
                        <xsl:choose>
                            <xsl:when test="@type='javax.xml.namespace.QName'">
                                writeQName((javax.xml.namespace.QName)localObject,xmlWriter);
@@ -830,9 +838,17 @@
 
                 <!-- write the type attribute if needed -->
                <xsl:if test="$extension">
-               writeAttribute("xsi","http://www.w3.org/2001/XMLSchema-instance","type",
-                       registerPrefix(xmlWriter,"<xsl:value-of select="$nsuri"/>")+":<xsl:value-of select="$originalName"/>",
+               java.lang.String namespacePrefix = registerPrefix(xmlWriter,"<xsl:value-of select="$nsuri"/>");
+               if ((namespacePrefix != null) &amp;&amp; (namespacePrefix.trim().length() > 0)){
+                   writeAttribute("xsi","http://www.w3.org/2001/XMLSchema-instance","type",
+                       namespacePrefix+":<xsl:value-of select="$originalName"/>",
                        xmlWriter);
+               } else {
+                   writeAttribute("xsi","http://www.w3.org/2001/XMLSchema-instance","type",
+                       "<xsl:value-of select="$originalName"/>",
+                       xmlWriter);
+               }
+
                </xsl:if>
                 <!--First serialize the attributes!-->
                 <xsl:for-each select="property[@attribute]">
@@ -903,10 +919,21 @@
                                             if (<xsl:value-of select="$varName"/> != null){
                                         </xsl:otherwise>
                                     </xsl:choose>
-                                        writeAttribute("<xsl:value-of select="$namespace"/>",
-                                                  "<xsl:value-of select="$propertyName"/>",
-                                                  org.apache.axis2.databinding.utils.ConverterUtil.convertToString(<xsl:value-of select="$varName"/>), xmlWriter);
-                                    }
+                                        <xsl:choose>
+                                            <xsl:when test="$propertyType='javax.xml.namespace.QName'">
+                                                writeQNameAttribute("<xsl:value-of select="$namespace"/>",
+                                                         "<xsl:value-of select="$propertyName"/>",
+                                                         <xsl:value-of select="$varName"/>, xmlWriter);
+
+                                            </xsl:when>
+                                            <xsl:otherwise>
+                                                writeAttribute("<xsl:value-of select="$namespace"/>",
+                                                         "<xsl:value-of select="$propertyName"/>",
+                                                         org.apache.axis2.databinding.utils.ConverterUtil.convertToString(<xsl:value-of select="$varName"/>), xmlWriter);
+
+                                            </xsl:otherwise>
+                                        </xsl:choose>
+                                      }
                                     <xsl:if test="not(@optional)">
                                       else {
                                           throw new RuntimeException("required attribute <xsl:value-of select="$varName"/> is null");
@@ -1702,22 +1729,48 @@
 
          }
 
-         /**
+        /**
           * Util method to write an attribute without the ns prefix
           */
           private void writeAttribute(java.lang.String namespace,java.lang.String attName,
                                       java.lang.String attValue,javax.xml.stream.XMLStreamWriter xmlWriter) throws javax.xml.stream.XMLStreamException{
-    	  	  if (namespace.equals(""))
-        	  {
-        		  xmlWriter.writeAttribute(attName,attValue);
-        	  }
-        	  else
-        	  {
+                if (namespace.equals(""))
+              {
+                  xmlWriter.writeAttribute(attName,attValue);
+              }
+              else
+              {
                   registerPrefix(xmlWriter, namespace);
                   xmlWriter.writeAttribute(namespace,attName,attValue);
               }
           }
 
+
+           /**
+             * Util method to write an attribute without the ns prefix
+             */
+            private void writeQNameAttribute(java.lang.String namespace, java.lang.String attName,
+                                             javax.xml.namespace.QName qname, javax.xml.stream.XMLStreamWriter xmlWriter) throws javax.xml.stream.XMLStreamException {
+
+                java.lang.String attributeNamespace = qname.getNamespaceURI();
+                java.lang.String attributePrefix = xmlWriter.getPrefix(attributeNamespace);
+                if (attributePrefix == null) {
+                    attributePrefix = registerPrefix(xmlWriter, attributeNamespace);
+                }
+                java.lang.String attributeValue;
+                if (attributePrefix.trim().length() > 0) {
+                    attributeValue = attributePrefix + ":" + qname.getLocalPart();
+                } else {
+                    attributeValue = qname.getLocalPart();
+                }
+
+                if (namespace.equals("")) {
+                    xmlWriter.writeAttribute(attName, attributeValue);
+                } else {
+                    registerPrefix(xmlWriter, namespace);
+                    xmlWriter.writeAttribute(namespace, attName, attributeValue);
+                }
+            }
         /**
          *  method to handle Qnames
          */
@@ -1732,7 +1785,14 @@
                     xmlWriter.writeNamespace(prefix, namespaceURI);
                     xmlWriter.setPrefix(prefix,namespaceURI);
                 }
-                xmlWriter.writeCharacters(prefix + ":" + org.apache.axis2.databinding.utils.ConverterUtil.convertToString(qname));
+
+                if (prefix.trim().length() > 0){
+                    xmlWriter.writeCharacters(prefix + ":" + org.apache.axis2.databinding.utils.ConverterUtil.convertToString(qname));
+                } else {
+                    // i.e this is the default namespace
+                    xmlWriter.writeCharacters(org.apache.axis2.databinding.utils.ConverterUtil.convertToString(qname));
+                }
+
             } else {
                 xmlWriter.writeCharacters(org.apache.axis2.databinding.utils.ConverterUtil.convertToString(qname));
             }
@@ -1760,7 +1820,12 @@
                             xmlWriter.writeNamespace(prefix, namespaceURI);
                             xmlWriter.setPrefix(prefix,namespaceURI);
                         }
-                        stringToWrite.append(prefix).append(":").append(org.apache.axis2.databinding.utils.ConverterUtil.convertToString(qnames[i]));
+
+                        if (prefix.trim().length() > 0){
+                            stringToWrite.append(prefix).append(":").append(org.apache.axis2.databinding.utils.ConverterUtil.convertToString(qnames[i]));
+                        } else {
+                            stringToWrite.append(org.apache.axis2.databinding.utils.ConverterUtil.convertToString(qnames[i]));
+                        }
                     } else {
                         stringToWrite.append(org.apache.axis2.databinding.utils.ConverterUtil.convertToString(qnames[i]));
                     }
@@ -2157,7 +2222,11 @@
                     for (int i = 0; i &lt; values.length; i++) {
                       <xsl:choose>
                           <xsl:when test="$varType='javax.xml.namespace.QName'">
-                              prefix = values[i].substring(0,values[i].indexOf(":"));
+                              if (values[i].indexOf(":") > 0){
+                                 prefix = values[i].substring(0,values[i].indexOf(":"));
+                              } else {
+                                 prefix = "";
+                              }
                               namespace = xmlStreamReader.getNamespaceURI(prefix);
                               objectValues[i] = org.apache.axis2.databinding.utils.ConverterUtil.convertToQName(values[i],namespace);
                           </xsl:when>
@@ -2165,11 +2234,11 @@
                            valueContent = values[i];
                            if (valueContent.indexOf(":") > 0){
                                prefix = valueContent.substring(0,valueContent.indexOf(":"));
-                               namespace = xmlStreamReader.getNamespaceURI(prefix);
-                               objectValues[i] = <xsl:value-of select="$varType"/>.Factory.fromString(valueContent,namespace);
                            } else {
-                               objectValues[i] = <xsl:value-of select="$varType"/>.Factory.fromString(valueContent,"");
+                               prefix = "";
                            }
+                           namespace = xmlStreamReader.getNamespaceURI(prefix);
+                           objectValues[i] = <xsl:value-of select="$varType"/>.Factory.fromString(valueContent,namespace);
                           </xsl:when>
                           <xsl:otherwise>
                            objectValues[i] =
@@ -2384,10 +2453,13 @@
                         <xsl:choose>
                             <xsl:when test="$propertyType='javax.xml.namespace.QName'">
                                 int index = <xsl:value-of select="$attribName"/>.indexOf(":");
-                                if(index > 0){
+                                if(index > -1){
                                      prefix = <xsl:value-of select="$attribName"/>.substring(0,index);
-                                     namespaceuri = reader.getNamespaceURI(prefix);
-                                 }
+                                } else {
+                                    // i.e this is in default namesace
+                                    prefix = "";
+                                }
+                                namespaceuri = reader.getNamespaceURI(prefix);
                                  <xsl:choose>
                                      <xsl:when test="$isEnumFacet">
                                         attributeMap.put("<xsl:value-of select="$javaName"/>",
@@ -3130,9 +3202,11 @@
                                             <xsl:when test="$propertyType='javax.xml.namespace.QName'">
                                             int index = content.indexOf(":");
                                             if(index > 0){
-                                                 prefix = content.substring(0,index);
-                                                 namespaceuri = reader.getNamespaceURI(prefix);
+                                                prefix = content.substring(0,index);
+                                             } else {
+                                                prefix = "";
                                              }
+                                             namespaceuri = reader.getNamespaceURI(prefix);
                                              object.set<xsl:value-of select="$javaName"/>(
                                                   org.apache.axis2.databinding.utils.ConverterUtil.convertToQName(content,namespaceuri));
                                             </xsl:when>

Added: webservices/axis2/branches/java/1_2/modules/adb-codegen/test-resources/testsuite/default_namespaces.xsd
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_2/modules/adb-codegen/test-resources/testsuite/default_namespaces.xsd?view=auto&rev=537181
==============================================================================
--- webservices/axis2/branches/java/1_2/modules/adb-codegen/test-resources/testsuite/default_namespaces.xsd (added)
+++ webservices/axis2/branches/java/1_2/modules/adb-codegen/test-resources/testsuite/default_namespaces.xsd Fri May 11 05:35:58 2007
@@ -0,0 +1,30 @@
+<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+            xmlns:tns="http://tempuri.org/defaultnamepaces"
+            targetNamespace="http://tempuri.org/defaultnamepaces"
+            elementFormDefault="qualified">
+
+    <!-- extension class -->
+    <xsd:simpleType name="TestSimpleUnion">
+        <xsd:union memberTypes="xsd:boolean xsd:QName"/>
+    </xsd:simpleType>
+    <xsd:element name="TestElement1" type="tns:TestParentType"/>
+    <xsd:complexType name="TestParentType">
+        <xsd:sequence>
+            <xsd:element name="param1" type="xsd:QName"/>
+            <xsd:element name="param2" type="xsd:string"/>
+        </xsd:sequence>
+    </xsd:complexType>
+    <xsd:complexType name="TestChildType">
+        <xsd:complexContent>
+            <xsd:extension base="tns:TestParentType">
+                <xsd:sequence>
+                    <xsd:element name="param3" type="xsd:QName"/>
+                    <xsd:element name="param4" type="xsd:string"/>
+                    <xsd:element name="param5" type="tns:TestSimpleUnion"/>
+                </xsd:sequence>
+                <xsd:attribute name="attribute1" type="xsd:string"/>
+                <xsd:attribute name="attribute2" type="xsd:QName"/>
+            </xsd:extension>
+        </xsd:complexContent>
+    </xsd:complexType>
+</xsd:schema>
\ No newline at end of file

Added: webservices/axis2/branches/java/1_2/modules/adb-codegen/test/org/apache/axis2/schema/defaultnamespaces/DefaultNamespacesTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_2/modules/adb-codegen/test/org/apache/axis2/schema/defaultnamespaces/DefaultNamespacesTest.java?view=auto&rev=537181
==============================================================================
--- webservices/axis2/branches/java/1_2/modules/adb-codegen/test/org/apache/axis2/schema/defaultnamespaces/DefaultNamespacesTest.java (added)
+++ webservices/axis2/branches/java/1_2/modules/adb-codegen/test/org/apache/axis2/schema/defaultnamespaces/DefaultNamespacesTest.java Fri May 11 05:35:58 2007
@@ -0,0 +1,91 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.axis2.schema.defaultnamespaces;
+
+import org.tempuri.defaultnamepaces.TestElement1;
+import org.tempuri.defaultnamepaces.TestChildType;
+import org.tempuri.defaultnamepaces.TestSimpleUnion;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.util.StAXUtils;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+import javax.xml.namespace.QName;
+
+import junit.framework.TestCase;
+
+import java.io.ByteArrayInputStream;
+import java.io.StringWriter;
+
+public class DefaultNamespacesTest extends TestCase {
+
+    public void testTestElement1() {
+
+        TestElement1 testElement1 = new TestElement1();
+
+        TestChildType testChildType = new TestChildType();
+        testChildType.setParam1(new QName("http://tempuri.org/defaultnamepaces", "param1"));
+        testChildType.setParam2("Param2");
+        testChildType.setParam3(new QName("http://tempuri.org/defaultnamepaces", "param3"));
+        testChildType.setParam4("Param4");
+
+        TestSimpleUnion testSimpleUnion1 = new TestSimpleUnion();
+        testSimpleUnion1.setObject(new QName("http://tempuri.org/defaultnamepaces", "param5"));
+
+        testChildType.setParam5(testSimpleUnion1);
+
+        testChildType.setAttribute1("attribute1");
+        testChildType.setAttribute2(new QName("http://tempuri.org/defaultnamepaces", "attribute2"));
+
+        TestSimpleUnion testSimpleUnion2 = new TestSimpleUnion();
+        testSimpleUnion2.setObject(new QName("http://tempuri.org/defaultnamepaces", "attribute3"));
+
+
+        testElement1.setTestElement1(testChildType);
+        StringWriter stringWriter = new StringWriter();
+
+        try {
+
+            XMLStreamWriter xmlStreamWriter = StAXUtils.createXMLStreamWriter(stringWriter);
+
+            testElement1.getTestElement1().serialize(new QName("http://tempuri.org/defaultnamepaces", "TestElement1", "ns1"),
+                    OMAbstractFactory.getSOAP11Factory(), xmlStreamWriter);
+            xmlStreamWriter.flush();
+            xmlStreamWriter.close();
+            String omElementString = stringWriter.toString();
+            System.out.println("OM String ==> " + omElementString);
+            XMLStreamReader xmlReader = StAXUtils.createXMLStreamReader(new ByteArrayInputStream(omElementString.getBytes()));
+            TestElement1 result = TestElement1.Factory.parse(xmlReader);
+            assertTrue(result.getTestElement1() instanceof TestChildType);
+            TestChildType resultType = (TestChildType) result.getTestElement1();
+            assertEquals(resultType.getParam1(), new QName("http://tempuri.org/defaultnamepaces", "param1"));
+            assertEquals(resultType.getParam2(), "Param2");
+            assertEquals(resultType.getParam3(), new QName("http://tempuri.org/defaultnamepaces", "param3"));
+            assertEquals(resultType.getParam4(), "Param4");
+            assertEquals(resultType.getAttribute1(), "attribute1");
+            assertEquals(resultType.getAttribute2(), new QName("http://tempuri.org/defaultnamepaces", "attribute2"));
+        } catch (XMLStreamException e) {
+
+            fail();
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail();
+        }
+
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org