1 // Copyright (C) 2006-2008 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.
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
19 #include "ProcCataLoader.hxx"
20 #include "parsers.hxx"
23 #include "TypeCode.hxx"
32 #include "YacsTrace.hxx"
34 using namespace YACS::ENGINE;
36 ProcCataLoader::ProcCataLoader(YACS::YACSLoader* xmlLoader,const std::string& path):CatalogLoader(path),_xmlLoader(xmlLoader)
38 //path should be a file path
41 ProcCataLoader::~ProcCataLoader()
43 DEBTRACE ("ProcCataLoader::~ProcCataLoader");
46 void ProcCataLoader::loadCata(Catalog* cata)
48 DEBTRACE("ProcCataLoader::load");
52 p=_xmlLoader->load(_path.c_str());
55 std::string msg="the file is probably not a YACS schema file";
57 std::cerr << msg << std::endl;
61 catch (YACS::Exception& e)
63 std::string msg="Caught a YACS exception";
65 std::cerr << msg << std::endl;
69 catch (const std::invalid_argument& e)
71 cata->setErrors(e.what());
74 catch (const std::ios_base::failure&)
76 std::string msg="Caught an io failure exception";
77 std::cerr << msg << std::endl;
82 //Get the parser logger
83 Logger* logger=p->getLogger("parser");
84 //Print errors logged if any
85 if(!logger->isEmpty())
87 std::string msg=logger->getStr();
88 std::cerr << msg << std::endl;
92 std::map<std::string,TypeCode*>& typeMap=cata->_typeMap;
93 std::map<std::string,Node*>& nodeMap=cata->_nodeMap;
94 std::map<std::string,ComposedNode*>& composednodeMap=cata->_composednodeMap;
95 std::map<std::string,ComponentDefinition*>& componentMap=cata->_componentMap;
97 std::map<std::string,TypeCode*>::iterator it=p->typeMap.begin();
98 while(it != p->typeMap.end())
100 typeMap[it->first]=it->second;
101 it->second->incrRef();
105 std::list<Node *> s=p->getChildren();
106 for(std::list<Node *>::iterator iter=s.begin();iter!=s.end();iter++)
108 YACS::ENGINE::ComposedNode * cnode= dynamic_cast<YACS::ENGINE::ComposedNode *>(*iter);
110 composednodeMap[cnode->getName()]=(YACS::ENGINE::ComposedNode *) cnode->clone(0);
112 nodeMap[(*iter)->getName()]=(*iter)->clone(0);