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

xmlflowexception.cpp

Go to the documentation of this file.
00001 //============================================================================= 
00002 //
00003 // XDFLengine library
00004 //
00005 //-----------------------------------------------------------------------------
00006 //  XMLFLOWEXCEPTION.CPP
00007 //-----------------------------------------------------------------------------
00013 //_____________________________________________________________________________
00014 //
00015 //  Copyright (C) 2003 Guillaume Baurand. All Rights Reserved.
00016 //
00017 //  This file is part of the XDFLengine project.
00018 //
00019 //  The XDFLengine is free software; you can redistribute it and/or modify
00020 //  it under the terms of the GNU General Public License as published by
00021 //  the Free Software Foundation; either version 2 of the License, or
00022 //  (at your option) any later version.
00023 //
00024 //  This program is distributed in the hope that it will be useful,
00025 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00026 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00027 //  GNU General Public License for more details.
00028 //
00029 //  You should have received a copy of the GNU General Public License
00030 //  along with this program; if not, write to the Free Software
00031 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
00032 //  USA.
00033 //
00034 //  For more information, 
00035 //      contact  : guillaume@baurand.net 
00036 //      or visit : http://xdflengine.sourceforge.net
00037 //
00038 //============================================================================= 
00039 
00040 #   include "flow/xmlstreamconsumer.hpp"
00041 #   include "processor/xmlflowexception.hpp"
00042 #   include "flow/xmlstreambuffer.hpp"
00043 
00044 BEGIN_XDFLENGINE_NS
00045 
00046 //============================================================================= 
00047 //  CLASS XMLFLOWEXCEPTION
00048 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00049 
00050     //_________________________________________________________________________
00051     //  THROWXMLFLOWEXCEPTION
00052     //-------------------------------------------------------------------------
00053     void XMLFlowException::throwXMLFlowException(int p_intNumber, const char* p_pszMessage, const char* p_pszContext, const char* p_pszLocalisation, const char* p_pszCause, bool p_boolFatal)
00054     {
00055         throw new XMLFlowException(p_intNumber, p_pszMessage, p_pszContext, p_pszLocalisation, p_pszCause, p_boolFatal);
00056     }
00057 
00058     //_________________________________________________________________________
00059     //  XMLFLOWEXCEPTION
00060     //-------------------------------------------------------------------------
00061     XMLFlowException::XMLFlowException(int p_intNumber, const char* p_pszMessage, const char* p_pszContext, const char* p_pszLocalisation, const char* p_pszCause, bool p_boolFatal)
00062     {       
00063 
00064         logout << "\n";
00065         if (p_boolFatal) logout << "FATAL ";
00066         logout << "ERROR #" << p_intNumber << " in "<< p_pszLocalisation << " :" << "\n";
00067         logout << p_pszMessage << "\n";
00068         logout << p_pszContext << "\n";
00069         
00070         m_intErrNumber = p_intNumber;
00071         m_pszErrMessage = importCharBuffer(0,p_pszMessage);
00072         m_pszErrContext = importCharBuffer(0,p_pszContext);
00073         m_pszErrLocalisation = importCharBuffer(0,p_pszLocalisation);
00074         m_pszErrCause = importCharBuffer(0,p_pszCause);
00075         m_boolFatal = p_boolFatal; 
00076 
00077         if(!m_boolFatal)
00078         {
00079             DEBUG_CREATE(******XMLFLOWEXCEPTION******)
00080         }
00081         else
00082         {
00083             DEBUG_CREATE(******FATAL XMLFLOWEXCEPTION******)
00084         }
00085 
00086         DEBUG_ECHO << "SENDER: " << p_pszLocalisation << "\n";
00087     }
00088 
00089     //_________________________________________________________________________
00090     //  ~XMLFLOWEXCEPTION
00091     //-------------------------------------------------------------------------
00092     XMLFlowException::~XMLFlowException()
00093     {
00094         if(!m_boolFatal)
00095         {
00096             DEBUG_DEL(******XMLFLOWEXCEPTION******)
00097         }
00098         else
00099         {
00100             DEBUG_DEL(******FATAL XMLFLOWEXCEPTION******)
00101         }
00102         m_pszErrMessage = releaseCharBuffer( m_pszErrMessage);
00103         m_pszErrContext = releaseCharBuffer( m_pszErrContext);
00104         m_pszErrLocalisation = releaseCharBuffer( m_pszErrLocalisation); 
00105         m_pszErrCause = releaseCharBuffer( m_pszErrCause);
00106     }
00107 
00108     //_________________________________________________________________________
00109     //  ISFATAL
00110     //-------------------------------------------------------------------------
00111     bool XMLFlowException::isFatal()
00112     {
00113         return m_boolFatal; 
00114     }
00115     
00116         
00117     //_____________________________________________________________________
00118     //  GETNUMBER
00119     //---------------------------------------------------------------------
00121     //
00123     //_____________________________________________________________________     
00124     int XMLFlowException::getNumber()
00125     {
00126         return  m_intErrNumber;
00127     }       
00128 
00129     //_________________________________________________________________________
00130     //  MAKEXML
00131     //-------------------------------------------------------------------------
00132     XMLFlowException& XMLFlowException::operator>> (XMLStreamConsumer & p_Output)
00133     {
00134         char l_cErrNum[10];
00135 
00136         sprintf( l_cErrNum, "%d",m_intErrNumber);
00137 
00138         if(!m_boolFatal) p_Output << "\n<ERROR>";
00139         else p_Output << "\n<FATAL_ERROR>";
00140 
00141         p_Output << "\n\t<number>"                  << l_cErrNum << "</number>";
00142         p_Output << "\n\t<message><![CDATA["        << m_pszErrMessage  << "]]></message>";
00143         p_Output << "\n\t<localisation><![CDATA["   << m_pszErrLocalisation << "]]></localisation>";
00144         p_Output << "\n\t<context><![CDATA["        << m_pszErrContext  << "]]></context>";
00145         p_Output << "\n\t<cause><![CDATA["          << m_pszErrCause    << "]]></cause>";
00146 
00147         if(!m_boolFatal) p_Output << "\n</ERROR>\n";
00148         else p_Output << "\n</FATAL_ERROR>";
00149         
00150         return (* this);
00151     }
00152 
00153 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00154 //=============================================================================
00155 
00156 
00157 //=============================================================================
00158 // CLASS XDFLSAXERRORREPORTER
00159 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00160 
00161 
00162 //  CONSTRUCTORS AND DESTRUCTOR
00163 
00164     //_________________________________________________________________________
00165     //  XDFLSAXERRORREPORTER
00166     //-------------------------------------------------------------------------
00167     XDFLSaxErrorReporter::XDFLSaxErrorReporter(const char* p_pszParseName)
00168     {       
00169         resetErrors();
00170         m_pszParseName = importCharBuffer(0,p_pszParseName);
00171 
00172         DEBUG_CREATE(XDFLSaxErrorReporter)
00173     }
00174 
00175     //_________________________________________________________________________
00176     //  ~XDFLSAXERRORREPORTER
00177     //-------------------------------------------------------------------------
00178     XDFLSaxErrorReporter::~XDFLSaxErrorReporter()
00179     {
00180         DEBUG_DEL(XDFLSaxErrorReporter)
00181 
00182         m_pszParseName = releaseCharBuffer(m_pszParseName);
00183     }
00184 
00185     //  Implementation of the error handler interface
00186 
00187     //_________________________________________________________________________
00188     //  WARNING
00189     //-------------------------------------------------------------------------
00190     void XDFLSaxErrorReporter::warning(const SAXParseException& toCatch)
00191     {
00192         DEBUG_FUNC(XDFLSaxErrorReporter::warning)
00193     }
00194 
00195     //_________________________________________________________________________
00196     //  ERROR
00197     //-------------------------------------------------------------------------
00198     void XDFLSaxErrorReporter::error(const SAXParseException& toCatch)
00199     {
00200         XMLFlowException* l_pXMLFlowException;
00201         char* l_pszMsg;
00202         char*   l_pszTmp;
00203 
00204         DEBUG_FUNC(XDFLSaxErrorReporter::error) 
00205 
00206         fSawErrors = true;
00207         l_pszMsg = copyCharBuffer( "XML Error at file ");
00208 
00209         l_pszTmp = XSTR( toCatch.getSystemId());
00210         l_pszMsg = concatCharBuffer( l_pszMsg,l_pszTmp);
00211         l_pszTmp = releaseCharBuffer(l_pszTmp);
00212 
00213         l_pszMsg = concatCharBuffer( l_pszMsg,":");
00214 
00215         l_pszTmp = XSTR( toCatch.getMessage());
00216         l_pszMsg = concatCharBuffer( l_pszMsg,l_pszTmp);
00217         l_pszTmp = releaseCharBuffer(l_pszTmp);
00218 
00219         l_pXMLFlowException=new XMLFlowException ( ERRCODE_LOC_OTHERS + ERRCODE_CAUSE_XML , l_pszMsg, m_pszParseName, "XDFLSaxErrorReporter", "", false);
00220         l_pszMsg = releaseCharBuffer(l_pszMsg);
00221         throw l_pXMLFlowException;
00222 
00223     }
00224 
00225     //_________________________________________________________________________
00226     //  FATALERROR
00227     //-------------------------------------------------------------------------
00228     void XDFLSaxErrorReporter::fatalError(const SAXParseException& toCatch)
00229     {
00230         XMLFlowException* l_pXMLFlowException;
00231         char* l_pszMsg;
00232         char*   l_pszTmp;
00233 
00234         DEBUG_FUNC(XDFLSaxErrorReporter::error) 
00235 
00236         fSawErrors = true;
00237         l_pszMsg = copyCharBuffer( "Fatal XML Error at file ");
00238 
00239         l_pszTmp = XSTR( toCatch.getSystemId());
00240         l_pszMsg = concatCharBuffer( l_pszMsg,l_pszTmp);
00241         l_pszTmp = releaseCharBuffer(l_pszTmp);
00242 
00243         l_pszMsg = concatCharBuffer( l_pszMsg,":");
00244 
00245         l_pszTmp = XSTR( toCatch.getMessage());
00246         l_pszMsg = concatCharBuffer( l_pszMsg,l_pszTmp);
00247         l_pszTmp = releaseCharBuffer(l_pszTmp);
00248 
00249         logout << "(" << (int)(toCatch.getLineNumber()) << "," << (int)(toCatch.getColumnNumber()) << ")\n";
00250 
00251         l_pXMLFlowException=new XMLFlowException ( ERRCODE_LOC_OTHERS + ERRCODE_CAUSE_XML , l_pszMsg, m_pszParseName, "XDFLSaxErrorReporter", "", false);
00252         l_pszMsg = releaseCharBuffer(l_pszMsg);
00253         throw l_pXMLFlowException;
00254     }
00255 
00256     //_________________________________________________________________________
00257     //  RESETERRORS
00258     //-------------------------------------------------------------------------
00259     void XDFLSaxErrorReporter::resetErrors()
00260     {
00261         DEBUG_FUNC(DOMTreeErrorReporter::resetErrors)
00262 
00263         fSawErrors=false;
00264     }
00265 
00266 //  GETTER METHODS
00267 
00268     //_________________________________________________________________________
00269     //  GETSAWERRORS
00270     //-------------------------------------------------------------------------
00271     bool XDFLSaxErrorReporter::getSawErrors() 
00272     {
00273         DEBUG_FUNC(DOMTreeErrorReporter::getSawErrors)
00274 
00275         return fSawErrors;
00276     }
00277 
00278 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00279 //=============================================================================
00280 
00281 END_XDFLENGINE_NS
00282 

Generated on Sat Oct 4 13:20:03 2003 for XDFLengine by doxygen1.3-rc2