summaryrefslogtreecommitdiff
path: root/trunk/CIAO/tools/Config_Handlers/Package_Handlers/Comp_Intf_Descr_Handler.cpp
blob: f13260480ad4185c80069b513f015b3ccb6526b9 (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 "Comp_Intf_Descr_Handler.h"

#include "Utils/XML_Helper.h"
#include "Utils/Exceptions.h"
#include "Utils/Functors.h"
#include "DataType_Handler.h"
#include "Property_Handler.h"
#include "Deployment.hpp"
#include "Package_Handlers/CPD_Handler.h"
#include "tools/Config_Handlers/CPD_Handler.h"
#include "ciao/CIAO_common.h"
namespace CIAO
{
  namespace Config_Handlers
  {
    namespace Packaging
    {
        struct Comp_Prop_Handler
        {
          static void handle_cpd (const ComponentPropertyDescription &desc,
                               ::Deployment::ComponentPropertyDescription &toconfig)
          {
            CIAO_TRACE ("Comp_Prop_Handler::get_cpd");

            toconfig.name = desc.name ().c_str ();
            DataType_Handler::data_type (desc.type (),
                                         toconfig.type);
          }

          static ComponentPropertyDescription
          get_cpd (const ::Deployment::ComponentPropertyDescription &src)
          {
            CIAO_TRACE ("Comp_Prop_Handler::get_cpd - reverse");

            return ComponentPropertyDescription (src.name.in (),
                                                 DataType_Handler::data_type (src.type));
          }

        };

        typedef Sequence_Handler < ComponentPropertyDescription,
                                   ::Deployment::ComponentPropertyDescriptions,
                                   ::Deployment::ComponentPropertyDescription,
                                   Comp_Prop_Handler::handle_cpd > Comp_Prop_Functor;


      void
      Comp_Intf_Descr_Handler::comp_intf_descr (
                                                const ComponentInterfaceDescription &desc,
                                                ::Deployment::ComponentInterfaceDescription &toconfig)
      {
        CIAO_TRACE ("Comp_Intf_Descr_Handler::comp_intf_descr");

        const ComponentInterfaceDescription *cid = 0;
        std::auto_ptr <ComponentInterfaceDescription> safe_cid;

        if (desc.href_p ())
          {
            safe_cid.reset (Comp_Intf_Descr_Handler::resolve_cid (desc.href ().c_str ()));
            cid = safe_cid.get ();
          }
        else
          cid = &desc;

        if (cid->label_p ())
          toconfig.label = cid->label ().c_str ();

        if (cid->UUID_p ())
          toconfig.UUID = cid->UUID ().c_str ();

        // MAJO: SpecificType should be required.
        if (cid->specificType_p ())
          toconfig.specificType = cid->specificType ().c_str ();

        toconfig.supportedType.length (cid->count_supportedType ());
        std::for_each (cid->begin_supportedType (),
                       cid->end_supportedType (),
                       String_Seq_Functor (toconfig.supportedType));

        toconfig.idlFile.length (cid->count_idlFile ());
        std::for_each (cid->begin_idlFile (),
                       cid->end_idlFile (),
                       String_Seq_Functor (toconfig.idlFile));

        toconfig.configProperty.length (cid->count_configProperty ());
        std::for_each (cid->begin_configProperty (),
                       cid->end_configProperty (),
                       Property_Functor (toconfig.configProperty));

        toconfig.port.length (cid->count_port ());
        std::for_each (cid->begin_port (),
                       cid->end_port (),
                       CIAO::Config_Handlers::CPD_Functor (toconfig.port));

        toconfig.property.length (cid->count_property ());
	SEQ_HAND_GCC_BUG_WORKAROUND (Comp_Prop_Handler::handle_cpd,
				     cid->begin_property (),
				     toconfig.property);
        std::for_each (cid->begin_property (),
                       cid->end_property (),
                       Comp_Prop_Functor (toconfig.property));

        toconfig.infoProperty.length (cid->count_infoProperty ());
        std::for_each (cid->begin_infoProperty (),
                       cid->end_infoProperty (),
                       Property_Functor (toconfig.infoProperty));
      }


      ComponentInterfaceDescription
      Comp_Intf_Descr_Handler::comp_intf_descr (
                                                const ::Deployment::ComponentInterfaceDescription &src)
      {
        CIAO_TRACE ("Comp_Intf_Descr_Handler::comp_intf_descr - reverse");
        ComponentInterfaceDescription retval;

        retval.label (src.label.in ());
        retval.UUID (src.UUID.in ());
        retval.specificType (src.specificType.in ());

        for (CORBA::ULong i = 0; i < src.supportedType.length (); ++i)
          retval.add_supportedType (src.supportedType[i].in ());

        for (CORBA::ULong i = 0; i < src.idlFile.length (); ++i)
          retval.add_idlFile (src.idlFile[i].in ());

        for (CORBA::ULong i = 0; i < src.configProperty.length (); ++i)
          retval.add_configProperty (
                                     Property_Handler::get_property (src.configProperty[i]));

        for (CORBA::ULong i = 0; i < src.port.length (); ++i)
          retval.add_port
            (CIAO::Config_Handlers::CPD_Handler::component_port_description (src.port[i]));

        for (CORBA::ULong i = 0; i < src.property.length (); ++i)
          retval.add_property (Comp_Prop_Handler::get_cpd (src.property[i]));

        for (CORBA::ULong i = 0; i < src.infoProperty.length (); ++i)
          retval.add_infoProperty (
                                   Property_Handler::get_property (src.infoProperty[i]));

        return retval;
      }

      ComponentInterfaceDescription *
      Comp_Intf_Descr_Handler::resolve_cid (const char *uri)
      {
        CIAO_TRACE ("Comp_Intf_Descr_Handler::resolve_cid");

        xercesc::DOMDocument *dom = XML_HELPER->create_dom (uri);

        if (!dom)
          throw Parse_Error ("Unable to create DOM for Component Interface Description.");

        try {
          return new ComponentInterfaceDescription
            (componentInterfaceDescription (dom));
        }
        catch (...) {
          throw Parse_Error ("Unable to create XSC structure for Component Interface Description");
        }
      }
    }
  }}