1 // Copyright (C) 2006-2013 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
20 #include "parsers.hxx"
27 #include "Runtime.hxx"
29 #include "ProcCataLoader.hxx"
32 #include "rootParser.hxx"
35 #include "YacsTrace.hxx"
37 YACS::ENGINE::Runtime* theRuntime=0;
43 extern YACS::ENGINE::Proc* currentProc;
49 YACSLoader::YACSLoader()
51 _defaultParsersMap.clear();
53 theRuntime = ENGINE::getRuntime();
56 void YACSLoader::registerProcCataLoader()
58 YACS::ENGINE::ProcCataLoader* factory= new YACS::ENGINE::ProcCataLoader(this);
59 theRuntime->setCatalogLoaderFactory("proc",factory);
62 ENGINE::Proc* YACSLoader::load(const char * file)
64 DEBTRACE("YACSLoader::load: " << file);
65 FILE* fin=fopen(file,"r");
68 std::cerr << "Couldn't open schema file" << std::endl;
69 throw std::invalid_argument("Couldn't open schema file");
72 p = XML_ParserCreate(NULL);
75 std::cerr << "Couldn't allocate memory for parser" << std::endl;
76 throw Exception("Couldn't allocate memory for parser");
78 XML_SetElementHandler(p, parser::start,parser::end);
79 XML_SetCharacterDataHandler(p,parser::charac );
81 parser::main_parser.SetUserDataAndPush(&YACS::roottypeParser::rootParser);
83 // OCC: san -- Allow external parsers for handling of unknown elements
84 // and attributes. This capability is used by YACS GUI to read
85 // graph presentation data
86 if ( !_defaultParsersMap.empty() )
87 roottypeParser::rootParser.setDefaultMap(&_defaultParsersMap);
89 roottypeParser::rootParser.setDefaultMap(0);
91 parser::main_parser._file=file;
102 len = fread(Buff, 1, BUFFSIZE, fin);
105 std::cerr << "Read error" << std::endl;
106 throw Exception("Read error");
110 if (XML_Parse(p, Buff, len, done) == XML_STATUS_ERROR)
114 std::cerr <<XML_ErrorString(XML_GetErrorCode(p))<<" "<<file<<" "<<XML_GetCurrentLineNumber(p)<<std::endl;
117 YACS::ENGINE::Logger* logger=currentProc->getLogger("parser");
118 logger->fatal(XML_ErrorString(XML_GetErrorCode(p)),file,XML_GetCurrentLineNumber(p));
131 //get line number from XML parser
132 YACS::ENGINE::Logger* logger=currentProc->getLogger("parser");
133 logger->fatal(e.what(),file,XML_GetCurrentLineNumber(p));
140 YACSLoader::~YACSLoader()