GME
13
|
00001 /* 00002 * Licensed to the Apache Software Foundation (ASF) under one or more 00003 * contributor license agreements. See the NOTICE file distributed with 00004 * this work for additional information regarding copyright ownership. 00005 * The ASF licenses this file to You under the Apache License, Version 2.0 00006 * (the "License"); you may not use this file except in compliance with 00007 * the License. You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 00018 /* 00019 * $Id: XMLException.cpp 673960 2008-07-04 08:50:12Z borisk $ 00020 */ 00021 00022 00023 // --------------------------------------------------------------------------- 00024 // Includes 00025 // --------------------------------------------------------------------------- 00026 #include <xercesc/util/XMLException.hpp> 00027 #include <xercesc/util/PlatformUtils.hpp> 00028 #include <xercesc/util/XMLMsgLoader.hpp> 00029 #include <xercesc/util/XMLString.hpp> 00030 #include <xercesc/util/XMLUniDefs.hpp> 00031 #include <xercesc/util/XMLInitializer.hpp> 00032 00033 00034 XERCES_CPP_NAMESPACE_BEGIN 00035 00036 static XMLMsgLoader* sMsgLoader = 0; 00037 00038 void XMLInitializer::initializeXMLException() 00039 { 00040 sMsgLoader = XMLPlatformUtils::loadMsgSet(XMLUni::fgExceptDomain); 00041 00042 if (!sMsgLoader) 00043 XMLPlatformUtils::panic(PanicHandler::Panic_CantLoadMsgDomain); 00044 } 00045 00046 void XMLInitializer::terminateXMLException() 00047 { 00048 delete sMsgLoader; 00049 sMsgLoader = 0; 00050 } 00051 00052 // 00053 // 00054 static XMLMsgLoader& gGetMsgLoader() 00055 { 00056 return *sMsgLoader; 00057 } 00058 00059 // --------------------------------------------------------------------------- 00060 // XMLException: Virtual destructor 00061 // --------------------------------------------------------------------------- 00062 XMLException::~XMLException() 00063 { 00064 fMemoryManager->deallocate(fMsg); 00065 fMemoryManager->deallocate(fSrcFile); 00066 } 00067 00068 00069 // --------------------------------------------------------------------------- 00070 // XMLException: Setter methods 00071 // --------------------------------------------------------------------------- 00072 void XMLException::setPosition(const char* const file, const XMLFileLoc line) 00073 { 00074 fSrcLine = line; 00075 fMemoryManager->deallocate(fSrcFile); 00076 fSrcFile = XMLString::replicate(file, fMemoryManager); 00077 } 00078 00079 00080 // --------------------------------------------------------------------------- 00081 // XMLException: Hidden constructors and operators 00082 // --------------------------------------------------------------------------- 00083 XMLException::XMLException() : 00084 00085 fCode(XMLExcepts::NoError) 00086 , fSrcFile(0) 00087 , fSrcLine(0) 00088 , fMsg(0) 00089 , fMemoryManager( 00090 XMLPlatformUtils::fgMemoryManager->getExceptionMemoryManager()) 00091 { 00092 } 00093 00094 00095 XMLException::XMLException( const char* const srcFile 00096 , const XMLFileLoc srcLine 00097 , MemoryManager* const memoryManager) : 00098 00099 fCode(XMLExcepts::NoError) 00100 , fSrcFile(0) 00101 , fSrcLine(srcLine) 00102 , fMsg(0) 00103 , fMemoryManager(0) 00104 { 00105 if (!memoryManager) 00106 fMemoryManager = 00107 XMLPlatformUtils::fgMemoryManager->getExceptionMemoryManager(); 00108 else 00109 fMemoryManager = memoryManager->getExceptionMemoryManager(); 00110 00111 fSrcFile = XMLString::replicate(srcFile, fMemoryManager); 00112 } 00113 00114 00115 XMLException::XMLException(const XMLException& toCopy) : 00116 XMemory(toCopy) 00117 , fCode(toCopy.fCode) 00118 , fSrcFile(0) 00119 , fSrcLine(toCopy.fSrcLine) 00120 , fMsg(XMLString::replicate(toCopy.fMsg, toCopy.fMemoryManager)) 00121 , fMemoryManager(toCopy.fMemoryManager) 00122 { 00123 if (toCopy.fSrcFile) { 00124 fSrcFile = XMLString::replicate 00125 ( 00126 toCopy.fSrcFile 00127 , fMemoryManager 00128 ); 00129 } 00130 } 00131 00132 00133 XMLException& XMLException::operator=(const XMLException& toAssign) 00134 { 00135 if (this != &toAssign) 00136 { 00137 //use the original memory manager to deallocate 00138 fMemoryManager->deallocate(fSrcFile); 00139 fSrcFile = 0; 00140 fMemoryManager->deallocate(fMsg); 00141 fMsg = 0; 00142 00143 fMemoryManager = toAssign.fMemoryManager; 00144 fSrcLine = toAssign.fSrcLine; 00145 fCode = toAssign.fCode; 00146 00147 if (toAssign.fMsg) { 00148 fMsg = XMLString::replicate 00149 ( 00150 toAssign.fMsg 00151 , fMemoryManager 00152 ); 00153 } 00154 00155 if (toAssign.fSrcFile) { 00156 fSrcFile = XMLString::replicate 00157 ( 00158 toAssign.fSrcFile 00159 , fMemoryManager 00160 ); 00161 } 00162 } 00163 return *this; 00164 } 00165 00166 00167 00168 // --------------------------------------------------------------------------- 00169 // XMLException: Protected methods 00170 // --------------------------------------------------------------------------- 00171 void XMLException::loadExceptText(const XMLExcepts::Codes toLoad) 00172 { 00173 // Store the error code 00174 fCode = toLoad; 00175 00176 // Load up the text into a local buffer 00177 const XMLSize_t msgSize = 2047; 00178 XMLCh errText[msgSize + 1]; 00179 00180 // load the text 00181 if (!gGetMsgLoader().loadMsg(toLoad, errText, msgSize)) 00182 { 00183 fMsg = XMLString::replicate 00184 ( 00185 XMLUni::fgDefErrMsg 00186 , fMemoryManager 00187 ); 00188 return; 00189 } 00190 00191 // We got the text so replicate it into the message member 00192 fMsg = XMLString::replicate(errText, fMemoryManager); 00193 } 00194 00195 00196 void 00197 XMLException::loadExceptText(const XMLExcepts::Codes toLoad 00198 , const XMLCh* const text1 00199 , const XMLCh* const text2 00200 , const XMLCh* const text3 00201 , const XMLCh* const text4) 00202 { 00203 // Store the error code 00204 fCode = toLoad; 00205 00206 // Load up the text into a local buffer 00207 const XMLSize_t msgSize = 4095; 00208 XMLCh errText[msgSize + 1]; 00209 00210 // load the text 00211 if (!gGetMsgLoader().loadMsg(toLoad, errText, msgSize, text1, text2, text3, text4, fMemoryManager)) 00212 { 00213 fMsg = XMLString::replicate 00214 ( 00215 XMLUni::fgDefErrMsg 00216 , fMemoryManager 00217 ); 00218 return; 00219 } 00220 00221 // We got the text so replicate it into the message member 00222 fMsg = XMLString::replicate(errText, fMemoryManager); 00223 } 00224 00225 00226 void 00227 XMLException::loadExceptText(const XMLExcepts::Codes toLoad 00228 , const char* const text1 00229 , const char* const text2 00230 , const char* const text3 00231 , const char* const text4) 00232 { 00233 // Store the error code 00234 fCode = toLoad; 00235 00236 // Load up the text into a local buffer 00237 const XMLSize_t msgSize = 4095; 00238 XMLCh errText[msgSize + 1]; 00239 00240 // load the text 00241 if (!gGetMsgLoader().loadMsg(toLoad, errText, msgSize, text1, text2, text3, text4, fMemoryManager)) 00242 { 00243 fMsg = XMLString::replicate 00244 ( 00245 XMLUni::fgDefErrMsg 00246 , fMemoryManager 00247 ); 00248 return; 00249 } 00250 00251 // We got the text so replicate it into the message member 00252 fMsg = XMLString::replicate(errText, fMemoryManager); 00253 } 00254 00255 XERCES_CPP_NAMESPACE_END