#ifndef NILLABLE_TYPE_HXX #define NILLABLE_TYPE_HXX #include #include #include #include #include #include "xml-schema.hxx" template class complex_nillable_type: public B { public: complex_nillable_type () : nil_ (false) { } template complex_nillable_type (A1& a1) : B (a1), nil_ (false) { } template complex_nillable_type (A1& a1, A2& a2) : B (a1, a2), nil_ (false) { } template complex_nillable_type (A1& a1, A2& a2, A3& a3) : B (a1, a2, a3), nil_ (false) { } template complex_nillable_type (A1& a1, A2& a2, A3& a3, A4& a4) : B (a1, a2, a3, a4), nil_ (false) { } template complex_nillable_type (A1& a1, A2& a2, A3& a3, A4& a4, A5& a5) : B (a1, a2, a3, a4, a5), nil_ (false) { } template complex_nillable_type (A1& a1, A2& a2, A3& a3, A4& a4, A5& a5, A6& a6) : B (a1, a2, a3, a4, a5, a6), nil_ (false) { } complex_nillable_type (const xercesc::DOMElement& e, xml_schema::flags f = 0, xml_schema::container* c = 0) : B (e, f | xml_schema::flags::base, c), nil_ (false) { if ((f & xml_schema::flags::base) == 0) { namespace xml = xsd::cxx::xml; if (e.hasAttributeNS (xercesc::SchemaSymbols::fgURI_XSI, xercesc::SchemaSymbols::fgATT_NILL)) { std::string v ( xml::transcode ( e.getAttributeNS ( xercesc::SchemaSymbols::fgURI_XSI, xercesc::SchemaSymbols::fgATT_NILL))); nil_ = (v == "true" || v == "1"); } XMLCh *pch =(XMLCh*) "ref"; if (e.hasAttributeNS (xercesc::SchemaSymbols::fgURI_XSI, pch)) { std::string strRef ( xml::transcode ( e.getAttributeNS ( xercesc::SchemaSymbols::fgURI_XSI, pch ))); ex::Entity::ref_optional ref_opt; ref_opt.set(strRef); ((ex::Entity*)this)->ref(strRef); } //leggo se c'è l'attributo id if (!nil_) { xsd::cxx::xml::dom::parser p (e, true, true); B::parse (p, f); } else{ if (e.hasAttributeNS (xercesc::SchemaSymbols::fgURI_XSI, xercesc::SchemaSymbols::fgATT_ID)) { std::string strID ( xml::transcode ( e.getAttributeNS ( xercesc::SchemaSymbols::fgURI_XSI, xercesc::SchemaSymbols::fgATT_ID))); ex::Entity::id_optional id_opt; id_opt.set(strID); ((ex::Entity*)this)->id(id_opt); } } } } complex_nillable_type (const complex_nillable_type& x, xml_schema::flags f = 0, xml_schema::container* c = 0) : B (x, f, c), nil_ (x.nil_) { } virtual complex_nillable_type* _clone (xml_schema::flags f = 0, xml_schema::container* c = 0) const { return new complex_nillable_type (*this, f, c); } public: bool _nil () const { return nil_; } void _nil (bool v) { nil_ = v; } std::string getID () const { return m_strID; } void setID (std::string v) { m_strID = v; } private: bool nil_; }; template void operator<< (xercesc::DOMElement& e, const complex_nillable_type& x) { if (!x._nil ()) e << static_cast (x); else { namespace xml = xsd::cxx::xml; e.setAttributeNS (xercesc::SchemaSymbols::fgURI_XSI, xml::string ("xsi:nil").c_str (), xercesc::SchemaSymbols::fgATTVAL_TRUE); } } template class simple_nillable_type: public B { public: simple_nillable_type () : nil_ (false) { } template simple_nillable_type (A1& a1) : B (a1), nil_ (false) { } simple_nillable_type (const xercesc::DOMElement& e, xml_schema::flags f = 0, xml_schema::container* c = 0) : B (B (), f, c), nil_ (false) { namespace xml = xsd::cxx::xml; if (e.hasAttributeNS (xercesc::SchemaSymbols::fgURI_XSI, xercesc::SchemaSymbols::fgATT_NILL)) { std::string v ( xml::transcode ( e.getAttributeNS ( xercesc::SchemaSymbols::fgURI_XSI, xercesc::SchemaSymbols::fgATT_NILL))); nil_ = (v == "true" || v == "1"); } XMLCh *pch =(XMLCh*) "ref"; if (e.hasAttributeNS (xercesc::SchemaSymbols::fgURI_XSI, pch)) { std::string strRef ( xml::transcode ( e.getAttributeNS ( xercesc::SchemaSymbols::fgURI_XSI, pch ))); ex::Entity::ref_optional ref_opt; ref_opt.set(strRef); ((ex::Entity*)this)->ref(strRef); } if (!nil_){ static_cast (*this) = B (e, f, c); }else { if (e.hasAttributeNS (xercesc::SchemaSymbols::fgURI_XSI, xercesc::SchemaSymbols::fgATT_ID)) { std::string strID ( xml::transcode ( e.getAttributeNS ( xercesc::SchemaSymbols::fgURI_XSI, xercesc::SchemaSymbols::fgATT_ID))); ex::Entity::id_optional id_opt; id_opt.set(strID); ((ex::Entity*)this)->id(id_opt); } } } simple_nillable_type (const xercesc::DOMAttr& a, xml_schema::flags f = 0, xml_schema::container* c = 0) : B (a, f, c), nil_ (false) { } simple_nillable_type (const std::string& s, const xercesc::DOMElement* e, xml_schema::flags f = 0, xml_schema::container* c = 0) : B (s, e, f, c), nil_ (false) { } simple_nillable_type (const simple_nillable_type& x, xml_schema::flags f = 0, xml_schema::container* c = 0) : B (x, f, c), nil_ (x.nil_) { } virtual simple_nillable_type* _clone (xml_schema::flags f = 0, xml_schema::container* c = 0) const { return new simple_nillable_type (*this, f, c); } public: bool _nil () const { return nil_; } void _nil (bool v) { nil_ = v; } private: bool nil_; }; template void operator<< (xercesc::DOMElement& e, const simple_nillable_type& x) { if (!x._nil ()) e << static_cast (x); else { namespace xml = xsd::cxx::xml; e.setAttributeNS (xercesc::SchemaSymbols::fgURI_XSI, xml::string ("xsi:nil").c_str (), xercesc::SchemaSymbols::fgATTVAL_TRUE); } } template void operator<< (xercesc::DOMAttr& a, const simple_nillable_type& x) { a << static_cast (x); } template void operator<< (xml_schema::list_stream& s, const simple_nillable_type& x) { s << static_cast (x); } #endif