00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "TypeBase.h"
00023 #include "Wsdl.h"
00024 #include <Sockets/XmlNode.h>
00025 #include "Split.h"
00026 #include "WsdlException.h"
00027
00028 #define DEB(x)
00029
00030
00031 TypeBase::TypeBase(const Wsdl& wsdl, const Xml::XmlNode& node, const std::string& ns_prefix, const std::string& type) : m_wsdl(wsdl)
00032 , m_node(node)
00033 , m_ns_href( ns_prefix )
00034 , m_type(type)
00035 , m_b_is_numeric(false)
00036 {
00037 if (!type.empty())
00038 {
00039 SetType( type );
00040 }
00041 }
00042
00043
00044 TypeBase::~TypeBase()
00045 {
00046 }
00047
00048
00049 const std::string TypeBase::Documentation(const Xml::XmlNode& node) const
00050 {
00051 Xml::XmlNode n(node, "annotation");
00052 if (n)
00053 {
00054 Xml::XmlNode n2(n, "documentation");
00055 if (n2)
00056 {
00057 return n2.GetContent();
00058 }
00059 }
00060 return "";
00061 }
00062
00063
00064 const std::string TypeBase::CType() const
00065 {
00066 std::string t;
00067 if (IsBuiltin())
00068 {
00069 t = Split(m_type).CName;
00070 if (t == "string" || t == "date" || t == "dateTime" ||
00071 t == "anySimpleType" || t == "anyURI" ||
00072 t == "time"
00073 )
00074 {
00075 t = "std::string";
00076 }
00077 if (t == "boolean")
00078 t = "bool";
00079 if (t == "byte")
00080 t = "char";
00081 if (t == "decimal")
00082 t = "double";
00083 if (t == "integer")
00084 t = "int";
00085 if (t == "unsignedByte")
00086 t = "unsigned char";
00087 if (t == "unsignedInt")
00088 t = "unsigned int";
00089 if (t == "unsignedShort")
00090 t = "unsigned short";
00091 }
00092 else
00093 {
00094 std::string parent = m_wsdl.GetParent(m_ns_href, m_type);
00095 std::string tmp;
00096 while (!parent.empty())
00097 {
00098 tmp = Split(parent).CName1up + "::" + tmp;
00099 parent = m_wsdl.GetParent(m_ns_href, parent);
00100 }
00101 if (m_wsdl.GetNamespace(m_ns_href).empty())
00102 t = tmp + Split(m_type).CName1up;
00103 else
00104 t = m_wsdl.GetNamespace(m_ns_href) + "::" + tmp + Split(m_type).CName1up;
00105 }
00106 return t;
00107 }
00108
00109
00110 void TypeBase::SetType(const std::string& x)
00111 {
00112 std::string href = m_node.GetNsMap()[Split(x).NS];
00113 if (Split(x).NS.empty())
00114 {
00115 href = m_wsdl.GetTargetNamespace();
00116 Xml::XmlNode n(m_node);
00117 std::string alt = n.FindProperty("targetNamespace", true);
00118 if (!alt.empty() && alt != href)
00119 {
00120 href = alt;
00121 }
00122 }
00123 if (href.empty())
00124 {
00125 std::map<std::string, std::string> mmap = m_node.GetNsMap();
00126 DEB( for (std::map<std::string, std::string>::iterator it = mmap.begin(); it != mmap.end(); it++)
00127 {
00128 printf("prefix '%s' namespace '%s'\n", it -> first.c_str(), it -> second.c_str());
00129 })
00130 throw WsdlException("Empty href, type = \"" + x + "\"");
00131 }
00132 m_ns_href = href;
00133 m_type = Split(x).Type;
00134 std::string ctype = CType();
00135 if (ctype.find("int") != std::string::npos ||
00136 ctype.find("short") != std::string::npos ||
00137 ctype.find("double") != std::string::npos)
00138 {
00139 m_b_is_numeric = true;
00140 }
00141 }
00142
00143
00144 bool TypeBase::IsBuiltin() const
00145 {
00146 return m_ns_href == "http://www.w3.org/2001/XMLSchema";
00147 }
00148
00149