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
|
// $Id$
#include "DynEnum_Handler.h"
#include "DynAny_Handler.h"
#include "dance/Logger/Log_Macros.h"
#include "Basic_Deployment_Data.hpp"
#include "Common.h"
#include "tao/AnyTypeCode/TypeCode.h"
#include "tao/TypeCodeFactory/TypeCodeFactory_Adapter_Impl.h"
#include "tao/AnyTypeCode/AnyTypeCode_methods.h"
#include "tao/AnyTypeCode/Enum_TypeCode.h"
#include "tao/IFR_Client/IFR_BasicC.h"
namespace DAnCE
{
namespace Config_Handlers
{
DynamicAny::DynAny_ptr
DynEnum_Handler::extract_into_dynany (const DataType &type,
const DataValue &value,
CORBA::TypeCode_ptr req_tc)
{
try
{
CORBA::TypeCode_var tc;
if (req_tc)
tc = req_tc;
else
tc = DynEnum_Handler::create_typecode (type);
// Make the actual DynEnum
DynamicAny::DynAny_var temp =
DYNANY_HANDLER->daf ()->create_dyn_any_from_type_code (tc);
DynamicAny::DynEnum_var retval = DynamicAny::DynEnum::_narrow (temp.in ());
retval->set_as_string (ACE_TEXT_ALWAYS_CHAR ((*value.begin_enum ())->c_str ()));
return retval._retn ();
}
catch (DynamicAny::DynAny::InvalidValue)
{
DANCE_DEBUG (1, (LM_ERROR, ACE_TEXT ("Invalid value provided in XML when trying to ")
ACE_TEXT ("initialize an instance of enumerated type %s\n"),
type.enum_ ().typeId ().c_str ()));
throw Config_Error (type.enum_ ().typeId (),
ACE_TEXT ("Invalid value provided in XML"));
}
catch (Config_Error &ex)
{
DANCE_DEBUG (1, (LM_ERROR, ACE_TEXT ("DynEnum_Handler caught Config_Error\n")));
if (type.enum_p ())
ex.add_name (type.enum_ ().typeId ());
throw ex;
}
catch (...)
{
DANCE_DEBUG (1, (LM_ERROR, ACE_TEXT ("DynEnum_Handler caught unknown exception\n")));
throw Config_Error (type.enum_ ().typeId (),
ACE_TEXT ("Unknown exception"));
}
}
void
DynEnum_Handler::extract_out_of_dynany (const DynamicAny::DynAny_ptr dyn)
{
ACE_UNUSED_ARG (dyn);
DANCE_DEBUG (1, (LM_ERROR, ACE_TEXT ("Extracting Enums not yet supported\n")));
}
CORBA::TypeCode_ptr
DynEnum_Handler::create_typecode (const DataType &type)
{
if (!type.enum_p ())
{
DANCE_DEBUG (1, (LM_ERROR, ACE_TEXT ("ERROR: Enum type description required")));
throw Config_Error (ACE_TEXT (""), ACE_TEXT ("Did not find expected enum type description, tk_kind may be wrong."));
}
// Construct TypeCode for the enum
CORBA::EnumMemberSeq members;
members.length (type.enum_ ().count_member ());
CORBA::ULong index (0);
for (EnumType::member_const_iterator i = type.enum_ ().begin_member ();
i != type.enum_ ().end_member ();
++i)
{
members[index++] = CORBA::string_dup (ACE_TEXT_ALWAYS_CHAR ((*i)->c_str ()));
}
CORBA::TypeCode_var tc =
DYNANY_HANDLER->orb ()->create_enum_tc (ACE_TEXT_ALWAYS_CHAR (type.enum_ ().typeId ().c_str ()),
ACE_TEXT_ALWAYS_CHAR (type.enum_ ().name ().c_str ()),
members);
DYNANY_HANDLER->register_typecode ((type.enum_ ().typeId ()),
tc.in ());
return tc._retn ();
}
}
}
|