diff options
author | David Wagner <david.wagner@intel.com> | 2014-12-09 15:26:06 +0100 |
---|---|---|
committer | David Wagner <david.wagner@intel.com> | 2015-01-22 11:53:51 +0100 |
commit | 8cb5d8815da673747b729d5e0a05a5cdc11a9081 (patch) | |
tree | 515424632d44e6f650a8eccab18c93c4730a05af /parameter/Element.cpp | |
parent | 1404cf730742a1adb0359bbc8c0ff79f216c4cb6 (diff) | |
download | external_parameter-framework-8cb5d8815da673747b729d5e0a05a5cdc11a9081.zip external_parameter-framework-8cb5d8815da673747b729d5e0a05a5cdc11a9081.tar.gz external_parameter-framework-8cb5d8815da673747b729d5e0a05a5cdc11a9081.tar.bz2 |
Allow more flexibility in overriding CElement::toXml
The toXml method has a default implementation that recursively calls toXml on
the children and set their "Name" attribute.
With this approach, the toplevel element's name isn't set unless its overrided
implementation explicitly does so.
A first approach for fixing that is to set the XmlElement's name and
recursively call toXml on children (without setting their name because it will
be done by their toXml method). However, the "CXmlElement" being created may or
may not be the object on which the toXml method is called, in which case the
name will be set on the wrong XmlElement.
Instead, in CElement::toXml, we set the XmlElement's name and call a new
virtual method, childrenToXml which only recursively call toXml on children.
This gives full flexibility to elements to choose how they want to serialize
themselves and how they want to serialize their children.
CConfigurableDomain::toXml is modified to take that change into account.
Change-Id: Id12a1023e91cb000e55c242c13643b1db7d46871
Signed-off-by: David Wagner <david.wagner@intel.com>
Diffstat (limited to 'parameter/Element.cpp')
-rwxr-xr-x | parameter/Element.cpp | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/parameter/Element.cpp b/parameter/Element.cpp index 2c8393d..4ccf149 100755 --- a/parameter/Element.cpp +++ b/parameter/Element.cpp @@ -292,8 +292,8 @@ bool CElement::fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& se return true; } -// From IXmlSource -void CElement::toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const +void CElement::childrenToXml(CXmlElement& xmlElement, + CXmlSerializingContext& serializingContext) const { // Browse children and propagate uint32_t uiNbChildren = getNbChildren(); @@ -308,15 +308,17 @@ void CElement::toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializin xmlElement.createChild(xmlChildElement, pChild->getKind()); - // Set attributes - pChild->setXmlNameAttribute(xmlChildElement); - - // Propagate pChild->toXml(xmlChildElement, serializingContext); } } +void CElement::toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const +{ + setXmlNameAttribute(xmlElement); + childrenToXml(xmlElement, serializingContext); +} + void CElement::setXmlNameAttribute(CXmlElement& xmlElement) const { // By default, set Name attribute if any |