source: pacpusframework/trunk/src/PacpusLib/XmlComponentConfig.cpp@ 13

Last change on this file since 13 was 3, checked in by sgosseli, 12 years ago
  • Add the existing Pacpus files from pacpusdev and pacpuscore.
  • Provide a clean build system based on multiple CMake files.
File size: 4.0 KB
RevLine 
[3]1/*********************************************************************
2// created: 2006/01/30
3// created: 2006/01/30 - 11:09
4// filename: xmlcomponentconfig.cpp
5//
6// author: Gerald Dherbomez
7//
8// purpose: implementation de la classe XmlComponentConfig
9*********************************************************************/
10
11#include "kernel/XmlComponentConfig.h"
12
13#include "kernel/Log.h"
14#include "kernel/XmlConfigFile.h"
15
16namespace pacpus {
17
18using namespace std;
19
20DECLARE_STATIC_LOGGER("pacpus.core.XmlComponentConfig");
21
22static const string kPropertyComponentType = "type";
23
24XmlComponentConfig::XmlComponentConfig(const QString& name)
25{
26 LOG_TRACE("XmlComponentConfig(QString)");
27
28 // Get the pointer to the document and create the component.
29 parentDocument_ = XmlConfigFile::create();
30 if (name != QString::null)
31 component_ = parentDocument_->createComponent(name);
32}
33
34/// Destructor.
35XmlComponentConfig::~XmlComponentConfig()
36{
37 LOG_TRACE("~XmlComponentConfig()");
38}
39
40void XmlComponentConfig::addProperty(const QString& name)
41{
42 if (hasProperty(name))
43 {
44 LOG_ERROR("cannot add component property:"
45 << " component '" << component_.tagName() << "'"
46 << " already contains property '" << name << "'"
47 << " and its value is '" << component_.attribute(name) << "'"
48 );
49 return;
50 }
51
52 // The property does not exist, it can be added.
53 component_.setAttribute(name, 0);
54 LOG_INFO("property '" << name << "'"
55 << " was added to the component " << component_.tagName() << "'"
56 << " and set to '" << component_.attribute(name) << "'"
57 );
58}
59
60int XmlComponentConfig::delProperty(const QString& name)
61{
62 if (!hasProperty(name))
63 {
64 LOG_WARN("cannot delete compoenent property '" << name << "'"
65 << " of component '" << component_.tagName() << "'"
66 << ". Component does not contain this property."
67 );
68 return false;
69 }
70
71 // The property exists, it can be removed.
72 component_.removeAttribute(name);
73 LOG_INFO("property '" << name << "' "
74 << " of component '" << component_.tagName() << "'"
75 << " was deleted"
76 );
77
78 return true;
79}
80
81QString XmlComponentConfig::getProperty(const QString& name, const QString& defaultValue) const
82{
83 if (!hasProperty(name))
84 {
85 LOG_WARN("cannot retrieve component property '" << name << "'"
86 << " of component '" << component_.tagName() << "'"
87 << ". Component does not contain this property."
88 );
89 return defaultValue;
90 }
91
92 // The property exists, the value can be retrieved.
93 return component_.attribute(name);
94}
95
96int XmlComponentConfig::getBoolProperty(const QString& name, bool defaultValue) const
97{
98 return hasProperty(name) ? getProperty(name) == "true" : defaultValue;
99}
100
101int XmlComponentConfig::getIntProperty(const QString& name, int defaultValue) const
102{
103 return hasProperty(name) ? getProperty(name).toInt() : defaultValue;
104}
105
106int XmlComponentConfig::getDoubleProperty(const QString& name, double defaultValue) const
107{
108 return hasProperty(name) ? getProperty(name).toDouble() : defaultValue;
109}
110
111void XmlComponentConfig::setProperty(const QString& name, const QString& value)
112{
113 component_.setAttribute(name, value);
114 LOG_INFO("property " << name
115 << " of the component " << component_.tagName()
116 << " was set to : " << value
117 );
118}
119
120bool XmlComponentConfig::hasProperty(const QString& name) const
121{
122 return component_.hasAttribute(name);
123}
124
125QDomElement XmlComponentConfig::qDomElement() const
126{
127 return component_;
128}
129
130void XmlComponentConfig::localCopy(const QDomElement& elementToCopy)
131{
132 component_ = elementToCopy;
133}
134
135QString const XmlComponentConfig::getComponentName() const
136{
137 return component_.tagName();
138}
139
140QString const XmlComponentConfig::getComponentType() const
141{
142 return getProperty(kPropertyComponentType.c_str());
143}
144
145} // namespace pacpus
Note: See TracBrowser for help on using the repository browser.