summaryrefslogtreecommitdiff
path: root/ACEXML/apps/svcconf/Svcconf.cpp
blob: 3ceb602e788daffd61d10337ca2afd1913b763e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// $Id$


#include "Svcconf.h"
#include "ACEXML/common/FileCharStream.h"
#include "ACEXML/common/StrCharStream.h"
#include "ACEXML/parser/parser/Parser.h"

#if (ACE_USES_CLASSIC_SVC_CONF == 0)

extern "C" ACE_Proper_Export_Flag ACE_XML_Svc_Conf *
_ACEXML_create_XML_Svc_Conf_Object (void)
{
  ACE_XML_Svc_Conf *retp = 0;

  ACE_NEW_RETURN (retp,
                  ACEXML_Svcconf_Parser (),
                  0);

  return retp;
}

ACEXML_Svcconf_Parser::ACEXML_Svcconf_Parser ()
{
  this->parser_.setContentHandler (&this->svcconf_handler_);
  this->parser_.setDTDHandler (&this->svcconf_handler_);
  this->parser_.setErrorHandler (&this->svcconf_handler_);
  this->parser_.setEntityResolver (&this->svcconf_handler_);
  ACEXML_TRY_NEW_ENV
    {
      this->parser_.setFeature (ACE_TEXT ("http://xml.org/sax/features/validation"),
                                0
                                ACEXML_ENV_ARG_PARAMETER);
      ACEXML_TRY_CHECK;
    }
  ACEXML_CATCH (ACEXML_SAXException, ex)
    {
      ex.print ();              // Can't do much except printing the error.
      return;
    }
  ACEXML_ENDTRY;
}

ACEXML_Svcconf_Parser::~ACEXML_Svcconf_Parser ()
{

}

void *
ACEXML_Svcconf_Parser::operator new (size_t s)
{
  return ::new char[s];
}

void
ACEXML_Svcconf_Parser::operator delete (void *p)
{
  delete[] (char*)p;
}

int
ACEXML_Svcconf_Parser::parse_file (const ACE_TCHAR file[])
{
  if (file == 0)
    ACE_ERROR_RETURN ((LM_ERROR, "ACEXML_Svcconf_Parser: No filename specified\n"), -1);

  ACEXML_FileCharStream *fstm = 0;
  ACE_NEW_RETURN (fstm,
                  ACEXML_FileCharStream (),
                  1);

  if (fstm->open (file) != 0)
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("ACEXML_Svcconf_Parser: Fail to open XML file: %s\n"),
                       file),
                      -1);

  this->input_stream_.setCharStream (fstm);

  ACEXML_TRY_NEW_ENV
    {
      this->parser_.parse (&this->input_stream_ ACEXML_ENV_ARG_PARAMETER);
      ACEXML_TRY_CHECK;
    }
  ACEXML_CATCH (ACEXML_SAXException, ex)
    {
      ex.print ();
      return -1;
    }
  ACEXML_ENDTRY;
  return 0;
}


int
ACEXML_Svcconf_Parser::parse_string (const ACE_TCHAR str[])
{
  if (str == 0)
    ACE_ERROR_RETURN ((LM_ERROR, "ACEXML_Svcconf_Parser: Can't parse a null string\n"), -1);

  ACEXML_StrCharStream *stm = 0;
  ACE_NEW_RETURN (stm, ACEXML_StrCharStream, -1);
  if (stm->open (str, ACE_TEXT ("Svcconf")) < 0)
    ACE_ERROR_RETURN ((LM_ERROR, "ACEXML_Svcconf_Parser: Unable to create "
                       "input stream.\n"), -1);

  this->input_stream_.setCharStream (stm);
  ACEXML_TRY_NEW_ENV
    {
      this->parser_.parse (&this->input_stream_ ACEXML_ENV_ARG_PARAMETER);
      ACEXML_TRY_CHECK;
    }
  ACEXML_CATCH (ACEXML_SAXException, ex)
    {
      ex.print ();
      return -1;
    }
  ACEXML_ENDTRY;
  return 0;
}

#else

#  if defined (_AIX) && \
     (defined (__IBMCPP__) && (__IBMCPP__ >= 500) && (__IBMCPP__ < 600))
// This simply shuts up the AIX linker that complains there are no
// csects or exported symbols when building with Visual Age C++ 5.
extern "C" void ace_shut_up_aix_ld (void) {};
#  endif /* AIX && __IBMCPP__ == 500 */

#endif /* ACE_USES_CLASSIC_SVC_CONF == 0 */