00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "Element.h"
00023 #include <Sockets/XmlNode.h>
00024 #include "WsdlException.h"
00025 #include "Wsdl.h"
00026 #include "Split.h"
00027 #include "SimpleType.h"
00028 #include <iostream>
00029 #include "Application.h"
00030
00031
00032 Element::Element(const Wsdl& wsdl, const Xml::XmlNode& node, bool in_sequence, bool in_choice, const std::string& name, const std::string& ns_prefix)
00033 : TypeBase(wsdl, node, ns_prefix, "")
00034 , m_appl(wsdl.GetApplication())
00035 , m_name(!name.empty() ? name : node.PropertyExists("name") ? node.GetProperty("name") : "")
00036 , m_minOccurs(node.PropertyExists("minOccurs") ? atoi(node.GetProperty("minOccurs").c_str()) : 1)
00037 , m_maxOccurs(1)
00038 {
00039 if (node.PropertyExists("type"))
00040 {
00041 std::string type = node.GetProperty("type");
00042 SetType(type);
00043 }
00044 else
00045 if (node.PropertyExists("ref"))
00046 {
00047 m_name = node.GetProperty("ref");
00048 Xml::XmlNode n = wsdl.GetElement( m_name );
00049 if (n)
00050 {
00051 if (n.PropertyExists("type"))
00052 {
00053 std::string type = n.GetProperty("type");
00054 SetType(type);
00055 }
00056 }
00057 }
00058 else
00059 {
00060 Xml::XmlNode n(node, "complexType");
00061 if (n)
00062 {
00063 std::string prefix = node.GetNsMapRe()[ns_prefix];
00064 std::string type = prefix + ":" + m_name + "_t";
00065 SetType(type);
00066 }
00067 }
00068 if (node.PropertyExists("maxOccurs"))
00069 {
00070 std::string max = node.GetProperty("maxOccurs");
00071 if (max == "unbounded")
00072 {
00073 if (!in_sequence)
00074 throw WsdlException("Using 'unbounded' on maxOccurs outside sequence");
00075 m_maxOccurs = -1;
00076 }
00077 else
00078 m_maxOccurs = atoi(max.c_str());
00079 }
00080
00081 std::string t = TypeBase::CType();
00082 if (IsSimpleType())
00083 {
00084 Xml::XmlNode n = m_wsdl.FindSimpleType(m_ns_href, m_type);
00085 SimpleType sim(m_wsdl, n, Split(m_type).Type, Split(m_type).NS);
00086 t = sim.CType();
00087 }
00088 m_base_type = t;
00089 }
00090
00091
00092 Element::~Element()
00093 {
00094 }
00095
00096
00097 const std::string Element::Documentation() const
00098 {
00099 Xml::XmlNode n(m_node, "annotation");
00100 if (n)
00101 {
00102 Xml::XmlNode n2(n, "documentation");
00103 if (n2)
00104 {
00105 return n2.GetContent();
00106 }
00107 }
00108 return "";
00109 }
00110
00111
00112 void Element::CreateInterface(FILE *fil) const
00113 {
00114 }
00115
00116
00117 const std::string Element::CType_decl() const
00118 {
00119 std::string t = TypeBase::CType();
00120 if (IsSimpleType())
00121 {
00122 Xml::XmlNode n = m_wsdl.FindSimpleType(m_ns_href, m_type);
00123 SimpleType sim(m_wsdl, n, Split(m_type).Type, Split(m_type).NS);
00124 t = sim.CType();
00125 }
00126 if (IsVector())
00127 {
00128 t = m_appl.ListType() + "<" + t + ">";
00129 }
00130 return t;
00131 }
00132
00133
00134 const std::string Element::CType_in() const
00135 {
00136 std::string t = TypeBase::CType();
00137 if (IsSimpleType())
00138 {
00139 Xml::XmlNode n = m_wsdl.FindSimpleType(m_ns_href, m_type);
00140 SimpleType sim(m_wsdl, n, Split(m_type).Type, Split(m_type).NS);
00141 t = sim.CType();
00142 }
00143 if (IsBuiltin() || IsSimpleType())
00144 {
00145 if (t == "std::string")
00146 {
00147 if (!IsVector())
00148 t = "const " + t + "&";
00149 }
00150 }
00151 else
00152 {
00153 if (!IsVector())
00154 t = "const " + t + "&";
00155 }
00156 if (IsVector())
00157 {
00158 t = "const " + m_appl.ListType() + "<" + t + ">&";
00159 }
00160 return t;
00161 }
00162
00163
00164 const std::string Element::CType_out() const
00165 {
00166 std::string t = TypeBase::CType();
00167 if (IsSimpleType())
00168 {
00169 Xml::XmlNode n = m_wsdl.FindSimpleType(m_ns_href, m_type);
00170 SimpleType sim(m_wsdl, n, Split(m_type).Type, Split(m_type).NS);
00171 t = sim.CType();
00172 }
00173 if (IsBuiltin() || IsSimpleType())
00174 {
00175 if (t == "std::string")
00176 {
00177 if (!IsVector())
00178 t = "const " + t + "&";
00179 }
00180 }
00181 else
00182 {
00183 if (!IsVector())
00184 t = t + "&";
00185 }
00186 if (IsVector())
00187 {
00188 t = m_appl.ListType() + "<" + t + ">&";
00189 }
00190 return t;
00191 }
00192
00193
00194 const std::string Element::CName() const
00195 {
00196 return Split(m_name).CName;
00197 }
00198
00199
00200 const std::string Element::CName1up() const
00201 {
00202 return Split(m_name).CName1up;
00203 }
00204
00205
00206 const std::string Element::DefaultValue() const
00207 {
00208 if (IsBuiltin())
00209 {
00210 std::string t = Split(m_type).CName;
00211 if (t == "string" || t == "date" || t == "dateTime")
00212 {
00213 }
00214 else
00215 return "0";
00216 }
00217 return "";
00218 }
00219
00220
00221 bool Element::IsComplexType() const
00222 {
00223 if (IsBuiltin())
00224 return false;
00225 try
00226 {
00227 Xml::XmlNode n = m_wsdl.FindComplexType(m_ns_href, m_type);
00228 return true;
00229 }
00230 catch (const Exception& e)
00231 {
00232 }
00233 return false;
00234 }
00235
00236
00237 bool Element::IsSimpleType() const
00238 {
00239 if (IsBuiltin())
00240 return false;
00241 try
00242 {
00243 Xml::XmlNode n = m_wsdl.FindSimpleType(m_ns_href, m_type);
00244 return true;
00245 }
00246 catch (const Exception& e)
00247 {
00248 }
00249 return false;
00250 }
00251
00252