// XmlMemberValidation_StaticEnumItem.h
//

#include "stdafx.h"
#include "XmlBaseElement.h"
#include "XmlMemberValidation_StaticEnumItem.h"

CXmlMemberValidation_StaticEnumItem::CXmlMemberValidation_StaticEnumItem():
	itemEnumValue_(0)
{}

CXmlMemberValidation_StaticEnumItem::~CXmlMemberValidation_StaticEnumItem()
{
	Clear();
}

bool CXmlMemberValidation_StaticEnumItem::BuildFromXml(IXMLDOMNode* node)
{
	Clear();

	ExtractMemberNode(node, _T("ItemName"), itemName_);
	ExtractMemberNode(node, _T("ItemEnumValue"), itemEnumValue_);
	ExtractMemberNode(node, _T("ItemValue"), itemValue_);
	ExtractMemberNode(node, _T("ItemDescription"), itemDescription_);

	return true;
}

bool CXmlMemberValidation_StaticEnumItem::AppendToDOMDocument(IXMLDOMDocument2* xmlDoc, IXMLDOMElement* parentElement)
{
	IXMLDOMElement* newElement;
	bool ret = true;
	HRESULT hr;

	hr = xmlDoc->createElement(CComBSTR((const TCHAR*)GetXmlNodeName()), &newElement);

	AppendMemberNode(_T("ItemName"), itemName_, newElement, xmlDoc);
	AppendMemberNode(_T("ItemEnumValue"), itemEnumValue_, newElement, xmlDoc);
	AppendMemberNode(_T("ItemValue"), itemValue_, newElement, xmlDoc);
	AppendMemberNode(_T("ItemDescription"), itemDescription_, newElement, xmlDoc);
	
	// append node to parent element
	//
	IXMLDOMNode* newOutNode;

	if (parentElement)
		hr = parentElement->appendChild(newElement, &newOutNode);
	else
		hr = xmlDoc->appendChild(newElement, &newOutNode);
	newOutNode->Release();

	return ret;
}

void CXmlMemberValidation_StaticEnumItem::SetItemName(const cmString& itemName)
{
	itemName_ = itemName;
}

cmString CXmlMemberValidation_StaticEnumItem::GetItemName() const
{
	return itemName_;
}

void CXmlMemberValidation_StaticEnumItem::SetItemValue(const cmString& itemValue)
{
	itemValue_ = itemValue;
}

cmString CXmlMemberValidation_StaticEnumItem::GetItemValue() const
{
	return itemValue_;
}

void CXmlMemberValidation_StaticEnumItem::SetItemDescription(const cmString& itemDescription)
{
	itemDescription_ = itemDescription;
}

cmString CXmlMemberValidation_StaticEnumItem::GetItemDescription() const
{
	return itemDescription_;
}

void CXmlMemberValidation_StaticEnumItem::Clear()
{

}
	
void CXmlMemberValidation_StaticEnumItem::SetDefaults()
{

}

cmString CXmlMemberValidation_StaticEnumItem::GetEscapedItemValue()
{
	cmString escapedName;

	for (int i = 0; i < itemName_.GetLength(); i++) {
		switch (itemName_[i]) {
			case '.':
				escapedName = _T("_dot_");
				break;

			case ' ':
				break;

			default:
				escapedName += itemName_[i];
		}
	}

	return escapedName;
}

void CXmlMemberValidation_StaticEnumItem::SetItemEnumValue(long value)
{
	itemEnumValue_ = value;
}

long CXmlMemberValidation_StaticEnumItem::GetItemEnumValue() const
{
	return itemEnumValue_;
}
