summaryrefslogtreecommitdiff
path: root/config_complex_types_1/Config_Handlers/IDD_Handler.cpp
blob: 758b395b3547918e83e852193ce74760cecb72de (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
// $Id$

#include "ace/UUID.h"
#include "IDD_Handler.h"
#include "IRDD_Handler.h"
#include "MDD_Handler.h"
#include "Property_Handler.h"
#include "Any_Handler.h"
#include "Basic_Deployment_Data.hpp"
#include "DAnCE/Deployment/Deployment_DataC.h"
#include "cdp.hpp"

namespace CIAO
{
  namespace Config_Handlers
  {
    IDREF_Base<CORBA::ULong> IDD_Handler::IDREF;

    void
    IDD_Handler::instance_deployment_descrs (
                                             const DeploymentPlan &src,
                                             Deployment::InstanceDeploymentDescriptions& dest)
      throw (Config_Error)
    {
      CIAO_TRACE("IDD_Handler::instance_deployment_descrs");
      DeploymentPlan::instance_const_iterator idd_e =
        src.end_instance ();

      CORBA::ULong pos = 0;
      dest.length (src.count_instance ());
      for (DeploymentPlan::instance_const_iterator idd_b =
             src.begin_instance ();
           idd_b != idd_e;
           ++idd_b)
        {
          IDD_Handler::instance_deployment_descr ((*idd_b),
                                                  dest[pos], pos);
          pos++;
        }
    }

    void
    IDD_Handler::instance_deployment_descr (
                                            const InstanceDeploymentDescription& src,
                                            Deployment::InstanceDeploymentDescription& dest,
                                            CORBA::ULong pos)
      throw (Config_Error)
    {
      CIAO_TRACE("IDD_Handler::instance_deployment_descr");
      try
        {
          dest.name = src.name ().c_str ();
          dest.node = src.node ().c_str ();

          if (src.id_p ())
            {
              ACE_CString cstr (src.id ().c_str ());
              IDD_Handler::IDREF.bind_ref (cstr, pos);
            }
          else
            {
              ACE_DEBUG((LM_ERROR,
                         "(%P|%t) Warning:  IDD %s has no idref \n",
                         src.name ().c_str ()));
            }

          // We know there should be only one element
          dest.source.length (1);
          dest.source [0] =
            src.source ().c_str ();

          CORBA::ULong tmp = 0;
          MDD_Handler::IDREF.find_ref
            (ACE_CString (src.implementation ().id ().c_str ()), tmp);

          dest.implementationRef = tmp;

          dest.configProperty.length (src.count_configProperty ());
          std::for_each (src.begin_configProperty (),
                         src.end_configProperty (),
                         Property_Functor (dest.configProperty));

          dest.deployedResource.length (src.count_deployedResource ());
          std::for_each (src.begin_deployedResource (),
                         src.end_deployedResource (),
                         IRDD_Functor (dest.deployedResource));

          if (src.deployedSharedResource_p ())
            {
              dest.deployedSharedResource.length (1);
              IRDD_Handler::instance_resource_deployment_descr (src.deployedSharedResource (),
                                                                dest.deployedSharedResource[0]);
            }

        }
      catch (Config_Error &ex)
        {
          ex.name_ = src.name ()  + ":" + ex.name_;
          throw ex;
        }
      // Done!
    }

    InstanceDeploymentDescription
    IDD_Handler::instance_deployment_descr (
                                            const Deployment::InstanceDeploymentDescription& src)
      throw (Config_Error)
    {
      CIAO_TRACE("IDD_Handler::instance_deployment_descr - reverse");
      //Get all the string/IDREFs
      XMLSchema::string < ACE_TCHAR > name ((src.name));
      XMLSchema::string < ACE_TCHAR > node ((src.node));
      XMLSchema::string < ACE_TCHAR > source ("");
      if (src.source.length () > 0)
      {
         XMLSchema::string < ACE_TCHAR > source_detail (src.source[0]);
         source = source_detail;
    }
      ACE_CString temp;
      MDD_Handler::IDREF.find_ref(src.implementationRef, temp);
      XMLSchema::IDREF< ACE_TCHAR > implementation ((temp.c_str()));

      // Instantiate the IDD
      InstanceDeploymentDescription idd (name, node, source, implementation);

      //Get and store the configProperty(s)
      size_t total = src.configProperty.length();
      for(size_t j = 0; j < total; j++)
        {
          idd.add_configProperty(
                                 Property_Handler::get_property (
                                                                 src.configProperty[j]));
        }

      // Get and store the deployedResource(s)
      size_t dp_total = src.deployedResource.length ();
      for (size_t k = 0; k < dp_total; k++)
        {
          idd.add_deployedResource (IRDD_Handler::instance_resource_deployment_descr (src.deployedResource[k]));
        }

      //Check if there is a deployedSharedResource, if so store it
      if(src.deployedSharedResource.length() != 0)
        idd. deployedSharedResource(IRDD_Handler::instance_resource_deployment_descr(src.deployedSharedResource[0]));

      // Generate a UUID to use for the IDREF.
      ACE_Utils::UUID uuid;
      ACE_Utils::UUID_GENERATOR::instance ()->generateUUID (uuid);
      ACE_CString idd_id ("_");
      idd_id += *uuid.to_string ();

      XMLSchema::ID< ACE_TCHAR > xml_id (idd_id.c_str ());

      // Bind the ref and set it in the IDD
      IDD_Handler::IDREF.bind_next_available (idd_id);

      idd.id (xml_id);

      return idd;
    }

  }
}