00001 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 #include "Attribute.h"
00023 #include <Sockets/XmlNode.h>
00024 #include "WsdlException.h"
00025 #include <Sockets/Debug.h>
00026 #include "Split.h"
00027 #include "Wsdl.h"
00028 #include "SimpleType.h"
00029 
00030 
00031 Attribute::Attribute(const Wsdl& wsdl, const Xml::XmlNode& node, const std::string& name, const std::string& ns_prefix)
00032 : TypeBase(wsdl, node, ns_prefix, Split(name).Type)
00033 , m_name(!name.empty() ? name : node.PropertyExists("name") ? node.GetProperty("name") : "")
00034 , m_b_default_is_set(false)
00035 , m_b_fixed_is_set(false)
00036 {
00037         if (node.PropertyExists("type"))
00038         {
00039                 std::string type = node.GetProperty("type");
00040                 SetType(type);
00041         }
00042         else
00043         {
00044                 Xml::XmlNode n(node, "simpleType");
00045                 if (n)
00046                 {
00047                         std::string type = ns_prefix + "::" + Split(m_name).Type + "_t";
00048                         SetType(type);
00049                 }
00050         }
00051         if (node.PropertyExists("use"))
00052                 m_use = node.GetProperty("use");
00053         if (node.PropertyExists("default"))
00054         {
00055                 m_default = node.GetProperty("default");
00056                 m_b_default_is_set = true;
00057         }
00058         if (node.PropertyExists("fixed"))
00059         {
00060                 m_fixed = node.GetProperty("fixed");
00061                 m_b_fixed_is_set = true;
00062         }
00063         
00064         std::string t = TypeBase::CType();
00065         if (IsSimpleType())
00066         {
00067                 Xml::XmlNode n = m_wsdl.FindSimpleType(m_ns_href, m_type);
00068                 SimpleType sim(m_wsdl, n, Split(m_type).Type, Split(m_type).NS);
00069                 t = sim.CType(); 
00070         }
00071         m_base_type = t;
00072 }
00073 
00074 
00075 Attribute::~Attribute()
00076 {
00077 }
00078 
00079 
00080 const std::string Attribute::Documentation() const
00081 {
00082         return TypeBase::Documentation(m_node);
00083 }
00084 
00085 
00086 const std::string Attribute::CType() const
00087 {
00088         return TypeBase::CType();
00089 }
00090 
00091 
00092 const std::string Attribute::CName() const
00093 {
00094         return Split(m_name).CName;
00095 }
00096 
00097 
00098 const std::string Attribute::CName1up() const
00099 {
00100         return Split(m_name).CName1up;
00101 }
00102 
00103 
00104 bool Attribute::IsOptional() const
00105 {
00106         return m_use != "required";
00107 }
00108 
00109 
00110 const std::string Attribute::CType_decl() const
00111 {
00112         std::string t = TypeBase::CType();
00113         if (IsSimpleType())
00114         {
00115                 Xml::XmlNode n = m_wsdl.FindSimpleType(m_ns_href, m_type);
00116                 SimpleType sim(m_wsdl, n, Split(m_type).Type, Split(m_type).NS);
00117                 t = sim.CType(); 
00118         }
00119         return t;
00120 }
00121 
00122 
00123 const std::string Attribute::CType_in() const
00124 {
00125         std::string t = TypeBase::CType();
00126         if (IsSimpleType())
00127         {
00128                 Xml::XmlNode n = m_wsdl.FindSimpleType(m_ns_href, m_type);
00129                 SimpleType sim(m_wsdl, n, Split(m_type).Type, Split(m_type).NS);
00130                 t = sim.CType(); 
00131         }
00132         if (IsBuiltin() || IsSimpleType())
00133         {
00134                 if (t == "std::string")
00135                 {
00136                         t = "const " + t + "&";
00137                 }
00138         }
00139         else
00140         {
00141                 t = "const " + t + "&";
00142         }
00143         return t;
00144 }
00145 
00146 
00147 const std::string Attribute::CType_out() const
00148 {
00149         std::string t = TypeBase::CType();
00150         if (IsSimpleType())
00151         {
00152                 Xml::XmlNode n = m_wsdl.FindSimpleType(m_ns_href, m_type);
00153                 SimpleType sim(m_wsdl, n, Split(m_type).Type, Split(m_type).NS);
00154                 t = sim.CType(); 
00155         }
00156         if (IsBuiltin() || IsSimpleType())
00157         {
00158                 if (t == "std::string")
00159                 {
00160                         t = "const " + t + "&";
00161                 }
00162         }
00163         else
00164         {
00165                 t = t + "&";
00166         }
00167         return t;
00168 }
00169 
00170 
00171 const std::string Attribute::DefaultValue() const
00172 {
00173         if (IsNumeric())
00174                 return "0";
00175         if (CType() == "bool")
00176                 return "false";
00177         return "";
00178 }
00179 
00180 
00181 bool Attribute::IsSimpleType() const
00182 {
00183         if (IsBuiltin())
00184                 return false;
00185         try
00186         {
00187                 Xml::XmlNode n = m_wsdl.FindSimpleType(m_ns_href, m_type);
00188                 return true;
00189         }
00190         catch (const Exception& e)
00191         {
00192         }
00193         return false;
00194 }
00195 
00196