1 #include "Locator_XMLHandler.h"
2 #include "XML_Backing_Store.h"
4 #include "ace/OS_NS_strings.h"
5 #include "ace/OS_NS_sys_time.h"
7 const ACE_TCHAR
* Locator_XMLHandler::ROOT_TAG
= ACE_TEXT("ImplementationRepository");
8 const ACE_TCHAR
* Locator_XMLHandler::SERVER_INFO_TAG
= ACE_TEXT("Servers");
9 const ACE_TCHAR
* Locator_XMLHandler::ACTIVATOR_INFO_TAG
= ACE_TEXT("Activators");
10 const ACE_TCHAR
* Locator_XMLHandler::ENVIRONMENT_TAG
= ACE_TEXT("EnvironmentVariables");
12 const ACE_TCHAR
* Locator_XMLHandler::SERVER_TAG
= ACE_TEXT("server_id");
13 const ACE_TCHAR
* Locator_XMLHandler::POANAME_TAG
= ACE_TEXT("poa_name");
14 const ACE_TCHAR
* Locator_XMLHandler::JACORB_TAG
= ACE_TEXT("is_jacorb");
15 const ACE_TCHAR
* Locator_XMLHandler::ACTNAME_TAG
= ACE_TEXT("activator");
16 const ACE_TCHAR
* Locator_XMLHandler::CMDLINE_TAG
= ACE_TEXT("command_line");
17 const ACE_TCHAR
* Locator_XMLHandler::DIR_TAG
= ACE_TEXT("working_dir");
18 const ACE_TCHAR
* Locator_XMLHandler::MODE_TAG
= ACE_TEXT("activation_mode");
19 const ACE_TCHAR
* Locator_XMLHandler::LIMIT_TAG
= ACE_TEXT("start_limit");
20 const ACE_TCHAR
* Locator_XMLHandler::PARTIOR_TAG
= ACE_TEXT("partial_ior");
21 const ACE_TCHAR
* Locator_XMLHandler::IOR_TAG
= ACE_TEXT("ior");
22 const ACE_TCHAR
* Locator_XMLHandler::STARTED_TAG
= ACE_TEXT("started");
23 const ACE_TCHAR
* Locator_XMLHandler::PEER_TAG
= ACE_TEXT("peer");
24 const ACE_TCHAR
* Locator_XMLHandler::PID_TAG
= ACE_TEXT("pid");
25 const ACE_TCHAR
* Locator_XMLHandler::KEYNAME_TAG
= ACE_TEXT("key_name");
26 const ACE_TCHAR
* Locator_XMLHandler::ALTKEY_TAG
= ACE_TEXT("altkey");
29 Locator_XMLHandler::Locator_XMLHandler (XML_Backing_Store
& repo
)
32 server_started_ (false),
39 static void convertEnvList (const Locator_XMLHandler::EnvList
& in
,
40 ImplementationRepository::EnvironmentList
& out
)
42 CORBA::ULong
const sz
= static_cast<CORBA::ULong
> (in
.size ());
44 for (CORBA::ULong i
= 0; i
< sz
; ++i
)
46 out
[i
].name
= ACE_TEXT_ALWAYS_CHAR (in
[i
].name
.c_str ());
47 out
[i
].value
= ACE_TEXT_ALWAYS_CHAR (in
[i
].value
.c_str ());
51 static void convertPeerList (const Locator_XMLHandler::PeerList
& in
,
52 CORBA::StringSeq
& out
)
54 CORBA::ULong
const sz
= static_cast<CORBA::ULong
> (in
.size ());
56 for (CORBA::ULong i
= 0; i
< sz
; ++i
)
58 out
[i
] = in
[i
].c_str ();
63 Locator_XMLHandler::startElement (const ACEXML_Char
*,
65 const ACEXML_Char
* qName
,
66 ACEXML_Attributes
* attrs
)
68 if (ACE_OS::strcasecmp (qName
, SERVER_INFO_TAG
) == 0)
70 ACE_NEW (this->si_
, Server_Info
);
71 this->env_vars_
.clear ();
73 // if attrs exists and if the previously required 9 fields
74 const size_t previous_size
= 9;
75 if (attrs
!= 0 && attrs
->getLength () >= previous_size
)
78 this->si_
->server_id
= ACE_TEXT_ALWAYS_CHAR (attrs
->getValue (index
++));
79 this->si_
->poa_name
= ACE_TEXT_ALWAYS_CHAR (attrs
->getValue (index
++));
80 this->si_
->activator
= ACE_TEXT_ALWAYS_CHAR (attrs
->getValue (index
++));
81 this->si_
->cmdline
= ACE_TEXT_ALWAYS_CHAR (attrs
->getValue (index
++));
82 this->si_
->dir
= ACE_TEXT_ALWAYS_CHAR (attrs
->getValue (index
++));
83 this->si_
->activation_mode_
=
84 ImR_Utils::stringToActivationMode (ACE_TEXT_ALWAYS_CHAR (attrs
->getValue (index
++)));
85 this->si_
->start_limit_
= ACE_OS::atoi (attrs
->getValue (index
++));
86 this->si_
->partial_ior
= ACE_TEXT_ALWAYS_CHAR (attrs
->getValue (index
++));
87 this->si_
->ior
= ACE_TEXT_ALWAYS_CHAR (attrs
->getValue (index
++));
89 if (attrs
->getLength () >= index
)
91 this->server_started_
=
92 (ACE_OS::atoi (attrs
->getValue (index
++)) != 0);
94 if (attrs
->getLength () >= index
)
96 this->si_
->is_jacorb
=
97 (ACE_OS::atoi (attrs
->getValue (index
++)) != 0);
100 for ( ; index
< attrs
->getLength(); ++index
)
102 ACE_TString
name (attrs
->getLocalName (index
));
103 ACE_CString
value (ACE_TEXT_ALWAYS_CHAR (attrs
->getValue (index
)));
104 if (name
== KEYNAME_TAG
)
106 this->si_
->key_name_
= value
;
108 else if (name
== ALTKEY_TAG
)
110 if (value
.length() > 0 &&
111 this->repo_
.servers ().find (value
, this->si_
->alt_info_
) != 0)
113 Server_Info
*base_si
= 0;
114 ACE_NEW (base_si
, Server_Info
);
115 base_si
->key_name_
= value
;
116 this->si_
->alt_info_
.reset (base_si
);
117 this->repo_
.servers ().bind (value
, this->si_
->alt_info_
);
120 else if (name
== PID_TAG
)
123 ACE_OS::atoi (attrs
->getValue (index
++));
127 const ACE_CString
name_cstr (ACE_TEXT_ALWAYS_CHAR (name
.c_str ()));
128 this->extra_params_
.push_back (std::make_pair (name_cstr
, value
));
133 else if (ACE_OS::strcasecmp (qName
, ACTIVATOR_INFO_TAG
) == 0)
135 if (attrs
!= 0 && attrs
->getLength () >= 3)
138 const ACE_CString aname
=
139 ACE_TEXT_ALWAYS_CHAR(attrs
->getValue (index
++));
140 const ACE_TString token_str
= attrs
->getValue (index
++);
141 long token
= ACE_OS::atoi (token_str
.c_str ());
142 const ACE_CString ior
=
143 ACE_TEXT_ALWAYS_CHAR(attrs
->getValue (index
++));
144 NameValues extra_params
;
145 for ( ; index
< attrs
->getLength(); ++index
)
147 ACE_CString
name (ACE_TEXT_ALWAYS_CHAR (attrs
->getLocalName(index
)));
148 ACE_CString
value (ACE_TEXT_ALWAYS_CHAR (attrs
->getValue(index
)));
149 extra_params
.push_back (std::make_pair (name
, value
));
151 this->repo_
.load_activator (aname
, token
, ior
, extra_params
);
154 else if (ACE_OS::strcasecmp (qName
, ENVIRONMENT_TAG
) == 0)
156 if (attrs
!= 0 && attrs
->getLength () == 2)
159 ev
.name
= attrs
->getValue ((size_t)0);
160 ev
.value
= attrs
->getValue ((size_t)1);
161 this->env_vars_
.push_back (ev
);
164 else if (ACE_OS::strcasecmp (qName
, PEER_TAG
) == 0)
168 ACE_CString
peer (ACE_TEXT_ALWAYS_CHAR (attrs
->getValue((size_t)0)));
169 this->peer_list_
.push_back (peer
);
175 Locator_XMLHandler::endElement (const ACEXML_Char
*,
177 const ACEXML_Char
* qName
)
179 if (ACE_OS::strcasecmp (qName
, SERVER_INFO_TAG
) == 0)
181 if (this->si_
->key_name_
.length () == 0)
183 Server_Info::gen_key (this->si_
->server_id
,
185 this->si_
->key_name_
);
187 convertEnvList (this->env_vars_
, this->si_
->env_vars
);
188 convertPeerList (this->peer_list_
, this->si_
->peers
);
190 this->repo_
.load_server (this->si_
,
191 this->server_started_
,
192 this->extra_params_
);
194 // activator info is handled in the startElement
198 Locator_XMLHandler::EnvVar::operator== (const EnvVar
& rhs
) const
200 return name
== rhs
.name
&& value
== rhs
.value
;
203 Locator_XMLHandler::EnvVar::operator!= (const EnvVar
& rhs
) const
205 return ! (rhs
== *this);