diff options
Diffstat (limited to 'parameter')
-rw-r--r-- | parameter/ComponentLibrary.cpp | 32 | ||||
-rw-r--r-- | parameter/ComponentLibrary.h | 4 | ||||
-rwxr-xr-x | parameter/Element.cpp | 33 | ||||
-rw-r--r-- | parameter/Element.h | 12 |
4 files changed, 73 insertions, 8 deletions
diff --git a/parameter/ComponentLibrary.cpp b/parameter/ComponentLibrary.cpp index f133213..f3576e8 100644 --- a/parameter/ComponentLibrary.cpp +++ b/parameter/ComponentLibrary.cpp @@ -45,3 +45,35 @@ const CComponentType* CComponentLibrary::getComponentType(const string& strName) return static_cast<const CComponentType*>(findChild(strName)); } +bool CComponentLibrary::fromXml(const CXmlElement& xmlElement, + CXmlSerializingContext& serializingContext) +{ + CXmlElement childElement; + + CXmlElement::CChildIterator it(xmlElement); + + // XML populate all component libraries + while (it.next(childElement)) { + + // Filter component library/type set elements + if (childElement.getType() == "ComponentLibrary" || + childElement.getType() == "ComponentTypeSet") { + + if (!fromXml(childElement, serializingContext)) { + + return false; + } + } else { + // Regular child creation and populating + CElement* pChild = createChild(childElement, serializingContext); + + if (!pChild || !pChild->fromXml(childElement, serializingContext)) { + + return false; + } + } + } + + return true; +} + diff --git a/parameter/ComponentLibrary.h b/parameter/ComponentLibrary.h index 443d634..835373b 100644 --- a/parameter/ComponentLibrary.h +++ b/parameter/ComponentLibrary.h @@ -38,6 +38,10 @@ public: const CComponentType* getComponentType(const string& strName) const; virtual string getKind() const; + + // From IXmlSink + virtual bool fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext); + private: virtual bool childrenAreDynamic() const; }; diff --git a/parameter/Element.cpp b/parameter/Element.cpp index b68205b..43f1c57 100755 --- a/parameter/Element.cpp +++ b/parameter/Element.cpp @@ -263,15 +263,9 @@ bool CElement::fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& se } else { // Child needs creation - pChild = elementSerializingContext.getElementLibrary()->createElement(childElement); + pChild = createChild(childElement, serializingContext); - if (pChild) { - - // Store created child! - addChild(pChild); - } else { - - elementSerializingContext.setError("Unable to create XML element " + childElement.getPath()); + if (!pChild) { return false; } @@ -403,6 +397,29 @@ CElement* CElement::getLastChild() return _childArray[uiNbChildren - 1]; } +CElement* CElement::createChild(const CXmlElement& childElement, + CXmlSerializingContext& serializingContext) +{ + // Context + CXmlElementSerializingContext& elementSerializingContext = + static_cast<CXmlElementSerializingContext&>(serializingContext); + + // Child needs creation + CElement* pChild = elementSerializingContext.getElementLibrary()->createElement(childElement); + + if (!pChild) { + + elementSerializingContext.setError( + "Unable to create XML element " + childElement.getPath()); + + return NULL; + } + // Store created child! + addChild(pChild); + + return pChild; +} + bool CElement::removeChild(CElement* pChild) { ChildArrayIterator it; diff --git a/parameter/Element.h b/parameter/Element.h index b381898..01e4254 100644 --- a/parameter/Element.h +++ b/parameter/Element.h @@ -120,6 +120,18 @@ protected: CElement* findAscendantOfKind(const string& strKind); CElement* getRoot(); const CElement* getRoot() const; + + /** + * Creates a child CElement from a child XML Element + * + * @param[in] childElement the XML element to create CElement from + * @param[in] elementSerializingContext the serializing context + * + * @return child a pointer on the CElement object that has been added to the tree + */ + CElement* createChild(const CXmlElement& childElement, + CXmlSerializingContext& elementSerializingContext); + private: // Logging (done by root) virtual void doLog(bool bIsWarning, const string& strLog) const; |