Merge pull request #2216 from jwillemsen/jwi-cxxversionchecks
[ACE_TAO.git] / ACE / ACEXML / apps / svcconf / Svcconf.cpp
blob66f74adb4b59810c9377ee7ec8d6f539606a7b41
2 #include "Svcconf.h"
3 #include "ACEXML/common/FileCharStream.h"
4 #include "ACEXML/common/StrCharStream.h"
5 #include "ACEXML/parser/parser/Parser.h"
7 #if (ACE_USES_CLASSIC_SVC_CONF == 0)
9 extern "C" ACE_Proper_Export_Flag ACE_XML_Svc_Conf *
10 _ACEXML_create_XML_Svc_Conf_Object ()
12 ACE_XML_Svc_Conf *retp = 0;
14 ACE_NEW_RETURN (retp,
15 ACEXML_Svcconf_Parser (),
16 0);
18 return retp;
21 ACEXML_Svcconf_Parser::ACEXML_Svcconf_Parser ()
23 this->parser_.setContentHandler (&this->svcconf_handler_);
24 this->parser_.setDTDHandler (&this->svcconf_handler_);
25 this->parser_.setErrorHandler (&this->svcconf_handler_);
26 this->parser_.setEntityResolver (&this->svcconf_handler_);
27 try
29 this->parser_.setFeature (ACE_TEXT ("http://xml.org/sax/features/validation"),
30 0);
32 catch (const ACEXML_SAXException& ex)
34 ex.print (); // Can't do much except printing the error.
38 ACEXML_Svcconf_Parser::~ACEXML_Svcconf_Parser ()
42 int
43 ACEXML_Svcconf_Parser::parse_file (const ACE_TCHAR file[])
45 if (file == 0)
46 ACE_ERROR_RETURN ((LM_ERROR, "ACEXML_Svcconf_Parser: No filename specified\n"), -1);
48 ACEXML_FileCharStream *fstm = 0;
49 ACE_NEW_RETURN (fstm,
50 ACEXML_FileCharStream (),
51 1);
53 if (fstm->open (file) != 0)
54 ACE_ERROR_RETURN ((LM_ERROR,
55 ACE_TEXT ("ACEXML_Svcconf_Parser: Fail to open XML file: %s\n"),
56 file),
57 -1);
59 this->input_stream_.setCharStream (fstm);
61 try
63 this->parser_.parse (&this->input_stream_);
65 catch (const ACEXML_SAXException& ex)
67 ex.print ();
68 return -1;
70 return 0;
74 int
75 ACEXML_Svcconf_Parser::parse_string (const ACE_TCHAR str[])
77 if (str == 0)
78 ACE_ERROR_RETURN ((LM_ERROR, "ACEXML_Svcconf_Parser: Can't parse a null string\n"), -1);
80 ACEXML_StrCharStream *stm = 0;
81 ACE_NEW_RETURN (stm, ACEXML_StrCharStream, -1);
82 if (stm->open (str, ACE_TEXT ("Svcconf")) < 0)
83 ACE_ERROR_RETURN ((LM_ERROR, "ACEXML_Svcconf_Parser: Unable to create "
84 "input stream.\n"), -1);
86 this->input_stream_.setCharStream (stm);
87 try
89 this->parser_.parse (&this->input_stream_);
91 catch (const ACEXML_SAXException& ex)
93 // If there was a problem parsing the stream, set the errno
94 // to EINVAL to indicate to upper levels that the stream was
95 // invalid.
96 ACE_OS::last_error (EINVAL);
97 ex.print ();
98 return -1;
100 return 0;
103 #endif /* ACE_USES_CLASSIC_SVC_CONF == 0 */