00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "ComplexType.h"
00023 #include <Sockets/XmlNode.h>
00024 #include "WsdlException.h"
00025 #include "Element.h"
00026 #include <Sockets/Debug.h>
00027 #include "Split.h"
00028 #include "Wsdl.h"
00029 #include "Attribute.h"
00030 #include "SimpleType.h"
00031 #include "Application.h"
00032 #include <iostream>
00033
00034
00035 std::map<std::string, bool> ComplexType::m_b_generated;
00036
00037
00038 ComplexType::ComplexType(const Wsdl& wsdl, const Xml::XmlNode& node, const std::string& name, const std::string& ns_prefix)
00039 : TypeBase(wsdl, node, ns_prefix, Split(name).Type)
00040 , m_name(!name.empty() ? name : node.PropertyExists("name") ? node.GetProperty("name") : "")
00041 , m_b_is_sequence(false)
00042 , m_b_is_all(false)
00043 , m_b_complexContent(false)
00044 , m_b_is_array(false)
00045 , m_b_is_mixed(false)
00046 {
00047 Xml::XmlNode start = Start();
00048 if (m_node.PropertyExists("mixed") && m_node.GetProperty("mixed") == "true")
00049 {
00050 m_b_is_mixed = true;
00051 }
00052 if (start.PropertyExists("base"))
00053 {
00054 m_extends = start.GetProperty("base");
00055 std::string ns_href = m_node.GetNsMap()[Split(m_extends).NS];
00056 if (ns_href.empty())
00057 m_extends_cls = Split(m_extends).CName1up;
00058 else
00059 m_extends_cls = m_wsdl.NamespaceFromHref(ns_href) + "::" + Split(m_extends).CName1up;
00060 }
00061
00062 {
00063 Xml::XmlNode n(start, "sequence");
00064 if (n)
00065 m_b_is_sequence = true;
00066 }
00067
00068 {
00069 Xml::XmlNode n(start, "all");
00070 if (n)
00071 m_b_is_all = true;
00072 }
00073
00074 {
00075
00076 Xml::XmlNode n(m_node, "complexContent");
00077 if (n)
00078 {
00079 m_b_complexContent = true;
00080 Xml::XmlNode n2(n, "restriction");
00081 if (n2)
00082 {
00083 if (n2.PropertyExists("base") && Split(n2.GetProperty("base")).Type == "Array")
00084 {
00085 Xml::XmlNode n3(n2, "attribute");
00086 if (n3 && n3.PropertyExists("arrayType"))
00087 {
00088 std::string tmp = n3.GetProperty("arrayType");
00089 Parse pa(tmp, "[]");
00090 tmp = pa.getword();
00091 SetType( tmp );
00092 m_b_is_array = true;
00093 }
00094 }
00095 }
00096 }
00097 }
00098 }
00099
00100
00101 ComplexType::~ComplexType()
00102 {
00103 }
00104
00105
00106 int ComplexType::NumberOfMembers() const
00107 {
00108 Xml::XmlNode n(Start(), m_b_is_sequence ? "sequence" : "all");
00109 int q = 0;
00110 if (n)
00111 {
00112 Xml::XmlNode n2(n, "element");
00113 while (n2)
00114 {
00115 q++;
00116 ++n2;
00117 }
00118 }
00119 return q;
00120 }
00121
00122
00123 bool ComplexType::GetRef(std::string& ref) const
00124 {
00125 Xml::XmlNode n(Start(), m_b_is_sequence ? "sequence" : "all");
00126 if (n)
00127 {
00128 Xml::XmlNode n2(n, "element");
00129 while (n2)
00130 {
00131 if (n2.PropertyExists("ref"))
00132 {
00133 ref = n2.GetProperty("ref");
00134 return true;
00135 }
00136 ++n2;
00137 }
00138 }
00139 return false;
00140 }
00141
00142
00143 std::list<std::pair<std::string, Xml::XmlNode> > ComplexType::GetMembers() const
00144 {
00145 std::list<std::pair<std::string, Xml::XmlNode> > vec;
00146 Xml::XmlNode n1(Start(), m_b_is_sequence ? "sequence" : "all");
00147 if (n1)
00148 {
00149 Xml::XmlNode n(n1, "element");
00150 while (n)
00151 {
00152 if (n.PropertyExists("ref"))
00153 {
00154 std::string name = n.GetProperty("ref");
00155 vec.push_back(std::pair<std::string, Xml::XmlNode>(name, n));
00156 }
00157 else
00158 {
00159 std::string name = n.GetProperty("name");
00160 vec.push_back(std::pair<std::string, Xml::XmlNode>(name, n));
00161 }
00162 ++n;
00163 }
00164 }
00165 return vec;
00166 }
00167
00168
00169 std::list<std::pair<std::string, Xml::XmlNode> > ComplexType::GetAttributes() const
00170 {
00171 std::list<std::pair<std::string, Xml::XmlNode> > vec;
00172 Xml::XmlNode n(Start(), "attribute");
00173 while (n)
00174 {
00175 std::string name = n.GetProperty("name");
00176 vec.push_back(std::pair<std::string, Xml::XmlNode>(name, n));
00177 ++n;
00178 }
00179 return vec;
00180 }
00181
00182
00183 const std::string ComplexType::Documentation() const
00184 {
00185 return TypeBase::Documentation(m_node);
00186 }
00187
00188
00189 const std::string ComplexType::CName() const
00190 {
00191 return Split(m_name).CName1up;
00192 }
00193
00194
00195 bool ComplexType::OkToGenerate() const
00196 {
00197 Debug deb("OkToGenerate for '" + Name() + "' in ns '" + NsHref() + "'");
00198 if (m_b_complexContent)
00199 {
00200 if (m_b_is_array)
00201 {
00202 try
00203 {
00204 Xml::XmlNode n = m_wsdl.FindComplexType( m_ns_href, Type() );
00205 ComplexType t(m_wsdl, n, Split(Type()).Type, Split(Type()).NS);
00206 if (!t.IsGenerated())
00207 {
00208 return false;
00209 }
00210 }
00211 catch (const Exception& )
00212 {
00213 }
00214 return true;
00215 }
00216 }
00217 std::list<std::pair<std::string, Xml::XmlNode> > members = GetMembers();
00218 std::list<std::pair<std::string, Xml::XmlNode> > attrs = GetAttributes();
00219 for (std::list<std::pair<std::string, Xml::XmlNode> >::const_iterator it = members.begin(); it != members.end(); it++)
00220 {
00221 const std::pair<std::string, Xml::XmlNode>& ref = *it;
00222 Element el(m_wsdl, ref.second, m_b_is_sequence, false, "", NsHref());
00223 if (el.IsComplexType())
00224 {
00225 Xml::XmlNode n = m_wsdl.FindComplexType( el.NsHref(), el.Type() );
00226 ComplexType t(m_wsdl, n, Split(el.Type()).Type, Split(el.Type()).NS);
00227 std::string parent = m_wsdl.GetParent(NsHref(), t.Name());
00228 if (!t.IsGenerated() && parent != Name())
00229 {
00230 return false;
00231 }
00232 }
00233 else
00234 {
00235 }
00236 }
00237 return true;
00238 }
00239
00240
00241 void ComplexType::SetGenerated(bool x)
00242 {
00243 m_b_generated[m_name] = x;
00244 }
00245
00246
00247 bool ComplexType::IsGenerated() const
00248 {
00249 std::map<std::string, bool>::const_iterator it = m_b_generated.find(m_name);
00250
00251 if (it != m_b_generated.end())
00252 {
00253 return true;
00254 }
00255 return false;
00256 }
00257
00258
00259 void ComplexType::CreateInterface(FILE *fil, int lvl) const
00260 {
00261 std::string prefix;
00262 for (int i = 0; i < lvl; i++)
00263 prefix += "\t";
00264 if (m_b_complexContent)
00265 {
00266 if (m_b_is_array)
00267 {
00268 fprintf(fil, "%stypedef %s<%s> %s;\n", prefix.c_str(), TypeBase::CType().c_str(), m_wsdl.GetApplication().ListType().c_str(), CName().c_str());
00269 }
00270 }
00271
00272 std::list<std::pair<std::string, Xml::XmlNode> > members = GetMembers();
00273 std::list<std::pair<std::string, Xml::XmlNode> > attrs = GetAttributes();
00274 if (members.empty() && attrs.empty() && !m_b_is_mixed)
00275 return;
00276
00277
00278 std::string parent = m_wsdl.GetParent(NsHref(), Name());
00279
00280
00281 if (m_extends.empty())
00282 {
00283 fprintf(fil, "%sclass %s\n%s{\n", prefix.c_str(), CName().c_str(), prefix.c_str());
00284 }
00285 else
00286 {
00287 fprintf(fil, "%sclass %s : public %s\n%s{\n", prefix.c_str(), CName().c_str(), m_extends_cls.c_str(), prefix.c_str());
00288 }
00289
00290
00291 try
00292 {
00293 const std::list<std::string>& ref = m_wsdl.ComplexTypes(NsHref());
00294 for (std::list<std::string>::const_iterator it = ref.begin(); it != ref.end(); it++)
00295 {
00296 std::string parent = m_wsdl.GetParent(NsHref(), *it);
00297 if (parent == Name())
00298 {
00299 fprintf(fil, "%spublic:\n", prefix.c_str());
00300 Xml::XmlNode n = m_wsdl.FindComplexType( m_ns_href, *it );
00301 ComplexType t(m_wsdl, n, *it, NsHref());
00302 t.CreateInterface(fil, lvl + 1);
00303 }
00304 }
00305 } catch (const Exception&) {}
00306 try
00307 {
00308 const std::list<std::string>& ref = m_wsdl.SimpleTypes(NsHref());
00309 for (std::list<std::string>::const_iterator it = ref.begin(); it != ref.end(); it++)
00310 {
00311 std::string parent = m_wsdl.GetParent(NsHref(), *it);
00312 if (parent == Name())
00313 {
00314 fprintf(fil, "%spublic:\n", prefix.c_str());
00315 Xml::XmlNode n = m_wsdl.FindSimpleType( m_ns_href, *it );
00316 SimpleType t(m_wsdl, n, *it, NsHref());
00317 t.CreateInterface(fil, lvl + 1);
00318 }
00319 }
00320 } catch (const Exception&) {}
00321
00322
00323 fprintf(fil, "%spublic:\n", prefix.c_str());
00324
00325 fprintf(fil, "%s\t%s();\n", prefix.c_str(), CName().c_str());
00326
00327 fprintf(fil, "%s\t%s(const Xml::XmlNode& it);\n", prefix.c_str(), CName().c_str());
00328
00329 fprintf(fil, "%s\tvirtual ~%s() {}\n", prefix.c_str(), CName().c_str());
00330 fprintf(fil, "\n");
00331
00332 fprintf(fil, "%s\tvoid FromXml(const Xml::XmlNode& it);\n", prefix.c_str());
00333 fprintf(fil, "\n");
00334
00335 fprintf(fil, "%s\tconst std::string ToString(const std::string& name = \"\") const;\n", prefix.c_str());
00336 fprintf(fil, "\n");
00337
00338 {
00339 fprintf(fil, "%s\tbool IsSet() const;\n", prefix.c_str());
00340 fprintf(fil, "\n");
00341 }
00342
00343 for (std::list<std::pair<std::string, Xml::XmlNode> >::const_iterator it = members.begin(); it != members.end(); it++)
00344 {
00345 const std::pair<std::string, Xml::XmlNode>& ref = *it;
00346 Element el(m_wsdl, ref.second, m_b_is_sequence, false, "", NsHref());
00347 if (el.IsVector() || el.IsComplexType())
00348 {
00349 fprintf(fil, "%s\tconst %s Get%s() const;\n", prefix.c_str(), el.CType_out().c_str(), el.CName1up().c_str());
00350 fprintf(fil, "%s\t%s Get%s();\n", prefix.c_str(), el.CType_out().c_str(), el.CName1up().c_str());
00351 fprintf(fil, "%s\tvoid Set%s(%s %s);\n",
00352 prefix.c_str(), el.CName1up().c_str(), el.CType_in().c_str(), el.CName().c_str());
00353 }
00354 else
00355 {
00356 fprintf(fil, "%s\t%s Get%s() const;\n", prefix.c_str(), el.CType_out().c_str(), el.CName1up().c_str());
00357 fprintf(fil, "%s\tvoid Set%s(%s %s);\n", prefix.c_str(), el.CName1up().c_str(),
00358 el.CType_in().c_str(), el.CName().c_str());
00359 }
00360 fprintf(fil, "\n");
00361 }
00362 for (std::list<std::pair<std::string, Xml::XmlNode> >::const_iterator it = attrs.begin(); it != attrs.end(); it++)
00363 {
00364 const std::pair<std::string, Xml::XmlNode>& ref = *it;
00365 Attribute attr(m_wsdl, ref.second, ref.first, NsHref());
00366
00367 fprintf(fil, "%s\t%s Get%s() const;\n", prefix.c_str(), attr.CType_out().c_str(), attr.CName1up().c_str());
00368
00369 {
00370 fprintf(fil, "%s\tvoid Set%s(%s %s);\n", prefix.c_str(), attr.CName1up().c_str(),
00371 attr.CType_in().c_str(), attr.CName().c_str());
00372 }
00373 }
00374 if (!attrs.empty())
00375 fprintf(fil, "\n");
00376 if (m_b_is_mixed)
00377 {
00378 fprintf(fil, "%s\tconst std::string& Get() const;\n", prefix.c_str());
00379 fprintf(fil, "%s\tvoid Set(const std::string&);\n", prefix.c_str());
00380 fprintf(fil, "\n");
00381 }
00382
00383 for (std::list<std::pair<std::string, Xml::XmlNode> >::const_iterator it = members.begin(); it != members.end(); it++)
00384 {
00385 const std::pair<std::string, Xml::XmlNode>& ref = *it;
00386 Element el(m_wsdl, ref.second, m_b_is_sequence, false, "", NsHref());
00387 if (el.IsVector() || el.IsComplexType())
00388 {
00389
00390 fprintf(fil, "%s\tbool %sIsSet() const;\n", prefix.c_str(), el.CName1up().c_str());
00391 }
00392 else
00393 {
00394 fprintf(fil, "%s\tbool %sIsSet() const { return _element_%s_is_set; }\n", prefix.c_str(), el.CName1up().c_str(), el.CName().c_str());
00395 }
00396 }
00397 if (!members.empty())
00398 fprintf(fil, "\n");
00399 for (std::list<std::pair<std::string, Xml::XmlNode> >::const_iterator it = attrs.begin(); it != attrs.end(); it++)
00400 {
00401 const std::pair<std::string, Xml::XmlNode>& ref = *it;
00402 Attribute attr(m_wsdl, ref.second, ref.first, NsHref());
00403
00404 fprintf(fil, "%s\tbool %sIsSet() const { return _attribute_%s_is_set; }\n", prefix.c_str(), attr.CName1up().c_str(), attr.CName().c_str());
00405 }
00406 if (!attrs.empty())
00407 fprintf(fil, "\n");
00408
00409 fprintf(fil, "%sprivate:\n", prefix.c_str());
00410
00411 for (std::list<std::pair<std::string, Xml::XmlNode> >::const_iterator it = members.begin(); it != members.end(); it++)
00412 {
00413 const std::pair<std::string, Xml::XmlNode>& ref = *it;
00414 Element el(m_wsdl, ref.second, m_b_is_sequence, false, "", NsHref());
00415 std::string doc = el.Documentation();
00416 if (!doc.empty())
00417 fprintf(fil, "%s\t/** %s */\n", prefix.c_str(), doc.c_str());
00418 fprintf(fil, "%s\t%s _element_%s;\n", prefix.c_str(), el.CType_decl().c_str(), el.CName().c_str());
00419 }
00420 for (std::list<std::pair<std::string, Xml::XmlNode> >::const_iterator it = attrs.begin(); it != attrs.end(); it++)
00421 {
00422 const std::pair<std::string, Xml::XmlNode>& ref = *it;
00423 Attribute attr(m_wsdl, ref.second, ref.first, NsHref());
00424
00425 fprintf(fil, "%s\t%s _attribute_%s;\n", prefix.c_str(), attr.CType_decl().c_str(), attr.CName().c_str());
00426 }
00427 if (m_b_is_mixed)
00428 {
00429 fprintf(fil, "%s\tstd::string m_mixed_content;\n", prefix.c_str());
00430 }
00431
00432 for (std::list<std::pair<std::string, Xml::XmlNode> >::const_iterator it = members.begin(); it != members.end(); it++)
00433 {
00434 const std::pair<std::string, Xml::XmlNode>& ref = *it;
00435 Element el(m_wsdl, ref.second, m_b_is_sequence, false, "", NsHref());
00436 if (el.IsVector() || el.IsComplexType())
00437 {
00438
00439 }
00440 else
00441 {
00442 fprintf(fil, "%s\tbool _element_%s_is_set;\n", prefix.c_str(), el.CName().c_str());
00443 }
00444 }
00445 for (std::list<std::pair<std::string, Xml::XmlNode> >::const_iterator it = attrs.begin(); it != attrs.end(); it++)
00446 {
00447 const std::pair<std::string, Xml::XmlNode>& ref = *it;
00448 Attribute attr(m_wsdl, ref.second, ref.first, NsHref());
00449
00450 fprintf(fil, "%s\tbool _attribute_%s_is_set;\n", prefix.c_str(), attr.CName().c_str());
00451 }
00452
00453 fprintf(fil, "%s};\n", prefix.c_str());
00454 fprintf(fil, "\n");
00455 }
00456
00457
00458 void ComplexType::reset_members(std::list<std::pair<std::string, Xml::XmlNode> >& members, std::list<std::pair<std::string, Xml::XmlNode> >& attrs, FILE *fil) const
00459 {
00460 std::string prefix = ": ";
00461 if (!m_extends.empty())
00462 {
00463 fprintf(fil, "%s%s()\n", prefix.c_str(), m_extends_cls.c_str());
00464 prefix = ", ";
00465 }
00466 for (std::list<std::pair<std::string, Xml::XmlNode> >::const_iterator it = members.begin(); it != members.end(); it++)
00467 {
00468 const std::pair<std::string, Xml::XmlNode>& ref = *it;
00469 Element el(m_wsdl, ref.second, m_b_is_sequence, false, "", NsHref());
00470 std::string def = el.DefaultValue();
00471 if (el.IsBuiltin() && !def.empty())
00472 {
00473 fprintf(fil, "%s_element_%s(%s)\n", prefix.c_str(), el.CName().c_str(), el.DefaultValue().c_str());
00474 prefix = ", ";
00475 }
00476 }
00477 for (std::list<std::pair<std::string, Xml::XmlNode> >::const_iterator it = members.begin(); it != members.end(); it++)
00478 {
00479 const std::pair<std::string, Xml::XmlNode>& ref = *it;
00480 Element el(m_wsdl, ref.second, m_b_is_sequence, false, "", NsHref());
00481 if (el.IsVector() || el.IsComplexType())
00482 {
00483
00484 }
00485 else
00486 {
00487 fprintf(fil, "%s_element_%s_is_set(false)\n", prefix.c_str(), el.CName().c_str());
00488 prefix = ", ";
00489 }
00490 }
00491 for (std::list<std::pair<std::string, Xml::XmlNode> >::const_iterator it = attrs.begin(); it != attrs.end(); it++)
00492 {
00493 const std::pair<std::string, Xml::XmlNode>& ref = *it;
00494 Attribute attr(m_wsdl, ref.second, "", NsHref());
00495 if (attr.DefaultIsSet())
00496 {
00497 if (attr.IsNumeric())
00498 fprintf(fil, "%s_attribute_%s(%s)\n", prefix.c_str(), attr.CName().c_str(), attr.Default().c_str());
00499 else
00500 fprintf(fil, "%s_attribute_%s(\"%s\")\n", prefix.c_str(), attr.CName().c_str(), attr.Default().c_str());
00501 prefix = ", ";
00502 }
00503 else
00504 if (attr.FixedIsSet())
00505 {
00506 if (attr.IsNumeric())
00507 fprintf(fil, "%s_attribute_%s(%s)\n", prefix.c_str(), attr.CName().c_str(), attr.Fixed().c_str());
00508 else
00509 fprintf(fil, "%s_attribute_%s(\"%s\")\n", prefix.c_str(), attr.CName().c_str(), attr.Fixed().c_str());
00510 prefix = ", ";
00511 }
00512 else
00513 {
00514 std::string def = attr.DefaultValue();
00515 if (attr.IsBuiltin() && !def.empty())
00516 {
00517 fprintf(fil, "%s_attribute_%s(%s)\n", prefix.c_str(), attr.CName().c_str(), attr.DefaultValue().c_str());
00518 prefix = ", ";
00519 }
00520 }
00521 }
00522 for (std::list<std::pair<std::string, Xml::XmlNode> >::const_iterator it = attrs.begin(); it != attrs.end(); it++)
00523 {
00524 const std::pair<std::string, Xml::XmlNode>& ref = *it;
00525 Attribute attr(m_wsdl, ref.second, "", NsHref());
00526 if (attr.DefaultIsSet() || attr.FixedIsSet())
00527 fprintf(fil, "%s_attribute_%s_is_set(true)\n", prefix.c_str(), attr.CName().c_str());
00528 else
00529 fprintf(fil, "%s_attribute_%s_is_set(false)\n", prefix.c_str(), attr.CName().c_str());
00530 prefix = ", ";
00531 }
00532 }
00533
00534
00535 void ComplexType::from_xml(std::list<std::pair<std::string, Xml::XmlNode> >& members, std::list<std::pair<std::string, Xml::XmlNode> >& attrs, FILE *fil) const
00536 {
00537 if (!m_extends.empty())
00538 {
00539 fprintf(fil, "\t%s::FromXml(it);\n", m_extends_cls.c_str());
00540 }
00541 for (std::list<std::pair<std::string, Xml::XmlNode> >::const_iterator it = members.begin(); it != members.end(); it++)
00542 {
00543 const std::pair<std::string, Xml::XmlNode>& ref = *it;
00544 Element el(m_wsdl, ref.second, m_b_is_sequence, false, "", NsHref());
00545 if (!el.IsOptional())
00546 {
00547 fprintf(fil, "\tif (!it.Exists(\"%s\"))\n", el.Name().c_str());
00548 fprintf(fil, "\t\tthrow Xml::XmlException(\"missing required node in element '%s': %s\");\n", m_name.c_str(), el.Name().c_str());
00549 }
00550 if (el.IsVector())
00551 {
00552 fprintf(fil, "\t{\n");
00553 fprintf(fil, "\t\tXml::XmlNode n(it, \"%s\");\n", el.Name().c_str());
00554 fprintf(fil, "\t\twhile (n)\n");
00555 fprintf(fil, "\t\t{\n");
00556 if (el.IsComplexType())
00557 {
00558 fprintf(fil, "\t\t\t%s tmp(n);\n", el.CType().c_str());
00559 fprintf(fil, "\t\t\t_element_%s.push_back( tmp );\n", el.CName().c_str());
00560 }
00561 else
00562 if (el.BaseType() == "std::string")
00563 {
00564 fprintf(fil, "\t\t\t_element_%s.push_back( n.GetContent() );\n", el.CName().c_str());
00565 }
00566 else
00567 {
00568 fprintf(fil, "\t\t\t_element_%s.push_back( atoi(n.GetContent().c_str()) );\n", el.CName().c_str());
00569 }
00570 fprintf(fil, "\t\t\t++n;\n");
00571 fprintf(fil, "\t\t}\n");
00572 fprintf(fil, "\t}\n");
00573 }
00574 else
00575 if (el.IsComplexType())
00576 {
00577 fprintf(fil, "\t{\n");
00578 fprintf(fil, "\t\tXml::XmlNode n(it, \"%s\");\n", el.Name().c_str());
00579 fprintf(fil, "\t\tif (n)\n");
00580 fprintf(fil, "\t\t\t_element_%s.FromXml( n );\n", el.CName().c_str());
00581 fprintf(fil, "\t}\n");
00582 }
00583 else
00584 if (el.BaseType() == "std::string")
00585 {
00586 if (el.IsOptional())
00587 fprintf(fil, "\tif (it.Exists(\"%s\"))\n\t", el.Name().c_str());
00588 fprintf(fil, "\tSet%s( it[\"%s\"] );\n", el.CName1up().c_str(), el.Name().c_str());
00589 }
00590 else
00591 {
00592 if (el.IsOptional())
00593 fprintf(fil, "\tif (it.Exists(\"%s\"))\n\t", el.Name().c_str());
00594 fprintf(fil, "\tSet%s( atoi(std::string(it[\"%s\"]).c_str()) );\n", el.CName1up().c_str(), el.Name().c_str());
00595 }
00596 }
00597 for (std::list<std::pair<std::string, Xml::XmlNode> >::const_iterator it = attrs.begin(); it != attrs.end(); it++)
00598 {
00599 const std::pair<std::string, Xml::XmlNode>& ref = *it;
00600 Attribute attr(m_wsdl, ref.second, "", NsHref());
00601
00602 if (attr.IsOptional())
00603 {
00604 fprintf(fil, "\tif (it.PropertyExists(\"%s\"))\n\t", attr.Name().c_str());
00605 }
00606 if (attr.BaseType() == "std::string")
00607 fprintf(fil, "\tSet%s(it.GetProperty(\"%s\"));\n", attr.CName1up().c_str(), attr.Name().c_str());
00608 else
00609 fprintf(fil, "\tSet%s( atoi(it.GetProperty(\"%s\").c_str()) );\n", attr.CName1up().c_str(), attr.Name().c_str());
00610 }
00611 if (m_b_is_mixed)
00612 {
00613 fprintf(fil, "\tm_mixed_content = it.GetContent();\n");
00614 }
00615 }
00616
00617
00618 void ComplexType::to_string(std::list<std::pair<std::string, Xml::XmlNode> >& members, std::list<std::pair<std::string, Xml::XmlNode> >& attrs, FILE *fil) const
00619 {
00620 fprintf(fil, "\tstd::string r;\n");
00621 if (attrs.empty())
00622 {
00623 fprintf(fil, "\tif (!name.empty())\n\t");
00624 fprintf(fil, "\tr += \"<\" + name + \">\";\n");
00625 }
00626 else
00627 {
00628 fprintf(fil, "\tif (!name.empty())\n\t");
00629 fprintf(fil, "\tr += \"<\" + name;\n");
00630
00631 for (std::list<std::pair<std::string, Xml::XmlNode> >::const_iterator it = attrs.begin(); it != attrs.end(); it++)
00632 {
00633 const std::pair<std::string, Xml::XmlNode>& ref = *it;
00634 Attribute attr(m_wsdl, ref.second, "", NsHref());
00635
00636 if (attr.IsOptional())
00637 {
00638 fprintf(fil, "\tif (%sIsSet())\n\t", attr.CName1up().c_str());
00639 }
00640 if (attr.BaseType() == "std::string")
00641 fprintf(fil, "\tr += \" %s='\" + Get%s() + \"'\";\n", attr.Name().c_str(), attr.CName1up().c_str());
00642 else
00643 {
00644 fprintf(fil, "{\n");
00645 fprintf(fil, "\t\tr = r + \" %s='\" + Utility::l2string(Get%s()) + \"'\";\n", attr.Name().c_str(), attr.CName1up().c_str());
00646 fprintf(fil, "\t}\n");
00647 }
00648 }
00649 fprintf(fil, "\tr += \">\";\n");
00650 }
00651 if (!m_extends.empty())
00652 {
00653 fprintf(fil, "\tr += %s::ToString();\n", m_extends_cls.c_str());
00654 }
00655 for (std::list<std::pair<std::string, Xml::XmlNode> >::const_iterator it = members.begin(); it != members.end(); it++)
00656 {
00657 const std::pair<std::string, Xml::XmlNode>& ref = *it;
00658 Element el(m_wsdl, ref.second, m_b_is_sequence, false, "", NsHref());
00659 if (el.IsVector())
00660 {
00661 fprintf(fil, "\tfor (%s<%s>::const_iterator it = _element_%s.begin(); it != _element_%s.end(); it++)\n",
00662 m_wsdl.GetApplication().ListType().c_str(),
00663 el.CType().c_str(), el.CName().c_str(), el.CName().c_str());
00664 fprintf(fil, "\t{\n");
00665
00666 if (el.IsComplexType())
00667 {
00668 fprintf(fil, "\t\tconst %s& ref = *it;\n", el.CType().c_str());
00669 fprintf(fil, "\t\tr += ref.ToString(\"%s\");\n", el.Name().c_str());
00670 }
00671 else
00672 if (el.BaseType() == "std::string")
00673 {
00674 fprintf(fil, "\t\tr += \"<%s>\" + *it + \"</%s>\";\n",
00675 el.Name().c_str(), el.Name().c_str());
00676 }
00677 else
00678 {
00679 fprintf(fil, "\t\t{\n");
00680 fprintf(fil, "\t\t\tr = r + \"<%s>\" + Utility::l2string(*it) + \"</%s>\";\n",
00681 el.Name().c_str(), el.Name().c_str());
00682 fprintf(fil, "\t\t}\n");
00683 }
00684
00685 fprintf(fil, "\t}\n");
00686 }
00687 else
00688 if (el.IsComplexType())
00689 {
00690 fprintf(fil, "\tr += _element_%s.ToString(\"%s\");\n", el.CName().c_str(), el.Name().c_str());
00691 }
00692 else
00693 if (el.BaseType() == "std::string")
00694 {
00695 if (el.IsOptional())
00696 fprintf(fil, "\tif (_element_%s_is_set)\n\t", el.CName().c_str());
00697 fprintf(fil, "\tr += \"<%s>\" + _element_%s + \"</%s>\";\n",
00698 el.Name().c_str(), el.CName().c_str(), el.Name().c_str());
00699 }
00700 else
00701 {
00702 if (el.IsOptional())
00703 fprintf(fil, "\tif (_element_%s_is_set)\n", el.CName().c_str());
00704 fprintf(fil, "\t{\n");
00705 fprintf(fil, "\t\tr = r + \"<%s>\" + Utility::l2string(_element_%s) + \"</%s>\";\n",
00706 el.Name().c_str(), el.CName().c_str(), el.Name().c_str());
00707 fprintf(fil, "\t}\n");
00708 }
00709 }
00710 if (m_b_is_mixed)
00711 {
00712 fprintf(fil, "\tr += m_mixed_content;\n");
00713 }
00714 fprintf(fil, "\tif (!name.empty())\n\t");
00715 fprintf(fil, "\tr += \"</\" + name + \">\";\n");
00716 fprintf(fil, "\treturn r;\n");
00717 }
00718
00719
00720 void ComplexType::CreateImplementation(FILE *fil) const
00721 {
00722 std::list<std::pair<std::string, Xml::XmlNode> > members = GetMembers();
00723 std::list<std::pair<std::string, Xml::XmlNode> > attrs = GetAttributes();
00724 if (members.empty() && attrs.empty() && !m_b_is_mixed)
00725 return;
00726
00727 std::string parent = m_wsdl.GetParent(NsHref(), Name());
00728 std::string tmp;
00729 while (!parent.empty())
00730 {
00731 tmp = Split(parent).CName1up + "::" + tmp;
00732 parent = m_wsdl.GetParent(NsHref(), parent);
00733 }
00734 std::string classname = tmp + CName();
00735
00736
00737 fprintf(fil, "// -----------------------------------------------------------------------------\n");
00738 fprintf(fil, "%s::%s()\n", classname.c_str(), CName().c_str());
00739 reset_members(members, attrs, fil);
00740 fprintf(fil, "{\n");
00741 fprintf(fil, "}\n\n\n");
00742
00743 fprintf(fil, "// -----------------------------------------------------------------------------\n");
00744 fprintf(fil, "%s::%s(const Xml::XmlNode& it)\n", classname.c_str(), CName().c_str());
00745 reset_members(members, attrs, fil);
00746 fprintf(fil, "{\n");
00747 fprintf(fil, "\tFromXml(it);\n");
00748 fprintf(fil, "}\n\n\n");
00749
00750 fprintf(fil, "// -----------------------------------------------------------------------------\n");
00751 fprintf(fil, "void %s::FromXml(const Xml::XmlNode& it)\n{\n", classname.c_str());
00752 from_xml(members, attrs, fil);
00753 fprintf(fil, "}\n\n\n");
00754
00755 fprintf(fil, "// -----------------------------------------------------------------------------\n");
00756 fprintf(fil, "const std::string %s::ToString(const std::string& name) const\n{\n", classname.c_str());
00757 to_string(members, attrs, fil);
00758 fprintf(fil, "}\n\n\n");
00759
00760 {
00761 fprintf(fil, "// -----------------------------------------------------------------------------\n");
00762 fprintf(fil, "bool %s::IsSet() const\n{\n", classname.c_str());
00763 std::string prefix = "\treturn ";
00764 for (std::list<std::pair<std::string, Xml::XmlNode> >::const_iterator it = members.begin(); it != members.end(); it++)
00765 {
00766 const std::pair<std::string, Xml::XmlNode>& ref = *it;
00767 Element el(m_wsdl, ref.second, m_b_is_sequence, false, "", NsHref());
00768 fprintf(fil, "%s%sIsSet()", prefix.c_str(), el.CName1up().c_str());
00769 prefix = " || ";
00770 }
00771 for (std::list<std::pair<std::string, Xml::XmlNode> >::const_iterator it = attrs.begin(); it != attrs.end(); it++)
00772 {
00773 const std::pair<std::string, Xml::XmlNode>& ref = *it;
00774 Attribute attr(m_wsdl, ref.second, "", NsHref());
00775 fprintf(fil, "%s%sIsSet()", prefix.c_str(), attr.CName1up().c_str());
00776 prefix = " || ";
00777 }
00778 if (m_b_is_mixed)
00779 {
00780 fprintf(fil, "%s!m_mixed_content.empty()", prefix.c_str());
00781 prefix = " || ";
00782 }
00783 fprintf(fil, ";\n");
00784 fprintf(fil, "}\n\n\n");
00785 }
00786
00787 for (std::list<std::pair<std::string, Xml::XmlNode> >::const_iterator it = members.begin(); it != members.end(); it++)
00788 {
00789 const std::pair<std::string, Xml::XmlNode>& ref = *it;
00790 Element el(m_wsdl, ref.second, m_b_is_sequence, false, "", NsHref());
00791 fprintf(fil, "// -----------------------------------------------------------------------------\n");
00792 if (el.IsVector() || el.IsComplexType())
00793 {
00794 fprintf(fil, "const %s %s::Get%s() const\n{\n", el.CType_out().c_str(), classname.c_str(), el.CName1up().c_str());
00795 fprintf(fil, "\treturn _element_%s;\n", el.CName().c_str());
00796 fprintf(fil, "}\n\n\n");
00797 fprintf(fil, "%s %s::Get%s()\n{\n", el.CType_out().c_str(), classname.c_str(), el.CName1up().c_str());
00798 fprintf(fil, "\treturn _element_%s;\n", el.CName().c_str());
00799 fprintf(fil, "}\n\n\n");
00800 fprintf(fil, "void %s::Set%s(%s %s)\n{\n\t_element_%s = %s;\n}\n\n\n",
00801 classname.c_str(),
00802 el.CName1up().c_str(), el.CType_in().c_str(), el.CName().c_str(),
00803 el.CName().c_str(), el.CName().c_str());
00804 }
00805 else
00806 {
00807 fprintf(fil, "%s %s::Get%s() const\n{\n", el.CType_out().c_str(), classname.c_str(), el.CName1up().c_str());
00808 fprintf(fil, "\treturn _element_%s;\n", el.CName().c_str());
00809 fprintf(fil, "}\n\n\n");
00810 fprintf(fil, "void %s::Set%s(%s %s)\n{\n", classname.c_str(), el.CName1up().c_str(),
00811 el.CType_in().c_str(), el.CName().c_str());
00812 fprintf(fil, "\t_element_%s = %s;\n", el.CName().c_str(), el.CName().c_str());
00813 fprintf(fil, "\t_element_%s_is_set = true;\n", el.CName().c_str());
00814 fprintf(fil, "}\n\n\n");
00815 }
00816 }
00817
00818 for (std::list<std::pair<std::string, Xml::XmlNode> >::const_iterator it = members.begin(); it != members.end(); it++)
00819 {
00820 const std::pair<std::string, Xml::XmlNode>& ref = *it;
00821 Element el(m_wsdl, ref.second, m_b_is_sequence, false, "", NsHref());
00822 if (el.IsVector() || el.IsComplexType())
00823 {
00824
00825 fprintf(fil, "// -----------------------------------------------------------------------------\n");
00826 fprintf(fil, "bool %s::%sIsSet() const\n{\n", classname.c_str(), el.CName1up().c_str());
00827 if (el.IsVector())
00828 fprintf(fil, "\treturn !_element_%s.empty();\n", el.CName().c_str());
00829 else
00830 fprintf(fil, "\treturn _element_%s.IsSet();\n", el.CName().c_str());
00831 fprintf(fil, "}\n\n\n");
00832 }
00833 else
00834 {
00835 }
00836 }
00837
00838 for (std::list<std::pair<std::string, Xml::XmlNode> >::const_iterator it = attrs.begin(); it != attrs.end(); it++)
00839 {
00840 const std::pair<std::string, Xml::XmlNode>& ref = *it;
00841 Attribute attr(m_wsdl, ref.second, "", NsHref());
00842 fprintf(fil, "// -----------------------------------------------------------------------------\n");
00843 {
00844 fprintf(fil, "%s %s::Get%s() const\n{\n", attr.CType_out().c_str(), classname.c_str(), attr.CName1up().c_str());
00845 fprintf(fil, "\treturn _attribute_%s;\n", attr.CName().c_str());
00846 fprintf(fil, "}\n\n\n");
00847
00848 {
00849 fprintf(fil, "void %s::Set%s(%s %s)\n{\n", classname.c_str(), attr.CName1up().c_str(),
00850 attr.CType_in().c_str(), attr.CName().c_str());
00851 fprintf(fil, "\t_attribute_%s = %s;\n", attr.CName().c_str(), attr.CName().c_str());
00852 fprintf(fil, "\t_attribute_%s_is_set = true;\n", attr.CName().c_str());
00853 fprintf(fil, "}\n\n\n");
00854 }
00855 }
00856 }
00857 if (m_b_is_mixed)
00858 {
00859 fprintf(fil, "// -----------------------------------------------------------------------------\n");
00860 fprintf(fil, "const std::string& %s::Get() const\n", classname.c_str());
00861 fprintf(fil, "{\n");
00862 fprintf(fil, "\treturn m_mixed_content;\n");
00863 fprintf(fil, "}\n\n\n");
00864 fprintf(fil, "// -----------------------------------------------------------------------------\n");
00865 fprintf(fil, "void %s::Set(const std::string& x)\n", classname.c_str());
00866 fprintf(fil, "{\n");
00867 fprintf(fil, "\tm_mixed_content = x;\n");
00868 fprintf(fil, "}\n\n\n");
00869 }
00870 }
00871
00872
00873 Xml::XmlNode ComplexType::Start() const
00874 {
00875 Xml::XmlNode complexContent(m_node, "complexContent");
00876 if (complexContent)
00877 {
00878 Xml::XmlNode extension(complexContent, "extension");
00879 if (extension)
00880 {
00881 if (extension.PropertyExists("base"))
00882 {
00883 return extension;
00884 }
00885 }
00886 }
00887 return m_node;
00888 }
00889
00890
00891 void ComplexType::ShowGenerated()
00892 {
00893 for (std::map<std::string, bool>::iterator it = m_b_generated.begin(); it != m_b_generated.end(); it++)
00894 {
00895 std::cout << "generated: " << it -> first << std::endl;
00896 }
00897 }
00898
00899