summaryrefslogtreecommitdiff
path: root/TAO/CIAO/tools/XML_Helpers/Cascadable_DocHandler.cpp
blob: 8a0bf8d0bc7a15b07fea8b3b2e7975a02a731107 (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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
// $Id$

#include "Cascadable_DocHandler.h"
#include "ace/Log_Msg.h"

#if !defined (__ACE_INLINE__)
# include "Cascadable_DocHandler.i"
#endif /* __ACE_INLINE__ */

CIAO::XMLHelpers::Cascadable_DocHandler::Cascadable_DocHandler (ACEXML_XMLReader *parser,
                                                                Cascadable_DocHandler *parent,
                                                                const ACEXML_Char *namespaceURI,
                                                                const ACEXML_Char *localName,
                                                                const ACEXML_Char *qName,
                                                                ACEXML_Attributes *
                                                                ACEXML_ENV_ARG_DECL)
  ACE_THROW_SPEC ((ACEXML_SAXException))
    : namespaceURI_ (ACE::strnew (namespaceURI)),
      localName_ (ACE::strnew (localName)),
      qName_ (ACE::strnew (qName)),
      parser_ (parser),
      parent_ (parent),
      child_ (0),
      locator_ (0)
{
#if !defined (ACE_HAS_EXCEPTIONS)
  ACE_UNUSED_ARG (ACEXML_ENV_SINGLE_ARG_PARAMETER);
#endif /*ACE_HAS_EXCEPTIONS*/
}

CIAO::XMLHelpers::Cascadable_DocHandler::~Cascadable_DocHandler ()
{
  delete[] this->namespaceURI_;
  delete[] this->localName_;
  delete[] this->qName_;
  delete[] this->child_;
}

void
CIAO::XMLHelpers::Cascadable_DocHandler::destroy ()
{
  delete this;
}


void
CIAO::XMLHelpers::Cascadable_DocHandler::push_handler (Cascadable_DocHandler *new_handler,
                                                       ACEXML_Attributes *atts
                                                       ACEXML_ENV_ARG_DECL)
  ACE_THROW_SPEC ((ACEXML_SAXException))
{
  // This method should be invoked from this->startElement ().

  new_handler->setDocumentLocator (this->locator_);
  this->child_ = new_handler;
  this->parser_->setContentHandler (new_handler);
  this->parser_->setDTDHandler (new_handler);
  this->parser_->setEntityResolver (new_handler);
  this->parser_->setErrorHandler (new_handler);

  new_handler->startElement (new_handler->namespaceURI (),
                             new_handler->localName (),
                             new_handler->qName (),
                             atts
                             ACEXML_ENV_ARG_PARAMETER);
  ACEXML_CHECK;
}

void
CIAO::XMLHelpers::Cascadable_DocHandler::pop_handler (const ACEXML_Char *namespaceURI,
                                                      const ACEXML_Char *localName,
                                                      const ACEXML_Char *qName
                                                      ACEXML_ENV_ARG_DECL)
  ACE_THROW_SPEC ((ACEXML_SAXException))
{
  // This method should be invoked from this->child_->endElement ().

  this->parser_->setContentHandler (this);
  this->parser_->setDTDHandler (this);
  this->parser_->setEntityResolver (this);
  this->parser_->setErrorHandler (this);

  // endElement should harvest the parse result stored in the
  // this->child_ somehow because it's the last chance to do so.
  this->endElement (namespaceURI,
                    localName,
                    qName
                    ACEXML_ENV_ARG_PARAMETER);
  ACEXML_CHECK;

  this->child_->destroy ();
  this->child_ = 0;
}

void
CIAO::XMLHelpers::Cascadable_DocHandler::print_warning (const ACEXML_Char *level,
                                                        ACEXML_SAXParseException & ex
                                                        ACEXML_ENV_ARG_DECL_NOT_USED)
      ACE_THROW_SPEC ((ACEXML_SAXException))
{
  ACE_DEBUG ((LM_DEBUG, "%s (%s): line :%d col: %d ",
              level,
              this->locator_->getSystemId (),
              this->locator_->getLineNumber(),
              this->locator_->getColumnNumber()));
  ex.print();
  ACE_DEBUG ((LM_DEBUG, "\n"));
}

CIAO::XMLHelpers::Skip_DocHandler::Skip_DocHandler (ACEXML_XMLReader *parser,
                                                    Cascadable_DocHandler *parent,
                                                    const ACEXML_Char *namespaceURI,
                                                    const ACEXML_Char *localName,
                                                    const ACEXML_Char *qName,
                                                    ACEXML_Attributes *attrs
                                                    ACEXML_ENV_ARG_DECL)
  ACE_THROW_SPEC ((ACEXML_SAXException))
  // The exception stuff will not work for platform without native exception.
    : Cascadable_DocHandler (parser,
                             parent,
                             namespaceURI,
                             localName,
                             qName,
                             attrs
                             ACEXML_ENV_ARG_PARAMETER),
      element_count_ (0)
{
}

CIAO::XMLHelpers::Skip_DocHandler::~Skip_DocHandler ()
{
}

void
CIAO::XMLHelpers::Skip_DocHandler::endElement (const ACEXML_Char *namespaceURI,
                                               const ACEXML_Char *localName,
                                               const ACEXML_Char *qName
                                               ACEXML_ENV_ARG_DECL)
  ACE_THROW_SPEC ((ACEXML_SAXException))
{
  ACE_TRACE ("CIAO::XMLHelpers::Skip_DocHandler::endElement");

  --this->element_count_;
  if (this->element_count_ == 0)
    {
      this->parent_->pop_handler (namespaceURI,
                                  localName,
                                  qName
                                  ACEXML_ENV_ARG_PARAMETER);
      ACEXML_CHECK;
    }
}

void
CIAO::XMLHelpers::Skip_DocHandler::startElement (const ACEXML_Char *,
                                                 const ACEXML_Char *,
                                                 const ACEXML_Char *,
                                                 ACEXML_Attributes *
                                                 ACEXML_ENV_ARG_DECL_NOT_USED)
  ACE_THROW_SPEC ((ACEXML_SAXException))
{
  ACE_TRACE ("CIAO::XMLHelpers::Skip_DocHandler::startElement");

  ++this->element_count_;
}