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 <libxml/parser.h>
19 #include <libxml/tree.h>
27 Config_ValidatorReader::Config_ValidatorReader(const std::string& theXmlFileName)
28 : Config_XMLReader(theXmlFileName)
32 Config_ValidatorReader::~Config_ValidatorReader()
36 void Config_ValidatorReader::processNode(xmlNodePtr theNode)
38 if (isNode(theNode, NODE_VALIDATOR, NULL)) {
39 processValidator(theNode);
40 } else if (isNode(theNode, NODE_SELFILTER, NULL)) {
41 processSelectionFilter(theNode);
42 } else if (isNode(theNode, NODE_FEATURE, NULL)) {
43 storeAttribute(theNode, _ID);
44 } else if (isWidgetNode(theNode)) {
45 storeAttribute(theNode, _ID);
46 // Store widget name to restore it's id on validator/selector processing
47 myCurrentWidget = getNodeName(theNode);
49 //Process SOURCE nodes.
50 Config_XMLReader::processNode(theNode);
53 void Config_ValidatorReader::cleanup(xmlNodePtr theNode)
55 if (isNode(theNode, NODE_FEATURE, NULL)) {
56 cleanupAttribute(theNode, _ID);
57 } else if (isWidgetNode(theNode)) {
58 cleanupAttribute(NODE_XMLPARENT, _ID);
59 // Cleanup widget name when leave the widget node.
64 bool Config_ValidatorReader::processChildren(xmlNodePtr aNode)
69 void Config_ValidatorReader::processValidator(xmlNodePtr theNode)
71 Events_ID aValidatoEvent = Events_Loop::eventByName(EVENT_VALIDATOR_LOADED);
72 Events_Loop* aEvLoop = Events_Loop::loop();
73 std::shared_ptr<Config_ValidatorMessage>
74 aMessage(new Config_ValidatorMessage(aValidatoEvent, this));
75 std::string aValidatorId;
76 std::list<std::string> aParameters;
77 getParametersInfo(theNode, aValidatorId, aParameters);
78 aMessage->setValidatorId(aValidatorId);
79 aMessage->setValidatorParameters(aParameters);
80 std::string aFeatureId = restoreAttribute(NODE_FEATURE, _ID);
81 aMessage->setFeatureId(aFeatureId);
82 // parent is attribute (widget)
83 if (!myCurrentWidget.empty()) {
84 std::string aParentId = restoreAttribute(myCurrentWidget.c_str(), _ID);
85 aMessage->setAttributeId(aParentId);
87 aEvLoop->send(aMessage);
90 void Config_ValidatorReader::processSelectionFilter(xmlNodePtr theNode)
92 Events_ID aFilterEvent = Events_Loop::eventByName(EVENT_SELFILTER_LOADED);
93 Events_Loop* aEvLoop = Events_Loop::loop();
94 std::shared_ptr<Config_SelectionFilterMessage> aMessage(
95 new Config_SelectionFilterMessage(aFilterEvent, this));
96 std::string aSelectionFilterId;
97 std::list<std::string> aParameters;
98 getParametersInfo(theNode, aSelectionFilterId, aParameters);
99 aMessage->setSelectionFilterId(aSelectionFilterId);
100 aMessage->setFilterParameters(aParameters);
101 std::string aFeatureId = restoreAttribute(NODE_FEATURE, _ID);
102 aMessage->setFeatureId(aFeatureId);
103 // parent is attribute (widget)
104 if (!myCurrentWidget.empty()) {
105 std::string aParentId = restoreAttribute(myCurrentWidget.c_str(), _ID);
106 aMessage->setAttributeId(aParentId);
108 aEvLoop->send(aMessage);