00001
00002
00003
00004 #include "Svcconf.h"
00005 #include "ACEXML/common/FileCharStream.h"
00006 #include "ACEXML/common/StrCharStream.h"
00007 #include "ACEXML/parser/parser/Parser.h"
00008
00009 #if (ACE_USES_CLASSIC_SVC_CONF == 0)
00010
00011 extern "C" ACE_Proper_Export_Flag ACE_XML_Svc_Conf *
00012 _ACEXML_create_XML_Svc_Conf_Object (void)
00013 {
00014 ACE_XML_Svc_Conf *retp = 0;
00015
00016 ACE_NEW_RETURN (retp,
00017 ACEXML_Svcconf_Parser (),
00018 0);
00019
00020 return retp;
00021 }
00022
00023 ACEXML_Svcconf_Parser::ACEXML_Svcconf_Parser ()
00024 {
00025 this->parser_.setContentHandler (&this->svcconf_handler_);
00026 this->parser_.setDTDHandler (&this->svcconf_handler_);
00027 this->parser_.setErrorHandler (&this->svcconf_handler_);
00028 this->parser_.setEntityResolver (&this->svcconf_handler_);
00029 ACEXML_TRY_NEW_ENV
00030 {
00031 this->parser_.setFeature (ACE_TEXT ("http://xml.org/sax/features/validation"),
00032 0
00033 ACEXML_ENV_ARG_PARAMETER);
00034 ACEXML_TRY_CHECK;
00035 }
00036 ACEXML_CATCH (ACEXML_SAXException, ex)
00037 {
00038 ex.print ();
00039 return;
00040 }
00041 ACEXML_ENDTRY;
00042 }
00043
00044 ACEXML_Svcconf_Parser::~ACEXML_Svcconf_Parser ()
00045 {
00046
00047 }
00048
00049
00050 int
00051 ACEXML_Svcconf_Parser::parse_file (const ACE_TCHAR file[])
00052 {
00053 if (file == 0)
00054 ACE_ERROR_RETURN ((LM_ERROR, "ACEXML_Svcconf_Parser: No filename specified\n"), -1);
00055
00056 ACEXML_FileCharStream *fstm = 0;
00057 ACE_NEW_RETURN (fstm,
00058 ACEXML_FileCharStream (),
00059 1);
00060
00061 if (fstm->open (file) != 0)
00062 ACE_ERROR_RETURN ((LM_ERROR,
00063 ACE_TEXT ("ACEXML_Svcconf_Parser: Fail to open XML file: %s\n"),
00064 file),
00065 -1);
00066
00067 this->input_stream_.setCharStream (fstm);
00068
00069 ACEXML_TRY_NEW_ENV
00070 {
00071 this->parser_.parse (&this->input_stream_ ACEXML_ENV_ARG_PARAMETER);
00072 ACEXML_TRY_CHECK;
00073 }
00074 ACEXML_CATCH (ACEXML_SAXException, ex)
00075 {
00076 ex.print ();
00077 return -1;
00078 }
00079 ACEXML_ENDTRY;
00080 return 0;
00081 }
00082
00083
00084 int
00085 ACEXML_Svcconf_Parser::parse_string (const ACE_TCHAR str[])
00086 {
00087 if (str == 0)
00088 ACE_ERROR_RETURN ((LM_ERROR, "ACEXML_Svcconf_Parser: Can't parse a null string\n"), -1);
00089
00090 ACEXML_StrCharStream *stm = 0;
00091 ACE_NEW_RETURN (stm, ACEXML_StrCharStream, -1);
00092 if (stm->open (str, ACE_TEXT ("Svcconf")) < 0)
00093 ACE_ERROR_RETURN ((LM_ERROR, "ACEXML_Svcconf_Parser: Unable to create "
00094 "input stream.\n"), -1);
00095
00096 this->input_stream_.setCharStream (stm);
00097 ACEXML_TRY_NEW_ENV
00098 {
00099 this->parser_.parse (&this->input_stream_ ACEXML_ENV_ARG_PARAMETER);
00100 ACEXML_TRY_CHECK;
00101 }
00102 ACEXML_CATCH (ACEXML_SAXException, ex)
00103 {
00104 ex.print ();
00105 return -1;
00106 }
00107 ACEXML_ENDTRY;
00108 return 0;
00109 }
00110
00111 #else
00112
00113 # if defined (_AIX) && \
00114 (defined (__IBMCPP__) && (__IBMCPP__ >= 500) && (__IBMCPP__ < 600))
00115
00116
00117 extern "C" void ace_shut_up_aix_ld (void) {};
00118 # endif
00119
00120 #endif