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);
}
Ejemplo n.º 2
0
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;
}
// 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;
}
// 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;
}
Ejemplo n.º 5
0
/**
* @ingroup XmlParser
* @brief 애트리뷰트에 해당하는 값을 검색한다.
* @param pszName Element 이름
* @param pszAttrName 애트리뷰트 이름
* @param iIndex		Element 인덱스. 0 을 입력하면 첫번째 검색된 하위 Element 를 리턴하고 1 을 입력하면 두번째 검색된 하위 Element 를 리턴한다.
* @returns 성공하면 애트리뷰트의 값을 리턴하고 그렇지 않으면 NULL 을 리턴한다.
*/
const char * CXmlSearch::SelectAttribute(const char * pszName, const char * pszAttrName, const int iIndex)
{
	CXmlElement * pclsElement = SelectElement(pszName, iIndex);
	if (pclsElement)
	{
		return pclsElement->SelectAttribute(pszAttrName);
	}

	return NULL;
}
Ejemplo n.º 6
0
/**
* @ingroup XmlParser
* @brief 애트리뷰트에 해당하는 값을 검색하여 int 변수에 저장한다.
* @param pszName Element 이름
* @param pszAttrName 애트리뷰트 이름
* @param iValue		애트리뷰트 값
* @param iIndex		Element 인덱스. 0 을 입력하면 첫번째 검색된 하위 Element 를 리턴하고 1 을 입력하면 두번째 검색된 하위 Element 를 리턴한다.
* @returns 성공하면 true 를 리턴하고 실패하면 false 를 리턴한다.
*/
bool CXmlSearch::SelectAttribute(const char * pszName, const char * pszAttrName, int & iValue, const int iIndex)
{
	CXmlElement * pclsElement = SelectElement(pszName, iIndex);
	if (pclsElement)
	{
		return pclsElement->SelectAttribute(pszAttrName, iValue);
	}

	return false;
}
Ejemplo n.º 7
0
CXmlElement* CXmlElement::SetElement(const TCHAR* name, const TCHAR* value, bool create_if_not_exist /* = false */)
{
	CXmlElement* element = GetElement(name, create_if_not_exist);
	if (element != NULL)
	{
		element->SetData(value);
	}

	return element;
}
// Serialize one configuration for one configurable element
bool CDomainConfiguration::importOneConfigurableElementSettings(
    CAreaConfiguration *areaConfiguration, CXmlElement &xmlConfigurableElementSettingsElement,
    CXmlDomainImportContext &context)
{
    const CConfigurableElement *destination = areaConfiguration->getConfigurableElement();

    // Check structure
    if (xmlConfigurableElementSettingsElement.getNbChildElements() != 1) {

        // Structure error
        context.setError("Struture error encountered while parsing settings of " +
                         destination->getKind() + " " + destination->getName() +
                         " in Configuration " + getPath());

        return false;
    }

    // Element content
    CXmlElement xmlConfigurableElementSettingsElementContent;
    // Check name and kind
    if (!xmlConfigurableElementSettingsElement.getChildElement(
            destination->getXmlElementName(), destination->getName(),
            xmlConfigurableElementSettingsElementContent)) {

        // "Component" tag has been renamed to "ParameterBlock", but retro-compatibility shall
        // be ensured.
        //
        // So checking if this case occurs, i.e. element name is "ParameterBlock"
        // but found xml setting name is "Component".
        bool compatibilityCase =
            (destination->getXmlElementName() == "ParameterBlock") &&
            xmlConfigurableElementSettingsElement.getChildElement(
                "Component", destination->getName(), xmlConfigurableElementSettingsElementContent);

        // Error if the compatibility case does not occur.
        if (!compatibilityCase) {
            context.setError("Couldn't find settings for " + destination->getXmlElementName() +
                             " " + destination->getName() + " for Configuration " + getPath());

            return false;
        }
    }

    // Create configuration access context
    string error;
    CConfigurationAccessContext configurationAccessContext(error, false);

    // Have domain configuration parse settings for configurable element
    bool success = areaConfiguration->serializeXmlSettings(
        xmlConfigurableElementSettingsElementContent, configurationAccessContext);

    context.appendToError(error);
    return success;
}
Ejemplo n.º 9
0
/**
* @ingroup XmlParser
* @brief 모든 하위 Element 를 검색하여서 bool 내용을 가져온다.
* @param pszName Element 이름
* @param pszChildName 하위 element 이름
* @param bData		하위 Element 의 값을 저장하는 변수
* @param iIndex		하위 Element 인덱스. 0 을 입력하면 첫번째 검색된 하위 Element 를 리턴하고 1 을 입력하면 두번째 검색된 하위 Element 를 리턴한다.
* @returns 성공하면 true 를 리턴하고 실패하면 false 를 리턴한다.
*/
bool CXmlSearch::SelectElementData(const char * pszName, const char * pszChildName, bool & bData, const int iIndex)
{
	CXmlElement * pclsElement = SelectElement(pszName, pszChildName, iIndex);
	if (pclsElement)
	{
		bData = GetBoolean(pclsElement->GetData());
		return true;
	}

	return false;
}
Ejemplo n.º 10
0
/**
* @ingroup XmlParser
* @brief 모든 하위 Element 를 검색하여서 내용을 저장한다.
* @param pszName		Element 이름
* @param pszChildName 하위 Element 이름
* @param strData		Elemnet 의 내용을 저장할 변수
* @param iIndex		Element 인덱스. 0 을 입력하면 첫번째 검색된 하위 Element 를 리턴하고 1 을 입력하면 두번째 검색된 하위 Element 를 리턴한다.
* @returns 성공하면 true 를 리턴하고 실패하면 false 를 리턴한다.
*/
bool CXmlSearch::SelectElementData(const char * pszName, const char * pszChildName, std::string & strData, const int iIndex)
{
	CXmlElement * pclsElement = SelectElement(pszName, pszChildName, iIndex);
	if (pclsElement)
	{
		strData = pclsElement->GetData();
		return true;
	}

	return false;
}
Ejemplo n.º 11
0
/**
* @ingroup XmlParser
* @brief 모든 하위 Element 를 검색하여서 정수 내용을 가져온다.
* @param pszName Element 이름
* @param iData	Element 의 값을 저장하는 변수
* @param iIndex	Element 인덱스. 0 을 입력하면 첫번째 검색된 하위 Element 를 리턴하고 1 을 입력하면 두번째 검색된 하위 Element 를 리턴한다.
* @returns 성공하면 true 를 리턴하고 실패하면 false 를 리턴한다.
*/
bool CXmlSearch::SelectElementData(const char * pszName, int & iData, const int iIndex)
{
	CXmlElement * pclsElement = SelectElement(pszName, iIndex);
	if (pclsElement)
	{
		iData = atoi(pclsElement->GetData());

		return true;
	}

	return false;
}
Ejemplo n.º 12
0
bool CXmlElement::getChildElement(const string& strType, const string& strNameAttribute, CXmlElement& childElement) const
{
    CChildIterator childIterator(*this);

    while (childIterator.next(childElement)) {

        if ((childElement.getType() == strType) && (childElement.getNameAttribute() == strNameAttribute)) {

            return true;
        }
    }
    return false;
}
// 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;
}
Ejemplo n.º 14
0
// 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);
}
// From IXmlSink
bool CParameterAdaptation::fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext)
{
    // Get offset
    if (xmlElement.hasAttribute("Offset")) {

        _iOffset = xmlElement.getAttributeSignedInteger("Offset");

    } else {
        // Default
        _iOffset = 0;
    }

    // Base
    return base::fromXml(xmlElement, serializingContext);
}
// 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 IXmlSource
void CConfigurableDomains::toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const
{
    // Set attribute
    xmlElement.setAttributeString("SystemClassName", getName());

    base::childrenToXml(xmlElement, serializingContext);
}
// From IXmlSource
void CEnumParameterType::toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const
{
    // Size
    xmlElement.setAttributeString("Size", toString(getSize() * 8));

    base::toXml(xmlElement, serializingContext);
}
// From IXmlSource
void CStringParameterType::toXml(CXmlElement &xmlElement, CXmlSerializingContext &serializingContext) const
{
    // MaxLength
    xmlElement.setAttributeInteger("MaxLength", _uiMaxLength);

    base::toXml(xmlElement, serializingContext);
}
Ejemplo n.º 20
0
void CElement::setXmlDescriptionAttribute(CXmlElement &xmlElement) const
{
    const string &description = getDescription();
    if (!description.empty()) {
        xmlElement.setAttribute(gDescriptionPropertyName, description);
    }
}
// From IXmlSource
void CBitParameterBlockType::toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const
{
    // Size
    xmlElement.setAttribute("Size", _uiSize * 8);

    base::toXml(xmlElement, serializingContext);
}
Ejemplo n.º 22
0
// From IXmlSink
bool CCompoundRule::fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext)
{
    // Get type
    _bTypeAll = xmlElement.getAttributeBoolean("Type", _apcTypes[true]);

    // Base
    return base::fromXml(xmlElement, serializingContext);
}
Ejemplo n.º 23
0
// From IXmlSource
void CCompoundRule::toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const
{
    // Set type
    xmlElement.setAttributeString("Type", _apcTypes[_bTypeAll]);

    // Base
    base::toXml(xmlElement, serializingContext);
}
// From IXmlSink
bool CStringParameterType::fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext)
{
    // MaxLength
    _uiMaxLength = xmlElement.getAttributeInteger("MaxLength");

    // Base
    return base::fromXml(xmlElement, serializingContext);
}
// Parse settings
bool CConfigurableDomain::parseSettings(const CXmlElement &xmlElement,
                                        CXmlDomainImportContext &serializingContext)
{
    // Check we actually need to parse configuration settings
    if (!serializingContext.withSettings()) {

        // No parsing required
        return true;
    }

    // Get Settings element
    CXmlElement xmlSettingsElement;
    if (!xmlElement.getChildElement("Settings", xmlSettingsElement)) {

        // No settings, bail out successfully
        return true;
    }

    // Parse configuration settings
    CXmlElement::CChildIterator it(xmlSettingsElement);

    CXmlElement xmlConfigurationSettingsElement;

    while (it.next(xmlConfigurationSettingsElement)) {
        // Get domain configuration
        CDomainConfiguration *pDomainConfiguration = static_cast<CDomainConfiguration *>(
            findChild(xmlConfigurationSettingsElement.getNameAttribute()));

        if (!pDomainConfiguration) {

            serializingContext.setError("Could not find domain configuration referred to by"
                                        " configurable domain \"" +
                                        getName() + "\".");

            return false;
        }
        // Have domain configuration parse settings for all configurable elements
        if (!pDomainConfiguration->parseSettings(xmlConfigurationSettingsElement,
                                                 serializingContext)) {

            return false;
        }
    }

    return true;
}
// From IXmlSink
bool CParameterAdaptation::fromXml(const CXmlElement &xmlElement,
                                   CXmlSerializingContext &serializingContext)
{
    xmlElement.getAttribute("Offset", _iOffset);

    // 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);
}
Ejemplo n.º 28
0
// Child creation
void CXmlElement::createChild(CXmlElement &childElement, const string &strType)
{
#ifdef LIBXML_TREE_ENABLED
    xmlNodePtr pChildNode = xmlNewChild(_pXmlElement, nullptr, BAD_CAST strType.c_str(), nullptr);

    childElement.setXmlElement(pChildNode);
#endif
}
// From IXmlSource
void CSelectionCriterionRule::toXml(CXmlElement &xmlElement, CXmlSerializingContext & /*ctx*/) const
{
    assert(_pSelectionCriterion);

    // Set selection criterion
    xmlElement.setAttribute("SelectionCriterion", _pSelectionCriterion->getName());

    // Set MatchesWhen
    xmlElement.setAttribute("MatchesWhen", _astMatchesWhen[_eMatchesWhen].pcMatchesWhen);

    // Set Value
    string strValue;

    _pSelectionCriterion->getCriterionType()->getLiteralValue(_iMatchValue, strValue);

    xmlElement.setAttribute("Value", strValue);
}
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);
}