[219] | 1 | #ifndef __XMLIO_GroupParser__ |
---|
| 2 | #define __XMLIO_GroupParser__ |
---|
| 3 | |
---|
| 4 | /// boost headers /// |
---|
| 5 | #include <boost/cast.hpp> |
---|
| 6 | |
---|
| 7 | namespace xmlioserver |
---|
| 8 | { |
---|
| 9 | /// ////////////////////// Définitions ////////////////////// /// |
---|
| 10 | template <class U, class V, class W> |
---|
| 11 | void CGroupTemplate<U, V, W>::parse(xml::CXMLNode & node, bool withAttr) |
---|
| 12 | { |
---|
| 13 | |
---|
| 14 | StdString name = node.getElementName(); |
---|
| 15 | if (withAttr) |
---|
| 16 | CGroupTemplate<U, V, W>::SuperClass::parse(node); |
---|
| 17 | |
---|
| 18 | // PARSING POUR GESTION DES ENFANTS |
---|
| 19 | xml::THashAttributes attributes; |
---|
| 20 | boost::shared_ptr<V> group_ptr = (this->hasId()) |
---|
| 21 | ? CObjectFactory::GetObject<V>(this->getId()) |
---|
| 22 | : CObjectFactory::GetObject(boost::polymorphic_downcast<V*>(this)); |
---|
| 23 | |
---|
| 24 | if (!(node.goToChildElement())) |
---|
| 25 | { |
---|
| 26 | if (this->hasId()) |
---|
| 27 | { |
---|
| 28 | DEBUG(<< "L'objet de type \'" << V::GetName() |
---|
| 29 | << "\' nommé \'" << this->getId() |
---|
| 30 | << "\' ne contient pas d\'enfant !"); |
---|
| 31 | } |
---|
| 32 | } |
---|
| 33 | else |
---|
| 34 | { |
---|
| 35 | do { // Parcours pour traitement. |
---|
| 36 | |
---|
| 37 | StdString name = node.getElementName(); |
---|
| 38 | attributes.clear(); |
---|
| 39 | attributes = node.getAttributes(); |
---|
| 40 | |
---|
| 41 | if (name.compare(V::GetName()) == 0) |
---|
| 42 | { |
---|
| 43 | if (attributes.end() == attributes.find("id")) |
---|
| 44 | CGroupFactory::CreateGroup(group_ptr)->parse(node); |
---|
| 45 | else |
---|
| 46 | CGroupFactory::CreateGroup(group_ptr, attributes["id"])->parse(node); |
---|
| 47 | continue; |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | if (name.compare(U::GetName()) == 0) |
---|
| 51 | { |
---|
| 52 | if (attributes.end() == attributes.find("id")) |
---|
| 53 | CGroupFactory::CreateChild(group_ptr)->parse(node); |
---|
| 54 | else |
---|
| 55 | CGroupFactory::CreateChild(group_ptr, attributes["id"])->parse(node); |
---|
| 56 | continue; |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | DEBUG(<< "Dans le contexte \'" << CObjectFactory::GetCurrentContextId() |
---|
| 60 | << "\', un objet de type \'" << V::GetName() |
---|
| 61 | << "\' ne peut contenir qu'un objet de type \'" << V::GetName() |
---|
| 62 | << "\' ou de type \'" << U::GetName() |
---|
| 63 | << "\' !"); |
---|
| 64 | |
---|
| 65 | } while (node.goToNextElement()); |
---|
| 66 | node.goToParentElement(); // Retour au parent |
---|
| 67 | } |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | } // namespace xmlioserver |
---|
| 71 | |
---|
| 72 | #endif // __XMLIO_GroupParser__ |
---|