Click here to Skip to main content
15,897,704 members
Articles / Programming Languages / XML

XMLFoundation

Rate me:
Please Sign up or sign in to vote.
4.82/5 (12 votes)
2 Jul 20029 min read 75.3K   1.4K   34  
Obtaining data marked up in XML creates the need for Application Layer tools to easily and efficiently work with XML data.
// --------------------------------------------------------------------------
//					www.UnitedBusinessTechnologies.com
//			  Copyright (c) 1998 - 2002  All Rights Reserved.
//
// Source in this file is released to the public under the following license:
// --------------------------------------------------------------------------
// This toolkit may be used free of charge for any purpose including corporate
// and academic use.  For profit, and Non-Profit uses are permitted.
//
// This source code and any work derived from this source code must retain 
// this copyright at the top of each source file.
// 
// UBT welcomes any suggestions, improvements or new platform ports.
// email to: XMLFoundation@UnitedBusinessTechnologies.com
// --------------------------------------------------------------------------
#include "MemberDescriptor.h"
#include "FactoryManager.h"
#include "FrameworkAuditLog.h"
#include "xmlObject.h"
#include "GProfile.h"
#include <stdio.h>  // for: sprintf()
#include <string.h> // for: strlen() strcpy()

#ifdef _WIN32
	#define strcasecmp	stricmp
#endif


int XMLObjectFactoryManager::m_UIDCounter = 0;


XMLObjectFactoryManager::XMLObjectFactoryManager()
{
}

XMLObjectFactoryManager::~XMLObjectFactoryManager()
{
	GListIterator Iter(&m_factoryList);
	while (Iter())
	{
		MemberDescriptor *p = (MemberDescriptor *)Iter++;
		delete[] (char *)((p->m_Member).pClassName);
		delete p;
	}
}


//*********************************************************
// Description:
//		called by macro REG_FACTORY to register this object and it's factory
// 
// Preconditions:
//		.
// 
// Postconditions:
//		. 
// 
//*********************************************************
void XMLObjectFactoryManager::Add( ObjectFactory pFactory, const char * szTag, const char * szClassName)
{
	MemberDescriptor *pMD = GetRootableMapEntry(szTag); 
	if ( pMD ) 
	{
		char szTemp[128];
		sprintf(szTemp, "Object <%s> and <%s> both map to tag <%s>.  <%s> takes precesedence.", 
			(const char *)pMD->m_Member.pClassName, szClassName, szTag, (const char *)pMD->m_Member.pClassName);
		if ( GetProfile().GetBool("Debug", "MultiMapWarnings", false))
		{
			TRACE_WARNING(szTemp);
		}
	}
	else
	{
		char *pHeapedClassName = new char[strlen(szClassName) + 1];
		strcpy(pHeapedClassName,szClassName);
		m_factoryList.AddLast(new MemberDescriptor(0, szTag,pFactory,pHeapedClassName));
	}
}


// called by macro IMP_BOL_RELATION to register this interface
void XMLObjectFactoryManager::Add(	
							IFaceFactory Iff, 
							ObjectFactory Of, 
							const char *iFaceClassName , 
							const char *BusObjClassName)
{
	structIFaceCreate *sIFC = new structIFaceCreate();
	sIFC->Iff = Iff;
	sIFC->Of = Of;
	sIFC->strBusObjClassName = BusObjClassName;
	sIFC->strIFaceObjClassName = iFaceClassName;
	m_IFacefactoryList.AddLast(sIFC);
}

XMLObjectFactoryManager::structIFaceCreate *XMLObjectFactoryManager::FindIFaceInfo( const char *pzBOLClassName )
{

	GListIterator Iter (&m_IFacefactoryList);
	while (Iter())
	{
		structIFaceCreate *pIFC = (structIFaceCreate *)Iter++;
		if( strcmp(pzBOLClassName,(const char *)pIFC->strBusObjClassName) == 0 )
		{
			// we found a match
			return pIFC;
		}
	}
	return 0;// no match
}

	

//*********************************************************
// Description:
//		Check all the objects registered with REG_FACTORY using tag name as search key
// 
// Preconditions:
//		.
// 
// Postconditions:
//		. 
// 
//*********************************************************
MemberDescriptor *XMLObjectFactoryManager::GetRootableMapEntry(const char * pzTag)
{
	GListIterator Iter (&m_factoryList);
	while (Iter())
	{
		MemberDescriptor *pRootable = (MemberDescriptor *)Iter++;
		if( strcasecmp((const char *)pRootable->strTagName, pzTag) == 0 )
		{
			// we found a match
			return pRootable;
		}
	}
	return 0;/*No Root element matches pzTag*/
}

ObjectFactory XMLObjectFactoryManager::GetFactory(const char * pzTag)
{
	GListIterator Iter (&m_factoryList);
	while (Iter())
	{
		MemberDescriptor *pRootable = (MemberDescriptor *)Iter++;
		if( strcasecmp((const char *)pRootable->strTagName, pzTag) == 0 )
		{
			// we found a match
			return pRootable->m_pfnFactoryCreate;
		}
	}
	return 0;/*No Root element matches pzTag*/
}


const char *XMLObjectFactoryManager::GetSDKClassName(const char * pzTag)
{
	GListIterator Iter (&m_factoryList);
	while (Iter())
	{
		MemberDescriptor *pRootable = (MemberDescriptor *)Iter++;
		if( strcasecmp((const char *)pRootable->strTagName, pzTag) == 0 )
		{
			// we found a match
			return pRootable->m_Member.pClassName;
		}
	}
	return 0;/*No Root element matches pzTag*/
}


//*********************************************************
// Description:
//		Check all the objects registered with REG_FACTORY 
//		using factory function as search key
// 
// Preconditions:
//		.
// 
// Postconditions:
//		. 
// 
//*********************************************************
MemberDescriptor *XMLObjectFactoryManager::GetRootableMapEntry(ObjectFactory pFn)
{
	GListIterator Iter (&m_factoryList);
	while (Iter())
	{
		MemberDescriptor *pRootable = (MemberDescriptor *)Iter++;
		if(pRootable->m_pfnFactoryCreate == pFn)
		{
			// we found a match
			return pRootable;
		}
	}
	return 0;/*No Root element matches pFn*/
}

const char *XMLObjectFactoryManager::GetTag(ObjectFactory pFn)
{
	GListIterator Iter (&m_factoryList);
	while (Iter())
	{
		MemberDescriptor *pRootable = (MemberDescriptor *)Iter++;
		if(pRootable->m_pfnFactoryCreate == pFn)
		{
			// we found a match
			return (const char *)pRootable->strTagName;
		}
	}
	return 0;/*No Root element matches pFn*/
}


RegisterBusinessObject::RegisterBusinessObject(	ObjectFactory Of, 
												const char * szXMLTagIdentifier, 
												const char * szBusObjClassName)
{
	XMLObjectFactoryManager &r = XMLObjectFactoryManager::getFactoryManager();
	r.Add( Of, szXMLTagIdentifier, szBusObjClassName);
}

RegisterInterface::RegisterInterface(	IFaceFactory If,
										ObjectFactory Of, 
										const char * szIFaceClassName, 
										const char * szBusObjClassName)
{
	XMLObjectFactoryManager &r = XMLObjectFactoryManager::getFactoryManager();
	r.Add(	If,
			Of,
			szIFaceClassName,
			szBusObjClassName);	
}

XMLObjectFactoryManager &XMLObjectFactoryManager::getFactoryManager()
{
	static XMLObjectFactoryManager factoryManager;
	return factoryManager;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Founder United Business Technologies
United States United States
http://about.me/brian.aberle
https://www.linkedin.com/in/brianaberle
http://SyrianRue.org/Brian

Comments and Discussions