1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
4 * Config_ValidatorReader.cpp
6 * Created on: Mar 20, 2015
10 #include <Config_ValidatorReader.h>
11 #include <Config_Keywords.h>
12 #include <Config_Common.h>
13 #include <Config_ValidatorMessage.h>
14 #include <Config_SelectionFilterMessage.h>
15 #include <Config_PropManager.h>
17 #include <Events_Loop.h>
18 #include <Events_Error.h>
19 #include <libxml/parser.h>
20 #include <libxml/tree.h>
28 Config_ValidatorReader::Config_ValidatorReader(const std::string& theXmlFileName)
29 : Config_XMLReader(theXmlFileName)
33 Config_ValidatorReader::~Config_ValidatorReader()
37 void Config_ValidatorReader::processNode(xmlNodePtr theNode)
39 if (isNode(theNode, NODE_VALIDATOR, NULL)) {
40 processValidator(theNode);
41 } else if (isNode(theNode, NODE_SELFILTER, NULL)) {
42 processSelectionFilter(theNode);
43 } else if (isNode(theNode, NODE_FEATURE, NULL)) {
44 storeAttribute(theNode, _ID);
45 } else if (isWidgetNode(theNode)) {
46 storeAttribute(theNode, _ID);
47 // Store widget name to restore it's id on validator/selector processing
48 myCurrentWidget = getNodeName(theNode);
50 //Process SOURCE nodes.
51 Config_XMLReader::processNode(theNode);
54 void Config_ValidatorReader::cleanup(xmlNodePtr theNode)
56 if (isNode(theNode, NODE_FEATURE, NULL)) {
57 cleanupAttribute(theNode, _ID);
58 } else if (isWidgetNode(theNode)) {
59 cleanupAttribute(NODE_XMLPARENT, _ID);
60 // Cleanup widget name when leave the widget node.
65 bool Config_ValidatorReader::processChildren(xmlNodePtr aNode)
70 void Config_ValidatorReader::processValidator(xmlNodePtr theNode)
72 Events_ID aValidatoEvent = Events_Loop::eventByName(EVENT_VALIDATOR_LOADED);
73 Events_Loop* aEvLoop = Events_Loop::loop();
74 std::shared_ptr<Config_ValidatorMessage>
75 aMessage(new Config_ValidatorMessage(aValidatoEvent, this));
76 std::string aValidatorId;
77 std::list<std::string> aParameters;
78 getParametersInfo(theNode, aValidatorId, aParameters);
79 aMessage->setValidatorId(aValidatorId);
80 aMessage->setValidatorParameters(aParameters);
81 std::string aFeatureId = restoreAttribute(NODE_FEATURE, _ID);
82 aMessage->setFeatureId(aFeatureId);
83 // parent is attribute (widget)
84 if (!myCurrentWidget.empty()) {
85 std::string aParentId = restoreAttribute(myCurrentWidget.c_str(), _ID);
86 aMessage->setAttributeId(aParentId);
88 aEvLoop->send(aMessage);
91 void Config_ValidatorReader::processSelectionFilter(xmlNodePtr theNode)
93 Events_ID aFilterEvent = Events_Loop::eventByName(EVENT_SELFILTER_LOADED);
94 Events_Loop* aEvLoop = Events_Loop::loop();
95 std::shared_ptr<Config_SelectionFilterMessage> aMessage(
96 new Config_SelectionFilterMessage(aFilterEvent, this));
97 std::string aSelectionFilterId;
98 std::list<std::string> aParameters;
99 getParametersInfo(theNode, aSelectionFilterId, aParameters);
100 aMessage->setSelectionFilterId(aSelectionFilterId);
101 aMessage->setFilterParameters(aParameters);
102 std::string aFeatureId = restoreAttribute(NODE_FEATURE, _ID);
103 aMessage->setFeatureId(aFeatureId);
104 // parent is attribute (widget)
105 if (!myCurrentWidget.empty()) {
106 std::string aParentId = restoreAttribute(myCurrentWidget.c_str(), _ID);
107 aMessage->setAttributeId(aParentId);
109 aEvLoop->send(aMessage);