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 cb...@apache.org on 2005/01/27 09:32:37 UTC
cvs commit: ws-axis/c/src/common BasicTypeSerializer.cpp Param.cpp ArrayBean.cpp BasicTypeSerializer.h
cblecken 2005/01/27 00:32:37
Modified: c/src/soap SoapSerializer.cpp SoapMethod.cpp
SoapSerializer.h
c/src/common BasicTypeSerializer.cpp Param.cpp ArrayBean.cpp
BasicTypeSerializer.h
Log:
Add namespace prefixing to several serializer methods (AXSICPP-197)
Revision Changes Path
1.90 +47 -4 ws-axis/c/src/soap/SoapSerializer.cpp
Index: SoapSerializer.cpp
===================================================================
RCS file: /home/cvs/ws-axis/c/src/soap/SoapSerializer.cpp,v
retrieving revision 1.89
retrieving revision 1.90
diff -u -r1.89 -r1.90
--- SoapSerializer.cpp 26 Jan 2005 14:38:20 -0000 1.89
+++ SoapSerializer.cpp 27 Jan 2005 08:32:37 -0000 1.90
@@ -53,6 +53,7 @@
m_pSoapEnvelope = NULL;
m_iSoapVersion = SOAP_VER_1_1;
m_pOutputStream = NULL;
+ m_pNamespace = NULL;
}
SoapSerializer::~SoapSerializer()
@@ -174,6 +175,9 @@
else
{
pAb->SetItemName(pName);
+ if (NULL != pNamespace) {
+ pParam->setUri(pNamespace);
+ }
pParam->setName("array");
}
pParam->m_Value.pIArray = pAb;
@@ -196,6 +200,7 @@
pParam->m_Value.pCplxObj->pObject = pObject;
pParam->m_Value.pCplxObj->pSZFunct = (AXIS_SERIALIZE_FUNCT)pSZFunct;
pParam->m_Value.pCplxObj->pDelFunct = (AXIS_OBJECT_DELETE_FUNCT)pDelFunct;
+
if(m_pSoapEnvelope && (m_pSoapEnvelope->m_pSoapBody) && (m_pSoapEnvelope->
m_pSoapBody->m_pSoapMethod))
{
@@ -529,7 +534,15 @@
}
pParam->m_Value.pIArray = pAb;
pParam->m_Type = XSD_ARRAY;
+ if (pNamespace != NULL) {
+ const AxisChar* np = getNamespacePrefix(pNamespace);
+ pParam->setPrefix(np);
+ setNamespace(pNamespace);
+ }
pParam->serialize(*this);
+ if (pNamespace != NULL) {
+ setNamespace(NULL);
+ }
/* Remove pointer to the array from the ArrayBean to avoid deleting the
* array when ArrayBean is deleted. Array will be deleted when the complex
* type that contains this array is deleted */
@@ -545,8 +558,20 @@
int SoapSerializer::serializeBasicArray(const Axis_Array* pArray,
XSDTYPE nType, const AxisChar* pName)
{
- ArrayBean* pAb = (ArrayBean*)makeArrayBean(nType,
- (void*)(pArray->m_Array));
+ return serializeBasicArray(pArray, NULL, nType, pName);
+}
+
+/*
+ * Used to Serialize an array of basic types inside a complex type. Contains
+ * the namespace so that it can be serialized. Called from within the Serialize
+ * wrapper method of the complex type.
+ */
+int SoapSerializer::serializeBasicArray(const Axis_Array* pArray,
+ const AxisChar* pNamespace,
+ XSDTYPE nType, const AxisChar* pName)
+{
+ ArrayBean* pAb = (ArrayBean*)makeArrayBean(nType,
+ (void*)(pArray->m_Array));
pAb->SetDimension(pArray->m_Size);
Param* pParam = new Param();
if (RPC_ENCODED == m_nStyle)
@@ -561,6 +586,11 @@
}
pParam->m_Value.pIArray = pAb;
pParam->m_Type = XSD_ARRAY;
+ if (pNamespace != NULL) {
+ const AxisChar* np = getNamespacePrefix(pNamespace);
+ pParam->setPrefix(np);
+ setNamespace(pNamespace);
+ }
pParam->serialize(*this);
/* Remove pointer to the array from the ArrayBean to avoid deleting the
* array when ArrayBean is deleted. Array will be deleted when the complex
@@ -667,7 +697,20 @@
int SoapSerializer::serializeAsElement(const AxisChar* pName, void* pValue,
XSDTYPE type)
{
- const AxisChar* pSerialized = m_BTSZ.serializeAsElement(pName, pValue,
+ return serializeAsElement(pName, NULL, pValue, type);
+}
+
+int SoapSerializer::serializeAsElement(const AxisChar* pName,
+ const AxisChar* pNamespace,
+ void* pValue,
+ XSDTYPE type)
+{
+ const AxisChar* pPrefix = NULL;
+ if (pNamespace)
+ {
+ pPrefix = getNamespacePrefix(pNamespace);
+ }
+ const AxisChar* pSerialized = m_BTSZ.serializeAsElement(pName, pPrefix, pValue,
type);
if (pSerialized)
{
@@ -678,7 +721,7 @@
{
return AXIS_FAIL;
}
-}
+}
int SoapSerializer::serializeAsAttribute(const AxisChar* pName,
const AxisChar* pNamespace,
1.30 +7 -0 ws-axis/c/src/soap/SoapMethod.cpp
Index: SoapMethod.cpp
===================================================================
RCS file: /home/cvs/ws-axis/c/src/soap/SoapMethod.cpp,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -r1.29 -r1.30
--- SoapMethod.cpp 23 Nov 2004 17:21:04 -0000 1.29
+++ SoapMethod.cpp 27 Jan 2005 08:32:37 -0000 1.30
@@ -97,7 +97,14 @@
pSZ.serialize(">\n", NULL);
+ // push the current NS to the NS stack
+ pSZ.getNamespacePrefix(m_strUri.c_str());
+
iStatus= serializeOutputParam(pSZ);
+
+ // remove the current NS from the NS stack
+ pSZ.removeNamespacePrefix(m_strUri.c_str());
+
if(iStatus==AXIS_FAIL)
{
break;
1.39 +12 -0 ws-axis/c/src/soap/SoapSerializer.h
Index: SoapSerializer.h
===================================================================
RCS file: /home/cvs/ws-axis/c/src/soap/SoapSerializer.h,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -r1.38 -r1.39
--- SoapSerializer.h 26 Jan 2005 11:10:08 -0000 1.38
+++ SoapSerializer.h 27 Jan 2005 08:32:37 -0000 1.39
@@ -68,7 +68,12 @@
map<AxisXMLString, AxisXMLString> m_NsStack;
/* Provider type of current service that uses this Serializer object */
PROVIDERTYPE m_ProviderType;
+ /* the local namespace for this serializer */
+ AxisChar* m_pNamespace;
+
public:
+ inline const AxisChar* AXISCALL getNamespace() const {return m_pNamespace;};
+ inline void AXISCALL setNamespace(const AxisChar* pNamespace) {m_pNamespace = (const_cast<AxisChar*>(pNamespace));};
#ifdef UNIT_TESTING_ON
int setOutputStreamForTesting(SOAPTransport* pStream);
@@ -133,6 +138,11 @@
int AXISCALL serializeBasicArray(const Axis_Array* pArray, XSDTYPE nType,
const AxisChar* pName);
+
+ int AXISCALL serializeBasicArray(const Axis_Array* pArray, const AxisChar* pNamespace,
+ XSDTYPE nType, const AxisChar* pName);
+
+
/* following two functions are needed by serializer functions of complex
* types for RPC style web services
*/
@@ -185,6 +195,8 @@
void* pValue, XSDTYPE type);
int AXISCALL serializeAsElement(const AxisChar* pchName,
void* pValue, XSDTYPE type);
+ int AXISCALL serializeAsElement(const AxisChar* pchName,
+ const AxisChar* pNamespace, void* pValue, XSDTYPE type);
int AXISCALL serializeAsAttribute(const AxisChar* pName,
const AxisChar* pNamespace, void* pValue, XSDTYPE type);
void AXISCALL serializeVargs(const char* pFirst, va_list vargs);
1.48 +30 -8 ws-axis/c/src/common/BasicTypeSerializer.cpp
Index: BasicTypeSerializer.cpp
===================================================================
RCS file: /home/cvs/ws-axis/c/src/common/BasicTypeSerializer.cpp,v
retrieving revision 1.47
retrieving revision 1.48
diff -u -r1.47 -r1.48
--- BasicTypeSerializer.cpp 25 Jan 2005 14:25:24 -0000 1.47
+++ BasicTypeSerializer.cpp 27 Jan 2005 08:32:37 -0000 1.48
@@ -41,8 +41,18 @@
const AxisChar* BasicTypeSerializer::serializeAsElement (const AxisChar* pName,
const void* pValue, XSDTYPE type)
{
+ return serializeAsElement(pName, NULL, pValue, type);
+}
+
+const AxisChar* BasicTypeSerializer::serializeAsElement (const AxisChar* pName,
+ const AxisChar* pPrefix, const void* pValue, XSDTYPE type)
+{
const AxisChar* pStr;
m_sSZ = "<";
+ if (NULL != pPrefix) {
+ m_sSZ += pPrefix;
+ m_sSZ += ":";
+ }
m_sSZ += pName;
if (RPC_ENCODED == m_nStyle)
{
@@ -146,8 +156,10 @@
*/
m_sSZ = "<";
m_sSZ += pName;
- m_sSZ += " xsi:nil=\"true\"/>\n";
- return m_sSZ.c_str ();
+ // direct return not good for maintainability
+ // m_sSZ += " xsi:nil=\"true\"/>\n";
+ // return m_sSZ.c_str ();
+ m_sSZ += " xsi:nil=\"true\" ";
}
{
String stringSerializer;
@@ -163,8 +175,10 @@
*/
m_sSZ = "<";
m_sSZ += pName;
- m_sSZ += " xsi:nil=\"true\"/>\n";
- return m_sSZ.c_str ();
+ // direct return not good for maintainability
+ // m_sSZ += " xsi:nil=\"true\"/>\n";
+ // return m_sSZ.c_str ();
+ m_sSZ += " xsi:nil=\"true\" ";
}
{
AnyURI anyURISerializer;
@@ -180,8 +194,10 @@
*/
m_sSZ = "<";
m_sSZ += pName;
- m_sSZ += " xsi:nil=\"true\"/>\n";
- return m_sSZ.c_str ();
+ // direct return not good for maintainability
+ // m_sSZ += " xsi:nil=\"true\"/>\n";
+ // return m_sSZ.c_str ();
+ m_sSZ += " xsi:nil=\"true\" ";
}
{
XSD_QName QNameSerializer;
@@ -197,8 +213,10 @@
*/
m_sSZ = "<";
m_sSZ += pName;
- m_sSZ += " xsi:nil=\"true\"/>\n";
- return m_sSZ.c_str ();
+ // direct return not good for maintainability
+ // m_sSZ += " xsi:nil=\"true\"/>\n";
+ // return m_sSZ.c_str ();
+ m_sSZ += " xsi:nil=\"true\" ";
}
{
NOTATION notationSerializer;
@@ -240,6 +258,10 @@
}
m_sSZ += "</";
+ if (NULL != pPrefix) {
+ m_sSZ += pPrefix;
+ m_sSZ += ":";
+ }
m_sSZ += pName;
m_sSZ += ">\n";
return m_sSZ.c_str ();
1.47 +6 -0 ws-axis/c/src/common/Param.cpp
Index: Param.cpp
===================================================================
RCS file: /home/cvs/ws-axis/c/src/common/Param.cpp,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -r1.46 -r1.47
--- Param.cpp 23 Nov 2004 17:21:02 -0000 1.46
+++ Param.cpp 27 Jan 2005 08:32:37 -0000 1.47
@@ -155,9 +155,15 @@
* So directly call Array Serializer
*/
{
+ if (!m_strUri.empty())
+ pSZ.setNamespace(m_strUri.c_str());
+
m_Value.pArray->Serialize (pSZ); /* Only serializes the inner
* items
*/
+ if (!m_strUri.empty())
+ pSZ.setNamespace(NULL);
+
}
break;
1.32 +19 -2 ws-axis/c/src/common/ArrayBean.cpp
Index: ArrayBean.cpp
===================================================================
RCS file: /home/cvs/ws-axis/c/src/common/ArrayBean.cpp,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -r1.31 -r1.32
--- ArrayBean.cpp 14 Jan 2005 13:42:18 -0000 1.31
+++ ArrayBean.cpp 27 Jan 2005 08:32:37 -0000 1.32
@@ -183,13 +183,30 @@
for (int x=0; x<m_nSize; x++)
{
pItem = reinterpret_cast<void*>(ptrval+x*itemsize);
- pSZ.serialize("<", m_ItemName.c_str(), NULL);
+
+ // try to find the prefix - array prefix overrides the
+ // serializer prefix
+ const AxisChar* pNamespace = pSZ.getNamespace();
+ const AxisChar* pPrefix = NULL;
+ if (NULL != pNamespace)
+ if (strlen(pNamespace) > 0)
+ pPrefix = pSZ.getNamespacePrefix(pNamespace);
+
+ if (pPrefix != NULL)
+ pSZ.serialize("<", pPrefix, ":", m_ItemName.c_str(), NULL);
+ else
+ pSZ.serialize("<", m_ItemName.c_str(), NULL);
+
/* note : ">" is not serialized to enable the type's serializer
* to add attributes
*/
m_value.cta->pSZFunct(pItem, &pSZ, true);
/* no matter true or false is passed */
- pSZ.serialize("</", m_ItemName.c_str(), ">", NULL);
+ if (pPrefix != NULL)
+ pSZ.serialize("</", pPrefix, ":", m_ItemName.c_str(), ">", NULL);
+ else
+ pSZ.serialize("</", m_ItemName.c_str(), ">", NULL);
+
}
}
else
1.32 +2 -0 ws-axis/c/src/common/BasicTypeSerializer.h
Index: BasicTypeSerializer.h
===================================================================
RCS file: /home/cvs/ws-axis/c/src/common/BasicTypeSerializer.h,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -r1.31 -r1.32
--- BasicTypeSerializer.h 25 Jan 2005 14:25:24 -0000 1.31
+++ BasicTypeSerializer.h 27 Jan 2005 08:32:37 -0000 1.32
@@ -88,6 +88,8 @@
const AxisString& getEntityReferenced(const AxisString& str);
const AxisChar* serializeAsElement(const AxisChar* pName,
const void* pValue, XSDTYPE type);
+ const AxisChar* serializeAsElement(const AxisChar* pName,
+ const AxisChar* pPrefix, const void* pValue, XSDTYPE type);
const AxisChar* serializeAsAttribute(const AxisChar* pName,
const AxisChar* pPrefix, const void* pValue, XSDTYPE type);
const AxisChar* encodeToHexBinary(const xsd__hexBinary* pBinary);