Exemple #1
0
const char *GStringIterator::operator ++ (int)
{
	GString *pRet = (GString *)pDataNode->Data;
	pCurrentNode = pDataNode;
	pDataNode = pDataNode->NextNode;
	return pRet->StrVal();
}
void XMLObjectCache::dumpStateCache()
{
	TRACE_MESSAGE("****** Begin Object State Cache Dump ******");
	gthread_mutex_lock(&m_csState);
	GHashIterator iter(m_cacheState);
	while (iter())
	{
		GString *pObj = (GString *)iter++;
		GString str;
		str.Format("State In Cache - %s", pObj->StrVal());
		TRACE_MESSAGE((const char *)str);
	}
	gthread_mutex_unlock(&m_csState);
	TRACE_MESSAGE("****** End Object State Cache Dump ******");
}
void XMLObjectCache::stateCacheStatus(GStringList *pDest)
{
	gthread_mutex_lock(&m_csState);

	GHashIterator iter(m_cacheState);
	
	GString strCacheEntry;
	while (iter())
	{
		GString* pObject = (GString*)iter++;
		if (pObject)
		{
			strCacheEntry += pObject->StrVal();
			strCacheEntry += "\n";
		}
		pDest->AddLast((const char *)strCacheEntry);
	}
	gthread_mutex_unlock(&m_csState);
}
XMLObject* XMLObjectFactory::CreateObject(const char *pzTag,MemberDescriptor *pMap, unsigned int *nFlags)
{
	int bDidCreate = 0;
	
	// Default to null if CreateObject() is given a Tag that does
	// not map to an object.  This does not indicate an error.
	// The caller of CreateObject() must determine if null is error. 
	XMLObject* pObject = 0;

	if ( pMap->DataType == MemberDescriptor::ManagedByDerivedClass )
	{
		// let the derived class figure out where the object comes from
		pObject = pMap->m_DataAbstractor.pMemberHandler->
						GetObject(pzTag,m_pzLastFoundOID,m_pzLastUpdateTime,&bDidCreate);
	}
	else if( pMap->IsSubObject() )
	{
		// Containment object instance, the owning object has already 
		// instanciated the object, we only need a pointer to it.
		// for example a 'Customer' that has a m_Order, that Order
		// was allocated along with the customer unlike ObjectPtr<Order> m_pOrder.
		if ( pMap->DataType == MemberDescriptor::XMLObj ) 
		{
			// do not Factory create, this maps to an existing sub-object 
			pObject = pMap->m_Member.pObject;

			if(m_pzLastFoundOID[0])
				pObject->Init( m_pzLastFoundOID, m_pzLastUpdateTime);

			// Add this static map to the 'active system maps'.
			// For all dynamic objects (in list, tree, hash, pointers, etc.)
			// The map will be added in MemberDescriptor::AddContainedObject() so that
			// only a single Map is stored for the N objects that it may create,
			g_ActiveObjectMap.AddActiveObjectMap(pMap);
		}

		// If this object is one of the following types, then we 
		// must obtain an instance of the destination object
		// a. from the factory - for non-cached objects
		// b. from the cache - for cached objects with OID's
		else if ( pMap->DataType == MemberDescriptor::XMLObjList ||
				  pMap->DataType == MemberDescriptor::XMLObjPtr  ||
				  pMap->DataType == MemberDescriptor::Root		 ||
				  pMap->DataType == MemberDescriptor::KeyedDataStructure)
		{
			if (pMap->m_pfnFactoryCreate && pMap->DataType != MemberDescriptor::Root)
			{
				// If we were explicitly given a factory, use it directly. 
				// This object will not be cached.
				pObject = (*(pMap->m_pfnFactoryCreate))();
				pObject->Init( m_pzLastFoundOID, m_pzLastUpdateTime);
				bDidCreate = 1; // flag indicating a new object was just constructed
			}
			else 
				 
			{	 
				// Request it from the Object Cache, create it if it does not already 
				// exist - and place it into the cache if the ObjectID is known
				pObject = cacheManager.getObject(pzTag,m_pzLastFoundOID,m_pzLastUpdateTime,&bDidCreate);
				if ( pObject->GetObjectBehaviorFlags() & USE_STATE_CACHE )
				{
					GString *pState = cacheManager.getState(pzTag,m_pzLastFoundOID);
					if (pState)
					{
						// load the object from the state found in the state cache.
						pObject->SetObjectDescriptor(pMap);
						pObject->FromXML(pState->StrVal());
					}
				}
			}
			
			// If we created the object put it where the owning object has requested
			if ( pObject )
			{
				if ( pMap->DataType == MemberDescriptor::Root )
				{
					// This is a 'Root' object that does not map to the query.
					// For example, we queried for "Orders' and got back a 'Customer'
					// that MAY contain an 'Order' as a child. (we don't know yet)
					// We will now be expecting the actual objects that the query
					// has asked for, to be contained somewhere within this object.
					m_bApplyQueryResults = 1;
				}
				// since this usage is rare, for performance we only hit this code
				// when we know to expect sibling result objects.
				if (m_bApplyQueryResults ) 
				{
					if ( m_pResultSetDescriptor )
					{
						if ( ( // All objects in the query result set are found 
							   // at the same recursion level in the xml stream
							   (m_nXMLRecurseLevel == m_nQueryResultsLevel) ||
							   (m_nQueryResultsLevel == -1)
							 ) &&
							 // And must match the expected tag of the m_pResultSetDescriptor
							 (strcasecmp( (const char *)m_pResultSetDescriptor->strTagName, pzTag ) == 0 )
						   )
						{
							m_nQueryResultsLevel = m_nXMLRecurseLevel;
							m_pResultSetDescriptor->m_DataAbstractor.pListHandler->append( m_pResultSetDescriptor->m_Member.pXMLObjList,pObject );
						}
					}
				}
			}
		}
	}
	
	// Tie together the creating MemberDescriptor with the instance.
	// This enables an object to know it's creator.  Bringing together
	// the Tree of MemberDescriptors with the actual runtime instance
	// of the object.  This framework allows implicit object model
	// navigation - For example, if an instance of an object wanted 
	// to know if it resided within a list in a 'Customer' or as a 
	// pointer within a 'Order', it could navigate to it's runtime
	// owning instance by looking at the ObjectDescriptor in the 
	// MemberDescriptor that now resides within the object.
	if (pObject)
	{
		if (pObject->SetObjectDescriptor(pMap))
		{
			*nFlags |= FACTORY_FLAG_FIRST_REFERENCE;
		}
		else
		{
			// 12/28/2009 clear this flag to prevent IncRef() in FactoryInitComplete()
			// It may have been inadvertantly set in receiveIntoObject(). Search for 
			// "nDeepFlags = nDataFlags" to see where our parent object passed its flags.
			*nFlags &= ~FACTORY_FLAG_FIRST_REFERENCE; 
		}
	}


	if (bDidCreate == 1)
		*nFlags |= FACTORY_FLAG_OBJ_FROM_FACTORY;


	return pObject;
}