Type defined as nillable is not defined as a pointer ----------------------------------------------------
Key: AXISCPP-693 URL: http://issues.apache.org/jira/browse/AXISCPP-693 Project: Axis-C++ Type: Bug Environment: n/a Reporter: Fred Preston Assigned to: Fred Preston The following XSD defines a complex type - MyClass:- <?xml version="1.0" encoding="UTF-8" ?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="Test_A" targetNamespace="Test_A"> <xs:complexType name="MyClass" mixed="true"> <xs:sequence> <xs:element name="Name" form="unqualified" nillable="true" minOccurs="0"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:maxLength value="20"/> </xs:restriction> </xs:simpleType> </xs:element> <xs:element name="Values" form="unqualified" nillable="true" minOccurs="0"> <xs:simpleType> <xs:restriction base="xs:base64Binary"> <xs:maxLength value="3"/> </xs:restriction> </xs:simpleType> </xs:element> </xs:sequence> <xs:attribute name="id" type="xs:NMTOKEN" use="optional" form="unqualified"/> </xs:complexType> </xs:schema> This XSD is defined in the WSDL (taken from CalculatorDoc):- <wsdl:definitions targetNamespace="http://localhost/axis/Test_A" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://localhost/axis/Test_A" xmlns:intf="http://localhost/axis/Test_A" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xs="Test_A" xmlns:xsd1="Test_A"> <wsdl:import namespace="Test_A" location="../WSDLs/Test_A.xsd"></wsdl:import> <wsdl:types> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:import namespace="Test_A" schemaLocation="Test_A.xsd"> </xsd:import> </xsd:schema> </wsdl:types> <wsdl:message name="addRequest"> <wsdl:part name="myClass" type="xs:MyClass"/> </wsdl:message> <wsdl:message name="addResponse"> <wsdl:part name="addReturn" type="xsd:int"/> </wsdl:message> <wsdl:portType name="Test_A"> <wsdl:operation name="add" parameterOrder="myClass"> <wsdl:input message="intf:addRequest" name="addRequest"/> <wsdl:output message="intf:addResponse" name="addResponse"/> </wsdl:operation> </wsdl:portType> <wsdl:binding name="Test_ASoapBinding" type="intf:Test_A"> <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> <wsdl:operation name="add"> <wsdlsoap:operation soapAction="Test_A#add" style="document"/> <wsdl:input name="addRequest"> <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://localhost/axis/Test_A" use="encoded"/> </wsdl:input> <wsdl:output name="addResponse"> <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://localhost/axis/Test_A" use="encoded"/> </wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:service name="Test_A"> <wsdl:port binding="intf:Test_ASoapBinding" name="Test_A"> <wsdlsoap:address location="http://localhost/axis/Test_A"/> </wsdl:port> </wsdl:service> </wsdl:definitions> When this is run through WSDL2Ws, it produces the following stub:- MyClass.hpp ----------------- static const char* Axis_TypeName_MyClass = "MyClass"; class STORAGE_CLASS_INFO MyClass { public: xsd__NMTOKEN id; xsd__string Name; xsd__base64Binary Values; xsd__NMTOKEN getid(); void setid(xsd__NMTOKEN InValue); xsd__string getName(); void setName(xsd__string InValue); xsd__base64Binary getValues(); void setValues(xsd__base64Binary InValue); MyClass(); ~MyClass(); }; #endif /* !defined(__MYCLASS_PARAM_H__INCLUDED_)*/ and MyClass.cpp ----------------------- #include <axis/AxisWrapperAPI.hpp> #include "MyClass.hpp" xsd__NMTOKEN MyClass::getid() { return id ; } void MyClass::setid(xsd__NMTOKEN InValue) { id = InValue ; } xsd__string MyClass::getName() { return Name ; } void MyClass::setName(xsd__string InValue) { Name = InValue ; } xsd__base64Binary MyClass::getValues() { return Values ; } void MyClass::setValues(xsd__base64Binary InValue) { Values = InValue ; } /* * This static method serialize a MyClass type of object */ int Axis_Serialize_MyClass(MyClass* param, IWrapperSoapSerializer* pSZ, bool bArray = false) { if ( param == NULL ) { /* TODO : may need to check nillable value - Now done*/ pSZ->serializeAsAttribute( "xsi:nil", 0, (void*)&(xsd_boolean_true), XSD_BOOLEAN); pSZ->serialize( ">", NULL); return AXIS_SUCCESS; } /* first serialize attributes if any*/ pSZ->serializeAsAttribute("id", 0, (void*)&(param->id), XSD_NMTOKEN); pSZ->serialize( ">", 0); /* then serialize elements if any*/ pSZ->serializeAsElement("Name", Axis_URI_MyClass, (void*)(param->Name), XSD_STRING); pSZ->serializeAsElement("Values", Axis_URI_MyClass, (void*)&(param->Values), XSD_BASE64BINARY); return AXIS_SUCCESS; } /* * This static method deserialize a MyClass type of object */ int Axis_DeSerialize_MyClass(MyClass* param, IWrapperSoapDeSerializer* pIWSDZ) { param->id = pIWSDZ->getAttributeAsString( "id",0); param->Name = pIWSDZ->getElementAsString( "Name",0); xsd__base64Binary * Values = NULL; if ((Values = pIWSDZ->getElementAsBase64Binary( "Values",0)) != NULL) param->Values = *( Values ); return pIWSDZ->getStatus(); } void* Axis_Create_MyClass(MyClass* pObj, bool bArray = false, int nSize=0) { if (bArray && (nSize > 0)) { if (pObj) { MyClass* pNew = new MyClass[nSize]; memcpy(pNew, pObj, sizeof(MyClass)*nSize/2); memset(pObj, 0, sizeof(MyClass)*nSize/2); delete [] pObj; return pNew; } else { return new MyClass[nSize]; } } else return new MyClass; } /* * This static method delete a MyClass type of object */ void Axis_Delete_MyClass(MyClass* param, bool bArray = false, int nSize=0) { if (bArray) { delete [] param; } else { delete param; } } /* * This static method gives the size of MyClass type of object */ int Axis_GetSize_MyClass() { return sizeof(MyClass); } MyClass::MyClass() { /*do not allocate memory to any pointer members here because deserializer will allocate memory anyway. */ memset( &id, 0, sizeof( xsd__NMTOKEN)); memset( &Name, 0, sizeof( xsd__string)); memset( &Values, 0, sizeof( xsd__base64Binary)); } MyClass::~MyClass() { /*delete any pointer and array members here*/ } This is wrong, as 'Values' is defined as a 'nillable', xsd__base64Binary type. So Values sould be a pointer and all references should be via pointer and not value. Thus, for eample, MyClass.hpp should define Values as follows:- static const char* Axis_TypeName_MyClass = "MyClass"; class STORAGE_CLASS_INFO MyClass { public: xsd__NMTOKEN id; xsd__string Name; xsd__base64Binary * Values; xsd__NMTOKEN getid(); void setid(xsd__NMTOKEN InValue); xsd__string getName(); void setName(xsd__string InValue); xsd__base64Binary * getValues(); void setValues(xsd__base64Binary * pInValue); MyClass(); ~MyClass(); }; #endif /* !defined(__MYCLASS_PARAM_H__INCLUDED_)*/ And, MyClass.cpp should change accordingly. -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira