summaryrefslogtreecommitdiff
path: root/modules/CIAO/DAnCE/NodeApplication/NodeApplication_Impl.cpp
blob: 23e44d52add9dc805c22ab2041536f5d1b934fbc (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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
// $Id$
#include "NodeApplication_Impl.h"

#include "ace/OS_Memory.h"

#include "ace/streams.h"
#include "tao/AnyTypeCode/Any.h"
#include "tao/Object.h"
#include "tao/ORB.h"
#include "ccm/CCM_ObjectC.h"
#include "ccm/CCM_SessionComponentC.h"
#include "ciao/Valuetype_Factories/ConfigValue.h"
#include "ciao/ComponentServer/CIAO_ServerActivator_Impl.h"
#include "ciao/ComponentServer/CIAO_ComponentInstallation_Impl.h"
#include "ciao/ComponentServer/CIAO_PropertiesC.h"
#include "DAnCE/Logger/Log_Macros.h"
#include "Deployment/Deployment_BaseC.h"
#include "Deployment/Deployment_ApplicationC.h"
#include "Deployment/Deployment_PlanErrorC.h"
#include "Deployment/Deployment_ApplicationManagerC.h"
#include "DAnCE/Deployment_common.h"
#include "DAnCE/DAnCE_PropertiesC.h"
#include "ComponentAttributesSetter.h"
#include "Name_Utilities.h"

#include <string>

#ifdef GEN_OSTREAM_OPS
#include <iostream>
#include <sstream>
#endif /* GEN_OSTREAM_OPS */

using namespace DAnCE;

namespace
{
  template<class T>
  bool get_property_value (const char *name, PROPERTY_MAP &properties, T &val)
  {
    DANCE_TRACE ("NodeApplication::<anonymous>::get_property_value<T>");
    CORBA::Any any;

    DANCE_DEBUG (9, (LM_TRACE, DLINFO
                  ACE_TEXT("NodeApplication::<anonymous>::get_property_value<T> - ")
                  ACE_TEXT("Finding property value for name '%C'\n"),
                  name));

    if (properties.find (name, any) == 0)
      {
        if (any >>= val)
          {
            return true;
          }
        else
          {
            DANCE_ERROR (1, (LM_WARNING, DLINFO
                          ACE_TEXT("NodeApplication::<anonymous>::get_property_value<T> - ")
                          ACE_TEXT("Failed to extract property value for %C\n"), name));
            return false;
          }
      }

    DANCE_DEBUG (9, (LM_TRACE, DLINFO
                  ACE_TEXT("NodeApplication::<anonymous>::get_property_value<T> - ")
                  ACE_TEXT("Property value for name '%C' has no value\n"), name));

    return false;
  }

  template<>
  bool get_property_value (const char *name, PROPERTY_MAP &properties, bool &val)
  {
    DANCE_TRACE ("NodeApplication::<anonymous>::get_property_value<bool>");

    DANCE_DEBUG (9, (LM_TRACE, DLINFO ACE_TEXT("NodeApplication::<anonymous>::get_property_value<bool> - ")
                  ACE_TEXT("Finding property value for name '%C'\n"),
                  name));

    CORBA::Any any;
    if (properties.find (name, any) == 0)
      {
        if (any >>= CORBA::Any::to_boolean(val))
          {
            return true;
          }
        else
          {
            DANCE_ERROR (1, (LM_WARNING, DLINFO ACE_TEXT("NodeApplication::<anonymous>::get_property_value<T> - ")
                          ACE_TEXT("Failed to extract property value for %C\n"), name));
            return false;
          }
      }

    DANCE_DEBUG (9, (LM_TRACE, DLINFO ACE_TEXT("NodeApplication::<anonymous>::get_property_value<bool> - ")
                  ACE_TEXT("Property value for name '%C' has no value\n"), name));

    return false;
  }

  template<>
  bool get_property_value (const char *name, PROPERTY_MAP &properties, const char * &val)
  {
    DANCE_TRACE ("NodeApplication::<anonymous>::get_property_value<const char *>");
    CORBA::Any any;

    DANCE_DEBUG (9, (LM_TRACE, DLINFO ACE_TEXT("NodeApplication::<anonymous>::get_property_value<bool> - ")
                  ACE_TEXT("Finding property value for name '%C'\n"),
                  name));

    if (properties.find (name, any) == 0)
      {
        if (any >>= CORBA::Any::to_string(val, 0))
          {
            return true;
          }
        else
          {
            DANCE_ERROR (1, (LM_WARNING, DLINFO ACE_TEXT("NodeApplication::<anonymous>::get_property_value<const char *> - ")
                          ACE_TEXT("Failed to extract property value for %C\n"), name));
            return false;
          }
      }

    DANCE_DEBUG (9, (LM_TRACE, DLINFO ACE_TEXT("NodeApplication::<anonymous>::get_property_value<bool> - ")
                  ACE_TEXT("Property value for name '%C' has no value\n"), name));

    return false;
  }

  template<class T>
  bool get_property_value (const char *name, const ::Deployment::Properties &properties, T &val)
  {
    DANCE_TRACE ("NodeApplication::<anonymous>::get_property_value<T>");

    DANCE_DEBUG (9, (LM_TRACE, DLINFO ACE_TEXT("NodeApplication::<anonymous>::get_property_value<T> - ")
                  ACE_TEXT("Finding property value for name '%C'\n"),
                  name));

    for (CORBA::ULong i = 0; i < properties.length (); ++i)
      {
        if (ACE_OS::strcmp (properties[i].name.in (), name) == 0)
          {
            DANCE_DEBUG (9, (LM_TRACE, DLINFO ACE_TEXT("NodeApplication::<anonymous>::get_property_value<T> - ")
                          ACE_TEXT("Found property '%C'\n"), name));
            if (properties[i].value >>= val)
              return true;
            else
              {
                DANCE_ERROR (1, (LM_WARNING, DLINFO ACE_TEXT("NodeApplication::<anonymous>::get_property_value<T> - ")
                              ACE_TEXT("Failed to extract property value for %C\n"), name));
                return false;
              }
          }
      }


    DANCE_DEBUG (9, (LM_TRACE, DLINFO ACE_TEXT("NodeApplication::<anonymous>::get_property_value<T> - ")
                  ACE_TEXT("Property value for name '%C' has no value\n"), name));

    return false;
  }

  template<>
  bool get_property_value (const char *name, const ::Deployment::Properties &properties, const char * &val)
  {
    DANCE_TRACE ("NodeApplication::<anonymous>::get_property_value<const char *>");

    DANCE_DEBUG (9, (LM_TRACE, DLINFO ACE_TEXT("NodeApplication::<anonymous>::get_property_value<T> - ")
                  ACE_TEXT("Finding property value for name '%C'\n"),
                  name));

    for (CORBA::ULong i = 0; i < properties.length (); ++i)
      {
        if (ACE_OS::strcmp (properties[i].name.in (), name) == 0)
          {
            DANCE_DEBUG (9, (LM_TRACE, DLINFO ACE_TEXT("NodeApplication::<anonymous>::get_property_value<T> - ")
                          ACE_TEXT("Found property '%C'\n"), name));
            if (properties[i].value >>= CORBA::Any::to_string (val, 0))
              {
                DANCE_DEBUG (9, (LM_TRACE,
                              DLINFO ACE_TEXT("NodeApplication::<anonymous>::get_property_value<T> - ")
                              ACE_TEXT("Value is %C\n"), val));
                return true;
              }
            else
              {
                DANCE_ERROR (1, (LM_WARNING, DLINFO ACE_TEXT("NodeApplication::<anonymous>::get_property_value<T> - ")
                              ACE_TEXT("Failed to extract property value for %C\n"), name));
                return false;
              }
          }
      }


    DANCE_DEBUG (9, (LM_TRACE, DLINFO ACE_TEXT("NodeApplication::<anonymous>::get_property_value<T> - ")
                  ACE_TEXT("Unable to find property named %C\n"), name));

    return false;
  }

  /// Tests flag, if false, sets it to true and replaces the name and
  /// reason flags of the exception.
  template <typename EXCEPTION>
  void test_and_set_exception (bool &flag, EXCEPTION &exception,
                               const char *name, const char *reason)
  {
    if (!flag)
      {
        flag = true;
        exception.name = name;
        exception.reason = reason;
      }
  }

  void append_properties (::Deployment::Properties &dest,
        const ::Deployment::Properties &src)
  {
    const char* edu_prop = "edu.vanderbilt.dre.CIAO.ComponentServer.";
    for (CORBA::ULong i = 0; i < src.length (); ++i)
      {
        if (ACE_OS::strncmp (src[i].name.in (), edu_prop, ACE_OS::strlen (edu_prop)) == 0)
          {
            DANCE_DEBUG (9, (LM_TRACE, DLINFO
                      ACE_TEXT("NodeApplication::append_properties - ")
                      ACE_TEXT("Adding property %C\n"), src[i].name.in ()));
            CORBA::ULong const dest_length = dest.length ();
            dest.length (dest_length + 1);
            dest[dest_length].name = CORBA::string_dup (src[i].name.in ());
            dest[dest_length].value = src[i].value;
          }
      }
  }
}


NodeApplication_Impl::NodeApplication_Impl (CORBA::ORB_ptr orb,
                                            PortableServer::POA_ptr poa,
                                            const ::Deployment::DeploymentPlan& plan,
                                            const ACE_CString& node_name,
                                            const PROPERTY_MAP &properties)
  : orb_ (CORBA::ORB::_duplicate (orb)),
    poa_ (PortableServer::POA::_duplicate (poa)),
    plan_ (plan),
    node_name_ (node_name),
    properties_ (),
    instances_ (plan.instance.length ())
{
  DANCE_TRACE ("NodeApplication_Impl::NodeApplication_Impl");
  PROPERTY_MAP::const_iterator i = properties.begin ();
  while (!i.done ())
    {
      DANCE_DEBUG (6, (LM_DEBUG, DLINFO ACE_TEXT("NodeApplication_Impl::NodeApplication_Impl - ")
                    ACE_TEXT("Binding value for property '%C'\n"), i->key ().c_str ()));
      this->properties_.bind (i->key (), i->item ());
      i.advance ();
    }
  this->init ();
}

NodeApplication_Impl::~NodeApplication_Impl()
{
  DANCE_TRACE( "NodeApplication_Impl::~NodeApplication_Impl()");

  using namespace Components;
  ConfigValues config_values;
  config_values.length (1L);
  CORBA::Any feature_any;

  /* TODO: This is highly suspect.  I believe we should be using get_component_server,
     not calling create_container. */
  DANCE_DEBUG (9, (LM_TRACE, DLINFO ACE_TEXT("NodeApplication_Impl::~NodeApplication_Impl - ")
                ACE_TEXT("Deactivating %u ComponentServers\n"),
                this->servers_.size ()));
  for (size_t i = 0; i < this->servers_.size (); ++i)
    {
      ComponentServer &server = this->servers_[i];

      DANCE_DEBUG (9, (LM_TRACE, DLINFO ACE_TEXT("NodeApplication_Impl::~NodeApplication_Impl - ")
                    ACE_TEXT("In ComponentServer %u, deactivating %u containers\n"), i, server.containers.size ()));
      for (size_t j = 0; j < server.containers.size (); ++j)
        {
          Container &container = server.containers[j];

          DANCE_DEBUG (9, (LM_TRACE, DLINFO ACE_TEXT("NodeApplication_Impl::~NodeApplication_Impl - ")
                        ACE_TEXT("In container %u hosted in server %u\n"), j, i));

          try
            {
              if (!CORBA::is_nil (container.ref))
                server.ref->remove_container (container.ref.in ());

              container.ref = CIAO::Deployment::Container::_nil ();
            }
          catch (const CORBA::Exception &ex)
            {
              DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT("NodeApplication_Impl::~NodeApplication_Impl - ")
                            ACE_TEXT("Caught CORBA exception while removing container %u on server %u: %C\n"),
                            j, i, ex._info ().c_str ()));
            }
          catch (...)
            {
              DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT("NodeApplication_Impl::~NodeApplication_Impl - ")
                            ACE_TEXT("Caught unknown C++ exception while removing container %u on server %u.\n"),
                            j, i));
            }
        }

      DANCE_DEBUG (9, (LM_TRACE, DLINFO ACE_TEXT("NodeApplication_Impl::~NodeApplication_Impl - ")
                    ACE_TEXT("Removing component server %u\n"), i));

      try
        {
          if (!CORBA::is_nil (server.ref))
            this->activator_->remove_component_server (server.ref.in ());
        }
      catch (const CORBA::Exception &ex)
        {
          DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT("NodeApplication_Impl::~NodeApplication_Impl - ")
                        ACE_TEXT("Caught CORBA exception while removing server %u: %C\n"),
                        i, ex._info ().c_str ()));
        }
      catch (...)
        {
          DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT("NodeApplication_Impl::~NodeApplication_Impl - ")
                        ACE_TEXT("Caught unknown C++ exception while removing server %u.\n"),
                        i));
        }

      DANCE_DEBUG (8, (LM_INFO, DLINFO ACE_TEXT("NodeApplication_Impl::~NodeApplication_Impl - ")
                    ACE_TEXT("Successfully removed container %u on node %C.\n"),
                    i, this->node_name_.c_str ()));
    }
}

void
NodeApplication_Impl::init()
{
  DANCE_TRACE( "NodeApplication_Impl::init()");

  /* TODO:  Lets move this stuff to the constructor, shall we?!? */
  /* TODO:  Might be nice to use a component configurator here to load the proper versions
     of the serveractivator.  */

  /* ServerActivator configuration */
  CORBA::ULong spawn = 0;
  const char *cs_path = 0;
  const char *cs_args = 0;
  CORBA::Boolean multithread = false;

  get_property_value (CIAO::Deployment::SERVER_EXECUTABLE, this->properties_, cs_path);
  DANCE_DEBUG (6, (LM_DEBUG, DLINFO ACE_TEXT("NodeApplication_Impl::init - ")
                ACE_TEXT("Component server path: %C\n"), cs_path));
  get_property_value (CIAO::Deployment::SERVER_ARGUMENTS, this->properties_, cs_args);
  DANCE_DEBUG (6, (LM_DEBUG, DLINFO ACE_TEXT("NodeApplication_Impl::init - ")
                ACE_TEXT("Component server arguments: %C\n"), cs_args));
  get_property_value (CIAO::Deployment::SERVER_TIMEOUT, this->properties_, spawn);
  DANCE_DEBUG (6, (LM_DEBUG, DLINFO ACE_TEXT("NodeApplication_Impl::init - ")
                ACE_TEXT("Spawn delay: %u\n"), spawn));
  get_property_value (CIAO::Deployment::SERVER_MULTITHREAD, this->properties_, multithread);
  DANCE_DEBUG (6, (LM_DEBUG, DLINFO ACE_TEXT("NodeApplication_Impl::init - ")
                ACE_TEXT("Threading: %C\n"), multithread ? "Multi" : "Single"));

  DANCE_DEBUG (9, (LM_TRACE, DLINFO ACE_TEXT("NodeApplication_Impl::init - ")
                ACE_TEXT("Spawning server activator\n")));

  CIAO::Deployment::ComponentInstallation_Impl *tmp_ci = 0;

  ACE_NEW_THROW_EX (tmp_ci,
                    CIAO::Deployment::ComponentInstallation_Impl (),
                    CORBA::NO_MEMORY ());

  PortableServer::ServantBase_var safe_servant = tmp_ci;

  PortableServer::ObjectId_var id = this->poa_->activate_object (tmp_ci);
  CORBA::Object_var ci_object = this->poa_->id_to_reference (id.in ());
  Components::Deployment::ComponentInstallation_var ci =
      Components::Deployment::ComponentInstallation::_narrow (ci_object.in ());

  for (CORBA::ULong i = 0; i < this->plan_.artifact.length (); ++i)
    {
      tmp_ci->install (this->plan_.artifact[i].name,
                       this->plan_.artifact[i].location[0]);
    }

  CIAO::Deployment::CIAO_ServerActivator_i *tmp_act = 0;
  ACE_NEW_THROW_EX (tmp_act,
                    CIAO::Deployment::CIAO_ServerActivator_i (spawn,
                                                              cs_path,
                                                              cs_args,
                                                              multithread,
                                                              ci.in (),
                                                              this->orb_.in(),
                                                              this->poa_.in()),
                    CORBA::NO_MEMORY ());
  this->activator_.reset (tmp_act);

  PortableServer::ObjectId_var sa_id =
    this->poa_->activate_object (this->activator_.get ());

  DANCE_DEBUG (9, (LM_TRACE, DLINFO ACE_TEXT("NodeApplication_Impl::init - ServerActivator object created\n")));

  const ACE_TCHAR *ior = 0;

  if (get_property_value (DAnCE::INSTANCE_NC, this->properties_, ior) ||
      get_property_value (DAnCE::DOMAIN_NC, this->properties_, ior))
    {
      try
        {
          CORBA::Object_var obj = this->orb_->string_to_object (ior);
          this->instance_nc_ = CosNaming::NamingContext::_narrow (obj);
        }
      catch (const CORBA::Exception &e)
        {
          DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT("NodeApplication_Impl::init - ")
                        ACE_TEXT("Unable to resolve the instance naming context:%C\n"),
                        e._info ().c_str ()));
        }
      DANCE_DEBUG (6, (LM_DEBUG, DLINFO ACE_TEXT("NodeApplication_Impl::init - ")
                    ACE_TEXT("Successfully resolved the instance naming context.\n")));
    }
  else DANCE_DEBUG (6, (LM_DEBUG, DLINFO ACE_TEXT("NodeApplication_Impl::init - ")
                     ACE_TEXT("No instance NC was provided\n")));
}

void
NodeApplication_Impl::configuration_complete_components ()
{
  DANCE_TRACE( "NodeApplication_Impl::configuration_complete_components");

  bool error = false;
  ::Deployment::StartError exception;

  for (INSTANCES::size_type k = 0; k < this->instances_.size (); ++k)
    {
      if (!this->instances_[k] ||
          this->instances_[k]->type == eHome ||
          this->instances_[k]->type == eComponentServer)
        {
          DANCE_DEBUG (9, (LM_TRACE, DLINFO
                           ACE_TEXT("NodeApplication_Impl::configuration_complete_components - ")
                           ACE_TEXT("Skipping non-component instance\n")));
          continue;
        }

      DANCE_DEBUG (9, (LM_TRACE, DLINFO ACE_TEXT("NodeApplication_Impl::configuration_complete_components - ")
                    ACE_TEXT("Invoking configuration_complete on component instance %C on node %C\n"),
                    this->plan_.instance[this->instances_[k]->idd_idx].name.in (),
                    this->node_name_.c_str ()));

      try
        {
          Components::CCMObject_var ccmobj =
            Components::CCMObject::_narrow (this->instances_[k]->ref.in ());
          if (CORBA::is_nil (this->instances_[k]->ref))
            {
              DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT("NodeApplication_Impl::configuration_complete_components - ")
                            ACE_TEXT("Failed to narrow object reference for component instance %C\n"),
                            this->plan_.instance[this->instances_[k]->idd_idx].name.in ()));
              continue;
            }

          if (this->instances_[k]->state == eInstalled)
            {
              ccmobj->configuration_complete ();
              this->instances_[k]->state = eConfigured;
            }
          else
            {
              if (!error)
                {
                  error = true;
                  exception.name = this->plan_.instance[this->instances_[k]->idd_idx].name.in ();
                  exception.reason = "Attempting to activate component that has already passed the configure stage.\n";
                  continue;
                }
            }

          DANCE_DEBUG (8, (LM_INFO, DLINFO ACE_TEXT("NodeApplication_Impl::configuration_complete_components - ")
                        ACE_TEXT("Component %C successfully configured.\n"),
                        this->plan_.instance[this->instances_[k]->idd_idx].name.in ()));
        }
      catch (const CORBA::Exception &ex)
        {
          DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT("NodeApplication_Impl::configuration_complete_components - ")
                        ACE_TEXT("Caught CORBA exception from ccm_activate on component %C: %C\n"),
                        this->plan_.instance[this->instances_[k]->idd_idx].name.in (),
                        ex._info ().c_str ()));
          if (!error)
            {
              error = true;
              exception.name = this->plan_.instance[this->instances_[k]->idd_idx].name.in ();
              exception.reason = ex._info ().c_str ();
            }
        }
      catch (...)
        {
          DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT("NodeApplication_Impl::configuration_complete_components - ")
                        ACE_TEXT("Caught unknown C++ exception from ccm_activate on component %C\n"),
                        this->plan_.instance[this->instances_[k]->idd_idx].name.in ()));
          if (!error)
            {
              error = true;
              exception.name = this->plan_.instance[this->instances_[k]->idd_idx].name.in ();
              exception.reason = "Unknown C++ exception";
            }
        }
    }

  if (error)
    throw exception;
}

void
NodeApplication_Impl::start ()
{
  DANCE_TRACE( "NodeApplication_Impl::start");

  bool error (false);
  ::Deployment::StartError exception;

  for (INSTANCES::size_type k = 0; k < this->instances_.size (); ++k)
    {
      if (this->instances_[k]->type == eHome ||
          this->instances_[k]->type == eComponentServer)
        {
          continue;
        }

      DANCE_DEBUG (9, (LM_TRACE, DLINFO ACE_TEXT("NodeApplication_Impl::start - ")
                    ACE_TEXT("Invoking start on component instance %C on node %C\n"),
                    this->plan_.instance[this->instances_[k]->idd_idx].name.in (),
                    this->node_name_.c_str ()));

      try
        {
          CIAO::Deployment::Container_var cont =
            CIAO::Deployment::Container::_narrow (this->instances_[k]->container->ref.in());

          if (CORBA::is_nil (this->instances_[k]->container->ref.in ()))
            {
              DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT("NodeApplication_Impl::start - ")
                            ACE_TEXT("Failed to narrow object reference for container managing ")
                            ACE_TEXT("component instance %C to a CIAO container reference\n"),
                            this->plan_.instance[this->instances_[k]->idd_idx].name.in ()));
              test_and_set_exception (error, exception,
                                      this->plan_.instance[this->instances_[k]->idd_idx].name.in (),
                                      "Failed to narrow managing container to CIAO container type");
              continue;
            }

          if (this->instances_[k]->state == eConfigured ||
              this->instances_[k]->state == ePassive)
            {
              Components::CCMObject_var comp (Components::CCMObject::_narrow (this->instances_[k]->ref));
              cont->activate_component (comp.in ());
              this->instances_[k]->state = eActive;
            }
          else
            {
              if (!error)
                {
                  error = true;
                  exception.name = this->plan_.instance[this->instances_[k]->idd_idx].name.in ();
                  exception.reason = "Attempting to activate component that is not configured or passive.\n";
                }
            }

          DANCE_DEBUG (8, (LM_INFO, DLINFO ACE_TEXT("NodeApplication_Impl::start - ")
                        ACE_TEXT("Component %C successfully activated.\n"),
                        this->plan_.instance[this->instances_[k]->idd_idx].name.in ()));
        }
      catch (const CORBA::Exception &ex)
        {
          DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT("NodeApplication_Impl::start - ")
                        ACE_TEXT("Caught CORBA exception from ccm_activate on component %C: %C\n"),
                        this->plan_.instance[this->instances_[k]->idd_idx].name.in (),
                        ex._info ().c_str ()));
          if (!error)
            {
              error = true;
              exception.name = this->plan_.instance[this->instances_[k]->idd_idx].name.in ();
              exception.reason = ex._info ().c_str ();
            }
        }
      catch (...)
        {
          DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT("NodeApplication_Impl::start - ")
                        ACE_TEXT("Caught unknown C++ exception from ccm_activate on component %C\n"),
                        this->plan_.instance[this->instances_[k]->idd_idx].name.in ()));
          if (!error)
            {
              error = true;
              exception.name = this->plan_.instance[this->instances_[k]->idd_idx].name.in ();
              exception.reason = "Unknown C++ exception";
            }
        }
    }

  if (error)
    throw exception;
}

void
NodeApplication_Impl::install_home (Container &cont, Instance &inst)
{
  DANCE_TRACE( "NodeApplication_Impl::install_home");

  const ::Deployment::MonolithicDeploymentDescription &mdd =
    this->plan_.implementation[inst.mdd_idx];
  const ::Deployment::InstanceDeploymentDescription &idd =
    this->plan_.instance[inst.idd_idx];

  DANCE_DEBUG (6, (LM_DEBUG, DLINFO ACE_TEXT("NodeApplication_Impl::install_home - ")
                ACE_TEXT("Starting installation of home %C on node %C\n"),
                idd.name.in (), idd.node.in ()));

  this->instances_[inst.idd_idx] = &inst;

  // Need to get significant property values
  const char *entrypt = 0;
  get_property_value (DAnCE::HOME_FACTORY, mdd.execParameter, entrypt);

  if (entrypt == 0)
    {
      DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT("NodeApplication_Impl::install_home - ")
                    ACE_TEXT("Unable to find home factory property on home %C\n"),
                    idd.name.in ()));
      throw ::Deployment::InvalidComponentExecParameter (mdd.name.in (),
                                                         "No 'home factory' property present on MDD\n");
    }

  // @@TODO: Perhaps need better way to do this.
  Components::ConfigValues config;
  config.length (mdd.execParameter.length () + idd.configProperty.length ());
  CORBA::ULong pos (0);

  for (CORBA::ULong i = 0; i < mdd.execParameter.length (); ++i)
    {
      DANCE_DEBUG (9, (LM_TRACE, DLINFO ACE_TEXT("NodeApplication_Impl::install_home - ")
                    ACE_TEXT("Inserting value for execParameter %C\n"), mdd.execParameter[i].name.in ()));
      config[pos++] = new CIAO::ConfigValue_impl (mdd.execParameter[i].name.in (),
                                                  mdd.execParameter[i].value);
    }

  for (CORBA::ULong i = 0; i < idd.configProperty.length (); ++i)
    {
      DANCE_DEBUG (9, (LM_TRACE, DLINFO ACE_TEXT("NodeApplication_Impl::install_home - ")
                    ACE_TEXT("Inserting value for configProperty %C\n"), idd.configProperty[i].name.in ()));
      config[pos++] =  new CIAO::ConfigValue_impl (idd.configProperty[i].name.in (),
                                                   idd.configProperty[i].value);
    }

  try
    {
      DANCE_DEBUG (6, (LM_DEBUG, DLINFO ACE_TEXT("NodeApplication_Impl::install_home - ")
                    ACE_TEXT("Calling install_home on container.  Home id '%C', entrypt '%C', ")
                    ACE_TEXT("length of config values is %u\n"),
                    idd.name.in (), entrypt, config.length ()));

      ::Components::CCMHome_var home = cont.ref->install_home (idd.name.in (),
                                                               entrypt,
                                                               config);

      if (CORBA::is_nil (home))
        {
          DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT("NodeApplication_Impl::install_home - ")
                        ACE_TEXT("Got nil object reference from container while installing home %C on node %C,")
                        ACE_TEXT("throwing PlanError\n"),
                        idd.name.in (), idd.node.in ()));
          throw ::Deployment::PlanError (idd.name.in (),
                                         "Nil object reference returned from conainer");
        }

      DANCE_DEBUG (8, (LM_INFO, DLINFO  ACE_TEXT("NodeApplication_Impl::install_home - ")
                    ACE_TEXT("Home '%C' on node '%C' successfully installed\n"),
                    idd.name.in (), idd.node.in ()));

      inst.ref = CORBA::Object::_narrow (home);

      DANCE_DEBUG (9, (LM_TRACE, DLINFO ACE_TEXT("NodeApplication_Impl::install_home - ")
                    ACE_TEXT("Populating attributes for home %C\n"),
                    idd.name.in ()));


      ComponentAttributesSetter::SetComponentAttributes (idd.name.in (),
                                                         inst.ref.in (),
                                                         idd.configProperty,
                                                         this->orb_.in ());

      inst.state = eInstalled;
    }
  catch (const Components::InvalidConfiguration &)
    {
      DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT("NodeApplication_Impl::install_home - ")
                    ACE_TEXT("Error creating home %C on node %C, caught InvalidConfiguration.  Throwing exception\n"),
                    idd.name.in (), idd.node.in ()));
      throw ::Deployment::InvalidProperty (idd.name.in (),
                                     "Invalid configuration exception from container");
    }
  catch (const CORBA::Exception &ex)
    {
      DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT("NodeApplication_Impl::install_home - ")
                    ACE_TEXT("Caught CORBA exception while installing home %C: %C\n"),
                    idd.name.in (),
                    ex._info ().c_str ()));
      throw ::Deployment::StartError (idd.name.in (),
                                      ex._info ().c_str ());
    }
  catch (...)
    {
      DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT("NodeApplication_Impl::install_home - ")
                    ACE_TEXT("Caught unknown C++ exception while installing home %C\n"),
                    idd.name.in ()));
      throw ::Deployment::StartError (idd.name.in (),
                                      "Unknown C++ exception");
    }
}

void
NodeApplication_Impl::install_component (Container &cont, Instance &inst)
{
  DANCE_TRACE( "NodeApplication_Impl::install_component");

  ::Deployment::MonolithicDeploymentDescription const &mdd =
    this->plan_.implementation[inst.mdd_idx];
  ::Deployment::InstanceDeploymentDescription const &idd =
    this->plan_.instance[inst.idd_idx];

  DANCE_DEBUG (6, (LM_DEBUG, DLINFO ACE_TEXT("NodeApplication_Impl::install_home - ")
                ACE_TEXT("Starting installation of home %C on node %C\n"),
                idd.name.in (), idd.node.in ()));

  this->instances_[inst.idd_idx] = &inst;

  const char *entrypt = 0;
  get_property_value (DAnCE::COMPONENT_FACTORY, mdd.execParameter, entrypt);

  if (entrypt == 0)
    {
      DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT("NodeApplication_Impl::install_component - ")
                    ACE_TEXT("Unable to find component factory property on component %C\n"),
                    idd.name.in ()));
      throw ::Deployment::InvalidComponentExecParameter (mdd.name.in (),
                                                         "No 'component factory' property present on MDD\n");
    }

  // @@TODO: Perhaps need better way to do this.
  Components::ConfigValues config;
  config.length (mdd.execParameter.length () + idd.configProperty.length ());
  CORBA::ULong pos (0);

    for (CORBA::ULong i = 0; i < mdd.execParameter.length (); ++i)
    {
      DANCE_DEBUG (9, (LM_TRACE, DLINFO ACE_TEXT("NodeApplication_Impl::install_component - ")
                    ACE_TEXT("Inserting value for execParameter %C\n"), mdd.execParameter[i].name.in ()));
      config[pos++] = new CIAO::ConfigValue_impl (mdd.execParameter[i].name.in (),
                                                  mdd.execParameter[i].value);
    }

  for (CORBA::ULong i = 0; i < idd.configProperty.length (); ++i)
    {
      DANCE_DEBUG (9, (LM_TRACE, DLINFO ACE_TEXT("NodeApplication_Impl::install_component - ")
                    ACE_TEXT("Inserting value for configProperty %C\n"), idd.configProperty[i].name.in ()));
      config[pos++] =  new CIAO::ConfigValue_impl (idd.configProperty[i].name.in (),
                                                   idd.configProperty[i].value);
    }

  ::CIAO::Deployment::Container_var ciao_cont = ::CIAO::Deployment::Container::_narrow (cont.ref.in ());

  if (CORBA::is_nil (ciao_cont.in ()))
    {
      DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT("NodeApplication_Impl::install_component - ")
                    ACE_TEXT("Unable to narrow container assigned for component instance %C to one that supports ")
                    ACE_TEXT("un-homed components.\n")));
      throw ::Deployment::PlanError (idd.name.in (),
                                     "Hosting container does not support unhomed components.\n");
    }

  try
    {
      DANCE_DEBUG (6, (LM_DEBUG, DLINFO ACE_TEXT("NodeApplication_Impl::install_component - ")
                    ACE_TEXT("Calling install_component on container.  Component id '%C', entrypt '%C', ")
                    ACE_TEXT("length of config values is %u\n"),
                    idd.name.in (), entrypt, config.length ()));

      ::Components::CCMObject_var comp = ciao_cont->install_component (idd.name.in (),
                                                                       entrypt,
                                                                       config);

      if (CORBA::is_nil (comp))
        {
          DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT("NodeApplication_Impl::install_component - ")
                        ACE_TEXT("Got nil object reference from container while installing component %C on node %C,")
                        ACE_TEXT("throwing PlanError\n"),
                        idd.name.in (), idd.node.in ()));
          throw ::Deployment::PlanError (idd.name.in (),
                                         "Nil object reference returned from install_component on conainer");
        }

      DANCE_DEBUG (8, (LM_INFO, DLINFO ACE_TEXT("NodeApplication_Impl::install_component - ")
                    ACE_TEXT("Component '%C' on node '%C' successfully installed\n"),
                    idd.name.in (), idd.node.in ()));

      inst.ref = CORBA::Object::_narrow (comp);

      DANCE_DEBUG (9, (LM_TRACE, DLINFO ACE_TEXT("NodeApplication_Impl::install_component - ")
                    ACE_TEXT("Populating attributes for home %C\n"),
                    idd.name.in ()));


      ComponentAttributesSetter::SetComponentAttributes (idd.name.in (),
                                                         inst.ref.in (),
                                                         idd.configProperty,
                                                         this->orb_.in ());

      inst.state = eInstalled;
    }
    catch (const Components::InvalidConfiguration &)
    {
      DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT("NodeApplication_Impl::install_component - ")
                    ACE_TEXT("Error creating component %C on node %C, caught InvalidConfiguration. Throwing exception\n"),
                    idd.name.in (), idd.node.in ()));
      throw ::Deployment::InvalidProperty (idd.name.in (),
                                           "Invalid configuration exception from container");
    }
  catch (const CORBA::Exception &ex)
    {
      DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT("NodeApplication_Impl::install_component - ")
                    ACE_TEXT("Caught CORBA exception while installing component %C: %C\n"),
                    idd.name.in (),
                    ex._info ().c_str ()));
      throw ::Deployment::StartError (idd.name.in (),
                                      ex._info ().c_str ());
    }
  catch (...)
    {
      DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT("NodeApplication_Impl::install_component - ")
                    ACE_TEXT("Caught unknown C++ exception while installing component %C\n"),
                    idd.name.in ()));
      throw ::Deployment::StartError (idd.name.in (),
                                      "Unknown C++ exception");
    }
}

void
NodeApplication_Impl::install_homed_component (Container &cont, Instance &inst)
{
  DANCE_TRACE("NodeApplication_Impl::install_homed_component (unsigned int index)");

  ::Deployment::InstanceDeploymentDescription const &idd =
    this->plan_.instance[inst.idd_idx];
  this->instances_[inst.idd_idx] = &inst;

  DANCE_DEBUG (9, (LM_TRACE, DLINFO ACE_TEXT("NodeApplication_Impl::install_homed_component - ")
                ACE_TEXT("Starting installation of homed component %C on node %C\n"),
                idd.name.in (),
                idd.node.in ()));

  const char *home_id = 0;
  get_property_value (DAnCE::EXPLICIT_HOME, idd.configProperty, home_id);

  DANCE_DEBUG (6, (LM_DEBUG, DLINFO ACE_TEXT("NodeApplication_Impl::install_homed_component - ")
                ACE_TEXT("Property %C has value %C\n"),
                DAnCE::EXPLICIT_HOME, home_id));


  if (home_id == 0)
    {
      DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT("Nodeapplication_Impl::install_homed_component - ")
                    ACE_TEXT("Apparent homed component %C lacks a %C configProperty, aborting installation\n"),
                    idd.name.in (), DAnCE::EXPLICIT_HOME));
      throw ::Deployment::PlanError (idd.name.in (),
                                     "No explicit home  property on component requiring explicit home.");
    }

  DANCE_DEBUG (6, (LM_DEBUG, DLINFO ACE_TEXT("NodeApplication_Impl::install_homed_component - ")
                ACE_TEXT("Found explicit home property '%C' for component '%C'\n"),
                home_id,
                idd.name.in ()));

  Instance *home_inst (0);

  for (size_t i = 0; i < cont.homes.size (); ++i)
    {
      if (ACE_OS::strcmp (home_id,
                          this->plan_.instance[cont.homes[i].idd_idx].name.in ()) == 0)
        {
          DANCE_DEBUG (9, (LM_TRACE, DLINFO ACE_TEXT("NodeApplication_Impl::install_homed_component - ")
                        ACE_TEXT("Found home designated for component '%C'\n"),
                        idd.name.in ()));
          home_inst = &cont.homes[i];
          break;
        }
    }

  if (home_inst == 0)
    {
      DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT("NodeApplication_Impl::install_homed_component - ")
                    ACE_TEXT("Unable to find home instance matching %C allocated to same container as component %C\n"),
                    home_id,
                    idd.name.in ()));
      throw ::Deployment::InvalidProperty (idd.name.in (),
                                           "Unable to find valid home allocated to same container.");
    }

  Components::KeylessCCMHome_var home =
    Components::KeylessCCMHome::_narrow (home_inst->ref.in ());

  if (CORBA::is_nil (home.in ()))
    {
      DANCE_ERROR (1, (LM_ERROR,  DLINFO ACE_TEXT("NodeApplication_Impl::install_homed_component - ")
                    ACE_TEXT("Object reference for home '%C' for homed component '%C' is nil\n"),
                    home_id,
                    idd.name.in ()));
      throw ::Deployment::PlanError (idd.name.in (),
                                     "Installed home for explicitly homed component has nil object reference\n");
    }

  try
    {
      inst.home = home_inst;
      DANCE_DEBUG (9, (LM_TRACE, DLINFO ACE_TEXT("NodeApplication_Impl::install_homed_component - ")
                    ACE_TEXT("Invoking create_component on home %C for component %C\n"),
                    home_id,
                    idd.name.in ()));

      Components::CCMObject_var ccm_obj = home->create_component ();

      if (CORBA::is_nil (ccm_obj))
        {
          DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT("NodeApplication_Impl::install_homed_component - ")
      ACE_TEXT("Received nil component reference from create_component on home %C ")
      ACE_TEXT(" while creating component %C\n"),
                        home_id, idd.name.in ()));
          throw ::Deployment::StartError (idd.name.in (),
                                          "Home for explicitly homed component returned nil");
        }

      inst.ref = CORBA::Object::_narrow (ccm_obj.in ());
      DANCE_DEBUG (8, (LM_INFO, DLINFO  ACE_TEXT("NodeApplication_Impl::install_homed_component - ")
                    ACE_TEXT("Component %C successfully installed in home %C\n"),
                    idd.name.in (),
                    home_id));

      DANCE_DEBUG (9, (LM_TRACE, DLINFO ACE_TEXT("NodeApplication_Impl::install_home - ")
                    ACE_TEXT("Populating attributes for component %C\n"),
                    idd.name.in ()));
      ComponentAttributesSetter::SetComponentAttributes (idd.name.in (),
                                                        inst.ref.in (),
                                                        idd.configProperty,
                                                        this->orb_.in ());
      inst.state = eInstalled;
    }
  catch (const Components::CreateFailure &)
    {
      DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT("NodeApplication_Impl::install_homed_component - ")
                    ACE_TEXT("Caught CreateFailure exception from home '%C' while installing component '%C'\n"),
                    home_inst,
                    idd.name.in ()));
      throw ::Deployment::StartError (idd.name.in (),
                                      "Caught CreateFailure exception");
    }
  catch (const CORBA::Exception &ex)
    {
      DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT("NodeApplication_Impl::install_homed_component - ")
                    ACE_TEXT("Caught CORBA exception while installing component %C in home %C: %C\n"),
                    idd.name.in (),
                    home_id,
                    ex._info ().c_str ()));
      throw ::Deployment::StartError (idd.name.in (),
                                      ex._info ().c_str ());
    }
  catch (...)
    {
      DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT("NodeApplication_Impl::install_homed_component - ")
                    ACE_TEXT("Caught unknown C++ exception while installing component %C in home  %C\n"),
                    idd.name.in (),
                    home_id));
      throw ::Deployment::StartError (idd.name.in (),
                                      "Unknown C++ exception");
    }
}

void
NodeApplication_Impl::create_component_server (size_t index)
{
  DANCE_TRACE ("NodeApplication_Impl::create_component_server");

  ComponentServer &server = this->servers_[index];

  try
    {
      DANCE_DEBUG (6, (LM_DEBUG, DLINFO ACE_TEXT("NodeApplication_Impl::create_component_Server - ")
                   ACE_TEXT("creating component server %u\n"), index));
      ::Components::ConfigValues config_values;

      if (this->servers_[index].properties != 0)
        {
          DANCE_DEBUG (9, (LM_DEBUG, DLINFO ACE_TEXT("NodeApplication_Impl::create_component_Server - ")
                           ACE_TEXT ("Passing %u properties to component server\n"),
                           this->servers_[index].properties->length ()));

          config_values.length (this->servers_[index].properties->length ());
          for (CORBA::ULong i = 0; i < this->servers_[index].properties->length ();
               ++i)
            {
              DANCE_DEBUG (9, (LM_DEBUG, DLINFO ACE_TEXT("NodeApplication_Impl::create_component_Server - ")
                               ACE_TEXT ("Copying value <%C>\n"),
                               (*this->servers_[index].properties)[i].name.in ()));

              config_values[i] = new CIAO::ConfigValue_impl ((*this->servers_[index].properties)[i].name.in (),
                                                             (*this->servers_[index].properties)[i].value);

            }
        }


      server.ref = this->activator_->create_component_server (config_values);
      DANCE_DEBUG (6, (LM_DEBUG, DLINFO ACE_TEXT("NodeApplication_Impl::create_component_server - ")
                   ACE_TEXT("component server created\n")));
    }
  catch (const ::Components::CreateFailure& )
    {
      DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT("NodeApplication_Impl::create_container - ")
                   ACE_TEXT("Components::Deployment::ServerActivator_var::create_component_server() ")
                   ACE_TEXT("returned ::Components::CreateFailure exception\n")));
      throw ::Deployment::StartError("",
                                     "Received a ::Components::CreateFailure exception while creating component server.");
    }
  catch (const ::Components::Deployment::InvalidConfiguration& )
    {
      DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT("NodeApplication_Impl::create_container - ")
                   ACE_TEXT("Components::Deployment::ServerActivator_var::create_component_server() ")
                   ACE_TEXT("returned ::Components::Deployment::InvalidConfiguration exception\n")));
      throw ::Deployment::InvalidProperty("",
                                          "::Components::Deployment::InvalidConfiguration exception caught while creating server");
    }

    try
      {
        for (size_t i = 0; i < server.containers.size (); ++i)
          {
            this->create_container (index, i);
          }
      }
    catch (...)
      {
        DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT("NodeApplication_Impl::create_container - ")
                      ACE_TEXT("Caught exception whilst creating container; re-throwing.\n")));
        throw;
      }
}

void
NodeApplication_Impl::store_instance_ior (Instance &inst)
{
  DANCE_TRACE ("NodeApplication_Impl::store_instance_ior");

  const char *name = 0;

  if (get_property_value (DAnCE::REGISTER_NAMING,
                          this->plan_.instance[inst.idd_idx].configProperty,
                          name))
    {
      DANCE_DEBUG (6, (LM_DEBUG, DLINFO ACE_TEXT("NodeApplication_Impl::store_instance_ior - ")
                    ACE_TEXT("Storing instance '%C' object reference in Naming Service as %C\n"),
                    this->plan_.instance[inst.idd_idx].name.in (),
                    name));

      Name_Utilities::bind_object (name, inst.ref.in (), this->instance_nc_.in ());
    }

  if (get_property_value (DAnCE::INSTANCE_IOR_FILE,
                          this->plan_.instance[inst.idd_idx].configProperty,
                          name))
    {
      CORBA::String_var ior = this->orb_->object_to_string (inst.ref.in ());
      Name_Utilities::write_ior (ACE_TEXT_CHAR_TO_TCHAR (name),
                                 (ior.in ()));
    }
}

void
NodeApplication_Impl::create_container (size_t server, size_t cont_idx)
{
  DANCE_TRACE ("NodeApplication_Impl::create_container");

  Container &container = this->servers_[server].containers[cont_idx];

  DANCE_DEBUG (9, (LM_TRACE, DLINFO ACE_TEXT("NodeApplication_Impl::create_container - ")
                ACE_TEXT("Creating container\n")));
  // TODO: Need to create configvalues
  Components::ConfigValues cvs;

  container.ref = this->servers_[server].ref->create_container (cvs);

  DANCE_DEBUG (9, (LM_TRACE, DLINFO ACE_TEXT("NodeApplication_Impl::create_container - ")
                ACE_TEXT("Configuring %u homes on container %u on server %u\n"),
                container.homes.size (),
                server, cont_idx));

  // Configure homes first
  for (size_t i = 0; i < container.homes.size (); ++i)
    {
      this->install_home (container, container.homes[i]);
      this->store_instance_ior (container.homes[i]);
    }

  DANCE_DEBUG (9, (LM_TRACE, DLINFO ACE_TEXT("NodeApplication_Impl::create_container - ")
                   ACE_TEXT("Configuring %u components on container %u on server %u\n"),
                   container.components.size (),
                   server,
                   cont_idx));

  // Configure components
  for (size_t i = 0; i < container.components.size (); ++i)
    {
      switch (container.components[i].type)
        {
        case eComponent:
          this->install_component (container, container.components[i]);
          break;
        case eHomedComponent:
          this->install_homed_component (container, container.components[i]);
          break;
        default:
          break;
        }
      this->store_instance_ior (container.components[i]);
    }
}

NodeApplication_Impl::ColocationMap
NodeApplication_Impl::create_colocation_groups (void)
{
  DANCE_TRACE ("NodeApplication_Impl::create_colocation_groups");

  ColocationMap  retval;
  this->servers_.max_size (this->plan_.localityConstraint.length () + 1);

  size_t num_servers = 0;

  for (CORBA::ULong i = 0; i < this->plan_.instance.length (); ++i)
    {
      retval [this->plan_.instance[i].name.in ()] = -1;
    }

  for (CORBA::ULong i = 0; i < this->plan_.localityConstraint.length (); ++i)
    {
      if (this->plan_.localityConstraint[i].constraint == ::Deployment::PlanNoConstraint)
        {
          DANCE_DEBUG (10, (LM_INFO, DLINFO
                            ACE_TEXT ("NodeApplication_Impl::create_colocation_groups - ")
                            ACE_TEXT ("Skipping NoConstraint Colocation group\n")));
          continue;
        }
      else if (this->plan_.localityConstraint[i].constraint != ::Deployment::PlanSameProcess)
        {
          DANCE_ERROR (1, (LM_ERROR, DLINFO
                        ACE_TEXT ("NodeApplication_Impl::create_colocation_groups - ")
                        ACE_TEXT ("Error: On locality constraint %u, unsupported locality constraint.\n"),
                        i));
          continue;
        }

      ::CORBA::ULongSeq const &instances =
        this->plan_.localityConstraint[i].constrainedInstanceRef;

      this->servers_.size (num_servers + 1);

      for (CORBA::ULong j = 0; j < instances.length (); ++j)
        {
          std::string id = this->plan_.instance[instances[j]].name.in ();

          DANCE_DEBUG (8, (LM_INFO, DLINFO
                        ACE_TEXT ("NodeApplication_Impl::create_colocation_groups - ")
                        ACE_TEXT ("Instance <%C> allocated to component server %u\n"),
                        id.c_str (), num_servers));

          retval[id] = num_servers;

          CORBA::ULong impl = this->plan_.instance[instances[j]].implementationRef;

          if (this->get_instance_type (this->plan_.implementation[impl].execParameter) ==
              eComponentServer)
            {
              DANCE_DEBUG (8, (LM_INFO, DLINFO
                               ACE_TEXT ("NodeApplication_Impl::create_colocation_groups - ")
                               ACE_TEXT ("Found component server instance\n")));

              this->servers_[num_servers].properties = &this->plan_.instance[instances[j]].configProperty;
            }
        }

      ++num_servers;
    }

  bool create_default_server (false);

  for (ColocationMap::iterator i = retval.begin ();
       i != retval.end (); ++i)
    {
      if (i->second == -1)
        {
          if (!create_default_server)
            {
              DANCE_DEBUG (8, (LM_INFO, DLINFO
                            ACE_TEXT ("NodeApplication_Impl::create_colocation_groups - ")
                            ACE_TEXT ("Creating default colocation group.\n")));
              create_default_server = true;
            }

          DANCE_DEBUG (8, (LM_INFO, DLINFO
                        ACE_TEXT ("NodeApplication_Impl::create_colocation_groups - ")
                        ACE_TEXT ("Assigning instance <%C> to default colocation group.\n"),
                        i->first.c_str ()));
          i->second = num_servers;
        }
      else
        {

        }
    }

  if (create_default_server)
    {
      ++num_servers;
    }

  this->servers_.size (num_servers);

  return retval;
}

void
NodeApplication_Impl::init_components()
{
  DANCE_TRACE ("NodeApplication_Impl::init_components");

  Components::ConfigValues config_values;
  DANCE_DEBUG (6, (LM_DEBUG, DLINFO
               ACE_TEXT("NodeApplication_Impl::init_components - ")
               ACE_TEXT("Configuring %u component/home instances\n"),
               this->plan_.instance.length()));

  if (this->plan_.instance.length () == 0)
    return;

  ColocationMap colocation_map = this->create_colocation_groups ();

  // @@TODO:  For the moment, we are only going to support a single container per server.
  // in the future, we will need to determine how many containers we need per server.
  for (size_t i = 0; i < this->servers_.size (); ++i)
    {
      this->servers_[i].containers.size (1);
    }

  for (CORBA::ULong i = 0; i < this->plan_.instance.length(); i++)
    {
      try
        {
          CORBA::ULong impl = this->plan_.instance[i].implementationRef;
          // Determine type from implementation properties, then from instance properties.
          EInstanceType type =
            this->get_instance_type (this->plan_.implementation[impl].execParameter);
          if (type == eInvalid)
            type = this->get_instance_type (this->plan_.instance[i].configProperty);
          if (type == eInvalid)
            continue;

          switch (type)
            {
            case eHome:
              {
                DANCE_DEBUG (6, (LM_DEBUG, DLINFO
                              ACE_TEXT("NodeApplication_Impl::init_components - ")
                              ACE_TEXT("Allocating instance %C as a home\n"),
                              this->plan_.instance[i].name.in ()));
                size_t const svr = colocation_map[this->plan_.instance[i].name.in ()];
                size_t const pos = this->servers_[svr].containers[0].homes.size ();

                //append_properties (this->servers_[svr].properties, this->plan_.instance[i].configProperty);

                this->servers_[svr].containers[0].homes.size (pos + 1);
                this->servers_[svr].containers[0].homes[pos] = Instance (eHome,
                                                                         &this->servers_[svr].containers[0],
                                                                         i,
                                                                         this->plan_.instance[i].implementationRef);
                break;
              }
            case eComponent:
              {
                DANCE_DEBUG (6, (LM_DEBUG, DLINFO ACE_TEXT("NodeApplication_Impl::init_components - ")
                              ACE_TEXT("Allocating instance %C as a standalone component\n"),
                              this->plan_.instance[i].name.in ()));
                size_t const svr = colocation_map[this->plan_.instance[i].name.in ()];
                size_t const pos = this->servers_[svr].containers[0].components.size ();
                //append_properties (this->servers_[svr].properties, this->plan_.instance[i].configProperty);
                this->servers_[svr].containers[0].components.size (pos + 1);
                this->servers_[svr].containers[0].components[pos] = Instance (eComponent,
                                                                              &this->servers_[svr].containers[0],
                                                                              i,
                                                                              this->plan_.instance[i].implementationRef);
                break;
              }
            case eHomedComponent:
              {
                DANCE_DEBUG (6, (LM_DEBUG, DLINFO ACE_TEXT("NodeApplication_Impl::init_components - ")
                              ACE_TEXT("Allocating instance %C as a home managed component\n"),
                              this->plan_.instance[i].name.in ()));
                size_t const svr = colocation_map[this->plan_.instance[i].name.in ()];
                size_t const pos = this->servers_[svr].containers[0].components.size ();
                //append_properties (this->servers_[svr].properties, this->plan_.instance[i].configProperty);
                this->servers_[svr].containers[0].components.size (pos + 1);
                this->servers_[svr].containers[0].components[pos] = Instance (eHomedComponent,
                                                                              &this->servers_[svr].containers[0],
                                                                              i,
                                                                              this->plan_.instance[i].implementationRef);
                break;
              }
            case eComponentServer:
              {
                size_t const svr = colocation_map[this->plan_.instance[i].name.in ()];
                this->servers_[svr].instance = Instance (eComponentServer,
                                                         0,
                                                         i,
                                                         this->plan_.instance[i].implementationRef);
                this->instances_[i] = &this->servers_[svr].instance;
                break;
              }

            default:
              {
                DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT(" NodeApplication_Impl::init_components - ")
                             ACE_TEXT("get_instance_type function returned invalid instance type\n")));
                throw ::Deployment::InvalidProperty (this->plan_.instance[i].name.in (),
                                                     "Unable to affirmatively determine instance type");
              }
            } // switch
        }
        catch (...)
        {
          DANCE_ERROR (1, (LM_ERROR, DLINFO
                      ACE_TEXT("Exception was thrown while sorting instance \"%C\".\n"),
                      this->plan_.instance[i].name.in()));
          throw;
        }
    }

  DANCE_DEBUG (9, (LM_TRACE, DLINFO
                ACE_TEXT("NodeApplication_Impl::init_components - ")
                ACE_TEXT("Creating component servers and installing components.\n")));

  for (size_t i = 0; i < this->servers_.size (); ++i)
    {
      DANCE_DEBUG (9, (LM_TRACE, DLINFO ACE_TEXT("NodeApplication_Impl::init_components - ")
                    ACE_TEXT("Creating component server with index %u\n"), i));
      this->create_component_server (i);
    }


  DANCE_DEBUG (6, (LM_DEBUG, DLINFO ACE_TEXT("NodeApplication_Impl::init_components - finished\n")));
}

void
NodeApplication_Impl::passivate_components()
{
  DANCE_TRACE ("NodeApplication_Impl::passivate_components()");

  bool error (false);
  ::Deployment::StopError exception ("unfilled", "unfilled passivate components");

  for (INSTANCES::size_type k = 0; k < this->instances_.size (); ++k)
    {
      if (this->instances_[k]->type == eHome ||
          this->instances_[k]->type == eComponentServer ||
          this->instances_[k]->type == eInvalid)
        continue;

      try
        {
          CIAO::Deployment::Container_var cont =
            CIAO::Deployment::Container::_narrow (this->instances_[k]->container->ref.in());

          if (CORBA::is_nil (this->instances_[k]->container->ref.in ()))
            {
              DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT("NodeApplication_Impl::start - ")
                            ACE_TEXT("Failed to narrow object reference for container managing ")
                            ACE_TEXT("component instance %C to a CIAO container reference\n"),
                            this->plan_.instance[this->instances_[k]->idd_idx].name.in ()));
              test_and_set_exception (error, exception,
                                      this->plan_.instance[this->instances_[k]->idd_idx].name.in (),
                                      "Failed to narrow managing container to CIAO container type");
              continue;
            }

          if (this->instances_[k]->state == eActive)
            {
              Components::CCMObject_var comp (Components::CCMObject::_narrow (this->instances_[k]->ref));
              cont->passivate_component (comp.in ());
              this->instances_[k]->state = ePassive;
            }
          else
            {
              DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT("NodeApplication_Impl::start - ")
                            ACE_TEXT("Attempting to passivate non-active component %C\n"),
                            this->plan_.instance[this->instances_[k]->idd_idx].name.in ()));
              test_and_set_exception (error, exception,
                                      this->plan_.instance[this->instances_[k]->idd_idx].name.in (),
                                      "Attempting to passivate non-active component.");
              continue;
            }

          DANCE_DEBUG (8, (LM_INFO, DLINFO ACE_TEXT("NodeApplication_Impl::passivate_components - ")
                        ACE_TEXT("Component %C successfully passivated.\n"),
                        this->plan_.instance[this->instances_[k]->idd_idx].name.in ()));
        }
      catch (const CORBA::Exception &ex)
        {
          DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT("NodeApplication_Impl::passivate_components - ")
                        ACE_TEXT("Caught CORBA exception from ccm_passivate on component %C: %C\n"),
                        this->plan_.instance[this->instances_[k]->idd_idx].name.in (),
                        ex._info ().c_str ()));
          if (!error)
            {
              error = true;
              exception.name = this->plan_.instance[this->instances_[k]->idd_idx].name.in ();
              exception.reason = ex._info ().c_str ();
            }
        }
      catch (...)
        {
          DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT("NodeApplication_Impl::passivate_components - ")
                        ACE_TEXT("Caught unknown C++ exception from ccm_passivate on component %C\n"),
                        this->plan_.instance[this->instances_[k]->idd_idx].name.in ()));
          if (!error)
            {
              error = true;
              exception.name = this->plan_.instance[this->instances_[k]->idd_idx].name.in ();
              exception.reason = "Unknown C++ exception";
            }
        }
    }

  if (error)
    throw exception;
}

void
NodeApplication_Impl::remove_components()
{
  DANCE_TRACE ("NodeApplication_Impl::remove_components()");

  bool error (false);
  ::Deployment::StopError exception ("unfilled", "unfilled remove_components");

  // Removing components first.
  for (INSTANCES::size_type k = 0; k < this->instances_.size (); ++k)
    {
      try
        {
          if (this->instances_[k]->type == eInvalid ||
              this->instances_[k]->type == eComponentServer ||
              this->instances_[k]->type == eHome)
            continue;

          if (this->instances_[k]->state != ePassive)
            DANCE_DEBUG (6, (LM_WARNING, DLINFO ACE_TEXT("NodeApplication_Impl::remove_components - ")
                          ACE_TEXT("Attempting to remove component that is not passive.\n")));

          if (this->instances_[k]->type == eComponent)
            {
              if (this->instances_[k]->container == 0)
                {
                  DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT("NodeApplication_Impl::remove_components - ")
                                ACE_TEXT("Container element in component data structure for '%C' is nill\n"),
                                this->plan_.instance[this->instances_[k]->idd_idx].name.in ()
                                ));

                  test_and_set_exception (error,
                                          exception,
                                          this->plan_.instance[this->instances_[k]->idd_idx].name.in (),
                                          "Container element in component data structure is nil\n");
                  this->instances_[k]->state = eInvalidState;
                  continue;
                }

              CIAO::Deployment::Container_var ciao_container =
                CIAO::Deployment::Container::_narrow (this->instances_[k]->container->ref.in ());

              if (CORBA::is_nil (ciao_container.in ()))
                {
                  DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT("NodeApplication_Impl::remove_components - ")
                                ACE_TEXT("Attempted to remove un-homed component from unsupported container\n")));

                  test_and_set_exception (error, exception,
                                          this->plan_.instance[this->instances_[k]->idd_idx].name.in (),
                                          "Attempted to remove un-homed component from unsupported container\n");
                  this->instances_[k]->state = eInvalidState;
                  continue;
                }

              ciao_container->remove_component (Components::CCMObject::_narrow (this->instances_[k]->ref.in ()));
            }
          else
            {
              Components::CCMHome_var home =
                Components::CCMHome::_narrow (this->instances_[k]->home->ref.in ());

              if (CORBA::is_nil (home))
                {
                  DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT("NodeApplication_Impl::remove_components - ")
                                ACE_TEXT("Object reference for home %C, managing component %C is nil.\n"),
                                this->plan_.instance[this->instances_[k]->home->idd_idx].name.in (),
                                this->plan_.instance[this->instances_[k]->idd_idx].name.in ()));
                  test_and_set_exception (error,
                                          exception,
                                          this->plan_.instance[this->instances_[k]->idd_idx].name.in (),
                                          "Managing home's object reference is invalid.");
                  this->instances_[k]->state = eInvalidState;
                  continue;
                }

              home->remove_component (Components::CCMObject::_narrow (this->instances_[k]->ref.in ()));
            }


          this->instances_[k]->state = eRemoved;

          DANCE_DEBUG (8, (LM_INFO, DLINFO ACE_TEXT("NodeApplication_Impl::remove_components - ")
                        ACE_TEXT("Component %C successfully removed.\n"),
                        this->plan_.instance[this->instances_[k]->idd_idx].name.in ()));

        }
      catch (const CORBA::Exception &ex)
        {
          DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT("NodeApplication_Impl::remove_components - ")
                        ACE_TEXT("Caught CORBA exception removing on component %C: %C\n"),
                        this->plan_.instance[this->instances_[k]->idd_idx].name.in (),
                        ex._info ().c_str ()));
          test_and_set_exception (error,
                                  exception,
                                  this->plan_.instance[this->instances_[k]->idd_idx].name.in (),
                                  exception.reason = ex._info ().c_str ());
        }
      catch (...)
        {
          DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT("NodeApplication_Impl::remove_components - ")
                        ACE_TEXT("Caught unknown C++ exception from ccm_remove on component %C\n"),
                        this->plan_.instance[this->instances_[k]->idd_idx].name.in ()));
          test_and_set_exception (error,
                                  exception,
                                  this->plan_.instance[this->instances_[k]->idd_idx].name.in (),
                                  "Unknown C++ exception");
        }
    }

  for (INSTANCES::size_type k = 0; k < this->instances_.size (); ++k)
    {
      try
        {
          if (this->instances_[k]->type != eHome)
            continue;

          DANCE_ERROR (1, (LM_TRACE, DLINFO ACE_TEXT("NodeApplication_Impl::remove_components - ")
                        ACE_TEXT("Removing home %C\n"),
                        this->plan_.instance[this->instances_[k]->idd_idx].name.in ()));

          if (this->instances_[k]->container == 0 ||
              CORBA::is_nil (this->instances_[k]->container->ref.in ()))
            {
              DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT("NodeApplication_Impl::remove_components - ")
                            ACE_TEXT("Home %C lacks an associated container reference\n"),
                            this->plan_.instance[this->instances_[k]->idd_idx].name.in ()));
              test_and_set_exception (error,
                                      exception,
                                      this->plan_.instance[this->instances_[k]->idd_idx].name.in (),
                                      "Didn't have a valid container reference");
              continue;
            }

          Components::CCMHome_var home = Components::CCMHome::_narrow (this->instances_[k]->ref.in ());
          this->instances_[k]->container->ref->remove_home (home.in ());

          DANCE_DEBUG (8, (LM_INFO, DLINFO ACE_TEXT("NodeApplication_Impl::remove_components - ")
                       ACE_TEXT("Successfully uninstalled home %C\n"),
                       this->plan_.instance[this->instances_[k]->idd_idx].name.in ()));
        }
      catch (const CORBA::Exception &ex)
        {
          DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT("NodeApplication_Impl::remove_components - ")
                        ACE_TEXT("Caught CORBA exception removing home %C: %C\n"),
                        this->plan_.instance[this->instances_[k]->idd_idx].name.in (),
                        ex._info ().c_str ()));
          test_and_set_exception (error,
                                  exception,
                                  this->plan_.instance[this->instances_[k]->idd_idx].name.in (),
                                  exception.reason = ex._info ().c_str ());
        }
      catch (...)
        {
          DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT("NodeApplication_Impl::remove_components - ")
                        ACE_TEXT("Caught unknown C++ exception from while removing home %C\n"),
                        this->plan_.instance[this->instances_[k]->idd_idx].name.in ()));
          test_and_set_exception (error,
                                  exception,
                                  this->plan_.instance[this->instances_[k]->idd_idx].name.in (),
                                  "Unknown C++ exception");
        }
    }

if (error)
  throw exception;
}

NodeApplication_Impl::EInstanceType
NodeApplication_Impl::get_instance_type (const ::Deployment::Properties& prop) const
{
  DANCE_TRACE ("NodeApplication_Impl::get_instance_type");

  for (CORBA::ULong i = 0; i < prop.length (); ++i)
    {
      DANCE_DEBUG (9, (LM_TRACE, DLINFO  ACE_TEXT("NodeApplication_Impl::get_instance_type - ")
                    ACE_TEXT("Checking property %C\n"),
                    prop[i].name.in ()));

      if (ACE_OS::strcmp (prop[i].name.in (),
                          DAnCE::HOME_FACTORY) == 0)
        {
          DANCE_DEBUG (9, (LM_TRACE, DLINFO ACE_TEXT("NodeApplication_Impl::get_instance_type - ")
                        ACE_TEXT("Found Home type\n")));
          return eHome;
        }
      if (ACE_OS::strcmp (prop[i].name.in (),
                          DAnCE::COMPONENT_FACTORY) == 0)
        {
          DANCE_DEBUG (9, (LM_TRACE, DLINFO ACE_TEXT("NodeApplication_Impl::get_instance_type - ")
                         ACE_TEXT("Found unmanaged component type.\n")));
          return eComponent;
        }
      if (ACE_OS::strcmp (prop[i].name.in (),
                          DAnCE::EXPLICIT_HOME) == 0)
        {
          DANCE_DEBUG (9, (LM_TRACE, DLINFO ACE_TEXT("NodeApplication_Impl::get_instance_type - ")
                        ACE_TEXT("Found explicit home component type.\n")));
          return eHomedComponent;
        }

      if (ACE_OS::strcmp (prop[i].name.in (),
                          DAnCE::IMPL_TYPE) == 0)
        {
          const char *val;
          if (get_property_value (DAnCE::IMPL_TYPE,
                                  prop,
                                  val) &&
              ACE_OS::strcmp (val,
                              DAnCE::SERVER_EXECUTABLE) == 0)
            {
              DANCE_DEBUG (9, (LM_TRACE, DLINFO ACE_TEXT("NodeApplication_Impl::get_instance_type - ")
                               ACE_TEXT("Found component server type.\n")));
              return eComponentServer;
            }
        }
    }

  DANCE_ERROR (1, (LM_INFO, DLINFO ACE_TEXT("NodeApplication_Impl::get_instance_type - ")
                ACE_TEXT("Unable to determine instance type, instance will be ignored.\n")));
  return eInvalid;
}

::Deployment::Connections*
NodeApplication_Impl::getAllConnections()
{
  DANCE_DEBUG (6, (LM_DEBUG, DLINFO ACE_TEXT("NodeApplication_Impl::getAllConnections - started\n")));

  ::Deployment::Connections_var conn;
  ACE_NEW_THROW_EX (conn,
                    ::Deployment::Connections (),
                    CORBA::NO_MEMORY ());
  unsigned int index = 0;

  for (CORBA::ULong i = 0; i < this->plan_.connection.length(); i++)
    {
      for (CORBA::ULong j = 0; j < this->plan_.connection[i].internalEndpoint.length(); j++)
        {
          if (this->plan_.connection[i].internalEndpoint[j].provider)
            {
              index = conn->length ();
              conn->length (index + 1);
              (*conn) [index].name = CORBA::string_dup (this->plan_.connection[i].name.in());

              ACE_CString const inst_name =
                this->plan_.instance[this->plan_.connection[i].internalEndpoint[j].instanceRef].name.in();

              DANCE_DEBUG (6, (LM_DEBUG, DLINFO ACE_TEXT("NodeApplication_Impl::getAllConnections - ")
                            ACE_TEXT("Found provider '%C' for connection '%C'\n"),
                            this->plan_.connection[i].name.in (),
                            inst_name.c_str ()));

              Components::CCMObject_var obj =
                Components::CCMObject::
                _narrow (this->instances_[this->plan_.connection[i].internalEndpoint[j].instanceRef]->ref.in ());

              (*conn) [index].endpoint.length (1L);
              switch (this->plan_.connection[i].internalEndpoint[j].kind)
                {
                case ::Deployment::Facet:
                  {
                    try
                      {
                        ACE_CString const name = this->plan_.connection[i].internalEndpoint[j].portName.in();
                        if (name.compare ("supports") != 0)
                          {
                            if (this->is_local_facet (this->plan_.connection[i]))
                              {
                                DANCE_DEBUG (6, (LM_DEBUG, DLINFO ACE_TEXT("NodeApplication_Impl::getAllConnections - ")
                                             ACE_TEXT("Found local facet for connection %C endpoint %C started\n"),
                                             this->plan_.connection[i].name.in(),
                                             name.c_str ()));
                                (*conn) [index].endpoint[0] = CORBA::Object::_duplicate (obj.in());
                              }
                            else
                              {
                                DANCE_DEBUG (6, (LM_DEBUG, DLINFO ACE_TEXT("NodeApplication_Impl::getAllConnections - ")
                                             ACE_TEXT("provide_facet for connection %C endpoint %C started\n"),
                                             this->plan_.connection[i].name.in(),
                                             name.c_str ()));
                                (*conn) [index].endpoint[0] = obj->provide_facet (name.c_str());
                                DANCE_DEBUG (6, (LM_DEBUG, DLINFO ACE_TEXT("NodeApplication_Impl::getAllConnections - ")
                                             ACE_TEXT("provide_facet for connection %C endpoint %C finished\n"),
                                             this->plan_.connection[i].name.in(),
                                             name.c_str ()));
                              }
                          }
                        else
                          {
                            DANCE_DEBUG (6, (LM_DEBUG, DLINFO ACE_TEXT("NodeApplication_Impl::getAllConnections - ")
                                         ACE_TEXT("provide_facet for connection %C endpoint %C started\n"),
                                         this->plan_.connection[i].name.in(),
                                         name.c_str ()));
                            (*conn) [index].endpoint[0] = CORBA::Object::_duplicate (obj.in());
                          }
                        DANCE_DEBUG (6, (LM_DEBUG, DLINFO ACE_TEXT("NodeApplication_Impl::getAllConnections - provide_facet finished\n")));
                      }
                    catch (const ::Components::InvalidName& )
                      {
                        DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT(" NodeApplication_Impl::getAllConnections - ")
                                     ACE_TEXT("Components::CCMObject_var::provide_facet() returned ")
                                     ACE_TEXT("::Components::InvalidName exception for connection %C and port %C\n"),
                                     this->plan_.connection[i].name.in (),
                                     this->plan_.connection[i].internalEndpoint[j].portName.in ()));
                        throw ::Deployment::InvalidProperty(this->plan_.connection[i].name.in (),
                                                            "Container returned InvalidName");
                      }
                    break;
                  }

                case ::Deployment::EventConsumer:
                  {
                    try
                      {
                        DANCE_DEBUG (6, (LM_DEBUG, DLINFO ACE_TEXT("NodeApplication_Impl::getAllConnections - ")
                                     ACE_TEXT("get_consumer for connection %C endpoint %C started\n"),
                                     this->plan_.connection[i].name.in(),
                                     this->plan_.connection[i].internalEndpoint[j].portName.in()));
                        (*conn) [index].endpoint[0] = obj->get_consumer (this->plan_.connection[i].internalEndpoint[j].portName.in());
                        DANCE_DEBUG (6, (LM_DEBUG, DLINFO ACE_TEXT("NodeApplication_Impl::getAllConnections - ")
                                     ACE_TEXT("get_consumer finished\n")));
                      }
                    catch (const ::Components::InvalidName& )
                      {
                        DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT(" NodeApplication_Impl::getAllConnections - ")
                                     ACE_TEXT("Components::CCMObject_var::get_consumer() returned ")
                                     ACE_TEXT("::Components::InvalidName exception for connection %C and port %C\n"),
                                     this->plan_.connection[i].name.in (),
                                     this->plan_.connection[i].internalEndpoint[j].portName.in ()));
                        throw ::Deployment::InvalidProperty(this->plan_.connection[i].name.in (),
                                                            "Container returned InvalidName exception");
                      }
                    break;
                  }
                default:
                  {
                    DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT(" NodeApplication_Impl::getAllConnections - ")
                                 ACE_TEXT("Connection.InternalEndPoint.Kind is not a ")
                                 ACE_TEXT("Deployment::Facet or Deployment::EventConsumer\n")));
                    throw ::Deployment::InvalidProperty(this->plan_.connection[i].name.in (),
                                                        "Invalid connection type, should be Facet or EventConsumer");
                  }
                }
            }
        }
    }
  DANCE_DEBUG (6, (LM_DEBUG, DLINFO ACE_TEXT("NodeApplication_Impl::getAllConnections - finished\n")));
  return conn._retn();
}

void
NodeApplication_Impl::finishLaunch (const ::Deployment::Connections & providedReference,
                                    ::CORBA::Boolean start)
{
  DANCE_TRACE ("NodeApplication_Impl::finishLaunch");

  DANCE_DEBUG (6, (LM_DEBUG, DLINFO ACE_TEXT("NodeApplication_Impl::finishLaunch - ")
               ACE_TEXT("started for connections sequence with length %d and plan size %d\n"),
               providedReference.length(),
               this->plan_.connection.length()));

#ifdef GEN_OSTREAM_OPS
  {
    std::ostringstream pr_stream;
    pr_stream << providedReference << std::endl;
    DANCE_DEBUG (9, (LM_TRACE, DLINFO "NodeApplication_Impl::finishLaunch - Provided references: %C\n",
                  pr_stream.str ().c_str ()));
  }
#endif /* GEN_OSTREAM_OPS */

  for (CORBA::ULong j = 0; j < this->plan_.connection.length(); ++j)
    {
      CORBA::ULong inst (this->plan_.connection[j].internalEndpoint[0].instanceRef);

      DANCE_DEBUG (9, (LM_TRACE, DLINFO ACE_TEXT("NodeApplication_Impl::finishLaunch - ")
                    ACE_TEXT("Connection %C, instance %u\n"),
                    this->plan_.connection[j].name.in (),
                    inst));

#ifdef GEN_OSTREAM_OPS
      {
        std::ostringstream conn_stream;
        conn_stream << this->plan_.connection[j] << std::endl;
        DANCE_DEBUG (9, (LM_TRACE, "NodeApplication_Impl::finishLaunch - Local connections: %C\n", conn_stream.str ().c_str ()));
      }
#endif /* GEN_OSTREAM_OPS  */

      Components::CCMObject_var obj =
        Components::CCMObject::_narrow (this->instances_[inst]->ref.in ());

      if (CORBA::is_nil (obj.in ()))
        {
          DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT("NodeApplication_Impl::finishLaunch - ")
                        ACE_TEXT("Unable to narrow apparent component instance reference to CCMObject for instance '%C'\n"),
                        this->plan_.instance[inst].name.in ()));
          throw ::Deployment::InvalidConnection (this->plan_.instance[inst].name.in (),
                                                 "Unable to narrow apparent component instance reference to CCMObject\n");
        }

      ::Deployment::PlanConnectionDescription const &conn = this->plan_.connection[j];

      ACE_CString const name = conn.name.in();

      for (CORBA::ULong i = 0; i < providedReference.length(); ++i)
        {
          if (name.compare (providedReference[i].name.in()) == 0)
            {
              try
                {
                  switch (conn.internalEndpoint[0].kind)
                    {
                    case ::Deployment::Facet:
                      {
                        DANCE_DEBUG (6, (LM_DEBUG, DLINFO ACE_TEXT("NodeApplication_Impl::finishLaunch - ")
                                     ACE_TEXT("Set for facet [%C]\n"), name.c_str ()));
                        Components::CCMObject_var ext_inst;
                        try
                          {
                            if (0 == conn.externalReference.length())
                              {
                                if (conn.internalEndpoint.length () == 2 &&
                                    (conn.internalEndpoint[1].kind == ::Deployment::MultiplexReceptacle ||
                                     conn.internalEndpoint[1].kind == ::Deployment::SimplexReceptacle))
                                  {
                                    obj = Components::CCMObject::
                                      _narrow (this->instances_[conn.internalEndpoint[1].instanceRef]->ref.in ());

                                    if (this->is_local_facet (conn))
                                      {
                                        ::Components::CCMObject_var facet =
                                          ::Components::CCMObject::_narrow (providedReference[i].endpoint[0].in ());

                                        ::Components::CCMObject_var recep =
                                            ::Components::CCMObject::_narrow (this->instances_[conn.internalEndpoint[1].instanceRef]->ref.in ());

                                        ::CIAO::Deployment::Container_var cont =
                                            ::CIAO::Deployment::Container::_narrow (this->instances_[conn.internalEndpoint[1].instanceRef]->container->ref.in ());

                                        this->connect_receptacle (conn,
                                                                  facet.in (),
                                                                  conn.internalEndpoint[0].portName.in (),
                                                                  obj.in (),
                                                                  conn.internalEndpoint[1].portName.in(),
                                                                  cont.in ());
                                      }
                                    else
                                      {
                                        this->connect_receptacle (conn,
                                                                  obj.in (),
                                                                  "",
                                                                  providedReference[i].endpoint[0].in(),
                                                                  conn.internalEndpoint[1].portName.in(),
                                                                  ::CIAO::Deployment::Container::_nil());
                                      }
                                  }
                                 break;
                              }
                            CORBA::Object_var tmp =
                              this->orb_->string_to_object (conn.externalReference[0].location.in());
                            ext_inst = Components::CCMObject::_narrow (tmp);
                            if (CORBA::is_nil (ext_inst.in()))
                              {
                                DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT("NodeApplication_Impl::finishLaunch - ")
                                             ACE_TEXT("facet for [%C] can't be narrowed\n"), name.c_str ()));
                                break;
                              }
                            this->connect_receptacle_ext (ext_inst,
                                                          conn.externalReference[0].portName.in(),
                                                          providedReference[i].endpoint[0].in());
                          }
                        catch (const CORBA::OBJECT_NOT_EXIST&)
                          {
                            // @@TODO: Shouldn't this be an error?!?
                            break;
                          }
                        catch (const CORBA::TRANSIENT&)
                          {
                            // @@TODO: Shouldn't this be an error?!?
                            break;
                          }

                        break;
                      }

                    case ::Deployment::EventConsumer:
                      {
                        DANCE_DEBUG (6, (LM_DEBUG, DLINFO ACE_TEXT("NodeApplication_Impl::finishLaunch - set for consumer\n")));
                        Components::CCMObject_var ext_inst;
                        try
                          {
                            if (0 == conn.externalReference.length())
                              {
                                break;
                              }
                            CORBA::Object_var tmp =
                              this->orb_->string_to_object (conn.externalReference[0].location.in());
                            ext_inst = Components::CCMObject::_narrow (tmp);
                            if (CORBA::is_nil (ext_inst.in()))
                              {
                                DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT(" NodeApplication_Impl::finishLaunch - ")
                                             ACE_TEXT("reference for %C can't be narrowed\n"), name.c_str ()));
                                throw ::Deployment::InvalidConnection(conn.name.in (),
                                                                      "Couldn't narrow reference for external reference");
                                break;
                              }
                            try
                              {
                                // Check is connection kind is consumer to emitter?
                                this->connect_emitter_ext (ext_inst,
                                                           conn.externalReference[0].portName.in(),
                                                           providedReference[i].endpoint[0].in());
                              }
                            catch (const ::Components::InvalidName&)
                              {
                                DANCE_DEBUG (6, (LM_DEBUG, DLINFO
                                                ACE_TEXT("NodeApplication_Impl::finishLaunch - ")
                                                ACE_TEXT("connect_emitter_ext resulted in InvalidName, trying connect_publisher\n")));
                                // No this is consumer to publisher
                                this->connect_publisher (ext_inst,
                                                         conn.externalReference[0].portName.in(),
                                                         providedReference[i].endpoint[0].in());
                              }
                          }
                        catch (const CORBA::OBJECT_NOT_EXIST&)
                          {
                            break;
                          }
                        catch (const CORBA::TRANSIENT&)
                          {
                            break;
                          }
                        break;
                      }
                    case ::Deployment::MultiplexReceptacle:
                    case ::Deployment::SimplexReceptacle:
                      {
                        // What we should do with Cookie, returned from connect call???
                        DANCE_DEBUG (6, (LM_DEBUG, DLINFO ACE_TEXT("NodeApplication_Impl::finishLaunch - Set for receptacle\n")));
                        if (CORBA::is_nil (providedReference[i].endpoint[0].in ()))
                          {
                            DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT ("NodeApplication_Impl::finishLaunch - ")
                                             ACE_TEXT ("Reference provided from DomainApplication was nil.\n")));
                            throw Deployment::InvalidConnection ("",
                                                                 "Nil provided reference from DomainApplication");
                          }

                        ::Components::CCMObject_var facet =
                           ::Components::CCMObject::_narrow (providedReference[i].endpoint[0].in ());

                        if (this->is_local_facet (conn))
                          {
                            ::CIAO::Deployment::Container_var cont =
                               ::CIAO::Deployment::Container::_narrow (this->instances_[conn.internalEndpoint[1].instanceRef]->container->ref.in ());
                            this->connect_receptacle (conn,
                                                      facet.in (),
                                                      conn.internalEndpoint[1].portName.in (),
                                                      obj.in(),
                                                      conn.internalEndpoint[0].portName.in(),
                                                      cont.in ());
                          }
                        else
                          {
                            CORBA::Object_var portref = CORBA::Object::_duplicate (providedReference[i].endpoint[0].in());

                            if (0 != conn.externalReference.length ())
                              {
                                ::Components::CCMObject_var facet =
                                  ::Components::CCMObject::_narrow (providedReference[i].endpoint[0].in ());

                                if (!CORBA::is_nil (facet.in ()))
                                  portref = facet->provide_facet (conn.externalReference[0].portName.in ());
                              }

                            this->connect_receptacle (conn,
                                                      obj.in (),
                                                      "",
                                                      portref.in (),
                                                      conn.internalEndpoint[0].portName.in(),
                                                      ::CIAO::Deployment::Container::_nil());

                          }

                        break;
                      }
                    case ::Deployment::EventEmitter:
                      {
                        DANCE_DEBUG (6, (LM_DEBUG, DLINFO ACE_TEXT("NodeApplication_Impl::finishLaunch - set for emitter\n")));
                        this->connect_emitter (obj.in(),
                                               conn.internalEndpoint[0].portName.in(),
                                               providedReference[i].endpoint[0].in());
                        break;
                      }
                    case ::Deployment::EventPublisher:
                      {
                        DANCE_DEBUG (6, (LM_DEBUG, DLINFO ACE_TEXT("NodeApplication_Impl::finishLaunch - set for publisher\n")));
                        this->connect_publisher (obj.in(),
                                                 conn.internalEndpoint[0].portName.in(),
                                                 providedReference[i].endpoint[0].in());
                        break;
                      }
                    default:
                      {
                        DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT("NodeApplication_Impl::finishLaunch - currect Connection.InternalEndPoint.Kind ")
                                     ACE_TEXT("is not a Deployment::SimplexReceptacle, Deployment::EventEmitter, Deployment::EventPublisher ")
                                     ACE_TEXT("(Connection:%C Kind:%i PortName:%C)\n"),
                                     conn.name.in(),
                                     conn.internalEndpoint[0].kind,
                                     conn.internalEndpoint[0].portName.in()
                                     ));
                        throw ::Deployment::InvalidConnection(conn.name.in (),
                                                              "Invalid connection type, should be Receptacle or even producer.");
                      }//default
                    }//switch
                }
              catch (::Deployment::StartError &ex)
                {
                  DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT("NodeApplication_Impl::finishLaunch - ")
                                ACE_TEXT("Intercepted StartError exception while configuring [%C] connection, rethrowing\n"),
                                name.c_str ()));
                  ex.name = name.c_str ();
                  throw;
                }
              catch (::Deployment::InvalidConnection &ex)
                {
                  DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT("NodeApplication_Impl::finishLaunch - ")
                                ACE_TEXT("Intercepted InvalidConnection exception while configuring [%C] connection, rethrowing\n"),
                                name.c_str ()));
                  ex.name = name.c_str ();
                  throw;
                }
            }//if(name.compare(providedReference[i].name.in()) == 0)
        }//for ( unsigned int i = 0; i < providedReference.length(); ++i )
    }//for ( unsigned int j = 0; j < this->plan_.connection.length(); ++j )

  this->configuration_complete_components ();

  if (start)
    {
      this->start();
    }

  DANCE_DEBUG (6, (LM_DEBUG, DLINFO ACE_TEXT("NodeApplication_Impl::finishLaunch - finished\n")));
}

bool
NodeApplication_Impl::is_local_facet (const ::Deployment::PlanConnectionDescription& conn)
{
  Deployment::Requirements const& deploy_req = conn.deployRequirement;
  for (CORBA::ULong i = 0; i < deploy_req.length (); i++)
  {
    if (ACE_OS::strcmp (deploy_req[i].name, "edu.dre.vanderbilt.DAnCE.ConnectionType") == 0 &&
        ACE_OS::strcmp (deploy_req[i].resourceType, "Local_Interface") == 0)
    {
      return true;
    }
  }
  return false;
}

Components::Cookie*
NodeApplication_Impl::connect_receptacle (const ::Deployment::PlanConnectionDescription& conn,
                                          Components::CCMObject_ptr facet,
                                          const ACE_CString &facet_name,
                                          CORBA::Object_ptr receptacle,
                                          const ACE_CString& recep_name,
                                          CIAO::Deployment::Container_ptr cont)
{
  Components::Cookie* res = 0;
  try
    {
      if (this->is_local_facet (conn))
        {
          ::Components::CCMObject_var ccm_receptacle =
             ::Components::CCMObject::_narrow (receptacle);

          if (CORBA::is_nil (facet))
            {
              DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT("NodeApplication_Impl::connect_receptacle - ")
                            ACE_TEXT ("Unable to narrow facet for local facet connection [%C] to receptable [%C]\n"),
                            facet_name.c_str (), recep_name.c_str ()));
              throw ::Deployment::InvalidConnection ("", "");
            }

          if (CORBA::is_nil (ccm_receptacle))
            {
              DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT("NodeApplication_Impl::connect_receptacle - ")
                            ACE_TEXT ("Unable to narrow receptacle for local facet connection [%C] to receptable [%C]\n"),
                            facet_name.c_str (), recep_name.c_str ()));
              throw ::Deployment::InvalidConnection ("", "");
            }

          if (CORBA::is_nil (cont))
            {
              DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT("NodeApplication_Impl::connect_receptacle - ")
                            ACE_TEXT ("Unable to narrow container for local facet connection [%C] to receptable [%C]\n"),
                            facet_name.c_str (), recep_name.c_str ()));
              throw ::Deployment::InvalidConnection ("", "");
            }

          DANCE_DEBUG (6, (LM_DEBUG, DLINFO ACE_TEXT ("NodeApplication_Impl::connect_receptacle - ")
                        ACE_TEXT ("Connecting local facet [%C] to receptacle [%C]\n"),
                        facet_name.c_str (), recep_name.c_str ()));

          cont->connect_local_facet (facet, facet_name.c_str (), ccm_receptacle, recep_name.c_str ());
          DANCE_DEBUG (6, (LM_DEBUG, DLINFO ACE_TEXT("NodeApplication_Impl::connect_receptacle - connect finished\n")));
        }
      else
        {
          DANCE_DEBUG (6, (LM_DEBUG, DLINFO ACE_TEXT("NodeApplication_Impl::connect_receptacle - ")
                       ACE_TEXT("connect SimplexReceptacle for [%C] started\n"), recep_name.c_str()));
          if (CORBA::is_nil (facet))
            {
              DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT ("NodeApplication_Impl::connect_receptacle - ")
                               ACE_TEXT ("Object reference for facet to connect to [%C] was nil\n"),
                               recep_name.c_str ()));
              throw ::Deployment::InvalidConnection ("",
                                                     "Provided facet reference was nil\n");
            }

          res = facet->connect (recep_name.c_str(), receptacle);
          DANCE_DEBUG (6, (LM_DEBUG, DLINFO ACE_TEXT("NodeApplication_Impl::connect_receptacle - connect finished\n")));
        }
    }
  catch (const ::Components::InvalidName& )
    {
      DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT("NodeApplication_Impl::connect_receptacle - ")
                   ACE_TEXT("Components::CCMObject_var::connect() returned ::Components::InvalidName exception\n")));
      throw ::Deployment::StartError(conn.name.in (),
                                     "Received InvalidName exception while connecting receptacle.");
    }
  catch (const ::Components::InvalidConnection& )
    {
      DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT(" NodeApplication_Impl::connect_receptacle - ")
                   ACE_TEXT("Components::CCMObject_var::connect() returned ::Components::InvalidConnection exception\n")));
      throw ::Deployment::InvalidConnection(conn.name.in (),
                                            "InvalidConnection caught while connecting receptacle.");
    }
  catch (const ::Components::AlreadyConnected& )
    {
      DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT(" NodeApplication_Impl::connect_receptacle - ")
                       ACE_TEXT("Components::CCMObject_var::connect() returned ::Components::AlreadyConnected exception ")
                       ACE_TEXT("for connection <%C>\n"),
                       conn.name.in ()));
      throw ::Deployment::InvalidConnection(conn.name.in (),
                                            "Caught AlreadyConnected exception while connecting receptacle");
    }
  catch (const ::Components::ExceededConnectionLimit& )
    {
      DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT(" NodeApplication_Impl::connect_receptacle - ")
                   ACE_TEXT("Components::CCMObject_var::connect() returned ::Components::ExceededConnectionLimit exception\n")));
      throw ::Deployment::InvalidConnection(conn.name.in (),
                                            "Caught ExceededConnectionLimit exception while connecting receptacle.");
    }
  catch (const ::CORBA::Exception &ex )
    {
      DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT("NodeApplication_Impl::connect_receptacle - ")
                       ACE_TEXT("Caught a CORBA exception while connecting <%C>: <%C>\n"),
                       conn.name.in (),
                       ex._info ().c_str ()));
      throw ::Deployment::StartError(conn.name.in (),
                                     ex._info ().c_str ());
    }
  return res;
}

Components::Cookie*
NodeApplication_Impl::connect_receptacle_ext (Components::CCMObject_ptr inst,
                                              const ACE_CString& port_name,
                                              CORBA::Object_ptr facet)
{
  Components::Cookie* res = 0;
  try
    {
      DANCE_DEBUG (6, (LM_DEBUG, DLINFO ACE_TEXT("NodeApplication_Impl::connect_receptacle_ext - ")
                   ACE_TEXT("connect SimplexReceptacle for %C started\n"), port_name.c_str()));
      res = inst->connect (port_name.c_str(), facet);
      DANCE_DEBUG (6, (LM_DEBUG, DLINFO ACE_TEXT("NodeApplication_Impl::connect_receptacle_ext - connect finished\n")));
    }
  catch (const ::Components::InvalidName& )
    {
      DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT(" NodeApplication_Impl::connect_receptacle_ext - ")
                   ACE_TEXT("Components::CCMObject_var::connect() returned ::Components::InvalidName exception\n")));
      throw ::Deployment::StartError("",
                                     "Caught InvalidName exception while connecting external receptacle.");
    }
  catch (const ::Components::InvalidConnection& )
    {
      DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT(" NodeApplication_Impl::connect_receptacle_ext - ")
                   ACE_TEXT("Components::CCMObject_var::connect() returned ::Components::InvalidConnection exception\n")));
      throw ::Deployment::InvalidConnection("",
                                            "Caught InvalidConnection exception while connecting external receptacle.");
    }
  catch (const ::Components::AlreadyConnected& )
    {
      DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT(" NodeApplication_Impl::connect_receptacle_ext - ")
                   ACE_TEXT("Components::CCMObject_var::connect() returned ::Components::AlreadyConnected exception\n")));
      throw ::Deployment::InvalidConnection("",
                                            "Caught AlreadyConnected exception while connecting external receptacle.");
    }
  catch (const ::Components::ExceededConnectionLimit& )
    {
      DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT(" NodeApplication_Impl::connect_receptacle_ext - ")
                   ACE_TEXT("Components::CCMObject_var::connect() returned ::Components::ExceededConnectionLimit exception\n")));
      throw ::Deployment::InvalidConnection("",
                                            "Caught ExceededConnectionLimit while connecting external receptacle.");
    }
  return res;
}

void
NodeApplication_Impl::connect_emitter (Components::CCMObject_ptr inst,
                                       const ACE_CString& port_name,
                                       CORBA::Object_ptr consumer)
{
  Components::EventConsumerBase_var event = Components::EventConsumerBase::_unchecked_narrow (consumer);
  try
    {
      DANCE_DEBUG (6, (LM_DEBUG, DLINFO ACE_TEXT("NodeApplication_Impl::connect_emitter - ")
                   ACE_TEXT("connect_consumer for %C started\n"), port_name.c_str()));
      inst->connect_consumer (port_name.c_str(), event);
      DANCE_DEBUG (6, (LM_DEBUG, DLINFO ACE_TEXT("NodeApplication_Impl::connect_emitter - ")
                   ACE_TEXT("connect_consumer finished\n")));
    }
  catch (const ::Components::InvalidName& )
    {
      DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT(" ACE_TEXT(NodeApplication_Impl::connect_emitter - ")
                   ACE_TEXT("Components::CCMObject_var::connect_consumer() returned ::Components::InvalidName exception\n")));
      throw ::Deployment::StartError("",
                                     "Caught InvalidName while connecting emitter.");
    }
  catch (const ::Components::AlreadyConnected& )
    {
      DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT(" NodeApplication_Impl::connect_emitter - ")
                   ACE_TEXT("Components::CCMObject_var::connect_consumer() returned ::Components::AlreadyConnected exception\n")));
      throw ::Deployment::InvalidConnection("",
                                            "Caught AlreadyConnected exception while connecting emitter");
    }
  catch (const ::Components::InvalidConnection& )
    {
      DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT(" NodeApplication_Impl::connect_emitter - ")
                   ACE_TEXT("Components::CCMObject_var::connect_consumer() returned ::Components::InvalidConnection exception\n")));
      throw ::Deployment::InvalidConnection("",
                                            "Caught InvalidConnection while connecting emitter.");
    }
}

void
NodeApplication_Impl::connect_emitter_ext (Components::CCMObject_ptr inst,
                                           const ACE_CString& port_name,
                                           CORBA::Object_ptr consumer)
{
  Components::EventConsumerBase_var event = Components::EventConsumerBase::_unchecked_narrow (consumer);
  try
    {
      DANCE_DEBUG (6, (LM_DEBUG, DLINFO ACE_TEXT("NodeApplication_Impl::connect_emitter_ext - ")
                   ACE_TEXT("connect_emitter_ext for %C started\n"), port_name.c_str()));
      inst->connect_consumer (port_name.c_str(), event);
      DANCE_DEBUG (6, (LM_DEBUG, DLINFO ACE_TEXT("NodeApplication_Impl::connect_emitter_ext - connect_emitter_ext finished\n")));
    }
  catch (const ::Components::AlreadyConnected& )
    {
      DANCE_DEBUG (6, (LM_WARNING, ACE_TEXT("NodeApplication_Impl::connect_emitter_ext - ")
                     ACE_TEXT("Components::CCMObject_var::connect_consumer() returned ::Components::AlreadyConnected exception\n")));
      throw ::Deployment::InvalidConnection("",
                                            "Caught AlreadyConnected exception while connecting external emitter.");
    }
  catch (const ::Components::InvalidConnection& )
    {
      DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT(" NodeApplication_Impl::connect_emitter_ext - ")
                   ACE_TEXT("Components::CCMObject_var::connect_consumer() returned ::Components::InvalidConnection exception\n")));
      throw ::Deployment::InvalidConnection("",
                                            "Caught InvalidConnection exception while connecting external emitter.");
    }
}

Components::Cookie*
NodeApplication_Impl::connect_publisher (Components::CCMObject_ptr inst,
                                         const ACE_CString& port_name,
                                         CORBA::Object_ptr consumer)
{
  DANCE_TRACE ("NodeApplication_Impl::connect_publisher");

  if (CORBA::is_nil (inst))
    {
      DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT("NodeApplication_Impl::connect_publisher - ")
                    ACE_TEXT("Provided a nil CCMObject reference while connecting port %C\n"),
                    port_name.c_str ()));
      throw ::Deployment::InvalidConnection ();
    }
  Components::Cookie* res = 0;
  Components::EventConsumerBase_var event = Components::EventConsumerBase::_unchecked_narrow (consumer);
  try
    {
      res = inst->subscribe (port_name.c_str(), event);
      DANCE_DEBUG (6, (LM_DEBUG, DLINFO ACE_TEXT("NodeApplication_Impl::connect_publisher - successfully subscribed %C\n"),
                   port_name.c_str ()));
    }
  catch (const ::Components::InvalidName& )
    {
      DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT(" NodeApplication_Impl::connect_publisher - ")
                   ACE_TEXT("Components::CCMObject_var::subscribe() returned ::Components::InvalidName exception\n")));
      throw ::Deployment::StartError("", "Caught InvalidName exception while connecting publisher");
    }
  catch (const ::Components::InvalidConnection& )
    {
      DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT(" NodeApplication_Impl::connect_publisher - ")
                   ACE_TEXT("Components::CCMObject_var::subscribe() returned ::Components::InvalidConnection exception\n")));
      throw ::Deployment::InvalidConnection("", "Caught InvalidConnection exception while connecting publisher.");
    }
  catch (const ::Components::ExceededConnectionLimit& )
    {
      DANCE_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT(" NodeApplication_Impl::connect_publisher - ")
                   ACE_TEXT("Components::CCMObject_var::subscribe() returned ::Components::ExceededCOnnectionLimit exception\n")));
      throw ::Deployment::InvalidConnection("", "Caught ExceededConnectionLimit exception while connecting publisher.");
    }
  return res;
}