void CElement::setXmlNameAttribute(CXmlElement &xmlElement) const { // By default, set Name attribute if any string strName = getName(); if (!strName.empty()) { xmlElement.setNameAttribute(strName); } }
void CConfigurableDomain::composeSettings(CXmlElement &xmlElement, CXmlDomainExportContext &context) const { if (!context.withSettings()) { return; } // Create Settings element CXmlElement xmlSettingsElement; xmlElement.createChild(xmlSettingsElement, "Settings"); // Serialize out all configurations settings size_t uiNbConfigurations = getNbChildren(); size_t uiChildConfiguration; for (uiChildConfiguration = 0; uiChildConfiguration < uiNbConfigurations; uiChildConfiguration++) { const CDomainConfiguration *pDomainConfiguration = static_cast<const CDomainConfiguration *>(getChild(uiChildConfiguration)); // Create child xml element for that configuration CXmlElement xmlConfigurationSettingsElement; xmlSettingsElement.createChild(xmlConfigurationSettingsElement, pDomainConfiguration->getXmlElementName()); // Set its name attribute xmlConfigurationSettingsElement.setNameAttribute(pDomainConfiguration->getName()); // Serialize out configuration settings pDomainConfiguration->composeSettings(xmlConfigurationSettingsElement, context); } }
// XML configuration settings parsing bool CConfigurableElement::serializeXmlSettings(CXmlElement& xmlConfigurationSettingsElementContent, CConfigurationAccessContext& configurationAccessContext) const { uint32_t uiIndex; uint32_t uiNbChildren = getNbChildren(); if (!configurationAccessContext.serializeOut()) { // Just do basic checks and propagate to children CXmlElement::CChildIterator it(xmlConfigurationSettingsElementContent); CXmlElement xmlChildConfigurableElementSettingsElement; // Propagate to children for (uiIndex = 0; uiIndex < uiNbChildren; uiIndex++) { // Get child const CConfigurableElement* pChildConfigurableElement = static_cast<const CConfigurableElement*>(getChild(uiIndex)); if (!it.next(xmlChildConfigurableElementSettingsElement)) { // Structure error configurationAccessContext.setError("Configuration settings parsing: Settings don't conform to structure of configurable element " + getName()); return false; } // Check element type matches in type if (xmlChildConfigurableElementSettingsElement.getType() != pChildConfigurableElement->getKind()) { // Type error configurationAccessContext.setError("Configuration settings parsing: Settings for configurable element " + pChildConfigurableElement->getName() + " does not match expected type: " + xmlChildConfigurableElementSettingsElement.getType() + " instead of " + pChildConfigurableElement->getKind()); return false; } // Check element type matches in name if (xmlChildConfigurableElementSettingsElement.getNameAttribute() != pChildConfigurableElement->getName()) { // Name error configurationAccessContext.setError("Configuration settings parsing: Under configurable elememnt " + getName() + ", expected element name " + pChildConfigurableElement->getName() + " but found " + xmlChildConfigurableElementSettingsElement.getNameAttribute() + " instead"); return false; } // Parse child configurable element's settings if (!pChildConfigurableElement->serializeXmlSettings(xmlChildConfigurableElementSettingsElement, configurationAccessContext)) { return false; } } // There should remain no configurable element to parse if (it.next(xmlChildConfigurableElementSettingsElement)) { // Structure error configurationAccessContext.setError("Configuration settings parsing: Settings don't conform to structure of configurable element " + getName()); return false; } } else { // Propagate to children for (uiIndex = 0; uiIndex < uiNbChildren; uiIndex++) { const CConfigurableElement* pChildConfigurableElement = static_cast<const CConfigurableElement*>(getChild(uiIndex)); // Create corresponding child element CXmlElement xmlChildConfigurableElementSettingsElement; xmlConfigurationSettingsElementContent.createChild(xmlChildConfigurableElementSettingsElement, pChildConfigurableElement->getKind()); // Handle element name attribute xmlChildConfigurableElementSettingsElement.setNameAttribute(pChildConfigurableElement->getName()); // Propagate pChildConfigurableElement->serializeXmlSettings(xmlChildConfigurableElementSettingsElement, configurationAccessContext); } } // Done return true; }