// WMSOAPBindingHandlers.h
//
//////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2000, 2001 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.
//
//////////////////////////////////////////////////////////////////////
//
// SOAP extensibility elements - support for SOAP binding elements in WSDL
//  
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_WMSOAPBINDINGHANDLERS_H__33DA6B5E_D082_4A66_9857_F73D91FA2128__INCLUDED_)
#define AFX_WMSOAPBINDINGHANDLERS_H__33DA6B5E_D082_4A66_9857_F73D91FA2128__INCLUDED_

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

#include "WSDLElements.h"

// SOAP extensibility elements
class WMSOAPBindingHeaderFaultExt : public WMWSDLEventHandler  
{
public:
	WMSOAPBindingHeaderFaultExt() {}
	virtual ~WMSOAPBindingHeaderFaultExt() {}

    WMWSDLEventHandler *StartElement(const wstring& wstrURI,
									const wstring& wstrLocalName,
									const wstring& wstrQualifiedName,
									WMXMLAttributeMap& mapAttributes,
									NSPrefixMap& mapNSPrefixes,
									WMXMLElement *pElement)
	{ return IGNORE_ELEMENT_HANDLER; }

    void ReadAttributes(WMXMLAttributeMap& mapAttributes, NSPrefixMap& mapNSPrefixes);

	void GetMessage(wstring& wstrMessage, wstring& wstrMessageNS)
	{
		wstrMessage = m_wstrMessage;
		wstrMessageNS = m_wstrMessageNS;
	}
	const wstring& GetPart() { return m_wstrPart; }
	const wstring& GetNamespaceURI() { return m_wstrNamespace; }
	const wstring& GetUse() { return m_wstrUse; }
	const wstring& GetEncodingStyle() { return m_wstrEncodingStyle; }
	bool GetHeaderPartMsg(  const wstring& wstrPartName,
							const wstring& wstrPartNS,
							wstring& wstrMsg,
							wstring& wstrMsgNS);
    bool GetHeaderPartEncStyle( const wstring& wstrPartName,
							    const wstring& wstrPartNS,
							    wstring& wstrEncStyle);

protected:
	wstring		m_wstrMessage;
	wstring		m_wstrMessageNS;
	wstring		m_wstrPart;
	wstring		m_wstrUse;
	wstring		m_wstrEncodingStyle;
	wstring		m_wstrNamespace;
};

class WMSOAPBindingHeaderExt : public WMSOAPBindingHeaderFaultExt  
{
public:
	WMSOAPBindingHeaderExt() {}
	virtual ~WMSOAPBindingHeaderExt()
	{
		list<WMSOAPBindingHeaderFaultExt *>::iterator iL;
		for (iL = m_listSOAPFaultHeaders.begin();
			iL != m_listSOAPFaultHeaders.end(); iL++)
		{
			delete *iL;
		}
	}
    WMWSDLEventHandler *StartElement(const wstring& wstrURI,
									const wstring& wstrLocalName,
									const wstring& wstrQualifiedName,
									WMXMLAttributeMap& mapAttributes,
									NSPrefixMap& mapNSPrefixes,
									WMXMLElement *pElement);
    void ReadAttributes(WMXMLAttributeMap& mapAttributes, NSPrefixMap& mapNSPrefixes);

	list<WMSOAPBindingHeaderFaultExt *>& GetFaultHeaders() { return m_listSOAPFaultHeaders; }

protected:

	list<WMSOAPBindingHeaderFaultExt *>	m_listSOAPFaultHeaders;
};

class WMSOAPBindingBodyExt : public WMWSDLEventHandler  
{
public:
	WMSOAPBindingBodyExt() {}
	virtual ~WMSOAPBindingBodyExt() {}
    WMWSDLEventHandler *StartElement(const wstring& wstrURI,
									const wstring& wstrLocalName,
									const wstring& wstrQualifiedName,
									WMXMLAttributeMap& mapAttributes,
									NSPrefixMap& mapNSPrefixes,
									WMXMLElement *pElement)
	{ return IGNORE_ELEMENT_HANDLER; }

    void ReadAttributes(WMXMLAttributeMap& mapAttributes, NSPrefixMap& mapNSPrefixes);
	const wstring& GetSOAPBodyNS() { return m_wstrNamespace; };
	const wstring& GetSOAPBodyEncStyle() { return m_wstrEncodingStyle; };
	const wstring& GetSOAPBodyUse() { return m_wstrUse; };
	const wstring& GetSOAPBodyParts() { return m_wstrParts; };

protected:
	wstring		m_wstrParts;
	wstring		m_wstrUse;
	wstring		m_wstrEncodingStyle;
	wstring		m_wstrNamespace;
};

class WMSOAPBindingFaultExt : public WMWSDLEventHandler  
{
public:
	WMSOAPBindingFaultExt() {}
	virtual ~WMSOAPBindingFaultExt() {}
    WMWSDLEventHandler *StartElement(const wstring& wstrURI,
									const wstring& wstrLocalName,
									const wstring& wstrQualifiedName,
									WMXMLAttributeMap& mapAttributes,
									NSPrefixMap& mapNSPrefixes,
									WMXMLElement *pElement)
	{ return IGNORE_ELEMENT_HANDLER; }
    void ReadAttributes(WMXMLAttributeMap& mapAttributes, NSPrefixMap& mapNSPrefixes);
	const wstring& GetName() { return m_wstrName; }
	const wstring& GetNamespaceURI() { return m_wstrNamespace; }
	const wstring& GetUse() { return m_wstrUse; }
	const wstring& GetEncodingStyle() { return m_wstrEncodingStyle; }

protected:
	wstring		m_wstrName;
	wstring		m_wstrUse;
	wstring		m_wstrEncodingStyle;
	wstring		m_wstrNamespace;
};

class WMSOAPBindingOpExt : public WMWSDLEventHandler  
{
public:
	WMSOAPBindingOpExt() { m_bSOAPActionRequired = false; }
	virtual ~WMSOAPBindingOpExt() {}
    WMWSDLEventHandler *StartElement(const wstring& wstrURI,
									const wstring& wstrLocalName,
									const wstring& wstrQualifiedName,
									WMXMLAttributeMap& mapAttributes,
									NSPrefixMap& mapNSPrefixes,
									WMXMLElement *pElement)
	{ return IGNORE_ELEMENT_HANDLER; }
    void ReadAttributes(WMXMLAttributeMap& mapAttributes, NSPrefixMap& mapNSPrefixes);
	const wstring& GetSOAPAction() { return m_wstrSOAPAction; }
	const wstring& GetStyle() { return m_wstrStyle; }
    bool SOAPActionRequired() { return m_bSOAPActionRequired; }

protected:
	wstring		m_wstrSOAPAction;
	wstring		m_wstrStyle;
    bool        m_bSOAPActionRequired;
};

class WMSOAPBindingBindingExt : public WMWSDLEventHandler  
{
public:
	WMSOAPBindingBindingExt() { m_wstrStyle = L"document"; }
	virtual ~WMSOAPBindingBindingExt() {}
    void ReadAttributes(WMXMLAttributeMap& mapAttributes, NSPrefixMap& mapNSPrefixes);
    WMWSDLEventHandler *StartElement(const wstring& wstrURI,
									const wstring& wstrLocalName,
									const wstring& wstrQualifiedName,
									WMXMLAttributeMap& mapAttributes,
									NSPrefixMap& mapNSPrefixes,
									WMXMLElement *pElement)
	{ return IGNORE_ELEMENT_HANDLER; }
	const wstring& GetSOAPBindingStyle() { return m_wstrStyle; };
	const wstring& GetSOAPBindingTransport() { return m_wstrTransport; };

protected:
	wstring		m_wstrStyle;
	wstring		m_wstrTransport;
};

class WMSOAPAddressExt : public WMWSDLEventHandler  
{
public:
	WMSOAPAddressExt() {}
	virtual ~WMSOAPAddressExt() {}
    void ReadAttributes(WMXMLAttributeMap& mapAttributes, NSPrefixMap& mapNSPrefixes);
    WMWSDLEventHandler *StartElement(const wstring& wstrURI,
									const wstring& wstrLocalName,
									const wstring& wstrQualifiedName,
									WMXMLAttributeMap& mapAttributes,
									NSPrefixMap& mapNSPrefixes,
									WMXMLElement *pElement)
	{ return IGNORE_ELEMENT_HANDLER; }
	const wstring& GetAddress() { return m_wstrSOAPAddress; }

protected:
	wstring m_wstrSOAPAddress;
};

// derived from base WSDL handlers

class WMSOAPFaultElemHandler : public WMFaultHandler  
{
public:
	WMSOAPFaultElemHandler() {}
	virtual ~WMSOAPFaultElemHandler() {}
    void ReadAttributes(WMXMLAttributeMap& mapAttributes, NSPrefixMap& mapNSPrefixes);
    WMWSDLEventHandler *StartElement(const wstring& wstrURI,
									const wstring& wstrLocalName,
									const wstring& wstrQualifiedName,
									WMXMLAttributeMap& mapAttributes,
									NSPrefixMap& mapNSPrefixes,
									WMXMLElement *pElement);
	const wstring& GetSOAPFaultName() { return m_SOAPFault.GetName(); }
	const wstring& GetSOAPFaultNamespace() { return m_SOAPFault.GetNamespaceURI(); }
	const wstring& GetSOAPFaultEncStyle() { return m_SOAPFault.GetEncodingStyle(); }
	const wstring& GetSOAPFaultUse() { return m_SOAPFault.GetUse(); }

protected:
	WMSOAPBindingFaultExt	m_SOAPFault;
};

class WMSOAPOutputHandler : public WMOutputHandler  
{
public:
	WMSOAPOutputHandler() {}
	virtual ~WMSOAPOutputHandler()
	{
		list<WMSOAPBindingHeaderExt *>::iterator iL;
		for (iL = m_listSOAPHeaders.begin();
			iL != m_listSOAPHeaders.end(); iL++)
		{
			delete *iL;
		}
	}
    WMWSDLEventHandler *StartElement(const wstring& wstrURI,
									const wstring& wstrLocalName,
									const wstring& wstrQualifiedName,
									WMXMLAttributeMap& mapAttributes,
									NSPrefixMap& mapNSPrefixes,
									WMXMLElement *pElement);
	const wstring& GetSOAPBodyNS() { return m_SOAPBody.GetSOAPBodyNS(); }
	const wstring& GetSOAPBodyEncStyle() { return m_SOAPBody.GetSOAPBodyEncStyle(); }
	const wstring& GetSOAPBodyUse() { return m_SOAPBody.GetSOAPBodyUse(); }
	const wstring& GetSOAPBodyParts() { return m_SOAPBody.GetSOAPBodyParts(); }
	bool GetHeaderPartMsg(  const wstring& wstrPartName,
							const wstring& wstrPartNS,
							wstring& wstrMsg,
							wstring& wstrMsgNS);
	bool GetHeaderPartEncStyle( const wstring& wstrPartName,
							    const wstring& wstrPartNS,
							    wstring& wstrEncStyle);
	bool GetHeaderFaultPartMsg( const wstring& wstrPartName,
								const wstring& wstrPartNS,
								wstring& wstrMsg,
								wstring& wstrMsgNS);
	bool GetHeaderFaultPartEncStyle(const wstring& wstrPartName,
								    const wstring& wstrPartNS,
								    wstring& wstrEncStyle);
	list<WMSOAPBindingHeaderExt *>& GetSOAPHeaders() { return m_listSOAPHeaders; }

protected:
	WMSOAPBindingBodyExt			m_SOAPBody;
	list<WMSOAPBindingHeaderExt *>	m_listSOAPHeaders;
};

class WMSOAPInputHandler : public WMInputHandler  
{
public:
	WMSOAPInputHandler() {}
	virtual ~WMSOAPInputHandler()
	{
		list<WMSOAPBindingHeaderExt *>::iterator iL;
		for (iL = m_listSOAPHeaders.begin();
			iL != m_listSOAPHeaders.end(); iL++)
		{
			delete *iL;
		}
	}
    WMWSDLEventHandler *StartElement(const wstring& wstrURI,
									const wstring& wstrLocalName,
									const wstring& wstrQualifiedName,
									WMXMLAttributeMap& mapAttributes,
									NSPrefixMap& mapNSPrefixes,
									WMXMLElement *pElement);
	const wstring& GetSOAPBodyNS() { return m_SOAPBody.GetSOAPBodyNS(); }
	const wstring& GetSOAPBodyEncStyle() { return m_SOAPBody.GetSOAPBodyEncStyle(); }
	const wstring& GetSOAPBodyUse() { return m_SOAPBody.GetSOAPBodyUse(); };
	const wstring& GetSOAPBodyParts() { return m_SOAPBody.GetSOAPBodyParts(); }
	bool GetHeaderPartMsg(  const wstring& wstrPartName,
							const wstring& wstrPartNS,
							wstring& wstrMsg,
							wstring& wstrMsgNS);
	bool GetHeaderPartEncStyle( const wstring& wstrPartName,
							    const wstring& wstrPartNS,
							    wstring& wstrEncStyle);
	bool GetHeaderFaultPartMsg( const wstring& wstrPartName,
								const wstring& wstrPartNS,
								wstring& wstrMsg,
								wstring& wstrMsgNS);
	bool GetHeaderFaultPartEncStyle(const wstring& wstrPartName,
								    const wstring& wstrPartNS,
								    wstring& wstrEncStyle);
	list<WMSOAPBindingHeaderExt *>& GetSOAPHeaders() { return m_listSOAPHeaders; }

protected:
	WMSOAPBindingBodyExt			m_SOAPBody;
	list<WMSOAPBindingHeaderExt *>	m_listSOAPHeaders;
};

class WMSOAPOperationHandler : public WMOperationHandler  
{
public:
	WMSOAPOperationHandler() {}
	virtual ~WMSOAPOperationHandler()
	{
		list<WMSOAPFaultElemHandler *>::iterator iL;
		for (iL = m_listFaults.begin();
			iL != m_listFaults.end(); iL++)
		{
			delete *iL;
		}
	}
    WMWSDLEventHandler *StartElement(const wstring& wstrURI,
									const wstring& wstrLocalName,
									const wstring& wstrQualifiedName,
									WMXMLAttributeMap& mapAttributes,
									NSPrefixMap& mapNSPrefixes,
									WMXMLElement *pElement);
    void ReadAttributes(WMXMLAttributeMap& mapAttributes, NSPrefixMap& mapNSPrefixes);
	void GetNames(wstring& wstrName, wstring& wstrNS)
	{	wstrName =  m_wstrName;
		wstrNS = m_wstrNS;
	}
	const wstring& GetSOAPAction() { return m_SOAPOperation.GetSOAPAction(); }
    bool SOAPActionRequired() { return m_SOAPOperation.SOAPActionRequired(); }
	const wstring& GetSOAPBindingStyle() { return m_SOAPOperation.GetStyle(); };
	const wstring& GetSOAPInputBodyNS() { return m_Input.GetSOAPBodyNS(); }
	const wstring& GetSOAPOutputBodyNS() { return m_Output.GetSOAPBodyNS(); }
	const wstring& GetSOAPInputBodyEncStyle() { return m_Input.GetSOAPBodyEncStyle(); }
	const wstring& GetSOAPOutputBodyEncStyle() { return m_Output.GetSOAPBodyEncStyle(); }
	const wstring& GetSOAPInputBodyUse() { return m_Input.GetSOAPBodyUse(); }
	const wstring& GetSOAPOutputBodyUse() { return m_Output.GetSOAPBodyUse(); }
	const wstring& GetSOAPInputBodyParts() { return m_Input.GetSOAPBodyParts(); }
	const wstring& GetSOAPOutputBodyParts() { return m_Output.GetSOAPBodyParts(); }
	WMSOAPInputHandler& GetInput() { return m_Input; }
	WMSOAPOutputHandler& GetOutput() { return m_Output; }
	list<WMSOAPFaultElemHandler	*>& GetFaultList() { return m_listFaults; }

protected:
	WMSOAPInputHandler				m_Input;
	WMSOAPOutputHandler				m_Output;
	WMSOAPBindingOpExt				m_SOAPOperation;
	wstring							m_wstrName;
	list<WMSOAPFaultElemHandler	*>	m_listFaults;
};

class WMSOAPBindingHandler : public WMBindingHandler  
{
public:
	WMSOAPBindingHandler() {}
	virtual ~WMSOAPBindingHandler()
	{
	}
    WMWSDLEventHandler *StartElement(const wstring& wstrURI,
									const wstring& wstrLocalName,
									const wstring& wstrQualifiedName,
									WMXMLAttributeMap& mapAttributes,
									NSPrefixMap& mapNSPrefixes,
									WMXMLElement *pElement);
	WMSOAPOperationHandler *GetSOAPOperation(const wstring& wstrOpName);
	WMSOAPOperationHandler *GetOpBySOAPAction(const wstring& wstrSOAPAction);

	const wstring& GetSOAPBindingStyle() { return m_SOAPBinding.GetSOAPBindingStyle(); };
	const wstring& GetSOAPBindingTransport() { return m_SOAPBinding.GetSOAPBindingTransport(); };
    const wstring& GetSOAPBindingVersion() { return m_SOAPBinding.GetNamespace(); }

protected:
	WMSOAPBindingBindingExt m_SOAPBinding;
};

class WMSOAPPortHandler : public WMPortHandler  
{
public:
	WMSOAPPortHandler() {}
	virtual ~WMSOAPPortHandler() {}
    WMWSDLEventHandler *StartElement(const wstring& wstrURI,
									const wstring& wstrLocalName,
									const wstring& wstrQualifiedName,
									WMXMLAttributeMap& mapAttributes,
									NSPrefixMap& mapNSPrefixes,
									WMXMLElement *pElement);
	const wstring& GetSOAPAddress() { return m_SOAPAddress.GetAddress(); }
	bool IsSOAPPort() { return (m_SOAPAddress.GetAddress().length() > 0); }

protected:
	WMSOAPAddressExt	m_SOAPAddress;
};

class WMSOAPServiceHandler : public WMServiceHandler  
{
public:
	WMSOAPServiceHandler() {}
	virtual ~WMSOAPServiceHandler() {}
    WMWSDLEventHandler *StartElement(const wstring& wstrURI,
									const wstring& wstrLocalName,
									const wstring& wstrQualifiedName,
									WMXMLAttributeMap& mapAttributes,
									NSPrefixMap& mapNSPrefixes,
									WMXMLElement *pElement);
};

class WMSOAPDefinitionsHandler : public WMDefinitionsHandler  
{
public:
	WMSOAPDefinitionsHandler() {}
	virtual ~WMSOAPDefinitionsHandler() {}
    WMWSDLEventHandler *StartElement(const wstring& wstrURI,
										const wstring& wstrLocalName,
										const wstring& wstrQualifiedName,
										WMXMLAttributeMap& mapAttributes,
										NSPrefixMap& mapNSPrefixes,
										WMXMLElement *pElement);

	WMSOAPBindingHandler *GetSOAPBinding(const wstring& wstrServiceName,
										const wstring& wstrPortName,
										const wstring& wstrNamespace);
	bool GetSOAPAddress(const wstring& wstrServiceName,
						const wstring& wstrPortName,
						const wstring& wstrNamespace,
						wstring& wstrAddress);
	const string& GetDocBase() { return m_strDocBase; }
	void SetDocBase(const string& strBase) { m_strDocBase = strBase; }

protected:
	string		m_strDocBase;
};

class WMSOAPWSDLDesc : public WMWSDLDesc  
{
public:
	WMSOAPWSDLDesc() {}
	virtual ~WMSOAPWSDLDesc() {}
    WMWSDLEventHandler *StartElement(const wstring& wstrURI,
									const wstring& wstrLocalName,
									const wstring& wstrQualifiedName,
									WMXMLAttributeMap& mapAttributes,
									NSPrefixMap& mapNSPrefixes,
									WMXMLElement *pElement);
	// query support
	WMSOAPDefinitionsHandler& GetSOAPDefinitions() { return m_Definitions; }
	const wstring& GetDefinitionsName() { return m_Definitions.GetName(); }
	const wstring& GetDefinitionsTNS() { return m_Definitions.GetTNS(); }
	const string& GetDocumentBase() { return m_Definitions.GetDocBase(); }
	void SetDocumentBase(const string& strBase) { m_Definitions.SetDocBase(strBase); }

protected:
	WMSOAPDefinitionsHandler	m_Definitions;
};


#endif // !defined(AFX_WMSOAPBINDINGHANDLERS_H__33DA6B5E_D082_4A66_9857_F73D91FA2128__INCLUDED_)
