dims 2003/01/08 08:06:29 Modified: java/src/org/apache/axis/utils BeanUtils.java java/test/encoding PackageTests.java java/src/org/apache/axis/description TypeDesc.java Added: java/test/encoding DerivatedBean.java SuperBean.java TestDerivatedBeanSerializer.java Log: Fix for Bug 14540 - Inherited attributes are lost during serialization. Thanks to [EMAIL PROTECTED] (Matthias David) for the test case and the bug report. Revision Changes Path 1.18 +1 -1 xml-axis/java/src/org/apache/axis/utils/BeanUtils.java Index: BeanUtils.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/utils/BeanUtils.java,v retrieving revision 1.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- BeanUtils.java 11 Dec 2002 22:38:27 -0000 1.17 +++ BeanUtils.java 8 Jan 2003 16:06:28 -0000 1.18 @@ -254,7 +254,7 @@ typeDesc.getFields() != null) { ArrayList ordered = new ArrayList(); // Add the TypeDesc elements first - FieldDesc[] fds = typeDesc.getFields(); + FieldDesc[] fds = typeDesc.getFields(true); for (int i=0; i<fds.length; i++) { FieldDesc field = fds[i]; if (field.isElement()) { 1.27 +1 -0 xml-axis/java/test/encoding/PackageTests.java Index: PackageTests.java =================================================================== RCS file: /home/cvs/xml-axis/java/test/encoding/PackageTests.java,v retrieving revision 1.26 retrieving revision 1.27 diff -u -r1.26 -r1.27 --- PackageTests.java 1 Dec 2002 19:48:17 -0000 1.26 +++ PackageTests.java 8 Jan 2003 16:06:29 -0000 1.27 @@ -19,6 +19,7 @@ { TestSuite suite = new TestSuite(); + suite.addTestSuite(TestDerivatedBeanSerializer.class); suite.addTestSuite(TestDeser.class); suite.addTestSuite(TestDeser1999.class); suite.addTestSuite(TestDeser2000.class); 1.1 xml-axis/java/test/encoding/DerivatedBean.java Index: DerivatedBean.java =================================================================== /* * The Apache Software License, Version 1.1 * * * Copyright (c) 2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Axis" and "Apache Software Foundation" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache", * nor may "Apache" appear in their name, without prior written * permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package test.encoding; /** * A type used for testing serialization of inherited elements */ public class DerivatedBean extends SuperBean { private String three; private String four; /** * Returns the four. * @return String */ public String getFour() { return four; } /** * Returns the three. * @return String */ public String getThree() { return three; } /** * Sets the four. * @param four The four to set */ public void setFour(String four) { this.four = four; } /** * Sets the three. * @param three The three to set */ public void setThree(String three) { this.three = three; } // Type metadata private static org.apache.axis.description.TypeDesc typeDesc = new org.apache.axis.description.TypeDesc(DerivatedBean.class); static { org.apache.axis.description.FieldDesc field = new org.apache.axis.description.ElementDesc(); field.setFieldName("three"); field.setXmlName(new javax.xml.namespace.QName("", "three")); field.setXmlType(new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "string")); typeDesc.addFieldDesc(field); field = new org.apache.axis.description.ElementDesc(); field.setFieldName("four"); field.setXmlName(new javax.xml.namespace.QName("", "four")); field.setXmlType(new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "string")); typeDesc.addFieldDesc(field); }; /** * Return type metadata object */ public static org.apache.axis.description.TypeDesc getTypeDesc() { return typeDesc; } } 1.1 xml-axis/java/test/encoding/SuperBean.java Index: SuperBean.java =================================================================== /* * The Apache Software License, Version 1.1 * * * Copyright (c) 2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Axis" and "Apache Software Foundation" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache", * nor may "Apache" appear in their name, without prior written * permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package test.encoding; /** * A simple type with several elements for testing serialization */ public class SuperBean { // Definition of three elements private String zero; private String one; private String two; /** * Returns the one. * @return String */ public String getOne() { return one; } /** * Returns the two. * @return String */ public String getTwo() { return two; } /** * Returns the zero. * @return String */ public String getZero() { return zero; } /** * Sets the one. * @param one The one to set */ public void setOne(String one) { this.one = one; } /** * Sets the two. * @param two The two to set */ public void setTwo(String two) { this.two = two; } /** * Sets the zero. * @param zero The zero to set */ public void setZero(String zero) { this.zero = zero; } // Type metadata private static org.apache.axis.description.TypeDesc typeDesc = new org.apache.axis.description.TypeDesc(SuperBean.class); static { org.apache.axis.description.FieldDesc field = new org.apache.axis.description.ElementDesc(); field.setFieldName("zero"); field.setXmlName(new javax.xml.namespace.QName("", "zero")); field.setXmlType(new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "string")); typeDesc.addFieldDesc(field); field = new org.apache.axis.description.ElementDesc(); field.setFieldName("one"); field.setXmlName(new javax.xml.namespace.QName("", "one")); field.setXmlType(new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "string")); typeDesc.addFieldDesc(field); field = new org.apache.axis.description.ElementDesc(); field.setFieldName("two"); field.setXmlName(new javax.xml.namespace.QName("", "two")); field.setXmlType(new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "string")); typeDesc.addFieldDesc(field); }; /** * Return type metadata object */ public static org.apache.axis.description.TypeDesc getTypeDesc() { return typeDesc; } } 1.1 xml-axis/java/test/encoding/TestDerivatedBeanSerializer.java Index: TestDerivatedBeanSerializer.java =================================================================== /* * The Apache Software License, Version 1.1 * * * Copyright (c) 2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Axis" and "Apache Software Foundation" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache", * nor may "Apache" appear in their name, without prior written * permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package test.encoding; import java.io.StringReader; import java.io.StringWriter; import javax.xml.namespace.QName; import junit.framework.TestCase; import org.apache.axis.Constants; import org.apache.axis.MessageContext; import org.apache.axis.encoding.SerializationContext; import org.apache.axis.encoding.SerializationContextImpl; import org.apache.axis.encoding.TypeMapping; import org.apache.axis.encoding.TypeMappingRegistry; import org.apache.axis.encoding.ser.BeanDeserializerFactory; import org.apache.axis.encoding.ser.BeanSerializer; import org.apache.axis.encoding.ser.BeanSerializerFactory; import org.apache.axis.server.AxisServer; import org.apache.xerces.parsers.DOMParser; import org.w3c.dom.Document; import org.w3c.dom.NodeList; import org.xml.sax.InputSource; /** * A little testcase for validating the serialization of inherited type. */ public class TestDerivatedBeanSerializer extends TestCase { QName superTypeQName = new QName("typeNS", "SuperBean"); QName inheritedTypeQName = new QName("typeNS", "DerivatedBean"); StringWriter stringWriter; SerializationContext context; /** * Constructor for DerivatedBeanSerializerTest. * @param arg0 */ public TestDerivatedBeanSerializer(String arg0) { super(arg0); } /** * @see TestCase#setUp() */ protected void setUp() throws Exception { super.setUp(); // Initialisation of attribute used in the testMethods. stringWriter = new StringWriter(); MessageContext msgContext = new MessageContext(new AxisServer()); context = new SerializationContextImpl(stringWriter, msgContext); // Create a TypeMapping and register the specialized Type Mapping TypeMappingRegistry reg = context.getTypeMappingRegistry(); TypeMapping tm = (TypeMapping) reg.createTypeMapping(); tm.setSupportedEncodings(new String[] {Constants.URI_DEFAULT_SOAP_ENC}); reg.register(Constants.URI_DEFAULT_SOAP_ENC, tm); tm.register(SuperBean.class, superTypeQName, new BeanSerializerFactory(SuperBean.class,superTypeQName), new BeanDeserializerFactory(SuperBean.class,superTypeQName)); tm.register(DerivatedBean.class, inheritedTypeQName, new BeanSerializerFactory(DerivatedBean.class,inheritedTypeQName), new BeanDeserializerFactory(DerivatedBean.class,inheritedTypeQName)); } /** * Test the serialization of an simple sequence. The bean contains three * elements (zero, one, two). The excepted result is something like: * <BR> * <PRE> * <SuperBean> * <zero/> * <one/> * <two/> * </SuperBean> * </PRE> */ /* public void testSuperBeanSerialize() throws Exception { BeanSerializer ser = new BeanSerializer(SuperBean.class, superTypeQName); Object object = new SuperBean(); ser.serialize(superTypeQName,null,object,context); // Check the result String msgString = stringWriter.toString(); StringReader reader = new StringReader(msgString); DOMParser parser = new DOMParser(); parser.parse(new InputSource(reader)); Document doc = parser.getDocument(); // We only test the order of the attributes. NodeList nodes = doc.getFirstChild().getChildNodes(); assertEquals("1st Attribute", "zero", nodes.item(0).getLocalName()); assertEquals("2nd Attribute", "one", nodes.item(1).getLocalName()); assertEquals("3rd Attribute", "two", nodes.item(2).getLocalName()); } */ /** * Test the serialization of an derivated sequence. The derivated bean contains two elements * (three, four) and the super class has three elements (zero, one, two). The excepted * result is something like: <BR> * <PRE> * <DerivatedBean> * <zero/> * <one/> * <two/> * <three/> * <four/> * </DerivatedBean> * </PRE> */ public void testDerivatedBeanSerialize() throws Exception { BeanSerializer ser = new BeanSerializer(DerivatedBean.class, inheritedTypeQName); Object object = new DerivatedBean(); ser.serialize(inheritedTypeQName,null,object,context); // Check the result String msgString = stringWriter.toString(); StringReader reader = new StringReader(msgString); DOMParser parser = new DOMParser(); parser.parse(new InputSource(reader)); Document doc = parser.getDocument(); NodeList nodes = doc.getFirstChild().getChildNodes(); assertEquals("1st Attribute", "zero", nodes.item(0).getLocalName()); assertEquals("2nd Attribute", "one", nodes.item(1).getLocalName()); assertEquals("3rd Attribute", "two", nodes.item(2).getLocalName()); assertEquals("4th Attribute", "three", nodes.item(3).getLocalName()); assertEquals("First Attribute", "four", nodes.item(4).getLocalName()); } } 1.25 +3 -2 xml-axis/java/src/org/apache/axis/description/TypeDesc.java Index: TypeDesc.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/description/TypeDesc.java,v retrieving revision 1.24 retrieving revision 1.25 diff -u -r1.24 -r1.25 --- TypeDesc.java 11 Dec 2002 22:38:13 -0000 1.24 +++ TypeDesc.java 8 Jan 2003 16:06:29 -0000 1.25 @@ -167,8 +167,9 @@ if (superDesc != null) { FieldDesc [] parentFields = superDesc.getFields(true); FieldDesc [] ret = new FieldDesc[parentFields.length + fields.length]; - System.arraycopy(fields, 0, ret, 0, fields.length); - System.arraycopy(parentFields, 0, ret, fields.length, parentFields.length); + System.arraycopy(parentFields, 0, ret, 0, parentFields.length); + System.arraycopy(fields, 0, ret, parentFields.length, fields.length); + fields = ret; } } }