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

Last change on this file since 2732 was 2722, checked in by cameron, 7 years ago

Original Xerces files with import mods for icxercesc

File size: 7.0 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        if (!gGetMsgLoader().loadMsg(toLoad, errText, msgSize))
182        {
183                fMsg = XMLString::replicate
184        (
185        XMLUni::fgDefErrMsg
186            , fMemoryManager
187        );
188                return;
189        }
190
191    // We got the text so replicate it into the message member
192    fMsg = XMLString::replicate(errText, fMemoryManager);
193}
194
195
196void
197XMLException::loadExceptText(const  XMLExcepts::Codes toLoad
198                            , const XMLCh* const        text1
199                            , const XMLCh* const        text2
200                            , const XMLCh* const        text3
201                            , const XMLCh* const        text4)
202{
203    // Store the error code
204    fCode = toLoad;
205
206    // Load up the text into a local buffer
207    const XMLSize_t msgSize = 4095;
208    XMLCh errText[msgSize + 1];
209
210    // load the text
211        if (!gGetMsgLoader().loadMsg(toLoad, errText, msgSize, text1, text2, text3, text4, fMemoryManager))
212        {
213                fMsg = XMLString::replicate
214        (
215        XMLUni::fgDefErrMsg
216            , fMemoryManager
217        );
218                return;
219        }
220
221    // We got the text so replicate it into the message member
222    fMsg = XMLString::replicate(errText, fMemoryManager);
223}
224
225
226void
227XMLException::loadExceptText(const  XMLExcepts::Codes toLoad
228                            , const char* const         text1
229                            , const char* const         text2
230                            , const char* const         text3
231                            , const char* const         text4)
232{
233    // Store the error code
234    fCode = toLoad;
235
236    // Load up the text into a local buffer
237    const XMLSize_t msgSize = 4095;
238    XMLCh errText[msgSize + 1];
239
240    // load the text
241        if (!gGetMsgLoader().loadMsg(toLoad, errText, msgSize, text1, text2, text3, text4, fMemoryManager))
242        {
243                fMsg = XMLString::replicate
244        (
245        XMLUni::fgDefErrMsg
246            , fMemoryManager
247        );
248                return;
249        }
250
251    // We got the text so replicate it into the message member
252    fMsg = XMLString::replicate(errText, fMemoryManager);
253}
254
255XERCES_CPP_NAMESPACE_END
Note: See TracBrowser for help on using the repository browser.