Back to index

nordugrid-arc-nox  1.1.0~rc6
schemaconv.cpp
Go to the documentation of this file.
00001 #ifdef HAVE_CONFIG_H
00002 #include <config.h>
00003 #endif
00004 
00005 #include <string>
00006 #include <iostream>
00007 
00008 #include <arc/XMLNode.h>
00009 #include <arc/StringConv.h>
00010 
00011 #include "schemaconv.h"
00012 
00013 using namespace Arc;
00014 
00015 
00016 bool schemaconv(XMLNode wsdl,std::ostream& h_file,std::ostream& cpp_file,const std::string& name) {
00017   h_file<<"\
00018 #include <arc/XMLNode.h>\n\
00019 \n\
00020 namespace "<<name<<" {\n\
00021 \n\
00022 ";
00023   cpp_file<<"\
00024 #include \""<<name<<".h\"\n\
00025 \n\
00026 namespace "<<name<<" {\n\
00027 \n\
00028 ";
00029   
00030   Arc::NS ns;
00031   ns["wsdl"]="http://schemas.xmlsoap.org/wsdl/";
00032   ns["xsd"]="http://www.w3.org/2001/XMLSchema";
00033   wsdl.Namespaces(ns);
00034   XMLNode schema;
00035   if(wsdl.FullName() == "wsdl:definitions") {
00036     schema = wsdl["wsdl:types"]["xsd:schema"];
00037     if(!schema) {
00038       std::cerr<<"No Schema in WSDL"<<std::endl;
00039       return false;
00040     };  
00041   } else if(wsdl.FullName() == "xsd:schema") {
00042     schema = wsdl;
00043   } else {
00044     std::cerr<<"Neither WSDL nor XSD found"<<std::endl;
00045   }
00046   std::string nnamespace = (std::string)(schema.Attribute("targetNamespace"));
00047   if(nnamespace.empty()) {
00048     std::cerr<<"No namespace for new elements in Schema"<<std::endl;
00049     return false;
00050   };
00051   // Declaring classes 
00052   for(int n = 0;;++n) {
00053     XMLNode type = schema.Child(n);
00054     if(!type) break;
00055     std::string ntype = type.Attribute("name");
00056     if(ntype.empty()) continue;
00057     strprintf(h_file,"class %s;\n",ntype);
00058   };
00059   // Simple types
00060   for(XMLNode stype = schema["xsd:simpleType"];(bool)stype;++stype) {
00061     simpletypeprint(stype,nnamespace,h_file,cpp_file);
00062   };
00063   // Complex types
00064   for(XMLNode ctype = schema["xsd:complexType"];(bool)ctype;++ctype) {
00065     complextypeprint(ctype,nnamespace,h_file,cpp_file);
00066   };
00067 
00068   h_file<<"\
00069 } // namespace A\n\
00070 ";
00071   cpp_file<<"\
00072 } // namespace A\n\
00073 \n\
00074 ";
00075 
00076   return true;
00077 }
00078 
00079