http://xml.apache.org/http://www.apache.org/http://www.w3.org/

Home

Readme
Release Info

Installation
Download
Build

FAQs
Samples
API Docs

DOM C++ Binding
Programming
Migration Guide

Feedback
Bug-Reporting
PDF Document

CVS Repository
Mail Archive

API Docs for SAX and DOM
 

Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

XMLException.hpp

Go to the documentation of this file.
00001 /*
00002  * The Apache Software License, Version 1.1
00003  *
00004  * Copyright (c) 1999-2000 The Apache Software Foundation.  All rights
00005  * reserved.
00006  *
00007  * Redistribution and use in source and binary forms, with or without
00008  * modification, are permitted provided that the following conditions
00009  * are met:
00010  *
00011  * 1. Redistributions of source code must retain the above copyright
00012  *    notice, this list of conditions and the following disclaimer.
00013  *
00014  * 2. Redistributions in binary form must reproduce the above copyright
00015  *    notice, this list of conditions and the following disclaimer in
00016  *    the documentation and/or other materials provided with the
00017  *    distribution.
00018  *
00019  * 3. The end-user documentation included with the redistribution,
00020  *    if any, must include the following acknowledgment:
00021  *       "This product includes software developed by the
00022  *        Apache Software Foundation (http://www.apache.org/)."
00023  *    Alternately, this acknowledgment may appear in the software itself,
00024  *    if and wherever such third-party acknowledgments normally appear.
00025  *
00026  * 4. The names "Xerces" and "Apache Software Foundation" must
00027  *    not be used to endorse or promote products derived from this
00028  *    software without prior written permission. For written
00029  *    permission, please contact apache\@apache.org.
00030  *
00031  * 5. Products derived from this software may not be called "Apache",
00032  *    nor may "Apache" appear in their name, without prior written
00033  *    permission of the Apache Software Foundation.
00034  *
00035  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
00036  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00037  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00038  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
00039  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00040  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00041  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
00042  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00043  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00044  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
00045  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00046  * SUCH DAMAGE.
00047  * ====================================================================
00048  *
00049  * This software consists of voluntary contributions made by many
00050  * individuals on behalf of the Apache Software Foundation, and was
00051  * originally based on software copyright (c) 1999, International
00052  * Business Machines, Inc., http://www.ibm.com .  For more information
00053  * on the Apache Software Foundation, please see
00054  * <http://www.apache.org/>.
00055  */
00056 
00057 /*
00058  * $Id: XMLException.hpp,v 1.7 2003/12/19 23:02:25 cargilld Exp $
00059  */
00060 
00061 #if !defined(EXCEPTION_HPP)
00062 #define EXCEPTION_HPP
00063 
00064 #include <xercesc/util/XMemory.hpp>
00065 #include <xercesc/util/XMLExceptMsgs.hpp>
00066 #include <xercesc/util/XMLUni.hpp>
00067 #include <xercesc/framework/XMLErrorReporter.hpp>
00068 
00069 XERCES_CPP_NAMESPACE_BEGIN
00070 
00071 // ---------------------------------------------------------------------------
00072 //  This is the base class from which all the XML parser exceptions are
00073 //  derived. The virtual interface is very simple and most of the functionality
00074 //  is in this class.
00075 //
00076 //  Because all derivatives are EXACTLY the same except for the static
00077 //  string that is used to hold the name of the class, a macro is provided
00078 //  below via which they are all created.
00079 // ---------------------------------------------------------------------------
00080 class  XMLException : public XMemory
00081 {
00082 public:
00083     // -----------------------------------------------------------------------
00084     //  Virtual Destructor
00085     // -----------------------------------------------------------------------
00086     virtual ~XMLException();
00087 
00088 
00089     // -----------------------------------------------------------------------
00090     //  The XML exception virtual interface
00091     // -----------------------------------------------------------------------
00092     virtual const XMLCh* getType() const = 0;
00093 
00094 
00095     // -----------------------------------------------------------------------
00096     //  Getter methods
00097     // -----------------------------------------------------------------------
00098     XMLExcepts::Codes getCode() const;
00099     const XMLCh* getMessage() const;
00100     const char* getSrcFile() const;
00101     unsigned int getSrcLine() const;
00102     XMLErrorReporter::ErrTypes getErrorType() const;
00103 
00104 
00105     // -----------------------------------------------------------------------
00106     //  Setter methods
00107     // -----------------------------------------------------------------------
00108     void setPosition(const char* const file, const unsigned int line);
00109 
00110 
00111     // -----------------------------------------------------------------------
00112     //  Hidden constructors and operators
00113     //
00114     //  NOTE:   Technically, these should be protected, since this is a
00115     //          base class that is never used directly. However, VC++ 6.0 will
00116     //          fail to catch via a reference to base class if the ctors are
00117     //          not public!! This seems to have been caused by the install
00118     //          of IE 5.0.
00119     // -----------------------------------------------------------------------
00120     XMLException();
00121     XMLException(const char* const srcFile, const unsigned int srcLine, MemoryManager* const memoryManager = 0);
00122     XMLException(const XMLException& toCopy);
00123     XMLException& operator=(const XMLException& toAssign);
00124 
00125     // -----------------------------------------------------------------------
00126     //  Notification that lazy data has been deleted
00127     // -----------------------------------------------------------------------
00128     static void reinitMsgMutex();
00129 
00130     static void reinitMsgLoader();
00131 
00132 protected :
00133     // -----------------------------------------------------------------------
00134     //  Protected methods
00135     // -----------------------------------------------------------------------
00136     void loadExceptText
00137     (
00138         const   XMLExcepts::Codes toLoad
00139     );
00140     void loadExceptText
00141     (
00142         const   XMLExcepts::Codes toLoad
00143         , const XMLCh* const        text1
00144         , const XMLCh* const        text2 = 0
00145         , const XMLCh* const        text3 = 0
00146         , const XMLCh* const        text4 = 0
00147     );
00148     void loadExceptText
00149     (
00150         const   XMLExcepts::Codes toLoad
00151         , const char* const         text1
00152         , const char* const         text2 = 0
00153         , const char* const         text3 = 0
00154         , const char* const         text4 = 0
00155     );
00156 
00157 
00158 private :
00159     // -----------------------------------------------------------------------
00160     //  Data members
00161     //
00162     //  fCode
00163     //      The error code that this exception represents.
00164     //
00165     //  fSrcFile
00166     //  fSrcLine
00167     //      These are the file and line information from the source where the
00168     //      exception was thrown from.
00169     //
00170     //  fMsg
00171     //      The loaded message text for this exception.
00172     // -----------------------------------------------------------------------
00173     XMLExcepts::Codes       fCode;
00174     char*                   fSrcFile;
00175     unsigned int            fSrcLine;
00176     XMLCh*                  fMsg;
00177 
00178 protected:
00179     MemoryManager*          fMemoryManager;
00180 };
00181 
00182 // ---------------------------------------------------------------------------
00183 //  XMLException: Getter methods
00184 // ---------------------------------------------------------------------------
00185 inline XMLExcepts::Codes XMLException::getCode() const
00186 {
00187     return fCode;
00188 }
00189 
00190 inline const XMLCh* XMLException::getMessage() const
00191 {
00192     return fMsg;
00193 }
00194 
00195 inline const char* XMLException::getSrcFile() const
00196 {
00197     if (!fSrcFile)
00198         return "";
00199     return fSrcFile;
00200 }
00201 
00202 inline unsigned int XMLException::getSrcLine() const
00203 {
00204     return fSrcLine;
00205 }
00206 
00207 inline XMLErrorReporter::ErrTypes XMLException::getErrorType() const
00208 {
00209    if ((fCode >= XMLExcepts::W_LowBounds) && (fCode <= XMLExcepts::W_HighBounds))
00210        return XMLErrorReporter::ErrType_Warning;
00211    else if ((fCode >= XMLExcepts::F_LowBounds) && (fCode <= XMLExcepts::F_HighBounds))
00212         return XMLErrorReporter::ErrType_Fatal;
00213    else if ((fCode >= XMLExcepts::E_LowBounds) && (fCode <= XMLExcepts::E_HighBounds))
00214         return XMLErrorReporter::ErrType_Error;
00215    return XMLErrorReporter::ErrTypes_Unknown;
00216 }
00217 
00218 // ---------------------------------------------------------------------------
00219 //  This macro is used to create derived classes. They are all identical
00220 //  except the name of the exception, so it crazy to type them in over and
00221 //  over.
00222 // ---------------------------------------------------------------------------
00223 #define MakeXMLException(theType, expKeyword) \
00224 class expKeyword theType : public XMLException \
00225 { \
00226 public: \
00227  \
00228     theType(const   char* const         srcFile \
00229             , const unsigned int        srcLine \
00230             , const XMLExcepts::Codes toThrow \
00231             , MemoryManager*            memoryManager = 0) : \
00232         XMLException(srcFile, srcLine, memoryManager) \
00233     { \
00234         loadExceptText(toThrow); \
00235     } \
00236  \
00237     theType(const theType& toCopy) : \
00238  \
00239         XMLException(toCopy) \
00240     { \
00241     } \
00242   \
00243     theType(const   char* const         srcFile \
00244             , const unsigned int        srcLine \
00245             , const XMLExcepts::Codes   toThrow \
00246             , const XMLCh* const        text1 \
00247             , const XMLCh* const        text2 = 0 \
00248             , const XMLCh* const        text3 = 0 \
00249             , const XMLCh* const        text4 = 0 \
00250             , MemoryManager*            memoryManager = 0) : \
00251         XMLException(srcFile, srcLine, memoryManager) \
00252     { \
00253         loadExceptText(toThrow, text1, text2, text3, text4); \
00254     } \
00255  \
00256     theType(const   char* const         srcFile \
00257             , const unsigned int        srcLine \
00258             , const XMLExcepts::Codes   toThrow \
00259             , const char* const         text1 \
00260             , const char* const         text2 = 0 \
00261             , const char* const         text3 = 0 \
00262             , const char* const         text4 = 0 \
00263             , MemoryManager*            memoryManager = 0) : \
00264         XMLException(srcFile, srcLine, memoryManager) \
00265     { \
00266         loadExceptText(toThrow, text1, text2, text3, text4); \
00267     } \
00268  \
00269     virtual ~theType() {} \
00270  \
00271     theType& operator=(const theType& toAssign) \
00272     { \
00273         XMLException::operator=(toAssign); \
00274         return *this; \
00275     } \
00276  \
00277     virtual XMLException* duplicate() const \
00278     { \
00279         return new (fMemoryManager) theType(*this); \
00280     } \
00281  \
00282     virtual const XMLCh* getType() const \
00283     { \
00284         return XMLUni::fg##theType##_Name; \
00285     } \
00286  \
00287 private : \
00288     theType(); \
00289 };
00290 
00291 
00292 
00293 // ---------------------------------------------------------------------------
00294 //  This macros is used to actually throw an exception. It is used in order
00295 //  to make sure that source code line/col info is stored correctly, and to
00296 //  give flexibility for other stuff in the future.
00297 // ---------------------------------------------------------------------------
00298 
00299 #define ThrowXML(type,code) throw type(__FILE__, __LINE__, code)
00300 
00301 #define ThrowXML1(type,code,p1) throw type(__FILE__, __LINE__, code, p1)
00302 
00303 #define ThrowXML2(type,code,p1,p2) throw type(__FILE__, __LINE__, code, p1, p2)
00304 
00305 #define ThrowXML3(type,code,p1,p2,p3) throw type(__FILE__, __LINE__, code, p1, p2, p3)
00306 
00307 #define ThrowXML4(type,code,p1,p2,p3,p4) throw type(__FILE__, __LINE__, code, p1, p2, p3, p4)
00308 
00309 #define ThrowXMLwithMemMgr(type,code,memMgr) throw type(__FILE__, __LINE__, code, memMgr)
00310 
00311 #define ThrowXMLwithMemMgr1(type,code,p1,memMgr) throw type(__FILE__, __LINE__, code, p1, 0, 0, 0, memMgr)
00312 
00313 #define ThrowXMLwithMemMgr2(type,code,p1,p2,memMgr) throw type(__FILE__, __LINE__, code, p1, p2, 0, 0, memMgr)
00314 
00315 #define ThrowXMLwithMemMgr3(type,code,p1,p2,p3,memMgr) throw type(__FILE__, __LINE__, code, p1, p2, p3, 0, memMgr)
00316 
00317 #define ThrowXMLwithMemMgr4(type,code,p1,p2,p3,p4,memMgr) throw type(__FILE__, __LINE__, code, p1, p2, p3, p4, memMgr)
00318 
00319 XERCES_CPP_NAMESPACE_END
00320 
00321 #endif


Copyright © 2004 The Apache Software Foundation. All Rights Reserved.