1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 * Config_ValidatorReader.cpp
23 * Created on: Mar 20, 2015
27 #include <Config_ValidatorReader.h>
28 #include <Config_Keywords.h>
29 #include <Config_Common.h>
30 #include <Config_ValidatorMessage.h>
31 #include <Config_PropManager.h>
33 #include <Events_Loop.h>
34 #include <libxml/parser.h>
35 #include <libxml/tree.h>
43 Config_ValidatorReader::Config_ValidatorReader(const std::string& theXmlFileName)
44 : Config_XMLReader(theXmlFileName)
48 Config_ValidatorReader::~Config_ValidatorReader()
52 void Config_ValidatorReader::processNode(xmlNodePtr theNode)
54 if (isNode(theNode, NODE_VALIDATOR, NULL)) {
55 processValidator(theNode);
56 } else if (isNode(theNode, NODE_FEATURE, NULL)) {
57 storeAttribute(theNode, _ID);
58 } else if (isWidgetNode(theNode)) {
59 storeAttribute(theNode, _ID);
60 // Store widget name to restore it's id on validator/selector processing
61 myCurrentWidget = getNodeName(theNode);
63 //Process SOURCE nodes.
64 Config_XMLReader::processNode(theNode);
67 void Config_ValidatorReader::cleanup(xmlNodePtr theNode)
69 if (isNode(theNode, NODE_FEATURE, NULL)) {
70 cleanupAttribute(theNode, _ID);
71 } else if (isWidgetNode(theNode)) {
72 cleanupAttribute(NODE_XMLPARENT, _ID);
73 // Cleanup widget name when leave the widget node.
78 bool Config_ValidatorReader::processChildren(xmlNodePtr aNode)
83 void Config_ValidatorReader::processValidator(xmlNodePtr theNode)
85 Events_ID aValidatoEvent = Events_Loop::eventByName(EVENT_VALIDATOR_LOADED);
86 Events_Loop* aEvLoop = Events_Loop::loop();
87 std::shared_ptr<Config_ValidatorMessage>
88 aMessage(new Config_ValidatorMessage(aValidatoEvent, this));
89 std::string aValidatorId;
90 std::list<std::string> aParameters;
91 getParametersInfo(theNode, aValidatorId, aParameters);
92 aMessage->setValidatorId(aValidatorId);
93 aMessage->setValidatorParameters(aParameters);
94 std::string aFeatureId = restoreAttribute(NODE_FEATURE, _ID);
95 aMessage->setFeatureId(aFeatureId);
96 // parent is attribute (widget)
97 if (!myCurrentWidget.empty()) {
98 std::string aParentId = restoreAttribute(myCurrentWidget.c_str(), _ID);
99 aMessage->setAttributeId(aParentId);
101 aEvLoop->send(aMessage);