#include "SonargraphXsdAbstractModule.h" #include "tinyxml.h" #include "logging.h" #include "SonargraphXsdCmakeJsonModule.h" #include "SonargraphXsdCppManualModule.h" #include "SonargraphXsdJavaModule.h" #include "SonargraphXsdRootPath.h" #include "SonargraphSoftwareSystem.h" #include "utilityString.h" #include "utilityXml.h" #include "utility.h" namespace Sonargraph { std::string XsdAbstractModule::getXsdTypeName() { return "xsdAbstractModule"; } std::shared_ptr XsdAbstractModule::create(const TiXmlElement* element, std::weak_ptr parent) { if (std::shared_ptr module = XsdCmakeJsonModule::create(element, parent)) { return module; } if (std::shared_ptr module = XsdCppManualModule::create(element, parent)) { return module; } if (std::shared_ptr module = XsdJavaModule::create(element, parent)) { return module; } return std::shared_ptr(); } std::wstring XsdAbstractModule::getName() const { return m_name; } std::wstring XsdAbstractModule::getDescription() const { return m_description; } std::vector XsdAbstractModule::getExcludeFilters() const { return m_excludeFilters; } std::vector XsdAbstractModule::getIncludeFilters() const { return m_includeFilters; } std::vector> XsdAbstractModule::getRootPaths() const { return m_rootPaths; } std::shared_ptr XsdAbstractModule::getSoftwareSystem() const { return m_parent.lock(); } std::vector XsdAbstractModule::getDerivedExcludeFilters() const { std::vector excludeFilters = getExcludeFilters(); if (std::shared_ptr parent = getSoftwareSystem()) { utility::append(excludeFilters, parent->getExcludeFilters()); } return excludeFilters; } std::vector XsdAbstractModule::getDerivedIncludeFilters() const { std::vector includeFilters = getIncludeFilters(); if (std::shared_ptr parent = getSoftwareSystem()) { utility::append(includeFilters, parent->getIncludeFilters()); } return includeFilters; } bool XsdAbstractModule::init(const TiXmlElement* element, std::weak_ptr parent) { m_parent = parent; if (element != nullptr) { { const char* value = element->Attribute("name"); if (value != nullptr) { m_name = utility::decodeFromUtf8(value); } else { LOG_WARNING("Unable to parse \"name\" attribute of Sonargraph " + getXsdTypeName() + "."); } } { const TiXmlElement* descriptionElement = element->FirstChildElement("description"); if (descriptionElement != nullptr) { const char* text = descriptionElement->GetText(); if (text != nullptr) { m_description = utility::decodeFromUtf8(text); } } } for (const TiXmlElement* excludeElement : utility::getXmlChildElementsWithName(element, "exclude")) { const char* text = excludeElement->GetText(); if (text != nullptr) { m_excludeFilters.push_back(FilePathFilter(utility::decodeFromUtf8(text))); } } for (const TiXmlElement* includeElement : utility::getXmlChildElementsWithName(element, "include")) { const char* text = includeElement->GetText(); if (text != nullptr) { m_includeFilters.push_back(FilePathFilter(utility::decodeFromUtf8(text))); } } for (const TiXmlElement* rootPathElement : utility::getXmlChildElementsWithName(element, "rootPath")) { if (std::shared_ptr rootPath = XsdRootPath::create(rootPathElement)) { m_rootPaths.push_back(rootPath); } else { LOG_ERROR("Unable to parse \"rootPath\" element of Sonargraph " + getXsdTypeName() + "."); return false; } } return true; } return false; } }