/* -*- c++ -*- */
#ifndef AKAXISO_XML_SERIALIZER_H__
#define AKAXISO_XML_SERIALIZER_H__

#include <akaxiso/serializer.h>
#include <akaxiso/classes/traits.h>

namespace aka2 {

  struct any;
  typedef std::vector<any> any_array;

  class xml_serializer : public serializer {
  public:
    explicit xml_serializer(const std::string &encoding = DEFAULT_ENCODING)
      : serializer(2, encoding), ns11_enabled_(true) {};
    virtual ~xml_serializer();
    void enable_ns11(bool value) { ns11_enabled_ = value; }

  private:
    bool ns11_enabled_;

    virtual void serialize_internal(const void *e, const element_props &props, 
				    const qname &name);

    void write_element(const void *e, const element_props &props, const element_op &op);
    void write_element_entity(const void *e, const element_props &props, const element_op &op);

    void write_sequence(const qname &tagname,
                        const void *e, const sequence_op &sop);
    void write_sequence_entity(const void *e, const sequence_op &sop);

    void write_choice(const qname &tagname, 
                      const void *e, const choice_op &sop);
    void write_choice_entity(const void *e, const choice_op &sop);

    void write_all(const qname &tagname,
                   const void *e, const all_op &sop);
    void write_all_entity(const void *e, const all_op &sop);

    void write_simplecontent(const qname &tagname, 
                             const void *e, const simplecontent_op &sop);

    void write_root_array(const qname &tagname, const void *e, const element_props &props);
    void write_array(const void *e, const element_props &props);
    void write_group_array(const void *e, const element_props &props);
    void write_ptrmember(const void *e, const element_props &props);
    void write_ptrmember_entity(const void *e, const element_props &props);

    void write_simpletype(const qname &tagname,
                          const void *e, const simpletype_op &sop);

    void write_fixed_simpletype(const element_props &props);


    void write_nill_element(const qname &tagname,
                            const void *e, const element_op &op);
    void write_beginning_tag(const qname& tagname,
                             const void *e, const element_op &op);
    void write_ending_tag(const qname &tagname);

    void write_attributes(const void *e, const element_op &op);
    void write_namespace_attributes();
    void write_ns(id_type nsid);
    void write_ns11_declaration(const qname &tagname, const element_op &op, const void *e);

    void write_any(const any &an);
    void write_any_array(const any_array &ar);
    void write_ns_decl_if_new(id_type nsid);
  };

} // namespace aka2

#endif /* AKAXISO_XML_SERIALIZER_H__ */
