source: NonGTP/Xerces/xercesc/util/XMLException.hpp @ 188

Revision 188, 12.1 KB checked in by mattausch, 19 years ago (diff)

added xercesc to support

Line 
1/*
2 * The Apache Software License, Version 1.1
3 *
4 * Copyright (c) 1999-2000 The Apache Software Foundation.  All rights
5 * reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * 1. Redistributions of source code must retain the above copyright
12 *    notice, this list of conditions and the following disclaimer.
13 *
14 * 2. Redistributions in binary form must reproduce the above copyright
15 *    notice, this list of conditions and the following disclaimer in
16 *    the documentation and/or other materials provided with the
17 *    distribution.
18 *
19 * 3. The end-user documentation included with the redistribution,
20 *    if any, must include the following acknowledgment:
21 *       "This product includes software developed by the
22 *        Apache Software Foundation (http://www.apache.org/)."
23 *    Alternately, this acknowledgment may appear in the software itself,
24 *    if and wherever such third-party acknowledgments normally appear.
25 *
26 * 4. The names "Xerces" and "Apache Software Foundation" must
27 *    not be used to endorse or promote products derived from this
28 *    software without prior written permission. For written
29 *    permission, please contact apache\@apache.org.
30 *
31 * 5. Products derived from this software may not be called "Apache",
32 *    nor may "Apache" appear in their name, without prior written
33 *    permission of the Apache Software Foundation.
34 *
35 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
36 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
37 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
38 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
42 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
43 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
44 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
45 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
46 * SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This software consists of voluntary contributions made by many
50 * individuals on behalf of the Apache Software Foundation, and was
51 * originally based on software copyright (c) 1999, International
52 * Business Machines, Inc., http://www.ibm.com .  For more information
53 * on the Apache Software Foundation, please see
54 * <http://www.apache.org/>.
55 */
56
57/*
58 * $Id: XMLException.hpp,v 1.7 2003/12/19 23:02:25 cargilld Exp $
59 */
60
61#if !defined(EXCEPTION_HPP)
62#define EXCEPTION_HPP
63
64#include <xercesc/util/XMemory.hpp>
65#include <xercesc/util/XMLExceptMsgs.hpp>
66#include <xercesc/util/XMLUni.hpp>
67#include <xercesc/framework/XMLErrorReporter.hpp>
68
69XERCES_CPP_NAMESPACE_BEGIN
70
71// ---------------------------------------------------------------------------
72//  This is the base class from which all the XML parser exceptions are
73//  derived. The virtual interface is very simple and most of the functionality
74//  is in this class.
75//
76//  Because all derivatives are EXACTLY the same except for the static
77//  string that is used to hold the name of the class, a macro is provided
78//  below via which they are all created.
79// ---------------------------------------------------------------------------
80class XMLUTIL_EXPORT XMLException : public XMemory
81{
82public:
83    // -----------------------------------------------------------------------
84    //  Virtual Destructor
85    // -----------------------------------------------------------------------
86    virtual ~XMLException();
87
88
89    // -----------------------------------------------------------------------
90    //  The XML exception virtual interface
91    // -----------------------------------------------------------------------
92    virtual const XMLCh* getType() const = 0;
93
94
95    // -----------------------------------------------------------------------
96    //  Getter methods
97    // -----------------------------------------------------------------------
98    XMLExcepts::Codes getCode() const;
99    const XMLCh* getMessage() const;
100    const char* getSrcFile() const;
101    unsigned int getSrcLine() const;
102    XMLErrorReporter::ErrTypes getErrorType() const;
103
104
105    // -----------------------------------------------------------------------
106    //  Setter methods
107    // -----------------------------------------------------------------------
108    void setPosition(const char* const file, const unsigned int line);
109
110
111    // -----------------------------------------------------------------------
112    //  Hidden constructors and operators
113    //
114    //  NOTE:   Technically, these should be protected, since this is a
115    //          base class that is never used directly. However, VC++ 6.0 will
116    //          fail to catch via a reference to base class if the ctors are
117    //          not public!! This seems to have been caused by the install
118    //          of IE 5.0.
119    // -----------------------------------------------------------------------
120    XMLException();
121    XMLException(const char* const srcFile, const unsigned int srcLine, MemoryManager* const memoryManager = 0);
122    XMLException(const XMLException& toCopy);
123    XMLException& operator=(const XMLException& toAssign);
124
125    // -----------------------------------------------------------------------
126    //  Notification that lazy data has been deleted
127    // -----------------------------------------------------------------------
128        static void reinitMsgMutex();
129
130        static void reinitMsgLoader();
131
132protected :
133    // -----------------------------------------------------------------------
134    //  Protected methods
135    // -----------------------------------------------------------------------
136    void loadExceptText
137    (
138        const   XMLExcepts::Codes toLoad
139    );
140    void loadExceptText
141    (
142        const   XMLExcepts::Codes toLoad
143        , const XMLCh* const        text1
144        , const XMLCh* const        text2 = 0
145        , const XMLCh* const        text3 = 0
146        , const XMLCh* const        text4 = 0
147    );
148    void loadExceptText
149    (
150        const   XMLExcepts::Codes toLoad
151        , const char* const         text1
152        , const char* const         text2 = 0
153        , const char* const         text3 = 0
154        , const char* const         text4 = 0
155    );
156
157
158private :
159    // -----------------------------------------------------------------------
160    //  Data members
161    //
162    //  fCode
163    //      The error code that this exception represents.
164    //
165    //  fSrcFile
166    //  fSrcLine
167    //      These are the file and line information from the source where the
168    //      exception was thrown from.
169    //
170    //  fMsg
171    //      The loaded message text for this exception.
172    // -----------------------------------------------------------------------
173    XMLExcepts::Codes       fCode;
174    char*                   fSrcFile;
175    unsigned int            fSrcLine;
176    XMLCh*                  fMsg;
177
178protected:
179    MemoryManager*          fMemoryManager;
180};
181
182// ---------------------------------------------------------------------------
183//  XMLException: Getter methods
184// ---------------------------------------------------------------------------
185inline XMLExcepts::Codes XMLException::getCode() const
186{
187    return fCode;
188}
189
190inline const XMLCh* XMLException::getMessage() const
191{
192    return fMsg;
193}
194
195inline const char* XMLException::getSrcFile() const
196{
197    if (!fSrcFile)
198        return "";
199    return fSrcFile;
200}
201
202inline unsigned int XMLException::getSrcLine() const
203{
204    return fSrcLine;
205}
206
207inline XMLErrorReporter::ErrTypes XMLException::getErrorType() const
208{
209   if ((fCode >= XMLExcepts::W_LowBounds) && (fCode <= XMLExcepts::W_HighBounds))
210       return XMLErrorReporter::ErrType_Warning;
211   else if ((fCode >= XMLExcepts::F_LowBounds) && (fCode <= XMLExcepts::F_HighBounds))
212        return XMLErrorReporter::ErrType_Fatal;
213   else if ((fCode >= XMLExcepts::E_LowBounds) && (fCode <= XMLExcepts::E_HighBounds))
214        return XMLErrorReporter::ErrType_Error;
215   return XMLErrorReporter::ErrTypes_Unknown;
216}
217
218// ---------------------------------------------------------------------------
219//  This macro is used to create derived classes. They are all identical
220//  except the name of the exception, so it crazy to type them in over and
221//  over.
222// ---------------------------------------------------------------------------
223#define MakeXMLException(theType, expKeyword) \
224class expKeyword theType : public XMLException \
225{ \
226public: \
227 \
228    theType(const   char* const         srcFile \
229            , const unsigned int        srcLine \
230            , const XMLExcepts::Codes toThrow \
231            , MemoryManager*            memoryManager = 0) : \
232        XMLException(srcFile, srcLine, memoryManager) \
233    { \
234        loadExceptText(toThrow); \
235    } \
236 \
237    theType(const theType& toCopy) : \
238 \
239        XMLException(toCopy) \
240    { \
241    } \
242  \
243    theType(const   char* const         srcFile \
244            , const unsigned int        srcLine \
245            , const XMLExcepts::Codes   toThrow \
246            , const XMLCh* const        text1 \
247            , const XMLCh* const        text2 = 0 \
248            , const XMLCh* const        text3 = 0 \
249            , const XMLCh* const        text4 = 0 \
250            , MemoryManager*            memoryManager = 0) : \
251        XMLException(srcFile, srcLine, memoryManager) \
252    { \
253        loadExceptText(toThrow, text1, text2, text3, text4); \
254    } \
255 \
256    theType(const   char* const         srcFile \
257            , const unsigned int        srcLine \
258            , const XMLExcepts::Codes   toThrow \
259            , const char* const         text1 \
260            , const char* const         text2 = 0 \
261            , const char* const         text3 = 0 \
262            , const char* const         text4 = 0 \
263            , MemoryManager*            memoryManager = 0) : \
264        XMLException(srcFile, srcLine, memoryManager) \
265    { \
266        loadExceptText(toThrow, text1, text2, text3, text4); \
267    } \
268 \
269    virtual ~theType() {} \
270 \
271    theType& operator=(const theType& toAssign) \
272    { \
273        XMLException::operator=(toAssign); \
274        return *this; \
275    } \
276 \
277    virtual XMLException* duplicate() const \
278    { \
279        return new (fMemoryManager) theType(*this); \
280    } \
281 \
282    virtual const XMLCh* getType() const \
283    { \
284        return XMLUni::fg##theType##_Name; \
285    } \
286 \
287private : \
288    theType(); \
289};
290
291
292
293// ---------------------------------------------------------------------------
294//  This macros is used to actually throw an exception. It is used in order
295//  to make sure that source code line/col info is stored correctly, and to
296//  give flexibility for other stuff in the future.
297// ---------------------------------------------------------------------------
298
299#define ThrowXML(type,code) throw type(__FILE__, __LINE__, code)
300
301#define ThrowXML1(type,code,p1) throw type(__FILE__, __LINE__, code, p1)
302
303#define ThrowXML2(type,code,p1,p2) throw type(__FILE__, __LINE__, code, p1, p2)
304
305#define ThrowXML3(type,code,p1,p2,p3) throw type(__FILE__, __LINE__, code, p1, p2, p3)
306
307#define ThrowXML4(type,code,p1,p2,p3,p4) throw type(__FILE__, __LINE__, code, p1, p2, p3, p4)
308
309#define ThrowXMLwithMemMgr(type,code,memMgr) throw type(__FILE__, __LINE__, code, memMgr)
310
311#define ThrowXMLwithMemMgr1(type,code,p1,memMgr) throw type(__FILE__, __LINE__, code, p1, 0, 0, 0, memMgr)
312
313#define ThrowXMLwithMemMgr2(type,code,p1,p2,memMgr) throw type(__FILE__, __LINE__, code, p1, p2, 0, 0, memMgr)
314
315#define ThrowXMLwithMemMgr3(type,code,p1,p2,p3,memMgr) throw type(__FILE__, __LINE__, code, p1, p2, p3, 0, memMgr)
316
317#define ThrowXMLwithMemMgr4(type,code,p1,p2,p3,p4,memMgr) throw type(__FILE__, __LINE__, code, p1, p2, p3, p4, memMgr)
318
319XERCES_CPP_NAMESPACE_END
320
321#endif
Note: See TracBrowser for help on using the repository browser.