Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:15:15

0001 /*
0002  * Licensed to the Apache Software Foundation (ASF) under one or more
0003  * contributor license agreements.  See the NOTICE file distributed with
0004  * this work for additional information regarding copyright ownership.
0005  * The ASF licenses this file to You under the Apache License, Version 2.0
0006  * (the "License"); you may not use this file except in compliance with
0007  * the License.  You may obtain a copy of the License at
0008  *
0009  *      http://www.apache.org/licenses/LICENSE-2.0
0010  *
0011  * Unless required by applicable law or agreed to in writing, software
0012  * distributed under the License is distributed on an "AS IS" BASIS,
0013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014  * See the License for the specific language governing permissions and
0015  * limitations under the License.
0016  */
0017 
0018 /*
0019  * $Id$
0020  */
0021 
0022 #if !defined(XERCESC_INCLUDE_GUARD_XMLEXCEPTION_HPP)
0023 #define XERCESC_INCLUDE_GUARD_XMLEXCEPTION_HPP
0024 
0025 #include <xercesc/util/XercesDefs.hpp>
0026 #include <xercesc/util/XMemory.hpp>
0027 #include <xercesc/util/XMLExceptMsgs.hpp>
0028 #include <xercesc/util/XMLUni.hpp>
0029 #include <xercesc/framework/XMLErrorReporter.hpp>
0030 
0031 XERCES_CPP_NAMESPACE_BEGIN
0032 
0033 // ---------------------------------------------------------------------------
0034 //  This is the base class from which all the XML parser exceptions are
0035 //  derived. The virtual interface is very simple and most of the functionality
0036 //  is in this class.
0037 //
0038 //  Because all derivatives are EXACTLY the same except for the static
0039 //  string that is used to hold the name of the class, a macro is provided
0040 //  below via which they are all created.
0041 // ---------------------------------------------------------------------------
0042 class XMLUTIL_EXPORT XMLException : public XMemory
0043 {
0044 public:
0045     // -----------------------------------------------------------------------
0046     //  Virtual Destructor
0047     // -----------------------------------------------------------------------
0048     virtual ~XMLException();
0049 
0050 
0051     // -----------------------------------------------------------------------
0052     //  The XML exception virtual interface
0053     // -----------------------------------------------------------------------
0054     virtual const XMLCh* getType() const = 0;
0055 
0056 
0057     // -----------------------------------------------------------------------
0058     //  Getter methods
0059     // -----------------------------------------------------------------------
0060     XMLExcepts::Codes getCode() const;
0061     const XMLCh* getMessage() const;
0062     const char* getSrcFile() const;
0063     XMLFileLoc getSrcLine() const;
0064     XMLErrorReporter::ErrTypes getErrorType() const;
0065 
0066 
0067     // -----------------------------------------------------------------------
0068     //  Setter methods
0069     // -----------------------------------------------------------------------
0070     void setPosition(const char* const file, const XMLFileLoc line);
0071 
0072 
0073     // -----------------------------------------------------------------------
0074     //  Hidden constructors and operators
0075     //
0076     //  NOTE:   Technically, these should be protected, since this is a
0077     //          base class that is never used directly. However, VC++ 6.0 will
0078     //          fail to catch via a reference to base class if the ctors are
0079     //          not public!! This seems to have been caused by the install
0080     //          of IE 5.0.
0081     // -----------------------------------------------------------------------
0082     XMLException();
0083     XMLException(const char* const srcFile, const XMLFileLoc srcLine, MemoryManager* const memoryManager = 0);
0084     XMLException(const XMLException& toCopy);
0085     XMLException& operator=(const XMLException& toAssign);
0086 
0087 protected :
0088     // -----------------------------------------------------------------------
0089     //  Protected methods
0090     // -----------------------------------------------------------------------
0091     void loadExceptText
0092     (
0093         const   XMLExcepts::Codes toLoad
0094     );
0095     void loadExceptText
0096     (
0097         const   XMLExcepts::Codes toLoad
0098         , const XMLCh* const        text1
0099         , const XMLCh* const        text2 = 0
0100         , const XMLCh* const        text3 = 0
0101         , const XMLCh* const        text4 = 0
0102     );
0103     void loadExceptText
0104     (
0105         const   XMLExcepts::Codes toLoad
0106         , const char* const         text1
0107         , const char* const         text2 = 0
0108         , const char* const         text3 = 0
0109         , const char* const         text4 = 0
0110     );
0111 
0112 
0113 private :
0114     // -----------------------------------------------------------------------
0115     //  Data members
0116     //
0117     //  fCode
0118     //      The error code that this exception represents.
0119     //
0120     //  fSrcFile
0121     //  fSrcLine
0122     //      These are the file and line information from the source where the
0123     //      exception was thrown from.
0124     //
0125     //  fMsg
0126     //      The loaded message text for this exception.
0127     // -----------------------------------------------------------------------
0128     XMLExcepts::Codes       fCode;
0129     char*                   fSrcFile;
0130     XMLFileLoc              fSrcLine;
0131     XMLCh*                  fMsg;
0132 
0133 protected:
0134     MemoryManager*          fMemoryManager;
0135 };
0136 
0137 // ---------------------------------------------------------------------------
0138 //  XMLException: Getter methods
0139 // ---------------------------------------------------------------------------
0140 inline XMLExcepts::Codes XMLException::getCode() const
0141 {
0142     return fCode;
0143 }
0144 
0145 inline const XMLCh* XMLException::getMessage() const
0146 {
0147     return fMsg;
0148 }
0149 
0150 inline const char* XMLException::getSrcFile() const
0151 {
0152     if (!fSrcFile)
0153         return "";
0154     return fSrcFile;
0155 }
0156 
0157 inline XMLFileLoc XMLException::getSrcLine() const
0158 {
0159     return fSrcLine;
0160 }
0161 
0162 inline XMLErrorReporter::ErrTypes XMLException::getErrorType() const
0163 {
0164    if ((fCode >= XMLExcepts::W_LowBounds) && (fCode <= XMLExcepts::W_HighBounds))
0165        return XMLErrorReporter::ErrType_Warning;
0166    else if ((fCode >= XMLExcepts::F_LowBounds) && (fCode <= XMLExcepts::F_HighBounds))
0167         return XMLErrorReporter::ErrType_Fatal;
0168    else if ((fCode >= XMLExcepts::E_LowBounds) && (fCode <= XMLExcepts::E_HighBounds))
0169         return XMLErrorReporter::ErrType_Error;
0170    return XMLErrorReporter::ErrTypes_Unknown;
0171 }
0172 
0173 // ---------------------------------------------------------------------------
0174 //  This macro is used to create derived classes. They are all identical
0175 //  except the name of the exception, so it crazy to type them in over and
0176 //  over.
0177 // ---------------------------------------------------------------------------
0178 #define MakeXMLException(theType, expKeyword) \
0179 class expKeyword theType : public XMLException \
0180 { \
0181 public: \
0182  \
0183     theType(const   char* const         srcFile \
0184             , const XMLFileLoc          srcLine \
0185             , const XMLExcepts::Codes toThrow \
0186             , MemoryManager*            memoryManager = 0) : \
0187         XMLException(srcFile, srcLine, memoryManager) \
0188     { \
0189         loadExceptText(toThrow); \
0190     } \
0191  \
0192     theType(const theType& toCopy) : \
0193  \
0194         XMLException(toCopy) \
0195     { \
0196     } \
0197   \
0198     theType(const   char* const         srcFile \
0199             , const XMLFileLoc          srcLine \
0200             , const XMLExcepts::Codes   toThrow \
0201             , const XMLCh* const        text1 \
0202             , const XMLCh* const        text2 = 0 \
0203             , const XMLCh* const        text3 = 0 \
0204             , const XMLCh* const        text4 = 0 \
0205             , MemoryManager*            memoryManager = 0) : \
0206         XMLException(srcFile, srcLine, memoryManager) \
0207     { \
0208         loadExceptText(toThrow, text1, text2, text3, text4); \
0209     } \
0210  \
0211     theType(const   char* const         srcFile \
0212             , const XMLFileLoc          srcLine \
0213             , const XMLExcepts::Codes   toThrow \
0214             , const char* const         text1 \
0215             , const char* const         text2 = 0 \
0216             , const char* const         text3 = 0 \
0217             , const char* const         text4 = 0 \
0218             , MemoryManager*            memoryManager = 0) : \
0219         XMLException(srcFile, srcLine, memoryManager) \
0220     { \
0221         loadExceptText(toThrow, text1, text2, text3, text4); \
0222     } \
0223  \
0224     virtual ~theType() {} \
0225  \
0226     theType& operator=(const theType& toAssign) \
0227     { \
0228         XMLException::operator=(toAssign); \
0229         return *this; \
0230     } \
0231  \
0232     virtual XMLException* duplicate() const \
0233     { \
0234         return new (fMemoryManager) theType(*this); \
0235     } \
0236  \
0237     virtual const XMLCh* getType() const \
0238     { \
0239         return XMLUni::fg##theType##_Name; \
0240     } \
0241  \
0242 private : \
0243     theType(); \
0244 };
0245 
0246 
0247 
0248 // ---------------------------------------------------------------------------
0249 //  This macros is used to actually throw an exception. It is used in order
0250 //  to make sure that source code line/col info is stored correctly, and to
0251 //  give flexibility for other stuff in the future.
0252 // ---------------------------------------------------------------------------
0253 
0254 #define ThrowXML(type,code) throw type(__FILE__, __LINE__, code)
0255 
0256 #define ThrowXML1(type,code,p1) throw type(__FILE__, __LINE__, code, p1)
0257 
0258 #define ThrowXML2(type,code,p1,p2) throw type(__FILE__, __LINE__, code, p1, p2)
0259 
0260 #define ThrowXML3(type,code,p1,p2,p3) throw type(__FILE__, __LINE__, code, p1, p2, p3)
0261 
0262 #define ThrowXML4(type,code,p1,p2,p3,p4) throw type(__FILE__, __LINE__, code, p1, p2, p3, p4)
0263 
0264 #define ThrowXMLwithMemMgr(type,code,memMgr) throw type(__FILE__, __LINE__, code, memMgr)
0265 
0266 #define ThrowXMLwithMemMgr1(type,code,p1,memMgr) throw type(__FILE__, __LINE__, code, p1, 0, 0, 0, memMgr)
0267 
0268 #define ThrowXMLwithMemMgr2(type,code,p1,p2,memMgr) throw type(__FILE__, __LINE__, code, p1, p2, 0, 0, memMgr)
0269 
0270 #define ThrowXMLwithMemMgr3(type,code,p1,p2,p3,memMgr) throw type(__FILE__, __LINE__, code, p1, p2, p3, 0, memMgr)
0271 
0272 #define ThrowXMLwithMemMgr4(type,code,p1,p2,p3,p4,memMgr) throw type(__FILE__, __LINE__, code, p1, p2, p3, p4, memMgr)
0273 
0274 XERCES_CPP_NAMESPACE_END
0275 
0276 #endif