// WMSOAPDeserializer.h: interface for the WMSOAPDeserializer class.
//
//////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2003 Robert Cunnings. All rights reserved.
//
// You may copy, modify, distribute or publish this code free of charge.
//
// NO WARRANTY: This software is provided AS IS, without warranty of any kind.
//
//////////////////////////////////////////////////////////////////////
//
// WMSOAPDeserializer class - a SOAP message deserializer abstract base class.
// Implements methods to deserialize message elements.
// Both "encoded" (SOAP encoding only) or "literal" usage supported.
// 
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_WMSOAPDESERIALIZER_H__123BD811_4294_4F1F_9B5A_4D9E446773B7__INCLUDED_)
#define AFX_WMSOAPDESERIALIZER_H__123BD811_4294_4F1F_9B5A_4D9E446773B7__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <comdef.h>
#include "SOAPEventHandler.h"

class WMSOAPMessage;

interface Iwmwsdlclient2;

class WMSOAPDeserializer  
{
public:
	enum XSDTypes {
		XT_ANYTYPE = 256,
		XT_DATE = 257,
		XT_TIME = 258,
		XT_DATETIME = 259,
		XT_BASE64 = 260,
		XT_HEXBIN = 261,
		XT_BOOLEAN = 262,
		XT_ANYURI = 263
	};

	WMSOAPDeserializer();
	virtual ~WMSOAPDeserializer();

	virtual bool Deserialize(WMSOAPMessage& Msg,
		Iwmwsdlclient2 *pIWSDLClient) = 0;


protected:

	bool DeserializeBuiltInType(WMSOAPMessage& Msg,
                                WMSOAPParamHandler *pHandler,
								const wstring& wstrType,
								_variant_t& varValue);
	bool DeserializeBuiltInTypeEnc( const wstring& wstrEncStyle,
                                    WMSOAPMessage& Msg,
                                    WMSOAPParamHandler *pHandler,
								    const wstring& wstrType,
								    _variant_t& varValue);
	bool DeserializeBuiltInTypeLit( WMSOAPMessage& Msg,
                                    WMSOAPParamHandler *pHandler,
								    const wstring& wstrType,
								    _variant_t& varValue);
	bool DeserializeComplexTypeEnc( const wstring& wstrEncStyle,
                                    WMSOAPMessage& Msg,
								    Iwmwsdlclient2 *pIWSDLClient,
								    WMSOAPParamHandler *pRefValue,
								    WMSOAPParamHandler *pParamHandler,
								    bool bIsRef,
								    BSTR bstrType,
								    BSTR bstrTypeNS,
								    _variant_t& varValue);
	bool DeserializeComplexTypeLit( WMSOAPMessage& Msg,
								    Iwmwsdlclient2 *pIWSDLClient,
								    WMSOAPParamHandler *pParamHandler,
								    BSTR bstrType,
								    BSTR bstrTypeNS,
								    _variant_t& varValue);
	bool LoadSafeArrayEnc(  const wstring& wstrEncStyle,
                            long lDim,
						    long *arrIndex,
						    SAFEARRAY *pArray,
						    VARTYPE VarType,
						    long *plCounter,
						    WMSOAPParamHandler *pParam,
						    BSTR bstrType,
						    BSTR bstrTypeNS,
						    WMSOAPMessage& Msg,
						    Iwmwsdlclient2 *pIWSDLClient);
	SAFEARRAY *DeserializeSafeArrayEnc( const wstring& wstrEncStyle,
                                        WMSOAPParamHandler *pParam,
									    VARTYPE VarType,
									    BSTR bstrType,
									    BSTR bstrTypeNS,
									    long lNumDims,
									    WMSOAPMessage& Msg,
									    Iwmwsdlclient2 *pIWSDLClient);
	SAFEARRAY *DeserializeSafeArrayLit( WMSOAPParamHandler *pParam,
									    VARTYPE VarType,
                                        BSTR bstrItemName,
                                        BSTR bstrItemNS,
									    BSTR bstrItemType,
									    BSTR bstrItemTypeNS,
									    WMSOAPMessage& Msg,
									    Iwmwsdlclient2 *pIWSDLClient);
	SAFEARRAY *DeserializeArrayEnc( const wstring& wstrEncStyle,
                                    BSTR bstrArrayName,
								    BSTR bstrArrayNS,
								    WMSOAPParamHandler *pParam,
								    WMSOAPMessage& Msg,
								    Iwmwsdlclient2 *pIWSDLClient);
    SAFEARRAY *DeserializeArrayLit( WMSOAPParamHandler *pParam,
                                    BSTR bstrItemName,
                                    BSTR bstrItemNS,
                                    BSTR bstrItemType,
                                    BSTR bstrItemTypeNS,
                                    WMSOAPMessage& Msg,
                                    Iwmwsdlclient2 *pIWSDLClient);
	SAFEARRAY *DeserializeBase64Vector(WMSOAPParamHandler *pParam);
	SAFEARRAY *DeserializeHexBinaryVector(WMSOAPParamHandler *pParam);
	bool DeserializeDateTime(WMSOAPParamHandler *pParam, DATE *pDate);
	bool DeserializeDate(WMSOAPParamHandler *pParam, DATE *pDate);
	bool DeserializeTime(WMSOAPParamHandler *pParam, DATE *pDate);
	IDispatch *DeserializeStructEnc(const wstring& wstrEncStyle,
                                    BSTR bstrStructName,
									BSTR bstrStructNS,
									WMSOAPParamHandler *pParam,
									WMSOAPMessage& Msg,
									Iwmwsdlclient2 *pIWSDLClient);
	IDispatch *DeserializeStructLit(BSTR bstrStructName,
									BSTR bstrStructNS,
									WMSOAPParamHandler *pParam,
									WMSOAPMessage& Msg,
									Iwmwsdlclient2 *pIWSDLClient);
	virtual WMSOAPParamHandler *GetMultiRefElem(WMSOAPParamHandler *pParam) { return NULL; };
	bool IsXSDType(const wstring& wstrTypeNS)
	{
		if (wstrTypeNS == g_pwszXMLSchemaNS2001 ||
			wstrTypeNS == g_pwszXMLSchemaNS1999 ||
			wstrTypeNS == g_pwszXMLSchemaNS2000)
		{
			return true;
		}
		return false;
	}
	bool IsSoapEncType(const wstring& wstrTypeNS)
	{
		if (wstrTypeNS == g_pwszSoapEncodingNS || wstrTypeNS == g_pwszSoap12EncodingNS)
		{
			return true;
		}
		return false;
	}
	bool GetDIMEAttachment( WMSOAPMessage& Msg,
							Iwmwsdlclient2 *pIWSDLClient,
							WMSOAPParamHandler *pParamHandler,
							const wstring& wstrParamType,
							const wstring& wstrParamTypeNS,
							_variant_t& varValue);
	// the parser
	WMXMLParser				m_Parser;
	// the parser event handler
	WMSOAPParseEventHandler m_ParseEventHandler;
	// type map
	map<wstring, VARTYPE>	m_mapVarTypes;
};

#endif // !defined(AFX_WMSOAPDESERIALIZER_H__123BD811_4294_4F1F_9B5A_4D9E446773B7__INCLUDED_)
