1 // Copyright (C) 2006-2019 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
20 #include "ProcCataLoader.hxx"
21 #include "parsers.hxx"
24 #include "TypeCode.hxx"
33 #include "YacsTrace.hxx"
35 using namespace YACS::ENGINE;
37 ProcCataLoader::ProcCataLoader(YACS::YACSLoader* xmlLoader,const std::string& path):CatalogLoader(path),_xmlLoader(xmlLoader)
39 //path should be a file path
42 ProcCataLoader::~ProcCataLoader()
44 DEBTRACE ("ProcCataLoader::~ProcCataLoader");
47 void ProcCataLoader::loadCata(Catalog* cata)
49 DEBTRACE("ProcCataLoader::load");
53 p=_xmlLoader->load(_path.c_str());
56 std::string msg="the file is probably not a YACS schema file";
58 std::cerr << msg << std::endl;
62 catch (YACS::Exception& e)
64 std::string msg="Caught a YACS exception";
66 std::cerr << msg << std::endl;
70 catch (const std::invalid_argument& e)
72 cata->setErrors(e.what());
75 catch (const std::ios_base::failure&)
77 std::string msg="Caught an io failure exception";
78 std::cerr << msg << std::endl;
83 //Get the parser logger
84 Logger* logger=p->getLogger("parser");
85 //Print errors logged if any
86 if(!logger->isEmpty())
88 std::string msg=logger->getStr();
89 std::cerr << msg << std::endl;
93 std::map<std::string,TypeCode*>& typeMap=cata->_typeMap;
94 std::map<std::string,Node*>& nodeMap=cata->_nodeMap;
95 std::map<std::string,ComposedNode*>& composednodeMap=cata->_composednodeMap;
96 std::map<std::string,ComponentDefinition*>& componentMap=cata->_componentMap;
98 std::map<std::string,TypeCode*>::iterator it=p->typeMap.begin();
99 while(it != p->typeMap.end())
101 typeMap[it->first]=it->second;
102 it->second->incrRef();
106 std::list<Node *> s=p->getChildren();
107 for(std::list<Node *>::iterator iter=s.begin();iter!=s.end();iter++)
109 YACS::ENGINE::ComposedNode * cnode= dynamic_cast<YACS::ENGINE::ComposedNode *>(*iter);
111 composednodeMap[cnode->getName()]=(YACS::ENGINE::ComposedNode *) cnode->clone(0);
113 nodeMap[(*iter)->getName()]=(*iter)->clone(0);