Generic hardware access library
/home/cschwick/hal/generic/src/common/VMEAddressTableXMLFileReader.cc
Go to the documentation of this file.
00001 #include "hal/VMEAddressTableXMLFileReader.hh"
00002 #include <sstream>
00003 
00004 using namespace XERCES_CPP_NAMESPACE;
00005 
00006 HAL::VMEAddressTableXMLFileReader::VMEAddressTableXMLFileReader( std::string fileName )
00007   throw ( HAL::XMLProcessingException ) {
00008 
00009   // Initialize the XML4C system
00010   try {
00011     XMLPlatformUtils::Initialize();
00012   } catch (const XMLException& toCatch) {
00013     throw( HAL::XMLProcessingException( "Error during Xerces-initialization\n     (HAL::VMEAddressTableXMLFileReader::VMEAddressTableXMLFileReader)", __FILE__, __LINE__, __FUNCTION__ ));
00014   }
00015 
00016   // Instantiate the DOM parser.
00017 
00018   XercesDOMParser* parser = new  XercesDOMParser;
00019   parser->setValidationScheme(XercesDOMParser::Val_Always);
00020   parser->setDoNamespaces(true);
00021   parser->setDoSchema(true);
00022   parser->setValidationSchemaFullChecking(false); // this is default
00023   parser->setCreateEntityReferenceNodes(true);  // this is default
00024   parser->setIncludeIgnorableWhitespace (false);
00025   HAL::XMLParserErrorHandler halHandler( fileName );
00026   parser->setErrorHandler( &halHandler );
00027   try {
00028     parser->parse(fileName.c_str());
00029   } catch (const XMLException& toCatch) {
00030     char * errptr = XMLString::transcode(toCatch.getMessage());
00031     std::string errorstr(errptr);
00032     XMLString::release( &errptr );
00033     std::string text = errorstr + "\n" +
00034       "     (HAL::VMEAddressTableXMLFileReader::VMEAddressTableXMLFileReader)";
00035     XMLPlatformUtils::Terminate();
00036 
00037     throw(HAL::XMLProcessingException( text, __FILE__, __LINE__, __FUNCTION__ ));
00038 
00039   } catch (const DOMException& toCatch) {
00040     char * errptr = XMLString::transcode(toCatch.msg);
00041     std::string errorstr(errptr);
00042     XMLString::release( &errptr );
00043     std::string text = errorstr + "\n    " +
00044       "    (HAL::VMEAddressTableXMLFileReader::VMEAddressTableXMLFileReader)";
00045     XMLPlatformUtils::Terminate();
00046     throw( HAL::XMLProcessingException( text, __FILE__, __LINE__, __FUNCTION__ ));
00047 
00048   } catch ( const SAXParseException& exception ) {
00049     // This exceptions is thrown in the errorHandler. We treat it a little
00050     // bit more in detail in order to give the user info where to find the
00051     // error in the xml-document.
00052     std::stringstream text;
00053     text << "Error during parsing file " << fileName
00054          << "\n     at line " << exception.getLineNumber()
00055          << " :\n";
00056     char * errptr = XMLString::transcode(exception.getMessage());
00057     std::string message( errptr );
00058     text << "     " << message
00059          << "\n     (HAL::VMEAddressTableXMLFileReader::VMEAddressTableXMLFileReader)"
00060          << std::ends;
00061     XMLString::release( &errptr );    
00062     XMLPlatformUtils::Terminate();
00063     throw(HAL::XMLProcessingException( text.str(), __FILE__, __LINE__, __FUNCTION__ ));
00064 
00065   } catch ( const SAXException& toCatch ) {
00066     char * errptr = XMLString::transcode(toCatch.getMessage());
00067     std::string errorstr(errptr);
00068     std::string text = errorstr + "\n" +
00069       "     (HAL::VMEAddressTableXMLFileReader::VMEAddressTableXMLFileReader)";
00070     XMLString::release( &errptr );    
00071     XMLPlatformUtils::Terminate();
00072     throw(HAL::XMLProcessingException( text, __FILE__, __LINE__, __FUNCTION__ ));
00073 
00074   } catch (...) {
00075     std::string text = "\nUnexpected exception during parsing: " + fileName  + "\n";
00076     XMLPlatformUtils::Terminate();
00077     throw( HAL::XMLProcessingException( text, __FILE__, __LINE__, __FUNCTION__ ));
00078   }
00079 
00080   DOMDocument* doc = parser->getDocument();
00081 
00082   HAL::DOMToVMEMapConverter::convert( doc, itemPointerList );
00083 
00084   delete parser;
00085 
00086   XMLPlatformUtils::Terminate();
00087 }