You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by am...@apache.org on 2007/03/21 13:14:18 UTC
svn commit: r520853 - in /webservices/axis2/trunk/java/modules: adb-codegen/
adb-codegen/src/org/apache/axis2/schema/template/
adb-codegen/test-resources/testsuite/
adb-codegen/test/org/apache/axis2/schema/attribute/
codegen/src/org/apache/axis2/wsdl/c...
Author: amilas
Date: Wed Mar 21 05:14:17 2007
New Revision: 520853
URL: http://svn.apache.org/viewvc?view=rev&rev=520853
Log:
fixed the issue 2360
Added:
webservices/axis2/trunk/java/modules/adb-codegen/test-resources/testsuite/testattribute.xsd
webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/attribute/
webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/attribute/AttributeTest.java
Modified:
webservices/axis2/trunk/java/modules/adb-codegen/maven.xml
webservices/axis2/trunk/java/modules/adb-codegen/pom.xml
webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate.xsl
webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/CodeGenerationEngine.java
Modified: webservices/axis2/trunk/java/modules/adb-codegen/maven.xml
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/adb-codegen/maven.xml?view=diff&rev=520853&r1=520852&r2=520853
==============================================================================
--- webservices/axis2/trunk/java/modules/adb-codegen/maven.xml (original)
+++ webservices/axis2/trunk/java/modules/adb-codegen/maven.xml Wed Mar 21 05:14:17 2007
@@ -249,6 +249,17 @@
<arg file="${testsuite.source.dir}/innersequence_choice.xsd"/>
<arg file="${schema.generated.src.dir}"/>
</java>
+
+ <!-- ################################################################### -->
+ <!-- All simple derived types xsd -->
+ <ant:echo>Compiling testattribute.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}/testattribute.xsd"/>
+ <arg file="${schema.generated.src.dir}"/>
+ </java>
<!-- ################################################################### -->
<!-- Compile the generated classes -->
Modified: webservices/axis2/trunk/java/modules/adb-codegen/pom.xml
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/adb-codegen/pom.xml?view=diff&rev=520853&r1=520852&r2=520853
==============================================================================
--- webservices/axis2/trunk/java/modules/adb-codegen/pom.xml (original)
+++ webservices/axis2/trunk/java/modules/adb-codegen/pom.xml Wed Mar 21 05:14:17 2007
@@ -332,7 +332,7 @@
<arg file="${testsuite.source.dir}/element_references.xsd"/>
<arg file="${schema.generated.src.dir}"/>
</java>
-<!-- ################################################################### -->
+ <!-- ################################################################### -->
<!-- All simple derived types xsd -->
<echo>Compiling innersequence_choice.xsd</echo>
<java classname="org.apache.axis2.schema.XSD2Java" fork="true">
@@ -340,6 +340,16 @@
<classpath refid="maven.runtime.classpath"/>
<classpath location="${compiled.classes.dir}"/>
<arg file="${testsuite.source.dir}/innersequence_choice.xsd"/>
+ <arg file="${schema.generated.src.dir}"/>
+ </java>
+ <!-- ################################################################### -->
+ <!-- All simple derived types xsd -->
+ <ant:echo>Compiling testattribute.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}/testattribute.xsd"/>
<arg file="${schema.generated.src.dir}"/>
</java>
Modified: webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate.xsl
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate.xsl?view=diff&rev=520853&r1=520852&r2=520853
==============================================================================
--- webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate.xsl (original)
+++ webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate.xsl Wed Mar 21 05:14:17 2007
@@ -826,6 +826,7 @@
<xsl:variable name="propertyName"><xsl:value-of select="@name"/></xsl:variable>
<xsl:variable name="varName">local<xsl:value-of select="@javaname"/></xsl:variable>
<xsl:variable name="namespace"><xsl:value-of select="@nsuri"/></xsl:variable>
+ <xsl:variable name="propertyType"><xsl:value-of select="@type"/></xsl:variable>
<xsl:choose>
<!-- Note - It is assumed that any attributes are OMAttributes-->
<xsl:when test="@any and not(@array)">
@@ -843,41 +844,61 @@
}
}
</xsl:when>
- <!-- there can never be attribute arrays in the normal case-->
- <xsl:when test="@optional">
- // optional attribute <xsl:value-of select="$propertyName"/>
- try {
- <xsl:choose>
- <xsl:when test="@ours">
- <!-- this can only be a simple type -->
- writeAttribute("<xsl:value-of select="$namespace"/>",
- "<xsl:value-of select="$propertyName"/>",
- <xsl:value-of select="$varName"/>.toString(), 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>
-
- } catch (NullPointerException e) {
- // If <xsl:value-of select="$varName"/> was null
- // it can not be serialized.
- }
- </xsl:when>
<xsl:otherwise>
- <xsl:choose>
+ <xsl:choose>
<xsl:when test="@ours">
<!-- this can only be a simple type -->
- writeAttribute("<xsl:value-of select="$namespace"/>",
+ if (<xsl:value-of select="$varName"/> != null){
+ writeAttribute("<xsl:value-of select="$namespace"/>",
"<xsl:value-of select="$propertyName"/>",
<xsl:value-of select="$varName"/>.toString(), xmlWriter);
+ }
+ <xsl:if test="not(@optional)">
+ else {
+ throw new RuntimeException("required attribute <xsl:value-of select="$varName"/> is null");
+ }
+ </xsl:if>
</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:choose>
+ <xsl:when test="@primitive">
+ <xsl:choose>
+ <xsl:when test="$propertyType='int'">
+ if (<xsl:value-of select="$varName"/>!=java.lang.Integer.MIN_VALUE) {
+ </xsl:when>
+ <xsl:when test="$propertyType='long'">
+ if (<xsl:value-of select="$varName"/>!=java.lang.Long.MIN_VALUE) {
+ </xsl:when>
+ <xsl:when test="$propertyType='byte'">
+ if (<xsl:value-of select="$varName"/>!=java.lang.Byte.MIN_VALUE) {
+ </xsl:when>
+ <xsl:when test="$propertyType='double'">
+ if (<xsl:value-of select="$varName"/>!=java.lang.Double.NaN) {
+ </xsl:when>
+ <xsl:when test="$propertyType='float'">
+ if (<xsl:value-of select="$varName"/>!=java.lang.Float.NaN) {
+ </xsl:when>
+ <xsl:when test="$propertyType='short'">
+ if (<xsl:value-of select="$varName"/>!=java.lang.Short.MIN_VALUE) {
+ </xsl:when>
+ <xsl:otherwise>
+ if (true) {
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:when>
+ <xsl:otherwise>
+ 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:if test="not(@optional)">
+ else {
+ throw new RuntimeException("required attribute <xsl:value-of select="$varName"/> is null");
+ }
+ </xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
@@ -2361,6 +2382,36 @@
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
+ } else {
+ <xsl:choose>
+ <xsl:when test="@optional">
+ <xsl:if test="@primitive">
+ <xsl:choose>
+ <xsl:when test="$propertyType='int'">
+ object.set<xsl:value-of select="$javaName"/>(java.lang.Integer.MIN_VALUE);
+ </xsl:when>
+ <xsl:when test="$propertyType='long'">
+ object.set<xsl:value-of select="$javaName"/>(java.lang.Long.MIN_VALUE);
+ </xsl:when>
+ <xsl:when test="$propertyType='byte'">
+ object.set<xsl:value-of select="$javaName"/>(java.lang.Byte.MIN_VALUE);
+ </xsl:when>
+ <xsl:when test="$propertyType='double'">
+ object.set<xsl:value-of select="$javaName"/>(java.lang.Double.NaN);
+ </xsl:when>
+ <xsl:when test="$propertyType='float'">
+ object.set<xsl:value-of select="$javaName"/>(java.lang.Float.NaN);
+ </xsl:when>
+ <xsl:when test="$propertyType='short'">
+ object.set<xsl:value-of select="$javaName"/>(java.lang.Short.MIN_VALUE);
+ </xsl:when>
+ </xsl:choose>
+ </xsl:if>
+ </xsl:when>
+ <xsl:otherwise>
+ throw new RuntimeException("Required attribute <xsl:value-of select="$propertyName"/> is missing");
+ </xsl:otherwise>
+ </xsl:choose>
}
handledAttributes.add("<xsl:value-of select="$propertyName"/>");
</xsl:if>
Added: webservices/axis2/trunk/java/modules/adb-codegen/test-resources/testsuite/testattribute.xsd
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/adb-codegen/test-resources/testsuite/testattribute.xsd?view=auto&rev=520853
==============================================================================
--- webservices/axis2/trunk/java/modules/adb-codegen/test-resources/testsuite/testattribute.xsd (added)
+++ webservices/axis2/trunk/java/modules/adb-codegen/test-resources/testsuite/testattribute.xsd Wed Mar 21 05:14:17 2007
@@ -0,0 +1,27 @@
+<xs:schema elementFormDefault="qualified"
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://tempuri.org/attribute"
+ targetNamespace="http://tempuri.org/attribute">
+
+ <xs:element name="TestElement1">
+ <xs:complexType>
+ <xs:attribute name="attribute1" type="xs:int" use="optional"/>
+ </xs:complexType>
+ </xs:element>
+ <xs:element name="TestElement2">
+ <xs:complexType>
+ <xs:attribute name="attribute1" type="xs:int"/>
+ </xs:complexType>
+ </xs:element>
+ <xs:element name="TestElement3">
+ <xs:complexType>
+ <xs:attribute name="attribute1" type="xs:string" use="optional"/>
+ </xs:complexType>
+ </xs:element>
+ <xs:element name="TestElement4">
+ <xs:complexType>
+ <xs:attribute name="attribute1" type="xs:string"/>
+ </xs:complexType>
+ </xs:element>
+
+</xs:schema>
\ No newline at end of file
Added: webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/attribute/AttributeTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/attribute/AttributeTest.java?view=auto&rev=520853
==============================================================================
--- webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/attribute/AttributeTest.java (added)
+++ webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/attribute/AttributeTest.java Wed Mar 21 05:14:17 2007
@@ -0,0 +1,148 @@
+/*
+ * 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.attribute;
+
+import junit.framework.TestCase;
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.util.StAXUtils;
+import org.tempuri.attribute.TestElement1;
+import org.tempuri.attribute.TestElement2;
+import org.tempuri.attribute.TestElement3;
+import org.tempuri.attribute.TestElement4;
+
+import javax.xml.stream.XMLStreamReader;
+import java.io.ByteArrayInputStream;
+
+public class AttributeTest extends TestCase {
+
+ public void testElement1(){
+
+ TestElement1 testElement = new TestElement1();
+ testElement.setAttribute1(1);
+
+ OMElement omElement = testElement.getOMElement(TestElement1.MY_QNAME, OMAbstractFactory.getOMFactory());
+ try {
+ String omElementString = omElement.toStringWithConsume();
+ System.out.println("OMElement ==> " + omElementString);
+ XMLStreamReader xmlReader = StAXUtils.createXMLStreamReader(new ByteArrayInputStream(omElementString.getBytes()));
+ TestElement1 result = TestElement1.Factory.parse(xmlReader);
+ assertEquals(result.getAttribute1(),1);
+ } catch (Exception e) {
+ fail();
+ }
+
+ testElement = new TestElement1();
+ testElement.setAttribute1(Integer.MIN_VALUE);
+
+ omElement = testElement.getOMElement(TestElement1.MY_QNAME, OMAbstractFactory.getOMFactory());
+ try {
+ String omElementString = omElement.toStringWithConsume();
+ System.out.println("OMElement ==> " + omElementString);
+ XMLStreamReader xmlReader = StAXUtils.createXMLStreamReader(new ByteArrayInputStream(omElementString.getBytes()));
+ TestElement1 result = TestElement1.Factory.parse(xmlReader);
+ assertEquals(result.getAttribute1(),Integer.MIN_VALUE);
+ } catch (Exception e) {
+ fail();
+ }
+ }
+
+ public void testElement2(){
+ TestElement2 testElement = new TestElement2();
+ testElement.setAttribute1(1);
+
+ OMElement omElement = testElement.getOMElement(TestElement2.MY_QNAME, OMAbstractFactory.getOMFactory());
+ try {
+ String omElementString = omElement.toStringWithConsume();
+ System.out.println("OMElement ==> " + omElementString);
+ XMLStreamReader xmlReader = StAXUtils.createXMLStreamReader(new ByteArrayInputStream(omElementString.getBytes()));
+ TestElement2 result = TestElement2.Factory.parse(xmlReader);
+ assertEquals(result.getAttribute1(),1);
+ } catch (Exception e) {
+ fail();
+ }
+
+ testElement = new TestElement2();
+ testElement.setAttribute1(Integer.MIN_VALUE);
+
+ omElement = testElement.getOMElement(TestElement2.MY_QNAME, OMAbstractFactory.getOMFactory());
+ try {
+ String omElementString = omElement.toStringWithConsume();
+ System.out.println("OMElement ==> " + omElementString);
+ fail();
+ } catch (Exception e) {
+ assertTrue(true);
+ }
+ }
+
+ public void testElement3(){
+ TestElement3 testElement = new TestElement3();
+ testElement.setAttribute1("test");
+
+ OMElement omElement = testElement.getOMElement(TestElement3.MY_QNAME, OMAbstractFactory.getOMFactory());
+ try {
+ String omElementString = omElement.toStringWithConsume();
+ System.out.println("OMElement ==> " + omElementString);
+ XMLStreamReader xmlReader = StAXUtils.createXMLStreamReader(new ByteArrayInputStream(omElementString.getBytes()));
+ TestElement3 result = TestElement3.Factory.parse(xmlReader);
+ assertEquals(result.getAttribute1(),"test");
+ } catch (Exception e) {
+ fail();
+ }
+
+ testElement = new TestElement3();
+
+ omElement = testElement.getOMElement(TestElement3.MY_QNAME, OMAbstractFactory.getOMFactory());
+
+ try {
+ String omElementString = omElement.toStringWithConsume();
+ System.out.println("OMElement ==> " + omElementString);
+ XMLStreamReader xmlReader = StAXUtils.createXMLStreamReader(new ByteArrayInputStream(omElementString.getBytes()));
+ TestElement3 result = TestElement3.Factory.parse(xmlReader);
+ assertEquals(result.getAttribute1(),null);
+ } catch (Exception e) {
+ fail();
+ }
+ }
+
+ public void testElement4(){
+ TestElement4 testElement = new TestElement4();
+ testElement.setAttribute1("test");
+
+ OMElement omElement = testElement.getOMElement(TestElement4.MY_QNAME, OMAbstractFactory.getOMFactory());
+ try {
+ String omElementString = omElement.toStringWithConsume();
+ System.out.println("OMElement ==> " + omElementString);
+ XMLStreamReader xmlReader = StAXUtils.createXMLStreamReader(new ByteArrayInputStream(omElementString.getBytes()));
+ TestElement4 result = TestElement4.Factory.parse(xmlReader);
+ assertEquals(result.getAttribute1(),"test");
+ } catch (Exception e) {
+ fail();
+ }
+
+ testElement = new TestElement4();
+
+ omElement = testElement.getOMElement(TestElement4.MY_QNAME, OMAbstractFactory.getOMFactory());
+
+ try {
+ String omElementString = omElement.toStringWithConsume();
+ System.out.println("OMElement ==> " + omElementString);
+ fail();
+ } catch (Exception e) {
+ assertTrue(true);
+ }
+ }
+}
Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/CodeGenerationEngine.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/CodeGenerationEngine.java?view=diff&rev=520853&r1=520852&r2=520853
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/CodeGenerationEngine.java (original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/CodeGenerationEngine.java Wed Mar 21 05:14:17 2007
@@ -260,7 +260,7 @@
* @param uri
* @throws WSDLException
*/
- private Definition readInTheWSDLFile(String uri) throws WSDLException {
+ public Definition readInTheWSDLFile(String uri) throws WSDLException {
WSDLReader reader = WSDLFactory.newInstance().newWSDLReader();
reader.setFeature("javax.wsdl.importDocuments", true);
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org