// 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;
}
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);
}
bool CComponentType::fromXml(const CXmlElement &xmlElement,
                             CXmlSerializingContext &serializingContext)
{
    // Context
    CXmlParameterSerializingContext &parameterBuildContext =
        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);
}
Esempio n. 6
0
string CXmlElement::getPath() const
{
    string strPathElement = "/" + getType();

    if (hasAttribute("Name")) {

        strPathElement += "[@Name=" + getNameAttribute() + "]";
    }

    CXmlElement parentElement;

    if (getParentElement(parentElement)) {

        // Done
        return parentElement.getPath() + strPathElement;
    }
    return strPathElement;
}
Esempio n. 7
0
// 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;
}
Esempio n. 8
0
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 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);
}
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);
}
// 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;
}