summaryrefslogtreecommitdiff
path: root/TAO/CIAO/DnC/Config_Handlers/CompPortDesc_Handler.cpp
blob: 2dfb1d40464457a332435e7e8c95bb66e119339a (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
177
178
179
180
181
182
183
184
185
186
187
188
189
//==================================================================
/**
 *  @file  CompPortDesc_Handler.cpp
 *
 *  $Id$
 *
 *  @author Emre Turkay  <turkaye@dre.vanderbilt.edu>
 */
//=====================================================================

#ifndef COMPPORTDESC_HANDLER_C
#define COMPPORTDESC_HANDLER_C

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

#include "IAD_Handler.h"
#include "CompPortDesc_Handler.h"

#include <iostream>

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

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

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


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

    /// handle the package configuration and populate it
    void CompPortDesc_Handler::process_ComponentPortDescription
      (::Deployment::ComponentPortDescription &compportdesc)
    {
      // 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 "label"
	      node = this->iter_->nextNode();
	      DOMText* text = ACE_reinterpret_cast (DOMText*, node);
              this->process_name (text->getNodeValue(), compportdesc);
	    }
          else if (node_name == XStr (ACE_TEXT ("specificType")))
            {
              // Fetch the text node which contains the "specificType"
              node = this->iter_->nextNode();
              DOMText* text = ACE_reinterpret_cast (DOMText*, node);
              this->process_specificType (text->getNodeValue(), compportdesc);
            }
          else if (node_name == XStr (ACE_TEXT ("supportedType")))
            {
              // Fetch the text node which contains the "supportedType"
              node = this->iter_->nextNode();
              DOMText* text = ACE_reinterpret_cast (DOMText*, node);
              this->process_supportedType (text->getNodeValue(), compportdesc);
            }
	  else if (node_name == XStr (ACE_TEXT ("provider")))
	    {
	      /// Fetch the text node which contains the "provider"
	      node = this->iter_->nextNode();
	      DOMText* text = ACE_reinterpret_cast (DOMText* node);
	      this->process_provider (text->getNodeValue(), compportdesc);
	    }
	  else if (node_name == XStr (ACE_TEXT ("exclusiveProvider")))
	    {
	      /// Fetch the text node which contains the "exclusiveProvider"
	      node = this->iter_->nextNode();
	      DOMText* text = ACE_reinterpret_cast (DOMText* node);
	      this->process_exclusiveProvider (text->getNodeValue(), compportdesc);
	    }
	  else if (node_name == XStr (ACE_TEXT ("exclusiveUser")))
	    {
	      /// Fetch the text node which contains the "exclusiveUser"
	      node = this->iter_->nextNode();
	      DOMText* text = ACE_reinterpret_cast (DOMText* node);
	      this->process_exclusiveUser (text->getNodeValue(), compportdesc);
	    }
	  else if (node_name == XStr (ACE_TEXT ("optional")))
	    {
	      /// Fetch the text node which contains the "optional"
	      node = this->iter_->nextNode();
	      DOMText* text = ACE_reinterpret_cast (DOMText* node);
	      this->process_optional (text->getNodeValue(), compportdesc);
	    }
	  else
            {
              // ??? How did we get here ???
              ACE_THROW (CORBA::INTERNAL());
            }
        }
      return;
    }

    /// handle name attribute
    void CompPortDesc_Handler::process_name
      (const XMLCh* name, ::Deployment::ComponentPortDescription &compportdesc)
    {
      if (name)
        {
          compportdesc.name = XMLString::transcode (name);
        }
    }

    /// handle specificType attribute
    void process_specificType (const XMLCh* specificType, ::Deployment::ComponentPortDescription &compportdesc)
    {
      if (specificType)
	{
	  compportdesc.specificType = XMLString::transcode (specificType);
	}
    }

    /// handle supportedType attribute
    void process_specificType (const XMLCh* specificType, ::Deployment::ComponentPortDescription &compportdesc)
    {
      if (supportedType)
	{
	  compportdesc.supportedType = XMLString::transcode (supportedType);
	}
    }

    /// handle provider attribute
    void process_provider (const XMLCh* provider, ::Deployment::ComponentPortDescription &compportdesc)
    {
      if (provider)
	{
	  compportdesc.provider = XMLString::transcode (provider);
	}
    }

    /// handle exclusiveProvider attribute
    void process_exclusiveProvider (const XMLCh* exclusiveProvider, ::Deployment::ComponentPortDescription &compportdesc)
    {
      if (exclusiveProvider)
	{
	  compportdesc.exclusiveProvider = XMLString::transcode (exclusiveProvider);
	}
    }

    /// handle exclusiveUser attribute
    void process_exclusiveUser (const XMLCh* name, ::Deployment::ComponentPortDescription &compportdesc)
    {
      if (exclusiveUser)
	{
	  compportdesc.exclusiveUser = XMLString::transcode (exclusiveUser);
	}
    }

    /// handle optional attribute
    void process_optional (const XMLCh* name, ::Deployment::ComponentPortDescription &compportdesc)
    {
      if (optional)
	{
	  compportdesc.optional = XMLString::transcode (optional);
	}
    }

  }
}

#endif /* COMPPORTDESC_HANDLER_C */