1 | #include "context.hpp" |
---|
2 | |
---|
3 | #include "attribute_template_impl.hpp" |
---|
4 | #include "object_template_impl.hpp" |
---|
5 | #include "group_template_impl.hpp" |
---|
6 | |
---|
7 | namespace xmlioserver |
---|
8 | { |
---|
9 | namespace tree |
---|
10 | { |
---|
11 | /// ////////////////////// Définitions ////////////////////// /// |
---|
12 | |
---|
13 | CContext::CContext(void) |
---|
14 | : CObjectTemplate<CContext>(), CContextAttributes() |
---|
15 | { /* Ne rien faire de plus */ } |
---|
16 | |
---|
17 | CContext::CContext(const StdString & id) |
---|
18 | : CObjectTemplate<CContext>(id), CContextAttributes() |
---|
19 | { /* Ne rien faire de plus */ } |
---|
20 | |
---|
21 | CContext::~CContext(void) |
---|
22 | { /* Ne rien faire de plus */ } |
---|
23 | |
---|
24 | StdString CContext::GetName(void) { return (StdString("context")); } |
---|
25 | StdString CContext::GetDefName(void){ return (CContext::GetName()); } |
---|
26 | |
---|
27 | boost::shared_ptr<CContextGroup> CContext::GetContextGroup(void) |
---|
28 | { static boost::shared_ptr<CContextGroup> group_context |
---|
29 | (new CContextGroup(xml::CXMLNode::GetRootName())); |
---|
30 | return (group_context); } |
---|
31 | |
---|
32 | void CContext::parse(xml::CXMLNode & node) |
---|
33 | { |
---|
34 | CContext::SuperClass::parse(node); |
---|
35 | |
---|
36 | // PARSING POUR GESTION DES ENFANTS |
---|
37 | xml::THashAttributes attributes; |
---|
38 | |
---|
39 | if (node.getElementName().compare(CContext::GetName())) |
---|
40 | DEBUG("Le noeud est mal nommé mais sera traité comme un contexte !"); |
---|
41 | |
---|
42 | if (!(node.goToChildElement())) |
---|
43 | { |
---|
44 | DEBUG("Le context ne contient pas d'enfant !"); |
---|
45 | } |
---|
46 | else |
---|
47 | { |
---|
48 | do { // Parcours des contextes pour traitement. |
---|
49 | |
---|
50 | StdString name = node.getElementName(); |
---|
51 | attributes.clear(); |
---|
52 | attributes = node.getAttributes(); |
---|
53 | |
---|
54 | if (attributes.end() != attributes.find("id")) |
---|
55 | { DEBUG(<< "Le noeud de définition possÚde un identifiant," |
---|
56 | << " ce dernier ne sera pas pris en compte lors du traitement !"); } |
---|
57 | |
---|
58 | #define DECLARE_NODE(Name_, name_) \ |
---|
59 | if (name.compare(C##Name_##Definition::GetDefName()) == 0) \ |
---|
60 | { CObjectFactory::CreateObject<C##Name_##Definition>(C##Name_##Definition::GetDefName()) -> parse(node); \ |
---|
61 | continue; } |
---|
62 | #define DECLARE_NODE_PAR(Name_, name_) |
---|
63 | #include "../config/node_type.conf" |
---|
64 | |
---|
65 | DEBUG(<< "L'élément nommé \'" << name |
---|
66 | << "\' dans le contexte \'" << CObjectFactory::GetCurrentContextId() |
---|
67 | << "\' ne représente pas une définition !"); |
---|
68 | |
---|
69 | } while (node.goToNextElement()); |
---|
70 | |
---|
71 | node.goToParentElement(); // Retour au parent |
---|
72 | } |
---|
73 | } |
---|
74 | |
---|
75 | void CContext::ShowTree(StdOStream & out) |
---|
76 | { |
---|
77 | StdString currentContextId = |
---|
78 | CObjectFactory::GetCurrentContextId(); |
---|
79 | std::vector<boost::shared_ptr<CContext> > def_vector = |
---|
80 | CContext::GetContextGroup()->getChildList(); |
---|
81 | |
---|
82 | out << "<? xml version=\"1.0\" ?>" << std::endl; |
---|
83 | out << "< " << xml::CXMLNode::GetRootName() << " >" << std::endl; |
---|
84 | BOOST_FOREACH(boost::shared_ptr<CContext> context, def_vector) |
---|
85 | { |
---|
86 | CObjectFactory::SetCurrentContextId(context->getId()); |
---|
87 | CGroupFactory::SetCurrentContextId(context->getId()); |
---|
88 | out << *context << std::endl; |
---|
89 | |
---|
90 | } |
---|
91 | out << "</ " << xml::CXMLNode::GetRootName() << " >" << std::endl; |
---|
92 | |
---|
93 | CObjectFactory::SetCurrentContextId(currentContextId); |
---|
94 | CGroupFactory::SetCurrentContextId(currentContextId); |
---|
95 | } |
---|
96 | |
---|
97 | StdString CContext::toString(void) const |
---|
98 | { |
---|
99 | StdOStringStream oss; |
---|
100 | oss << "< " << CContext::GetName() |
---|
101 | << " id=\"" << this->getId() << "\" " |
---|
102 | << SuperClassAttribute::toString() << ">" << std::endl; |
---|
103 | if (!this->hasChild()) |
---|
104 | { |
---|
105 | //oss << "<!-- No definition -->" << std::endl; // fait planter l'incrémentation |
---|
106 | } |
---|
107 | else |
---|
108 | { |
---|
109 | |
---|
110 | #define DECLARE_NODE(Name_, name_) \ |
---|
111 | if (CObjectFactory::HasObject<C##Name_##Definition>(C##Name_##Definition::GetDefName())) \ |
---|
112 | oss << *CObjectFactory::GetObject<C##Name_##Definition>(C##Name_##Definition::GetDefName()) << std::endl; |
---|
113 | #define DECLARE_NODE_PAR(Name_, name_) |
---|
114 | #include "../config/node_type.conf" |
---|
115 | |
---|
116 | } |
---|
117 | |
---|
118 | oss << "</ " << CContext::GetName() << " >"; |
---|
119 | |
---|
120 | return (oss.str()); |
---|
121 | } |
---|
122 | |
---|
123 | void CContext::solveDescInheritance(const CAttributeMap * const UNUSED(parent)) |
---|
124 | { |
---|
125 | #define DECLARE_NODE(Name_, name_) \ |
---|
126 | if (CObjectFactory::HasObject<C##Name_##Definition>(C##Name_##Definition::GetDefName())) \ |
---|
127 | CObjectFactory::GetObject<C##Name_##Definition>(C##Name_##Definition::GetDefName())->solveDescInheritance(); |
---|
128 | #define DECLARE_NODE_PAR(Name_, name_) |
---|
129 | #include "../config/node_type.conf" |
---|
130 | } |
---|
131 | |
---|
132 | bool CContext::hasChild(void) const |
---|
133 | { |
---|
134 | return (false || |
---|
135 | #define DECLARE_NODE(Name_, name_) \ |
---|
136 | CObjectFactory::HasObject<C##Name_##Definition> (C##Name_##Definition::GetDefName()) || |
---|
137 | #define DECLARE_NODE_PAR(Name_, name_) |
---|
138 | #include "../config/node_type.conf" |
---|
139 | false); |
---|
140 | } |
---|
141 | |
---|
142 | void CContext::solveFieldRefInheritance(void) |
---|
143 | { |
---|
144 | if (!this->hasId()) return; |
---|
145 | std::vector<boost::shared_ptr<CField> > allField |
---|
146 | = CObjectTemplate<CField>::GetAllVectobject(this->getId()); |
---|
147 | BOOST_FOREACH(boost::shared_ptr<CField> field, allField) |
---|
148 | field->solveRefInheritance(); |
---|
149 | } |
---|
150 | |
---|
151 | } // namespace tree |
---|
152 | } // namespace xmlioserver |
---|