[GME-commit] GMESRC/GME/XmlBackEnd CoreXmlFile.cpp, 1.34, 1.35 CoreXmlFile.h, 1.17, 1.18

Log messages of CVS commits gme-commit at list.isis.vanderbilt.edu
Wed May 7 15:51:47 CDT 2008


Update of /project/gme-repository/GMESRC/GME/XmlBackEnd
In directory escher:/tmp/cvs-serv29660

Modified Files:
	CoreXmlFile.cpp CoreXmlFile.h 
Log Message:
Xerces/Parser errors shown better.


CVS User: Zoltan Molnar, ISIS (zolmol)

Index: CoreXmlFile.cpp
===================================================================
RCS file: /project/gme-repository/GMESRC/GME/XmlBackEnd/CoreXmlFile.cpp,v
retrieving revision 1.34
retrieving revision 1.35
diff -C2 -d -r1.34 -r1.35
*** CoreXmlFile.cpp	21 Feb 2008 18:49:15 -0000	1.34
--- CoreXmlFile.cpp	7 May 2008 20:51:45 -0000	1.35
***************
*** 3213,3222 ****
  
  
! 	DOMBuilder * parser = NULL;
! 	DOMImplementationLS * domimpl = DOMImplementationRegistry::getDOMImplementation(NULL);
! 	ASSERT( domimpl != NULL );
! 	parser = !domimpl? 0: domimpl->createDOMBuilder( DOMImplementationLS::MODE_SYNCHRONOUS, NULL );
  	ASSERT( parser != NULL );
! 	if( !domimpl || !parser)
  	{
  		sendMsg( "Exception: Could not create parser!", MSG_ERROR);
--- 3213,3220 ----
  
  
! 	DOMBuilder * parser = getFreshParser( "ProjectFileReader");
! 
  	ASSERT( parser != NULL );
! 	if( !parser)
  	{
  		sendMsg( "Exception: Could not create parser!", MSG_ERROR);
***************
*** 4799,4825 ****
  	try
  	{
! back_again:
! 		bool held = true;
! 		while( held)
  		{
! 			held = anybodyElseHolding();
! 			if( held)
  			{
! 				// others hold a lock to the signin file
! 				// notify user and retry if needed
! 				if( IDCANCEL == AfxMessageBox( in?msg_in:msg_out, MB_OKCANCEL))
! 					break; // quit, no further attempts
  			}
  		}
  
! 		if( !held)
  		{
- 			try {
- 				acquireFile();
- 			}
- 			catch(hresult_exception&) {
- 				// somebody else acquired it in the meantime
- 				goto back_again;
- 			}
  			if( isSV()) {
  				std::string owner;
--- 4797,4834 ----
  	try
  	{
! 		bool lost_patience          = false; // once this will turn true further attempts will cease
! 		bool successful_acquisition = false;
! 
! 		while( !successful_acquisition && !lost_patience)
  		{
! 			bool chance_for_acquisition = false;
! 
! 			while( !chance_for_acquisition && !lost_patience)
  			{
! 				chance_for_acquisition = !anybodyElseHolding();
! 				if( !chance_for_acquisition)
! 				{
! 					// others hold a lock to the signin file
! 					// notify user and retry if needed
! 					if( IDCANCEL == AfxMessageBox( in?msg_in:msg_out, MB_OKCANCEL))
! 						lost_patience = true; // quit, no further attempts
! 				}
! 			}
! 
! 			if( chance_for_acquisition) // user did not give up, no one holding the file, chance to acquire it
! 			{
! 				try {
! 					acquireFile();
! 					successful_acquisition = true;
! 				}
! 				catch(hresult_exception&) {
! 					// somebody else acquired it in the meantime
! 				}
  			}
+ 			// else: lost_patience turned true, so this loop will terminate too
  		}
  
! 		if( successful_acquisition)
  		{
  			if( isSV()) {
  				std::string owner;
***************
*** 4832,4836 ****
  			}
  
! 			update( in, SignFileEntry( userName(), CTime::GetCurrentTime()));
  
  			releaseFile();
--- 4841,4849 ----
  			}
  
! 			try {
! 				update( in, SignFileEntry( userName(), CTime::GetCurrentTime()));
! 			} catch(hresult_exception&) { // handled cases throw HRESULT from inside
! 				m_parent->sendMsg( "Could not update signature file! Exception happened.", MSG_ERROR);
! 			}
  
  			releaseFile();
***************
*** 4845,4868 ****
  void SignManager::update( bool p_in, const SignFileEntry& p_entry)
  {
! 	DOMBuilder * parser = NULL;
  	try {
! 		DOMImplementationLS * domimpl = DOMImplementationRegistry::getDOMImplementation(NULL);
! 		ASSERT( domimpl != NULL );
! 		parser = !domimpl? 0: domimpl->createDOMBuilder( DOMImplementationLS::MODE_SYNCHRONOUS, NULL );
! 		ASSERT( parser != NULL );
! 		if( !domimpl || !parser)
  		{
! 			m_parent->sendMsg( "Exception: Could not create parser!", MSG_ERROR);
! 			HR_THROW(E_FILEOPEN);
  		}
! 
! 		XERCES_CPP_NAMESPACE::DOMDocument * doc = parser->parseURI( m_localFileName.c_str() );
! 		if( doc == NULL )
  		{
! 			m_parent->sendMsg( "Exception: Could not parse signature file!", MSG_ERROR);
! 			HR_THROW(E_FILEOPEN);
  		}
  
- 		DOMElement * doc_e = doc->getDocumentElement();
  		if( doc_e == NULL)
  		{
--- 4858,4944 ----
  void SignManager::update( bool p_in, const SignFileEntry& p_entry)
  {
! 	DOMImplementationLS    * domimpl = NULL;
! 	DOMBuilder             * parser  = m_parent->getFreshParser( "SignatureFileUpdater", &domimpl);
! 
! 	ASSERT( parser != NULL );
! 	if( !parser) {
! 		m_parent->sendMsg( "DOMBuilder pointer is NULL!", MSG_ERROR);
! 		HR_THROW(E_FILEOPEN);
! 	}
! 
! 	//
! 	// Parsing
! 	XERCES_CPP_NAMESPACE::DOMDocument * doc = 0;
  	try {
! 
! 		doc = parser->parseURI( m_localFileName.c_str() );
! 
! 	} 
! 	catch( const OutOfMemoryException&) {
! 
! 		doc = 0;
! 
! 		m_parent->sendMsg( "OutOfMemoryException during parsing.", MSG_ERROR);
! 	}
! 	catch (const SAXException&) { 
! 
! 		doc = 0;
! 
! 		m_parent->sendMsg( "SAXException during parsing.", MSG_ERROR);
! 	}
! 	catch (const XMLException& e) 
! 	{
! 		doc = 0;
! 
! 		char* e_msg = XMLString::transcode( e.getMessage());
! 		m_parent->sendMsg( (std::string( "XMLException during parsing. Message: ") + e_msg).c_str(), MSG_ERROR);
! 
! 		XMLString::release( &e_msg);
! 	}
! 	catch (const DOMException& e) 
! 	{
! 		doc = 0;
! 
! 		char*              e_msg    = 0;
! 		const unsigned int maxChars = 2047;
! 		XMLCh              errText[maxChars + 1];
! 
! 		if( DOMImplementation::loadDOMExceptionMsg( e.code, errText, maxChars))
  		{
! 			e_msg = XMLString::transcode( errText);
! 			m_parent->sendMsg( (std::string( "DOMException during parsing. Message: ") + e_msg).c_str(), MSG_ERROR);
  		}
! 		else
  		{
! 			e_msg = XMLString::transcode( e.getMessage());
! 			m_parent->sendMsg( (std::string( "DOMException during parsing. Message: ") + e_msg).c_str(), MSG_ERROR);
  		}
+ 		XMLString::release( &e_msg);
+ 	}
+ 	catch (...) {
+ 
+ 		doc = 0;
+ 
+ 		m_parent->sendMsg( "GenException during parsing.", MSG_ERROR);
+ 	}
+ 
+ 	if( doc == NULL )
+ 	{
+ 		m_parent->sendMsg( "DOMDocument pointer is NULL. Parsing of signature file failed.", MSG_ERROR);
+ 		HR_THROW(E_FILEOPEN);
+ 	}
+ 
+ 	//
+ 	// The updating process itself:
+ 	try
+ 	{
+ 		DOMElement * doc_e = 0;
+ 		try {
+ 			doc_e = doc->getDocumentElement();
+ 		}
+ 		catch( const XMLException& e) { doc_e = 0; }
+ 		catch( const DOMException& e) { doc_e = 0; }
+ 		catch( ... )                  { doc_e = 0; }
  
  		if( doc_e == NULL)
  		{
***************
*** 4956,4962 ****
  		XMLString::release( &x_time);
  		XMLString::release( &x_username);
  
  
! 		//do a DOM save as follows:
  		XMLCh* x_filenm = XMLString::transcode( m_localFileName.c_str());
  		XMLFormatTarget* outfile = new LocalFileFormatTarget( x_filenm);
--- 5032,5048 ----
  		XMLString::release( &x_time);
  		XMLString::release( &x_username);
+ 	}
+ 	catch(...)
+ 	{
+ 		if( parser) delete parser;
+ 		m_parent->sendMsg( "Exception during signature file update!", MSG_ERROR);
  
+ 		HR_THROW(E_FILEOPEN);
+ 	}
  
! 	//
! 	// do a DOM save as follows:
! 	try
! 	{
  		XMLCh* x_filenm = XMLString::transcode( m_localFileName.c_str());
  		XMLFormatTarget* outfile = new LocalFileFormatTarget( x_filenm);
***************
*** 4964,4968 ****
  
  		DOMWriter* writer = domimpl->createDOMWriter();
! 		if( writer->canSetFeature( XMLUni::fgDOMXMLDeclaration, false))
  			writer->setFeature( XMLUni::fgDOMXMLDeclaration, false);
  
--- 5050,5054 ----
  
  		DOMWriter* writer = domimpl->createDOMWriter();
! 		if( writer && writer->canSetFeature( XMLUni::fgDOMXMLDeclaration, false))
  			writer->setFeature( XMLUni::fgDOMXMLDeclaration, false);
  
***************
*** 4977,4982 ****
  	{
  		if( parser) delete parser;
! 		m_parent->sendMsg( "Parser exception during signature file update!", MSG_ERROR);
! 		return;
  	}
  }
--- 5063,5069 ----
  	{
  		if( parser) delete parser;
! 		m_parent->sendMsg( "DOMWriter exception during signature file update!", MSG_ERROR);
! 		
! 		HR_THROW(E_FILEOPEN);
  	}
  }
***************
*** 4986,5001 ****
  	SignFileDataVec res;
  
! 	DOMBuilder * parser = NULL;
! 	try {
! 		DOMImplementationLS * domimpl = DOMImplementationRegistry::getDOMImplementation(NULL);
! 		ASSERT( domimpl != NULL );
! 		parser = !domimpl? 0: domimpl->createDOMBuilder( DOMImplementationLS::MODE_SYNCHRONOUS, NULL );
! 		ASSERT( parser != NULL );
! 		if( !domimpl || !parser)
! 		{
! 			m_parent->sendMsg( "Exception: Could not create parser!", MSG_ERROR);
! 			HR_THROW(E_FILEOPEN);
! 		}
  
  		XERCES_CPP_NAMESPACE::DOMDocument * doc = parser->parseURI( m_localFileName.c_str());
  		if( doc == NULL )
--- 5073,5086 ----
  	SignFileDataVec res;
  
! 	DOMBuilder * parser = m_parent->getFreshParser( "SignatureFileAnalyzer");
  
+ 	ASSERT( parser != NULL );
+ 	if( !parser)
+ 	{
+ 		m_parent->sendMsg( "Exception: Could not create parser!", MSG_ERROR);
+ 		return res;
+ 	}
+ 
+ 	try {
  		XERCES_CPP_NAMESPACE::DOMDocument * doc = parser->parseURI( m_localFileName.c_str());
  		if( doc == NULL )
***************
*** 5160,5169 ****
  void ProtectList::writeProtList()
  {
! 	DOMBuilder * parser = NULL;
  	try {
! 		DOMImplementationLS * domimpl = DOMImplementationRegistry::getDOMImplementation(NULL);
! 		ASSERT( domimpl != NULL );
! 		parser = !domimpl? 0: domimpl->createDOMBuilder( DOMImplementationLS::MODE_SYNCHRONOUS, NULL );
! 		ASSERT( parser != NULL );
  		if( !domimpl || !parser)
  		{
--- 5245,5255 ----
  void ProtectList::writeProtList()
  {
! 	DOMImplementationLS          * domimpl = NULL; 
! 	DOMBuilder                   * parser  = NULL;
! 
  	try {
! 
! 		parser = m_parent->getFreshParser( "ProtectionListWriter", &domimpl);
! 
  		if( !domimpl || !parser)
  		{
***************
*** 5261,5270 ****
  void ProtectList::purgeProtList( CTime& p_lastSyncTime)
  {
! 	DOMBuilder * parser = NULL;
  	try {
! 		DOMImplementationLS * domimpl = DOMImplementationRegistry::getDOMImplementation(NULL);
! 		ASSERT( domimpl != NULL );
! 		parser = !domimpl? 0: domimpl->createDOMBuilder( DOMImplementationLS::MODE_SYNCHRONOUS, NULL );
! 		ASSERT( parser != NULL );
  		if( !domimpl || !parser)
  		{
--- 5347,5357 ----
  void ProtectList::purgeProtList( CTime& p_lastSyncTime)
  {
! 	DOMImplementationLS          * domimpl = NULL; 
! 	DOMBuilder                   * parser  = NULL;
! 
  	try {
! 
! 		parser = m_parent->getFreshParser( "ProtectionListPurger", &domimpl);
! 
  		if( !domimpl || !parser)
  		{
***************
*** 7120,7147 ****
  }
  
! DOMImplementationLS * CCoreXmlFile::giveDomImpl()
! {
! 	if( m_strategyShared)
! 		return m_domImpl;
! 	else
! 	{
! 		DOMImplementationLS * domimpl = DOMImplementationRegistry::getDOMImplementation( XMLString::transcode("XML 1.0"));//NULL
! 		ASSERT( domimpl != NULL );
! 		return domimpl;
! 	}
! }
! 
! DOMBuilder * CCoreXmlFile::giveDomParser( DOMImplementationLS * domimpl)
! {
! 	if( m_strategyShared)
! 		return m_domParser;
! 	else
! 	{
! 		DOMBuilder *parser = !domimpl? 0: domimpl->createDOMBuilder( DOMImplementationLS::MODE_SYNCHRONOUS, NULL );
! 		ASSERT( parser != NULL );
! 		return parser;
! 	}
! }
! 
  XERCES_CPP_NAMESPACE::DOMDocument* CCoreXmlFile::enclosedParse( const std::string& p_fileName, DOMBuilder* p_parser, bool *p_success)
  {
--- 7207,7234 ----
  }
  
! //DOMImplementationLS * CCoreXmlFile::giveDomImpl()
! //{
! //	if( m_strategyShared)
! //		return m_domImpl;
! //	else
! //	{
! //		DOMImplementationLS * domimpl = DOMImplementationRegistry::getDOMImplementation( XMLString::transcode("XML 1.0"));//NULL
! //		ASSERT( domimpl != NULL );
! //		return domimpl;
! //	}
! //}
! //
! //DOMBuilder * CCoreXmlFile::giveDomParser( DOMImplementationLS * domimpl)
! //{
! //	if( m_strategyShared)
! //		return m_domParser;
! //	else
! //	{
! //		DOMBuilder *parser = !domimpl? 0: domimpl->createDOMBuilder( DOMImplementationLS::MODE_SYNCHRONOUS, NULL );
! //		ASSERT( parser != NULL );
! //		return parser;
! //	}
! //}
! //
  XERCES_CPP_NAMESPACE::DOMDocument* CCoreXmlFile::enclosedParse( const std::string& p_fileName, DOMBuilder* p_parser, bool *p_success)
  {
***************
*** 7193,7197 ****
--- 7280,7365 ----
  }
  
+ DOMBuilder* CCoreXmlFile::getFreshParser( const std::string& p_whoIsTheUser, DOMImplementationLS ** p_ptrRetDomImpl /* = 0 */)
+ {
+ 	DOMImplementationLS * domimpl = NULL;
+ 	DOMBuilder*           parser  = NULL;
+ 	
+ 	
+ 	//
+ 	// DOM implementation factory creation
+ 	//
+ 	const char            di_msg[] = "Exception: Could not create DOMImplementation for ";
+ 	try {
+ 
+ 		domimpl = DOMImplementationRegistry::getDOMImplementation(NULL);
  
+ 	} catch(...) {
  
+ 		// was not initialized already? let's do our best
+ 		XMLPlatformUtils::Initialize();
+ 
+ 		// try again
+ 		try {
+ 
+ 			domimpl = DOMImplementationRegistry::getDOMImplementation(NULL); // 2nd attempt, hoping that XMLPlatformUtils::Initialize() was missing the time before
+ 			
+ 			if( domimpl) sendMsg( "Warning: DOMImplementation created in the second attempt only for " + p_whoIsTheUser, MSG_WARNING);
+ 
+ 		} catch(...) {
+ 
+ 			domimpl = 0;
+ 
+ 			sendMsg( di_msg + p_whoIsTheUser, MSG_ERROR);
+ 
+ 		}
+ 	}
+ 
+ 	ASSERT( domimpl != NULL );
+ 
+ 	//
+ 	// can the DOMBuilder/parser be created ?
+ 	//
+ 	try {
  
+ 		parser = !domimpl? 0: domimpl->createDOMBuilder( DOMImplementationLS::MODE_SYNCHRONOUS, NULL );
+ 
+ 	}
+ 	catch(const DOMException& e) {
+ 
+ 		parser = 0;
+ 
+ 		char*              e_msg    = 0;
+ 		const unsigned int maxChars = 2047;
+ 		XMLCh errText[maxChars + 1];
+ 		const char         s_msg[]  = "DOMException during parser object creation for ";
+ 		const char         m_msg[]  = ". Message: ";
+ 
+ 		if( DOMImplementation::loadDOMExceptionMsg( e.code, errText, maxChars))
+ 		{
+ 			e_msg = XMLString::transcode( errText);
+ 			sendMsg( s_msg + p_whoIsTheUser + m_msg + e_msg, MSG_ERROR);
+ 		}
+ 		else
+ 		{
+ 			e_msg = XMLString::transcode( e.getMessage());
+ 			sendMsg( s_msg + p_whoIsTheUser + m_msg + e_msg, MSG_ERROR);
+ 		}
+ 		XMLString::release( &e_msg);
+ 	}
+ 	catch(...) {
+ 
+ 		parser = 0;
+ 
+ 		sendMsg( "Exception: Could not create parser for " + p_whoIsTheUser, MSG_ERROR);
+ 	}
+ 
+ 	if( domimpl != 0 && parser != 0)
+ 	{
+ 		if( p_ptrRetDomImpl != 0)             // if user interested in the DomImpl
+ 			*p_ptrRetDomImpl = domimpl;       // then fill the ptr
+ 
+ 		return parser;
+ 	}
+ 
+ 	return 0;
+ }

Index: CoreXmlFile.h
===================================================================
RCS file: /project/gme-repository/GMESRC/GME/XmlBackEnd/CoreXmlFile.h,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -d -r1.17 -r1.18
*** CoreXmlFile.h	21 Feb 2008 18:16:58 -0000	1.17
--- CoreXmlFile.h	7 May 2008 20:51:45 -0000	1.18
***************
*** 788,793 ****
  	             enclosedParse          ( const std::string& p_fileName, XERCES_CPP_NAMESPACE::DOMBuilder* p_parser, bool *p_success);
  
! 	XERCES_CPP_NAMESPACE::DOMImplementationLS * giveDomImpl();
! 	XERCES_CPP_NAMESPACE::DOMBuilder*           giveDomParser( XERCES_CPP_NAMESPACE::DOMImplementationLS * domimpl);
  	void         giveDOMObjs( XERCES_CPP_NAMESPACE::DOMImplementationLS* *p_domImpl, XERCES_CPP_NAMESPACE::DOMBuilder* *p_domParser, XERCES_CPP_NAMESPACE::DOMErrorHandler* *p_domErrHandler);
  	void         newDOMObjs( XERCES_CPP_NAMESPACE::DOMImplementationLS* *p_domImpl, XERCES_CPP_NAMESPACE::DOMBuilder* *p_domParser, XERCES_CPP_NAMESPACE::DOMErrorHandler* *p_domErrHandler);
--- 788,793 ----
  	             enclosedParse          ( const std::string& p_fileName, XERCES_CPP_NAMESPACE::DOMBuilder* p_parser, bool *p_success);
  
! 	//XERCES_CPP_NAMESPACE::DOMImplementationLS * giveDomImpl();
! 	//XERCES_CPP_NAMESPACE::DOMBuilder*           giveDomParser( XERCES_CPP_NAMESPACE::DOMImplementationLS * domimpl);
  	void         giveDOMObjs( XERCES_CPP_NAMESPACE::DOMImplementationLS* *p_domImpl, XERCES_CPP_NAMESPACE::DOMBuilder* *p_domParser, XERCES_CPP_NAMESPACE::DOMErrorHandler* *p_domErrHandler);
  	void         newDOMObjs( XERCES_CPP_NAMESPACE::DOMImplementationLS* *p_domImpl, XERCES_CPP_NAMESPACE::DOMBuilder* *p_domParser, XERCES_CPP_NAMESPACE::DOMErrorHandler* *p_domErrHandler);
***************
*** 801,804 ****
--- 801,807 ----
  	DOMBuilder *                         m_domParser;
  	DOMErrorHandler*                     m_domErrHandler;
+ 
+ public: // parser creation for other tasks than the individual xml file scannning
+ 	DOMBuilder*  getFreshParser          ( const std::string& p_whoIsTheUser, DOMImplementationLS ** p_ptrRetDomImpl = 0);
  
  protected:



More information about the GME-commit mailing list