axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ros...@apache.org
Subject cvs commit: ws-axis/c/src/soap SoapSerializer.cpp SoapHeader.cpp SoapDeSerializer.cpp HeaderBlock.cpp ComplexElement.cpp Attribute.cpp
Date Tue, 03 Feb 2004 05:19:10 GMT
roshan      2004/02/02 21:19:10

  Modified:    c/src/soap SoapSerializer.cpp SoapHeader.cpp
                        SoapDeSerializer.cpp HeaderBlock.cpp
                        ComplexElement.cpp Attribute.cpp
  Log:
  changes for header support
  
  Revision  Changes    Path
  1.36      +23 -2     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.35
  retrieving revision 1.36
  diff -u -r1.35 -r1.36
  --- SoapSerializer.cpp	19 Jan 2004 07:44:12 -0000	1.35
  +++ SoapSerializer.cpp	3 Feb 2004 05:19:10 -0000	1.36
  @@ -296,6 +296,10 @@
   	m_pSoapEnvelope->addStandardNamespaceDecl(SoapKeywordMapping::Map(nSoapVersion).pEnv);
   	m_pSoapEnvelope->addStandardNamespaceDecl(SoapKeywordMapping::Map(nSoapVersion).pXsd);
   	m_pSoapEnvelope->addStandardNamespaceDecl(SoapKeywordMapping::Map(nSoapVersion).pXsi);
  +
  +	/* Adding the standard SOAP namespace to the namespace stack */
  +	m_NsStack[SoapKeywordMapping::Map(nSoapVersion).pchNamespaceUri] = SoapKeywordMapping::Map(nSoapVersion).pchPrefix;
  +
   	return AXIS_SUCCESS;
   }
   void SoapSerializer::RemoveNamespacePrefix(const AxisChar* pNamespace)
  @@ -317,6 +321,18 @@
   	return m_NsStack[pNamespace].c_str();
   }
   
  +const AxisChar* SoapSerializer::GetNamespacePrefix(const AxisChar* pNamespace, bool&
blnIsNewPrefix)
  +{
  +	if (m_NsStack.find(pNamespace) == m_NsStack.end())
  +	{
  +		m_nCounter++;
  +		AxisSprintf(m_Buf, 8, "ns%d", m_nCounter);
  +		m_NsStack[pNamespace] = m_Buf;
  +		blnIsNewPrefix = true;
  +	}
  +	return m_NsStack[pNamespace].c_str();
  +}
  +
   IWrapperSoapSerializer& SoapSerializer::operator <<(const AxisChar* cSerialized)
   {
   	if (AXIS_SUCCESS != m_nStatus) 
  @@ -545,6 +561,13 @@
   	return AXIS_SUCCESS;
   }
   
  +int SoapSerializer::setOutputStreamForTesting(const Ax_soapstream* pStream)
  +{
  +	m_pOutputStream = pStream;
  +
  +	return AXIS_SUCCESS;
  +}
  +
   /**
    * Basic output parameter going to be serialized as an Element later
    */
  @@ -739,5 +762,3 @@
   	char *pChar = const_cast<char*>(buffer);
   	pChar[0] = '\0'; /* set nul */ 
   }
  -
  -
  
  
  
  1.11      +12 -7     ws-axis/c/src/soap/SoapHeader.cpp
  
  Index: SoapHeader.cpp
  ===================================================================
  RCS file: /home/cvs/ws-axis/c/src/soap/SoapHeader.cpp,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- SoapHeader.cpp	12 Jan 2004 12:20:54 -0000	1.10
  +++ SoapHeader.cpp	3 Feb 2004 05:19:10 -0000	1.11
  @@ -187,17 +187,22 @@
   
   IHeaderBlock* SoapHeader::getHeaderBlock()
   {
  +	HeaderBlock* tmpHeaderBlock = NULL;
  +
   	list<HeaderBlock*>::iterator itCurrHeaderBlock= m_headerBlocks.begin();
   
   	if(itCurrHeaderBlock != m_headerBlocks.end()) {			
  -
  -		/*
  -		 *Actually a dynamic cast is not needed here. But it
  -		 * is done for safe side.
  -		 */
  -		return dynamic_cast<IHeaderBlock*>(*itCurrHeaderBlock);
  +		tmpHeaderBlock = (*itCurrHeaderBlock);
  +		m_headerBlocks.pop_front();
   	}
   
  -	return NULL;
  +	return tmpHeaderBlock;
  +
  +}
  +
  +int SoapHeader::setPrefix(const char* pcPrefix)
  +{
  +	m_pcPrefix = pcPrefix;
   
  +	return AXIS_SUCCESS;
   }
  
  
  
  1.25      +72 -5     ws-axis/c/src/soap/SoapDeSerializer.cpp
  
  Index: SoapDeSerializer.cpp
  ===================================================================
  RCS file: /home/cvs/ws-axis/c/src/soap/SoapDeSerializer.cpp,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- SoapDeSerializer.cpp	20 Jan 2004 14:05:16 -0000	1.24
  +++ SoapDeSerializer.cpp	3 Feb 2004 05:19:10 -0000	1.25
  @@ -72,6 +72,8 @@
   #include <axis/soap/SoapMethod.h>
   #include <axis/soap/SoapBody.h>
   #include <axis/soap/SoapFault.h>
  +#include <axis/soap/ComplexElement.h>
  +#include <axis/soap/CharacterElement.h>
   #include <axis/common/GDefine.h>
   #include <axis/common/Packet.h>
   #include <axis/common/AxisTrace.h>
  @@ -184,13 +186,78 @@
   		m_nStatus = AXIS_FAIL;
   		return m_nStatus;
   	}
  -	if ((START_ELEMENT != m_pNode->m_type) && (0 == strcmp(m_pNode->m_pchNameOrValue,
SoapKeywordMapping::Map(m_nSoapVersion).pchWords[SKW_HEADER])))
  +
  +	if ((START_ELEMENT == m_pNode->m_type) && (0 == strcmp(m_pNode->m_pchNameOrValue,
SoapKeywordMapping::Map(m_nSoapVersion).pchWords[SKW_HEADER])))
   	{
   		m_pHeader = new SoapHeader();
   		/* Set any attributes/namspaces to the SoapHeader object */
  -		m_pNode = NULL; /*This is to indicate that node is identified and used */
  -		return m_nStatus;
  +
  +		bool blnConStatus = true;
  +		int iLevel = HEADER_LEVEL;
  +		int iHeaderBlockStackLevel = 0;
  +		HeaderBlock* pHeaderBlock;
  +		ComplexElement* pComplexElement;
  +		CharacterElement* pCharacterElement;
  +
  +		while (blnConStatus) {
  +			m_pNode = m_pParser->Next();
  +
  +			if ((END_ELEMENT == m_pNode->m_type) && (0 == strcmp(m_pNode->m_pchNameOrValue,
SoapKeywordMapping::Map(m_nSoapVersion).pchWords[SKW_HEADER]))) {
  +				m_pNode = NULL; /*This is to indicate that node is identified and used */
  +				return m_nStatus;
  +			} else {
  +				if (START_ELEMENT == m_pNode->m_type) {
  +					if (iLevel == HEADER_LEVEL) {
  +						pHeaderBlock = new HeaderBlock();
  +		
  +						pHeaderBlock->setUri(m_pNode->m_pchNamespace);
  +						pHeaderBlock->setLocalName(m_pNode->m_pchNameOrValue);
  +
  +						if ((m_pNode->m_pchAttributes) != NULL) {
  +							int iAttributeArrayIndex = 0;
  +							while (true) {
  +								Attribute* pAttribute = new Attribute();
  +								pAttribute->setLocalName(m_pNode->m_pchAttributes[iAttributeArrayIndex++]);
  +								pAttribute->setUri(m_pNode->m_pchAttributes[iAttributeArrayIndex++]);
  +								pAttribute->setValue(m_pNode->m_pchAttributes[iAttributeArrayIndex++]);
  +
  +								pHeaderBlock->addAttribute(pAttribute);
  +								
  +								if (m_pNode->m_pchAttributes[iAttributeArrayIndex] == '\0') {
  +									break;
  +								}
  +							}
  +						}
  +
  +						iLevel = HEADER_BLOCK_LEVEL;
  +					} else if (iLevel == HEADER_BLOCK_LEVEL) {
  +						iHeaderBlockStackLevel++;
  +
  +						pComplexElement = new ComplexElement();
  +						
  +						pComplexElement->setURI(m_pNode->m_pchNamespace);
  +						pComplexElement->setLocalName(m_pNode->m_pchNameOrValue);
  +
  +						iLevel = HEADER_BLOCK_INSIDE_LEVEL;
  +					}
  +				} else if (END_ELEMENT == m_pNode->m_type) {
  +					if ((iLevel == HEADER_BLOCK_LEVEL) && (iHeaderBlockStackLevel==0)) {
  +						m_pHeader->addHeaderBlock(pHeaderBlock);
  +						iLevel = HEADER_LEVEL;
  +					} else if ((iLevel == HEADER_BLOCK_INSIDE_LEVEL) && (iHeaderBlockStackLevel>0))
{
  +						pHeaderBlock->addChild(pComplexElement);
  +						iHeaderBlockStackLevel--;
  +						iLevel = HEADER_BLOCK_LEVEL;
  +					}
  +				} else if (CHARACTER_ELEMENT == m_pNode->m_type) {
  +					pCharacterElement = new CharacterElement(m_pNode->m_pchNameOrValue);
  +
  +					pComplexElement->addChild(pCharacterElement);
  +				}
  +			}
  +		}
   	}
  +
   	return m_nStatus;
   }
   
  @@ -2090,8 +2157,8 @@
   HeaderBlock* SoapDeSerializer::GetHeaderBlock()
   {
   	if (!m_pHeader) return NULL;
  -	/*TODO : get a header block left in the m_pHeader (remove it from there) and return */
  -	return NULL;
  +
  +	return (HeaderBlock*)m_pHeader->getHeaderBlock();
   }
   /**
    * Used probably by a handler to add a header block to the Deserializer. Probably to be

  
  
  
  1.9       +98 -29    ws-axis/c/src/soap/HeaderBlock.cpp
  
  Index: HeaderBlock.cpp
  ===================================================================
  RCS file: /home/cvs/ws-axis/c/src/soap/HeaderBlock.cpp,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- HeaderBlock.cpp	12 Jan 2004 12:20:54 -0000	1.8
  +++ HeaderBlock.cpp	3 Feb 2004 05:19:10 -0000	1.9
  @@ -69,6 +69,7 @@
   #include <axis/soap/SoapSerializer.h>
   #include <axis/common/GDefine.h>
   #include <axis/soap/BasicNode.h>
  +#include <axis/soap/ComplexElement.h>
   #include <axis/soap/CharacterElement.h>
   
   //////////////////////////////////////////////////////////////////////
  @@ -129,40 +130,60 @@
   
   	int iStatus= AXIS_SUCCESS;
   
  +	list<AxisChar*> lstTmpNameSpaceStack;
  +	bool blnIsNewNamespace = false;
  +
   	do {
  -		if(isSerializable()) {
  +		/*
  +		TO DO: ReWrite the following logic to deal with name spaces
  +		*/
   
  -			pSZ.Serialize("<", m_prefix.c_str(), ":", m_localname.c_str(),
  -				" xmlns:", m_prefix.c_str(), "=\"", m_uri.c_str(), "\"", NULL);
  +		pSZ.Serialize("<", NULL);
   
  -			iStatus= attrSerialize(pSZ);
  -			if(iStatus==AXIS_FAIL) {
  -				break;
  +		if(m_prefix.length() == 0) {
  +			m_prefix = pSZ.GetNamespacePrefix(m_uri.c_str(), blnIsNewNamespace);
  +			if (blnIsNewNamespace) {
  +				lstTmpNameSpaceStack.push_back((AxisChar*)m_uri.c_str());
   			}
  +		}
   
  -			iStatus= serializeNamespaceDecl(pSZ);
  -			if(iStatus==AXIS_FAIL) {
  -				break;
  -			}
  -			
  -			pSZ.Serialize(">", NULL);
  +		pSZ.Serialize(m_prefix.c_str(), ":", m_localname.c_str(),
  +			" xmlns:", m_prefix.c_str(), "=\"", m_uri.c_str(), "\"", NULL);
   
  -			iStatus= serializeChildren(pSZ);
  -			if(iStatus==AXIS_FAIL) {
  -				break;
  -			}
  +		iStatus= attrSerialize(pSZ, lstTmpNameSpaceStack);
  +		if(iStatus==AXIS_FAIL) {
  +			break;
  +		}
   
  -			pSZ.Serialize("</", m_prefix.c_str(), ":", m_localname.c_str(), ">", NULL);
  -			
  -		} else {
  -			iStatus= AXIS_FAIL;
  +		iStatus= serializeNamespaceDecl(pSZ);
  +		if(iStatus==AXIS_FAIL) {
  +			break;
  +		}
  +		
  +		pSZ.Serialize(">", NULL);
  +
  +		iStatus= serializeChildren(pSZ, lstTmpNameSpaceStack);
  +		if(iStatus==AXIS_FAIL) {
  +			break;
   		}
  +
  +		pSZ.Serialize("</", m_prefix.c_str(), ":", m_localname.c_str(), ">", NULL);
  +
  +		/*
  +		 *Removing the namespace list of this headerblock from the stack.
  +		 */
  +		list<AxisChar*>::iterator itCurrentNamespace = lstTmpNameSpaceStack.begin();
  +		while (itCurrentNamespace != lstTmpNameSpaceStack.end()) {
  +			pSZ.RemoveNamespacePrefix(*itCurrentNamespace);
  +			itCurrentNamespace++;
  +		}
  +			
   	} while(0);
   
   	return iStatus;
   }
   
  -int HeaderBlock::attrSerialize(SoapSerializer& pSZ)
  +int HeaderBlock::attrSerialize(SoapSerializer& pSZ, list<AxisChar*>& lstTmpNameSpaceStack)
   {
   	int iStatus= AXIS_SUCCESS;
   
  @@ -170,12 +191,12 @@
   
   	while(itCurrAttribute != m_attributes.end()) {		
   
  -		iStatus= (*itCurrAttribute)->serialize(pSZ);
  +		iStatus= (*itCurrAttribute)->serialize(pSZ, lstTmpNameSpaceStack);
   		if(iStatus==AXIS_FAIL) {
   			break;
   		}
  -		itCurrAttribute++;		
  -	}	
  +		itCurrAttribute++;
  +	}
   
   	return iStatus;
   }
  @@ -233,14 +254,19 @@
   	return AXIS_SUCCESS;
   }
   
  -int HeaderBlock::serializeChildren(SoapSerializer& pSZ)
  +int HeaderBlock::serializeChildren(SoapSerializer& pSZ, list<AxisChar*>&
lstTmpNameSpaceStack)
   {
   	list<BasicNode*>::iterator itCurrBasicNode= m_children.begin();
   
  -	while(itCurrBasicNode != m_children.end()) {		
  -		(*itCurrBasicNode)->serialize(pSZ);
  -		itCurrBasicNode++;		
  -	}	
  +	while(itCurrBasicNode != m_children.end()) {
  +		if ((*itCurrBasicNode)->getNodeType() == ELEMENT_NODE) {
  +			(*itCurrBasicNode)->serialize(pSZ, lstTmpNameSpaceStack);
  +		} else {
  +			/* for CHARACTER_NODE types */
  +			(*itCurrBasicNode)->serialize(pSZ);
  +		}
  +		itCurrBasicNode++;
  +	}
   
   	return AXIS_SUCCESS;
   }
  @@ -302,3 +328,46 @@
   
   	return pBasicNode;
   }
  +
  +int HeaderBlock::initializeForTesting()
  +{
  +	setPrefix("m");
  +	setLocalName("reservation");
  +	setUri("http://travelcompany.example.org/reservation");
  +
  +	Attribute* pAttribute2 = new Attribute();
  +	pAttribute2->setPrefix("SOAP-ENV");
  +	pAttribute2->setLocalName("role");
  +	pAttribute2->setValue("http://www.w3.org/2003/05/soap-envelope/role/next");
  +
  +	Attribute* pAttribute3 = new Attribute();
  +	pAttribute3->setPrefix("SOAP-ENV");
  +	pAttribute3->setLocalName("mustUnderstand");
  +	pAttribute3->setValue("true");
  +
  +	addAttribute(pAttribute2);
  +	addAttribute(pAttribute3);
  +
  +	ComplexElement* pComplexElement = new ComplexElement();
  +	pComplexElement->setPrefix("m");
  +	pComplexElement->setLocalName("reference");
  +	pComplexElement->addChild(new CharacterElement("abcdefgh"));
  +
  +	ComplexElement* pComplexElement2 = new ComplexElement();
  +	pComplexElement2->setPrefix("m");
  +	pComplexElement2->setLocalName("dateAndTime");
  +	pComplexElement2->addChild(new CharacterElement("2001-11-29T13:20:00.000-05:00"));
  +
  +	addChild(pComplexElement);
  +	addChild(pComplexElement2);
  +
  +	return AXIS_SUCCESS;	
  +}
  +
  +bool HeaderBlock::operator ==( const HeaderBlock &objHeaderBlock)
  +{
  +	/*
  +	 *TODO : the logic
  +	 */
  +	return true;
  +}
  \ No newline at end of file
  
  
  
  1.8       +65 -9     ws-axis/c/src/soap/ComplexElement.cpp
  
  Index: ComplexElement.cpp
  ===================================================================
  RCS file: /home/cvs/ws-axis/c/src/soap/ComplexElement.cpp,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- ComplexElement.cpp	12 Jan 2004 12:20:54 -0000	1.7
  +++ ComplexElement.cpp	3 Feb 2004 05:19:10 -0000	1.8
  @@ -135,6 +135,51 @@
   	return iStatus;
   }
   
  +int ComplexElement::serialize(SoapSerializer& pSZ, list<AxisChar*>& lstTmpNameSpaceStack)
  +{
  +	int iStatus= AXIS_SUCCESS;
  +	do {
  +		if(isSerializable()) 
  +		{	
  +			bool blnIsNewNamespace = false;
  +
  +			pSZ.Serialize("<", NULL);	
  +			if(m_sPrefix.length() != 0) {				
  +				pSZ.Serialize(m_sPrefix.c_str(), ":", NULL);
  +			} else if (m_sURI.length() != 0) {
  +				m_sPrefix = pSZ.GetNamespacePrefix(m_sURI.c_str(), blnIsNewNamespace);
  +				if (blnIsNewNamespace) {
  +					lstTmpNameSpaceStack.push_back((AxisChar*)m_sURI.c_str());
  +				}
  +				pSZ.Serialize(m_sPrefix.c_str(), ":", NULL);
  +			}
  +
  +			pSZ.Serialize(m_sLocalName.c_str(), NULL);
  +
  +			if((m_sPrefix.length() != 0) && (m_sURI.length() != 0) && (blnIsNewNamespace))
{
  +				pSZ.Serialize(" xmlns:", m_sPrefix.c_str(), "=\"", m_sURI.c_str(), "\"", NULL);
  +			}
  +			pSZ.Serialize(">", NULL);
  +
  +			iStatus= serializeChildren(pSZ, lstTmpNameSpaceStack);
  +			if(iStatus==AXIS_FAIL) {
  +				break;
  +			}
  +			pSZ.Serialize("</", NULL);
  +			if(m_sPrefix.length() != 0) {				
  +				pSZ.Serialize(m_sPrefix.c_str(), ":", NULL);
  +			}
  +			pSZ.Serialize(m_sLocalName.c_str(), ">", NULL);
  +			iStatus= AXIS_SUCCESS;
  +		} 
  +		else
  +		{
  +			iStatus= AXIS_FAIL;
  +		}
  +	} while(0);	
  +	return iStatus;
  +}
  +
   /*
   comm on 10/7/2003 6.20pm
   int ComplexElement::serialize(string &sSerialized)
  @@ -186,13 +231,6 @@
   	bool bStatus= true;
   
   	do {
  -		if(m_sURI.length()!=0) {
  -			if(m_sPrefix.length()==0) {
  -				bStatus= false;
  -				break;
  -			}
  -		}
  -
   		if(m_sLocalName.length()==0) {
   			bStatus= false;
   			break;
  @@ -210,11 +248,29 @@
   
   int ComplexElement::serializeChildren(SoapSerializer& pSZ)
   {
  -
   	list<BasicNode*>::iterator itCurrBasicNode= m_children.begin();
   
  -	while(itCurrBasicNode != m_children.end()) {		
  +	while(itCurrBasicNode != m_children.end()) {
  +		
   		(*itCurrBasicNode)->serialize(pSZ);
  +		
  +		itCurrBasicNode++;		
  +	}	
  +
  +	return AXIS_SUCCESS;
  +}
  +
  +int ComplexElement::serializeChildren(SoapSerializer& pSZ, list<AxisChar*>&
lstTmpNameSpaceStack)
  +{
  +	list<BasicNode*>::iterator itCurrBasicNode= m_children.begin();
  +
  +	while(itCurrBasicNode != m_children.end()) {
  +		if ((*itCurrBasicNode)->getNodeType() == ELEMENT_NODE) {
  +			(*itCurrBasicNode)->serialize(pSZ, lstTmpNameSpaceStack);	
  +		} else {
  +			/* for CHARACTER_NODE */
  +			(*itCurrBasicNode)->serialize(pSZ);
  +		}
   		itCurrBasicNode++;		
   	}	
   
  
  
  
  1.10      +37 -0     ws-axis/c/src/soap/Attribute.cpp
  
  Index: Attribute.cpp
  ===================================================================
  RCS file: /home/cvs/ws-axis/c/src/soap/Attribute.cpp,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- Attribute.cpp	12 Jan 2004 12:20:54 -0000	1.9
  +++ Attribute.cpp	3 Feb 2004 05:19:10 -0000	1.10
  @@ -133,6 +133,33 @@
   	return intStatus;	
   }
   
  +int Attribute::serialize(SoapSerializer& pSZ, list<AxisChar*>& lstTmpNameSpaceStack)
  +{	
  +	int intStatus= AXIS_FAIL;
  +
  +	if (isSerializable()) {		
  +		pSZ.Serialize(" ", NULL);
  +
  +		if(!m_prefix.empty()) {			
  +			pSZ.Serialize(m_prefix.c_str(), ":", NULL);
  +		} else if (!m_uri.empty()) {
  +			bool blnIsNewNamespace = false;
  +			m_prefix = pSZ.GetNamespacePrefix(m_uri.c_str(), blnIsNewNamespace);
  +			if (blnIsNewNamespace) {
  +				lstTmpNameSpaceStack.push_back((AxisChar*)m_uri.c_str());
  +			}
  +
  +			pSZ.Serialize(m_prefix.c_str(), ":", NULL);
  +		}
  +
  +		pSZ.Serialize(m_localname.c_str(), "=\"", m_value.c_str(), "\"", NULL);
  +
  +		intStatus= AXIS_SUCCESS;
  +	}
  +
  +	return intStatus;	
  +}
  +
   /*
   commented on 10Jul2003 3.30 pm
   int Attribute::serialize(string& sSerialized)
  @@ -165,4 +192,14 @@
   	}
   
   	return bStatus;
  +}
  +
  +int Attribute::initializeForTesting()
  +{
  +	m_prefix = "pr";
  +	m_localname = "age";
  +	m_uri = "http://myurl.com";
  +	m_value = "25";
  +
  +	return AXIS_SUCCESS;
   }
  
  
  

Mime
View raw message