summaryrefslogtreecommitdiff
path: root/TAO/CIAO/DnC/Config_Handlers/PCD_Handler.cpp
blob: eb5792bb1b2f076115b4f60bae41b915286c4fd3 (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
166
167
168
169
170
171
172
173
174
175
176
// $Id$

#ifndef PCD_HANDLER_C
#define PCD_HANDLER_C

#include "tao/Exception.h"
#include "ace/Auto_Ptr.h"
#include "ace/Log_Msg.h"

#include "Requirement_Handler.h"
#include "ERE_Handler.h"
#include "CEPE_Handler.h"
#include "CRDD_Handler.h"
#include "PSPE_Handler.h"
#include "PCD_Handler.h"

#include <iostream>

using std::cerr;
using std::endl;


namespace CIAO
{
  namespace Config_Handler
  {
    PCD_Handler::PCD_Handler (DOMDocument* doc, unsigned long filter)
      : doc_ (doc),
        root_ (doc->getDocumentElement()),
        filter_ (filter),
        iter_ (doc_->createNodeIterator (this->root_,
                                         this->filter_,
                                         0,
                                         true)),
        release_ (true)
    {}

    PCD_Handler::PCD_Handler (DOMNodeIterator* iter, bool release)
      : doc_ (0), root_ (0), filter_ (0), iter_ (iter), release_ (release)
    {}


    PCD_Handler::~PCD_Handler()
    {
      if (this->release_)
        this->iter_->release();
    }

    /// handle the plan connection description and populate it
    void PCD_Handler::process_PlanConnectionDescription
    (::Deployment::PlanConnectionDescription &pcd)
    {
      // This is bogus and should be replaced later.
      ACE_DECLARE_NEW_CORBA_ENV;

      for (DOMNode* node = this->iter_->nextNode();
           node != 0;
           node = this->iter_->nextNode())
        {
          XStr node_name (node->getNodeName());
          if (node_name == XStr (ACE_TEXT ("name")))
            {
              // Fetch the text node which contains the "name"
              node = this->iter_->nextNode();
              DOMText* text = ACE_reinterpret_cast (DOMText*, node);
              this->process_name (text->getNodeValue(), pcd);
            }
          else if (node_name == XStr (ACE_TEXT ("source")))
            {
              // Fetch the text node which contains the "source"
              node = this->iter_->nextNode();
              DOMText* text = ACE_reinterpret_cast (DOMText*, node);
              this->process_source (text->getNodeValue(), pcd);
            }
          else if (node_name == XStr (ACE_TEXT ("deployRequirement")))
            {
              // increase the length of the sequence
              CORBA::ULong i (pcd.deployRequirement.length ());
              pcd.deployRequirement.length (i + 1);

              // delegate the populating process
              // @@ need to avoid this copy, possible memory leak @@
              // Arvind: Addressed
              Requirement_Handler::process_Requirement (this->iter_,
                                                        pcd.deployRequirement[i]);
            }
          else if (node_name == XStr (ACE_TEXT ("deployedResource")))
            {
              // increase the length of the sequence
              CORBA::ULong i (pcd.deployedResource.length ());
              pcd.deployedResource.length (i + 1);

              // fetch the ConnectionResourceDeployment Description
              // handler
              CRDD_Handler crdd_handler (this->iter_, false);

              // delegate the populating process
              crdd_handler.process_ConnectionResourceDeploymentDescription (pcd.deployedResource[i]);
            }
          else if (node_name == XStr (ACE_TEXT ("internalEndpoint")))
            {
              // increase the length of the sequence
              CORBA::ULong i (pcd.internalEndpoint.length ());
              pcd.internalEndpoint.length (i + 1);

              // fetch the PlanSubcomponentPortEndpoint handler
              PSPE_Handler pspe_handler (this->iter_, false);

              // delegate the populating process
              pspe_handler.process_PlanSubcomponentPortEndpoint (pcd.internalEndpoint[i]);
            }
          else if (node_name == XStr (ACE_TEXT ("externalReference")))
            {
              // increase the length of the sequence
              CORBA::ULong i (pcd.externalReference.length ());
              pcd.externalReference.length (i + 1);

              // fetch the ExternalReferenceEndpoint handler and
              // delegate to it
              // @@ need to avoid this copy, possible memory leak @@
              pcd.externalReference[i] =
                *ERE_Handler::process_ExternalReferenceEndpoint (this->iter_);

            }
          else if (node_name == XStr (ACE_TEXT ("externalEndpoint")))
            {
              // increase the length of the sequence
              CORBA::ULong i (pcd.externalEndpoint.length ());
              pcd.externalEndpoint.length (i + 1);

              // fetch the ComponentExternalPortEndpoint handler and
              // delegate to it
              // @@ need to avoid this copy, possible memory leak @@
              // Arvind: Addressed
              CEPE_Handler::
                process_ComponentExternalPortEndpoint
                (this->iter_, pcd.externalEndpoint[i]);

            }
          else
            {
              // ??? How did we get here ???
              ACE_THROW (CORBA::INTERNAL());
            }
        }
      return;
    }

    /// handle name attribute
    void PCD_Handler::process_name (const XMLCh* name,
                                    ::Deployment::PlanConnectionDescription &pcd)
    {
      if (name)
        {
          pcd.name = XMLString::transcode (name);
        }
    }

    /// handle source attribute
    void PCD_Handler::process_source (const XMLCh* source,
                                      ::Deployment::PlanConnectionDescription &pcd)
    {
      if (source)
        {
          // first increment the length of the sequence
          CORBA::ULong i (pcd.source.length ());
          pcd.source.length (i+1);
          // insert the new source
          pcd.source[i] = XMLString::transcode (source);
        }
    }

  }
}

#endif /* PCD_HANDLER_C */