// SoapFaultMessage.h
//
//////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2002 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.
//
//////////////////////////////////////////////////////////////////////
//
// WMSOAPFaultMessage class - a class representing a SOAP Fault message.
// 
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_SOAPFAULTMESSAGE_H__CE664AFE_9841_4FCF_9368_37A155603AB9__INCLUDED_)
#define AFX_SOAPFAULTMESSAGE_H__CE664AFE_9841_4FCF_9368_37A155603AB9__INCLUDED_

#include "XMLDocFragment.h"
#include <string>
#include <list>
using namespace std;

class WMXMLElement;

class WMSOAPFaultMessage : public WMXMLDocFragment
{
public:
    WMSOAPFaultMessage(void);
    WMSOAPFaultMessage( const wstring& wstrCodeNS,
                        const wstring& wstrCode,
                        const wstring& wstrReason,
                        bool bDetailRequired);
    ~WMSOAPFaultMessage(void);

    bool FromElement(WMXMLElement *pElem);
    WMXMLElement *ToElement(int nSOAPVersion);

    bool Serialize(string& strXML, int nSOAPVersion);
    bool Serialize(wstring& wstrXML, int nSOAPVersion);
    bool Serialize(BSTR *pbstrXML, int nSOAPVersion);
    bool Deserialize(const string& strXML);
    bool Deserialize(const wstring& wstrXML);
    bool Deserialize(const BSTR bstrXML);

    int GetSOAPVersion() { return m_nSOAPVersion; }
    void SetSOAPVersion(int nSOAPVersion) { m_nSOAPVersion = nSOAPVersion; }

    bool GetDetailRequired() { return m_bDetailRequired; }
    void SetDetailRequired(bool bDetailRequired) { m_bDetailRequired = bDetailRequired; }
    bool AddDetailEntry(WMXMLElement *pElem);
    WMXMLElement *CreateDetailEntry(const wstring& wstrNamespace,
                                    const wstring& wstrPrefix,
                                    const wstring& wstrLocalName);
    WMXMLElement *GetDetailEntry(   const wstring& wstrNamespace,
                                    const wstring& wstrName);

    bool GetSOAPFaultCode(wstring& wstrValueNS, wstring& wstrValue);
    bool GetSOAPFaultString(wstring& wstrValue);
    bool GetSOAPFaultActor(wstring& wstrValue);
    bool GetSOAPFaultNode(wstring& wstrValue);

    void SetSOAPFaultCode(const wstring& wstrValueNS, const wstring& wstrValue)
    { 
        m_wstrCodeNS = wstrValueNS;
        m_wstrCode = wstrValue;
    }
    void SetSOAPFaultString(const wstring& wstrValue) { m_wstrReason = wstrValue; }
    void SetSOAPFaultActor(const wstring& wstrValue) { m_wstrRole = wstrValue; }
    void SetSOAPFaultNode(const wstring& wstrValue) { m_wstrNode = wstrValue; }

protected:

    WMXMLElement *BuildFaultMsg(int nSOAPVersion);
    void ClearDetails();

    // SOAP version
    int                                 m_nSOAPVersion;
    // faultcode (Code in SOAP 1.2)
    wstring                             m_wstrCode;
    wstring                             m_wstrCodeNS;
    // faultstring (Reason in SOAP 1.2)
    wstring                             m_wstrReason;
    // faultactor (Role in SOAP 1.2)
    wstring                             m_wstrRole;
    // fault node (SOAP 1.2 only)
    wstring                             m_wstrNode;
    // is detail element required?
    bool                                m_bDetailRequired;
    // detail element entries
    list<WMXMLElement *>                m_listDetailEntries;
};

#endif // !defined(AFX_SOAPFAULTMESSAGE_H__CE664AFE_9841_4FCF_9368_37A155603AB9__INCLUDED_)
