// file      : xsd/cxx/tree/exceptions.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_TREE_EXCEPTIONS_HXX
#define XSD_CXX_TREE_EXCEPTIONS_HXX

#include <string>
#include <xsd/cxx/exceptions.hxx> // xsd::cxx::exception

namespace xsd
{
  namespace cxx
  {
    namespace tree
    {
      //
      //
      struct exception: virtual xsd::cxx::exception
      {
      };


      //
      //
      struct invalid_instance: virtual exception
      {
        virtual char const*
        what () const throw ()
        {
          return "instance document is not valid";
        }
      };


      //
      //
      template <typename C>
      struct unexpected_element: virtual exception
      {
        virtual
        ~unexpected_element () throw ()
        {
        }

        unexpected_element (std::basic_string<C> const& encountered_name,
                            std::basic_string<C> const& encountered_namespace,
                            std::basic_string<C> const& expected_name,
                            std::basic_string<C> const& expected_namespace)
            : encountered_name_ (encountered_name),
              encountered_namespace_ (encountered_namespace),
              expected_name_ (expected_name),
              expected_namespace_ (expected_namespace)
        {
        }

        virtual char const*
        what () const throw ()
        {
          return "unexpected element encountered";
        }

        // Encountered element.
        //
        std::basic_string<C> const&
        encountered_name () const
        {
          return encountered_name_;
        }

        std::basic_string<C> const&
        encountered_namespace () const
        {
          return encountered_namespace_;
        }

        // Expected element.
        //
        std::basic_string<C> const&
        expected_name () const
        {
          return expected_name_;
        }

        std::basic_string<C> const&
        expected_namespace () const
        {
          return expected_namespace_;
        }

      private:
        std::basic_string<C> encountered_name_;
        std::basic_string<C> encountered_namespace_;
        std::basic_string<C> expected_name_;
        std::basic_string<C> expected_namespace_;
      };


      //
      //
      template <typename C>
      struct unexpected_attribute: virtual exception
      {
        virtual
        ~unexpected_attribute () throw ()
        {
        }

        unexpected_attribute (std::basic_string<C> const& encountered,
                              std::basic_string<C> const& expected)
            : encountered_ (encountered),
              expected_ (expected)
        {
        }

        virtual char const*
        what () const throw ()
        {
          return "unexpected attribute encountered";
        }

        std::basic_string<C> const&
        encountered () const
        {
          return encountered_;
        }

        // Space-separated list of names of expected attributes.
        //
        std::basic_string<C> const&
        expected () const
        {
          return expected_;
        }

      private:
        std::basic_string<C> encountered_;
        std::basic_string<C> expected_;
      };


      //
      //
      template <typename C>
      struct unexpected_enumerator: virtual exception
      {
        virtual
        ~unexpected_enumerator () throw ()
        {
        }

        unexpected_enumerator (std::basic_string<C> const& encountered,
                               std::basic_string<C> const& expected)
            : encountered_ (encountered),
              expected_ (expected)
        {
        }

        virtual char const*
        what () const throw ()
        {
          return "unexpected enumerator encountered";
        }

        std::basic_string<C> const&
        encountered () const
        {
          return encountered_;
        }

        // Space-separated list of names of expected enumerators.
        //
        std::basic_string<C> const&
        expected () const
        {
          return expected_;
        }

      private:
        std::basic_string<C> encountered_;
        std::basic_string<C> expected_;
      };


      //
      //
      template <typename C>
      struct duplicate_id: virtual exception
      {
        virtual
        ~duplicate_id () throw ()
        {
        }

        duplicate_id (std::basic_string<C> const& id)
            : id_ (id)
        {
        }

        virtual char const*
        what () const throw ()
        {
          return "duplicate id";
        }

        std::basic_string<C> const&
        id () const
        {
          return id_;
        }

      private:
        std::basic_string<C> id_;
      };


      //
      //
      struct serialization: virtual exception
      {
        virtual
        ~serialization () throw ()
        {
        }

        virtual char const*
        what () const throw ()
        {
          return "serialization failed";
        }
      };


      //
      //
      template <typename C>
      struct mapping: virtual exception
      {
        virtual
        ~mapping () throw ()
        {
        }

        mapping (std::basic_string<C> const& name)
            : name_ (name)
        {
        }

        // Namespace name for which prefix-namespace mapping hasn't been
        // provided.
        //
        std::basic_string<C> const&
        name () const
        {
          return name_;
        }

        virtual char const*
        what () const throw ()
        {
          return "no mapping provided for a namespace";
        }

      private:
        std::basic_string<C> name_;
      };


      //
      //
      struct xsi_already_in_use: virtual exception
      {
        virtual char const*
        what () const throw ()
        {
          return "'xsi' prefix is already in use and no user-defined mapping "
            "has been provided";
        }
      };
    }
  }
}

#endif  // XSD_CXX_TREE_EXCEPTIONS_HXX
