// From IXmlSink bool CConfigurableDomain::fromXml(const CXmlElement &xmlElement, CXmlSerializingContext &serializingContext) { // Context CXmlDomainImportContext &xmlDomainImportContext = static_cast<CXmlDomainImportContext &>(serializingContext); // Sequence awareness (optional) xmlElement.getAttribute("SequenceAware", _bSequenceAware); std::string name; xmlElement.getAttribute("Name", name); setName(name); // Local parsing. Do not dig if (!parseDomainConfigurations(xmlElement, xmlDomainImportContext) || !parseConfigurableElements(xmlElement, xmlDomainImportContext) || !parseSettings(xmlElement, xmlDomainImportContext)) { return false; } // All provided configurations are parsed // Attempt validation on areas of non provided configurations for all configurable elements if // required if (xmlDomainImportContext.autoValidationRequired()) { autoValidateAll(); } return true; }
// From IXmlSink bool CSelectionCriterionRule::fromXml(const CXmlElement &xmlElement, CXmlSerializingContext &serializingContext) { // Retrieve actual context CXmlDomainImportContext &xmlDomainImportContext = static_cast<CXmlDomainImportContext &>(serializingContext); // Get selection criterion string strSelectionCriterion; xmlElement.getAttribute("SelectionCriterion", strSelectionCriterion); _pSelectionCriterion = xmlDomainImportContext.getSelectionCriteriaDefinition()->getSelectionCriterion( strSelectionCriterion); // Check existence if (!_pSelectionCriterion) { xmlDomainImportContext.setError("Couldn't find selection criterion " + strSelectionCriterion + " in " + getKind() + " " + xmlElement.getPath()); return false; } // Get MatchesWhen string strMatchesWhen; xmlElement.getAttribute("MatchesWhen", strMatchesWhen); string strError; if (!setMatchesWhen(strMatchesWhen, strError)) { xmlDomainImportContext.setError("Wrong MatchesWhen attribute " + strMatchesWhen + " in " + getKind() + " " + xmlElement.getPath() + ": " + strError); return false; } // Get Value string strValue; xmlElement.getAttribute("Value", strValue); if (!_pSelectionCriterion->getCriterionType()->getNumericalValue(strValue, _iMatchValue)) { xmlDomainImportContext.setError("Wrong Value attribute value " + strValue + " in " + getKind() + " " + xmlElement.getPath()); return false; } // Done return true; }
// From IXmlSink bool CParameterFrameworkConfiguration::fromXml(const CXmlElement &xmlElement, CXmlSerializingContext &serializingContext) { // System class name xmlElement.getAttribute("SystemClassName", _strSystemClassName); // Tuning allowed xmlElement.getAttribute("TuningAllowed", _bTuningAllowed); // Server port xmlElement.getAttribute("ServerPort", _uiServerPort); // Base return base::fromXml(xmlElement, serializingContext); }
// From IXmlSink bool CLinearParameterAdaptation::fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) { // Get SlopeNumerator xmlElement.getAttribute("SlopeNumerator", _dSlopeNumerator); // Get SlopeDenominator if (xmlElement.getAttribute("SlopeDenominator", _dSlopeDenominator) && (_dSlopeDenominator == 0)) { // Avoid by 0 division errors serializingContext.setError("SlopeDenominator attribute can't be 0 on element" + xmlElement.getPath()); return false; } // Base return base::fromXml(xmlElement, serializingContext); }
// From IXmlSink bool CBitParameterType::fromXml(const CXmlElement &xmlElement, CXmlSerializingContext &serializingContext) { // Pos xmlElement.getAttribute("Pos", _bitPos); // Size xmlElement.getAttribute("Size", _uiBitSize); // Validate bit pos and size still fit into parent type const CBitParameterBlockType *pBitParameterBlockType = static_cast<const CBitParameterBlockType *>(getParent()); size_t uiParentBlockBitSize = pBitParameterBlockType->getSize() * 8; if (_bitPos + _uiBitSize > uiParentBlockBitSize) { // Range exceeded std::ostringstream strStream; strStream << "Pos and Size attributes inconsistent with maximum container element size (" << uiParentBlockBitSize << " bits) for " + getKind(); serializingContext.setError(strStream.str()); return false; } // Max _uiMax = getMaxEncodableValue(); if (xmlElement.getAttribute("Max", _uiMax) && (_uiMax > getMaxEncodableValue())) { // Max value exceeded std::ostringstream strStream; strStream << "Max attribute inconsistent with maximum encodable size (" << getMaxEncodableValue() << ") for " + getKind(); serializingContext.setError(strStream.str()); return false; } // Base return base::fromXml(xmlElement, serializingContext); }
// From IXmlSink bool CStringParameterType::fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) { // MaxLength xmlElement.getAttribute("MaxLength", _uiMaxLength); // Base return base::fromXml(xmlElement, serializingContext); }
// From IXmlSink bool CParameterAdaptation::fromXml(const CXmlElement &xmlElement, CXmlSerializingContext &serializingContext) { xmlElement.getAttribute("Offset", _iOffset); // Base return base::fromXml(xmlElement, serializingContext); }
bool CLogarithmicParameterAdaptation::fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) { if (xmlElement.getAttribute("LogarithmBase", _dLogarithmBase) && (_dLogarithmBase <= 0 || _dLogarithmBase == 1)) { // Avoid negative and 1 values serializingContext.setError("LogarithmBase attribute cannot be negative or 1 on element" + xmlElement.getPath()); return false; } xmlElement.getAttribute("FloorValue", _dFloorValue); // Base return base::fromXml(xmlElement, serializingContext); }
// Parse configurable elements bool CConfigurableDomain::parseConfigurableElements(const CXmlElement &xmlElement, CXmlDomainImportContext &serializingContext) { CSystemClass &systemClass = serializingContext.getSystemClass(); // Get ConfigurableElements element CXmlElement xmlConfigurableElementsElement; xmlElement.getChildElement("ConfigurableElements", xmlConfigurableElementsElement); // Parse it and associate found configurable elements to it CXmlElement::CChildIterator it(xmlConfigurableElementsElement); CXmlElement xmlConfigurableElementElement; while (it.next(xmlConfigurableElementElement)) { // Locate configurable element string strConfigurableElementPath; xmlConfigurableElementElement.getAttribute("Path", strConfigurableElementPath); CPathNavigator pathNavigator(strConfigurableElementPath); string strError; // Is there an element and does it match system class name? if (!pathNavigator.navigateThrough(systemClass.getName(), strError)) { serializingContext.setError( "Could not find configurable element of path " + strConfigurableElementPath + " from ConfigurableDomain description " + getName() + " (" + strError + ")"); return false; } // Browse system class for configurable element CConfigurableElement *pConfigurableElement = static_cast<CConfigurableElement *>(systemClass.findDescendant(pathNavigator)); if (!pConfigurableElement) { serializingContext.setError("Could not find configurable element of path " + strConfigurableElementPath + " from ConfigurableDomain description " + getName()); return false; } // Add found element to domain core::Results infos; if (!addConfigurableElement(pConfigurableElement, NULL, infos)) { strError = utility::asString(infos); serializingContext.setError(strError); return false; } } return true; }
// From IXmlSink bool CBitParameterBlockType::fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) { // Size xmlElement.getAttribute("Size", _uiSize); _uiSize /= 8; // Base return base::fromXml(xmlElement, serializingContext); }
bool CTypeElement::fromXml(const CXmlElement &xmlElement, CXmlSerializingContext &serializingContext) { // Array Length attribute xmlElement.getAttribute("ArrayLength", _arrayLength); // Manage mapping attribute std::string rawMapping; if (xmlElement.getAttribute("Mapping", rawMapping) && !rawMapping.empty()) { std::string error; if (!getMappingData()->init(rawMapping, error)) { serializingContext.setError("Invalid Mapping data from XML element '" + xmlElement.getPath() + "': " + error); return false; } } return base::fromXml(xmlElement, serializingContext); }
// From IXmlSink bool CFrameworkConfigurationLocation::fromXml(const CXmlElement &xmlElement, CXmlSerializingContext &serializingContext) { xmlElement.getAttribute("Path", _configurationUri); if (_configurationUri.empty()) { serializingContext.setError("Empty Path attribute in element " + xmlElement.getPath()); return false; } return true; }
bool CEnumParameterType::fromXml(const CXmlElement &xmlElement, CXmlSerializingContext &serializingContext) { // Size in bits size_t sizeInBits = 0; if (not xmlElement.getAttribute("Size", sizeInBits)) { return false; } // Size setSize(sizeInBits / 8); // Base return base::fromXml(xmlElement, serializingContext); }
// From IXmlSink bool CElement::fromXml(const CXmlElement &xmlElement, CXmlSerializingContext &serializingContext) { xmlElement.getAttribute(gDescriptionPropertyName, _strDescription); // Propagate through children CXmlElement::CChildIterator childIterator(xmlElement); CXmlElement childElement; while (childIterator.next(childElement)) { CElement *pChild; if (!childrenAreDynamic()) { pChild = findChildOfKind(childElement.getType()); if (!pChild) { serializingContext.setError("Unable to handle XML element: " + childElement.getPath()); return false; } } else { // Child needs creation pChild = createChild(childElement, serializingContext); if (!pChild) { return false; } } // Dig if (!pChild->fromXml(childElement, serializingContext)) { return false; } } return true; }
bool CComponentType::fromXml(const CXmlElement &xmlElement, CXmlSerializingContext &serializingContext) { // Context CXmlParameterSerializingContext ¶meterBuildContext = static_cast<CXmlParameterSerializingContext &>(serializingContext); const CComponentLibrary *pComponentLibrary = parameterBuildContext.getComponentLibrary(); // Populate children if (!base::fromXml(xmlElement, serializingContext)) { return false; } // Check for Extends attribute (extensions will be populated after and not before) if (xmlElement.hasAttribute("Extends")) { std::string strExtendsType; xmlElement.getAttribute("Extends", strExtendsType); _pExtendsComponentType = pComponentLibrary->getComponentType(strExtendsType); if (!_pExtendsComponentType) { serializingContext.setError("ComponentType " + strExtendsType + " referred to by " + xmlElement.getPath() + " not found!"); return false; } if (_pExtendsComponentType == this) { serializingContext.setError("Recursive ComponentType definition of " + xmlElement.getPath()); return false; } } return true; }
// XML configuration settings parsing bool CDomainConfiguration::parseSettings(CXmlElement &xmlConfigurationSettingsElement, CXmlDomainImportContext &context) { // Parse configurable element's configuration settings CXmlElement::CChildIterator it(xmlConfigurationSettingsElement); CXmlElement xmlConfigurableElementSettingsElement; auto insertLocation = begin(mAreaConfigurationList); while (it.next(xmlConfigurableElementSettingsElement)) { // Retrieve area configuration string configurableElementPath; xmlConfigurableElementSettingsElement.getAttribute("Path", configurableElementPath); auto areaConfiguration = findAreaConfigurationByPath(configurableElementPath); if (areaConfiguration == end(mAreaConfigurationList)) { context.setError("Configurable Element " + configurableElementPath + " referred to by Configuration " + getPath() + " not associated to Domain"); return false; } // Parse if (!importOneConfigurableElementSettings(areaConfiguration->get(), xmlConfigurableElementSettingsElement, context)) { return false; } // Take into account the new configuration order by moving the configuration associated to // the element to the n-th position of the configuration list. // It will result in prepending to the configuration list wit the configuration of all // elements found in XML, keeping the order of the processing of the XML file. mAreaConfigurationList.splice(insertLocation, mAreaConfigurationList, areaConfiguration); // areaConfiguration is still valid, but now refer to the reorderer list insertLocation = std::next(areaConfiguration); } return true; }
// From IXmlSink bool CXmlFileIncluderElement::fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) { // Context CXmlElementSerializingContext& elementSerializingContext = static_cast<CXmlElementSerializingContext&>(serializingContext); // Parse included document std::string strPath; xmlElement.getAttribute("Path", strPath); // Relative path? if (strPath[0] != '/') { strPath = elementSerializingContext.getXmlFolder() + "/" + strPath; } // Instantiate parser std::string strIncludedElementType = getIncludedElementType(); { // Open a log section titled with loading file path CAutoLog autolog(this, "Loading " + strPath); // Use a doc source that load data from a file std::string strPathToXsdFile = elementSerializingContext.getXmlSchemaPathFolder() + "/" + strIncludedElementType + ".xsd"; _xmlDoc *doc = CXmlDocSource::mkXmlDoc(strPath, true, true, elementSerializingContext); CXmlDocSource docSource(doc, _bValidateSchemasOnStart, strPathToXsdFile, strIncludedElementType); if (!docSource.isParsable()) { elementSerializingContext.setError("Could not parse document \"" + strPath + "\""); return false; } // Get top level element CXmlElement childElement; docSource.getRootElement(childElement); // Create child element CElement* pChild = elementSerializingContext.getElementLibrary()->createElement(childElement); if (pChild) { // Store created child! getParent()->addChild(pChild); } else { elementSerializingContext.setError("Unable to create XML element " + childElement.getPath()); return false; } // Use a doc sink that instantiate the structure from the doc source CXmlMemoryDocSink memorySink(pChild); if (!memorySink.process(docSource, elementSerializingContext)) { return false; } } // Detach from parent getParent()->removeChild(this); // Self destroy delete this; return true; }