summaryrefslogtreecommitdiff
path: root/trunk/CIAO/tools/Config_Handlers/Package_Handlers/CPD_Handler.cpp
blob: b857c893bf858038e661334ad9bf7d2968f41464 (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
// $Id$
#include "tao/AnyTypeCode/AnyTypeCode_methods.h"
#include "Package_Handlers/CPD_Handler.h"
#include "Package_Handlers/CID_Handler.h"
#include "Package_Handlers/Comp_Intf_Descr_Handler.h"
#include "Basic_Deployment_Data.hpp"
#include "DAnCE/Deployment/Deployment_Packaging_DataC.h"
#include "Deployment.hpp"
#include "Utils/Exceptions.h"
#include "Property_Handler.h"

namespace CIAO
{
  namespace Config_Handlers
  {
    namespace Packaging
    {
      struct Packaging_Handlers_Export PCI_Handler
      {
	static void handle_pci (const PackagedComponentImplementation &desc,
				::Deployment::PackagedComponentImplementation &toconfig)
	{
	  CIAO_TRACE ("PCI_Handler::get_pci");
	  toconfig.name = desc.name ().c_str ();

	  CID_Handler::component_impl_descr (desc.referencedImplementation (),
					     toconfig.referencedImplementation);
	}

	static PackagedComponentImplementation
	get_pci (const ::Deployment::PackagedComponentImplementation &src)
	{
	  CIAO_TRACE ("PCI_Handler::get_pci - reverse");
	  return PackagedComponentImplementation (src.name.in (),
						  CID_Handler::component_impl_descr (src.referencedImplementation));
	}
      };

      typedef Sequence_Handler < PackagedComponentImplementation,
				 ::Deployment::PackagedComponentImplementations,
				 ::Deployment::PackagedComponentImplementation,
				 PCI_Handler::handle_pci > PCI_Functor;
     

      void
      CPD_Handler::handle_component_package_descr (const ComponentPackageDescription &desc,
						   ::Deployment::ComponentPackageDescription &toconfig)
      {
        CIAO_TRACE ("CPD_Handler::component_package_descr");

        auto_ptr < ComponentPackageDescription > xsc_cpd;
        const ComponentPackageDescription *cpd = 0;

        if (desc.href_p ())
          {
            xsc_cpd.reset (CPD_Handler::resolve_cpd (desc.href ().c_str ()));
            cpd = xsc_cpd.get ();
          }
        else
          cpd = &desc;

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

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

        // CID
        if (cpd->realizes_p ())
          Comp_Intf_Descr_Handler::comp_intf_descr (cpd->realizes (),
                                                    toconfig.realizes);

        // Config Properties
        toconfig.configProperty.length (desc.count_configProperty ());
        std::for_each (cpd->begin_infoProperty (),
                       cpd->end_infoProperty (),
                       Property_Functor (toconfig.configProperty));

        //        ACE_ERROR ((LM_ERROR, "***** Count of PCIs is %i\n",
        //           cpd->count_implementation ()));

        // Packaged Component Implementations
        toconfig.implementation.length ( cpd->count_implementation ());
	SEQ_HAND_GCC_BUG_WORKAROUND (PCI_Handler::handle_pci,
				     cpd->begin_implementation (),
				     toconfig.implementation);
        std::for_each (cpd->begin_implementation (),
                       cpd->end_implementation (),
                       PCI_Functor (toconfig.implementation));

        // Info Properties
        toconfig.infoProperty.length (cpd->count_infoProperty ());
        std::for_each (cpd->begin_infoProperty (),
                       cpd->end_infoProperty (),
                       Property_Functor (toconfig.infoProperty));
      }

      ComponentPackageDescription
      CPD_Handler::component_package_descr (const Deployment::ComponentPackageDescription& src)
      {
        CIAO_TRACE ("CPD_Handler::component_package_descr - reverse");
        ComponentPackageDescription toconfig;

        if (src.label.in () != 0)
          toconfig.label (src.label.in ());

        if (src.UUID.in () != 0)
          toconfig.UUID (src.UUID.in ());

        {
          toconfig.realizes
            (Comp_Intf_Descr_Handler::comp_intf_descr (src.realizes));
        }

        for (size_t i = 0; i < src.configProperty.length (); ++i)
          {
            toconfig.add_configProperty (
					 Property_Handler::get_property (src.configProperty[i]));
          }

        { // Packaged Component Implementations
          for (size_t i = 0; i < src.implementation.length (); ++i)
            toconfig.add_implementation (
					 PCI_Handler::get_pci (src.implementation[i]));
        }

        for (size_t i = 0; i < src.infoProperty.length (); ++i)
          {
            toconfig.add_infoProperty (
				       Property_Handler::get_property (src.infoProperty[i]));
          }

        return toconfig;
      }

      ComponentPackageDescription * CPD_Handler::resolve_cpd (const char *uri)
      {
        CIAO_TRACE ("CPD_Handler::resolve_cpd");
        if (!XML_HELPER->is_initialized ())
          return 0;

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

        if (!dom)
          throw Parse_Error ("Unable to create DOM for component package description");

        try {
          //ACE_ERROR ((LM_ERROR, "Creating new CPD XSC Object\n"));
          return new ComponentPackageDescription (componentPackageDescription (dom));
        }
        catch (...) {
          throw Parse_Error ("Unable to create XSC structure for CID");
        }
      }
    }


  }
}