00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "xercesmanager.h"
00024 #include "xercesutils.h"
00025
00026 #include <xercesc/util/PlatformUtils.hpp>
00027 #include <xercesc/util/XercesDefs.hpp>
00028
00029 #include <cassert>
00030 #include <cstdlib>
00031 #include <iostream>
00032
00033 using namespace sheep;
00034 using namespace std;
00035 using namespace xercesc;
00036
00037
00038
00039 int XercesManager::m_uses = 0;
00040 static XercesManager xercesmanager;
00041
00042 XercesManager::~XercesManager() {
00043 if(m_uses > 0) {
00044 #ifdef VERBOSE
00045 cerr << "Automatically shutting down Xerces-C XML Parser..." << endl;
00046 #endif // VERBOSE
00047 XMLPlatformUtils::Terminate();
00048 }
00049 }
00050
00051 void XercesManager::Initialize() {
00052 if(m_uses == 0) {
00053 try {
00054 XMLPlatformUtils::Initialize();
00055 }
00056 catch(const XMLException &e) {
00057 cerr << "Error during Xerces-C initialization." << endl;
00058 cerr << "Exception message: " << e.getMessage() << endl;
00059 exit(EXIT_FAILURE);
00060 }
00061 }
00062
00063 ++m_uses;
00064 }
00065
00066 void XercesManager::Shutdown() {
00067 assert(m_uses > 0);
00068
00069 --m_uses;
00070
00071 if(m_uses == 0)
00072 XMLPlatformUtils::Terminate();
00073 }