source: icXML/icXML-devel/src/xercesc/util/XMLException.cpp

Last change on this file was 3157, checked in by cameron, 6 years ago

Fixes for icXML 0.9

File size: 6.9 KB
Line 
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements.  See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License.  You may obtain a copy of the License at
8 *
9 *      http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18/*
19 * $Id: XMLException.cpp 673960 2008-07-04 08:50:12Z borisk $
20 */
21
22
23// ---------------------------------------------------------------------------
24//  Includes
25// ---------------------------------------------------------------------------
26#include <xercesc/util/XMLException.hpp>
27#include <icxercesc/util/PlatformUtils.hpp>
28#include <xercesc/util/XMLMsgLoader.hpp>
29#include <icxercesc/util/XMLString.hpp>
30#include <xercesc/util/XMLUniDefs.hpp>
31#include <xercesc/util/XMLInitializer.hpp>
32
33
34XERCES_CPP_NAMESPACE_BEGIN
35
36static XMLMsgLoader* sMsgLoader = 0;
37
38void XMLInitializer::initializeXMLException()
39{
40    sMsgLoader = XMLPlatformUtils::loadMsgSet(XMLUni::fgExceptDomain);
41
42    if (!sMsgLoader)
43      XMLPlatformUtils::panic(PanicHandler::Panic_CantLoadMsgDomain);
44}
45
46void XMLInitializer::terminateXMLException()
47{
48    delete sMsgLoader;
49    sMsgLoader = 0;
50}
51
52//
53//
54static XMLMsgLoader& gGetMsgLoader()
55{
56    return *sMsgLoader;
57}
58
59// ---------------------------------------------------------------------------
60//  XMLException: Virtual destructor
61// ---------------------------------------------------------------------------
62XMLException::~XMLException()
63{
64    fMemoryManager->deallocate(fMsg);
65    fMemoryManager->deallocate(fSrcFile);
66}
67
68
69// ---------------------------------------------------------------------------
70//  XMLException: Setter methods
71// ---------------------------------------------------------------------------
72void XMLException::setPosition(const char* const file, const XMLFileLoc line)
73{
74    fSrcLine = line;
75        fMemoryManager->deallocate(fSrcFile);
76    fSrcFile = XMLString::replicate(file, fMemoryManager);
77}
78
79
80// ---------------------------------------------------------------------------
81//  XMLException: Hidden constructors and operators
82// ---------------------------------------------------------------------------
83XMLException::XMLException() :
84
85    fCode(XMLExcepts::NoError)
86    , fSrcFile(0)
87    , fSrcLine(0)
88    , fMsg(0)
89    , fMemoryManager(
90        XMLPlatformUtils::fgMemoryManager->getExceptionMemoryManager())
91{
92}
93
94
95XMLException::XMLException( const   char* const     srcFile
96                            , const XMLFileLoc      srcLine
97                            , MemoryManager* const  memoryManager) :
98
99    fCode(XMLExcepts::NoError)
100    , fSrcFile(0)
101    , fSrcLine(srcLine)
102    , fMsg(0)
103    , fMemoryManager(0)
104{
105    if (!memoryManager)
106      fMemoryManager =
107        XMLPlatformUtils::fgMemoryManager->getExceptionMemoryManager();
108    else
109      fMemoryManager = memoryManager->getExceptionMemoryManager();
110
111    fSrcFile = XMLString::replicate(srcFile, fMemoryManager);
112}
113
114
115XMLException::XMLException(const XMLException& toCopy) :
116    XMemory(toCopy)
117    , fCode(toCopy.fCode)
118    , fSrcFile(0)
119    , fSrcLine(toCopy.fSrcLine)
120    , fMsg(XMLString::replicate(toCopy.fMsg, toCopy.fMemoryManager))
121    , fMemoryManager(toCopy.fMemoryManager)
122{
123    if (toCopy.fSrcFile) {
124        fSrcFile = XMLString::replicate
125        (
126            toCopy.fSrcFile
127            , fMemoryManager
128        );
129    }
130}
131
132
133XMLException& XMLException::operator=(const XMLException& toAssign)
134{
135    if (this != &toAssign)
136    {
137        //use the original memory manager to deallocate
138        fMemoryManager->deallocate(fSrcFile);
139        fSrcFile = 0;
140        fMemoryManager->deallocate(fMsg);
141        fMsg = 0;
142
143        fMemoryManager = toAssign.fMemoryManager;
144        fSrcLine = toAssign.fSrcLine;
145        fCode = toAssign.fCode;
146
147        if (toAssign.fMsg) {
148            fMsg = XMLString::replicate
149            (
150                toAssign.fMsg
151                , fMemoryManager
152            );
153        }
154
155        if (toAssign.fSrcFile) {
156            fSrcFile = XMLString::replicate
157            (
158                toAssign.fSrcFile
159                , fMemoryManager
160            );
161        }
162    }
163    return *this;
164}
165
166
167
168// ---------------------------------------------------------------------------
169//  XMLException: Protected methods
170// ---------------------------------------------------------------------------
171void XMLException::loadExceptText(const XMLExcepts::Codes toLoad)
172{
173    // Store the error code
174    fCode = toLoad;
175
176    // Load up the text into a local buffer
177    const XMLSize_t msgSize = 2047;
178    XMLCh errText[msgSize + 1];
179
180    // load the text
181    const bool found = gGetMsgLoader().loadMsg(toLoad, errText, msgSize);
182    // We got the text so replicate it into the message member
183    fMsg = XMLString::replicate(found ? errText : XMLUni::fgDefErrMsg, fMemoryManager);
184}
185
186
187void
188XMLException::loadExceptText(const  XMLExcepts::Codes toLoad
189                            , const XMLCh* const        text1
190                            , const XMLCh* const        text2
191                            , const XMLCh* const        text3
192                            , const XMLCh* const        text4)
193{
194    // Store the error code
195    fCode = toLoad;
196
197    // Load up the text into a local buffer
198    const XMLSize_t msgSize = 4095;
199    XMLCh errText[msgSize + 1];
200
201    // load the text
202        if (!gGetMsgLoader().loadMsg(toLoad, errText, msgSize, text1, text2, text3, text4, fMemoryManager))
203        {
204                fMsg = XMLString::replicate
205        (
206        XMLUni::fgDefErrMsg
207            , fMemoryManager
208        );
209                return;
210        }
211
212    // We got the text so replicate it into the message member
213    fMsg = XMLString::replicate(errText, fMemoryManager);
214}
215
216
217void
218XMLException::loadExceptText(const  XMLExcepts::Codes toLoad
219                            , const char* const         text1
220                            , const char* const         text2
221                            , const char* const         text3
222                            , const char* const         text4)
223{
224    // Store the error code
225    fCode = toLoad;
226
227    // Load up the text into a local buffer
228    const XMLSize_t msgSize = 4095;
229    XMLCh errText[msgSize + 1];
230
231    // load the text
232        if (!gGetMsgLoader().loadMsg(toLoad, errText, msgSize, text1, text2, text3, text4, fMemoryManager))
233        {
234                fMsg = XMLString::replicate
235        (
236        XMLUni::fgDefErrMsg
237            , fMemoryManager
238        );
239                return;
240        }
241
242    // We got the text so replicate it into the message member
243    fMsg = XMLString::replicate(errText, fMemoryManager);
244}
245
246XERCES_CPP_NAMESPACE_END
Note: See TracBrowser for help on using the repository browser.