// file      : xsd/cxx/xml/sax/error-handler.hxx
// author    : Boris Kolpackov <boris@codesynthesis.com>
// copyright : Copyright (c) 2005 Code Synthesis Tools CC
// license   : GNU GPL v2 + exceptions; see accompanying LICENSE file

#ifndef XSD_CXX_XML_SAX_ERROR_HANDLER_HXX
#define XSD_CXX_XML_SAX_ERROR_HANDLER_HXX

#include <xercesc/sax/ErrorHandler.hpp>

namespace xsd
{
  namespace cxx
  {
    namespace xml
    {
      namespace sax
      {
        template <typename C>
        class error_handler: public  xercesc::ErrorHandler
        {
        public:
          error_handler (xercesc::ErrorHandler* eh = 0)
              : failed_ (false), eh_ (eh)
          {
          }

        public:
          struct severity
          {
            enum value
            {
              warning,
              error,
              fatal
            };
          };

          virtual void
          warning (xercesc::SAXParseException const& e)
          {
            if (eh_)
              eh_->warning (e);
            else
              handle (e, severity::warning);
          }

          virtual void
          error (xercesc::SAXParseException const& e)
          {
            failed_ = true;

            if (eh_)
              eh_->error (e);
            else
              handle (e, severity::error);
          }


          virtual void
          fatalError (xercesc::SAXParseException const& e)
          {
            failed_ = true;

            if (eh_)
              eh_->fatalError (e);
            else
              handle (e, severity::fatal);
          }

          virtual void
          handle (xercesc::SAXParseException const&,
                  typename severity::value);

        public:
          bool
          failed () const
          {
            return failed_;
          }

          virtual void
          resetErrors()
          {
            failed_ = false;
          }

        private:
          bool failed_;
          xercesc::ErrorHandler* eh_;
        };
      }
    }
  }
}

#endif  // XSD_CXX_XML_SAX_ERROR_HANDLER_HXX

#include <xsd/cxx/xml/sax/error-handler.ixx>
