bool CComponentInstance::fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) { // Context CXmlParameterSerializingContext& parameterBuildContext = static_cast<CXmlParameterSerializingContext&>(serializingContext); const CComponentLibrary* pComponentLibrary = parameterBuildContext.getComponentLibrary(); std::string strComponentType = xmlElement.getAttributeString("Type"); _pComponentType = pComponentLibrary->getComponentType(strComponentType); if (!_pComponentType) { serializingContext.setError("Unable to create Component " + xmlElement.getPath() + ". ComponentType " + strComponentType + " not found!"); return false; } if (_pComponentType == getParent()) { serializingContext.setError("Recursive definition of " + _pComponentType->getName() + " due to " + xmlElement.getPath() + " referring to one of its own type."); return false; } return base::fromXml(xmlElement, serializingContext); }
// From IXmlSink bool CBitParameterType::fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) { // Pos _uiBitPos = xmlElement.getAttributeInteger("Pos"); // Size _uiBitSize = xmlElement.getAttributeInteger("Size"); // Validate bit pos and size still fit into parent type const CBitParameterBlockType* pBitParameterBlockType = static_cast<const CBitParameterBlockType*>(getParent()); uint32_t uiParentBlockBitSize = pBitParameterBlockType->getSize() * 8; if (_uiBitPos + _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 if (xmlElement.hasAttribute("Max")) { _uiMax = xmlElement.getAttributeInteger("Max"); if (_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; } } else { _uiMax = getMaxEncodableValue(); } // Base return base::fromXml(xmlElement, serializingContext); }
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; }
// 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 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); }
// 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 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 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 CSubsystem::fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) { // Context CXmlParameterSerializingContext& parameterBuildContext = static_cast<CXmlParameterSerializingContext&>(serializingContext); // Install temporary component library for further component creation parameterBuildContext.setComponentLibrary(_pComponentLibrary); CXmlElement childElement; // XML populate ComponentLibrary xmlElement.getChildElement("ComponentLibrary", childElement); if (!_pComponentLibrary->fromXml(childElement, serializingContext)) { return false; } // XML populate InstanceDefintion xmlElement.getChildElement("InstanceDefintion", childElement); if (!_pInstanceDefinition->fromXml(childElement, serializingContext)) { return false; } // Create components _pInstanceDefinition->createInstances(this); // Execute mapping to create subsystem mapping entities string strError; if (!mapSubsystemElements(strError)) { serializingContext.setError(strError); return false; } // Endianness _bBigEndian = xmlElement.getAttributeBoolean("Endianness", "Big"); return true; }
bool CXmlDocSource::populate(CXmlSerializingContext &serializingContext) { // Check that the doc has been created if (!_pDoc) { serializingContext.setError("Could not parse document "); return false; } // Validate if necessary if (_bValidateWithSchema) { if (!isInstanceDocumentValid()) { serializingContext.setError("Document is not valid"); return false; } } // Check Root element type if (getRootElementName() != _strRootElementType) { serializingContext.setError("Error: Wrong XML structure document "); serializingContext.appendLineToError("Root Element " + getRootElementName() + " mismatches expected type " + _strRootElementType); return false; } if (!_strNameAttributeName.empty()) { string strRootElementNameCheck = getRootElementAttributeString(_strNameAttributeName); // Check Root element name attribute (if any) if (!_strRootElementName.empty() && strRootElementNameCheck != _strRootElementName) { serializingContext.setError("Error: Wrong XML structure document "); serializingContext.appendLineToError( _strRootElementType + " element " + _strRootElementName + " mismatches expected " + _strRootElementType + " type " + strRootElementNameCheck); return false; } } return true; }
bool CFixedPointParameterType::fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) { // Size uint32_t uiSizeInBits = xmlElement.getAttributeInteger("Size"); // Q notation _uiIntegral = xmlElement.getAttributeInteger("Integral"); _uiFractional = xmlElement.getAttributeInteger("Fractional"); // Size vs. Q notation integrity check if (uiSizeInBits < getUtilSizeInBits()) { serializingContext.setError("Inconsistent Size vs. Q notation for " + getKind() + " " + xmlElement.getPath() + ": Summing (Integral + _uiFractional + 1) should not exceed given Size (" + xmlElement.getAttributeString("Size") + ")"); return false; } // Set the size setSize(uiSizeInBits / 8); return base::fromXml(xmlElement, serializingContext); }