📄 service.cpp
字号:
types.gen((*schema)->targetNamespace, (*attribute).name, *(*attribute).simpleTypePtr(), false); // URI = NULL won't generate type in schema (type without namespace qualifier) } } for (vector<xs__complexType>::iterator complexType = (*schema)->complexType.begin(); complexType != (*schema)->complexType.end(); ++complexType) { if ((*complexType).baseLevel() == baseLevel) found = true; } } ++baseLevel; } while (found); // generate complex type defs. Problem: what if a simpleType restriction/extension depends on a complexType simpleContent restriction/extension? int maxLevel = baseLevel; for (baseLevel = 1; baseLevel < maxLevel; ++baseLevel) { for (vector<xs__schema*>::iterator schema = definitions.types->xs__schema_.begin(); schema != definitions.types->xs__schema_.end(); ++schema) { for (vector<xs__complexType>::iterator complexType = (*schema)->complexType.begin(); complexType != (*schema)->complexType.end(); ++complexType) { if ((*complexType).baseLevel() == baseLevel) types.gen((*schema)->targetNamespace, NULL, *complexType, false); } for (vector<xs__element>::iterator element = (*schema)->element.begin(); element != (*schema)->element.end(); ++element) { if (!(*element).type && (*element).complexTypePtr() && (*element).complexTypePtr()->baseLevel() == baseLevel) { fprintf(stream, "\n\n/// Element \"%s\":%s of complexType.\n", (*schema)->targetNamespace, (*element).name); types.document((*element).annotation); types.gen((*schema)->targetNamespace, (*element).name, *(*element).complexTypePtr(), false); } } } } // option to consider: generate local complexTypes iteratively /* for (MapOfStringToType::const_iterator local = types.locals.begin(); local != types.locals.end(); ++local) { types.gen(NULL, (*local).first, *(*local).second); } */ for (vector<xs__schema*>::iterator schema = definitions.types->xs__schema_.begin(); schema != definitions.types->xs__schema_.end(); ++schema) { if (vflag) fprintf(stderr, "\nGenerating elements in %s\n", (*schema)->targetNamespace); for (vector<xs__element>::iterator element = (*schema)->element.begin(); element != (*schema)->element.end(); ++element) { if ((*element).name && (*element).type && !(*element).abstract) { fprintf(stream, "\n/// Element \"%s\":%s of type %s.\n", (*schema)->targetNamespace, (*element).name, (*element).type); types.document((*element).annotation); if (!types.is_defined("_", (*schema)->targetNamespace, (*element).name)) { const char *s = types.tname(NULL, (*schema)->targetNamespace, (*element).type); const char *t = types.deftname(TYPEDEF, NULL, false, "_", (*schema)->targetNamespace, (*element).name); if (gflag) { if (strncmp(s, "char", 4) && strchr(s, '*')) // don't want pointer typedef, unless char* { size_t n = strlen(s); char *r = (char*)malloc(n); strncpy(r, s, n - 1); r[n - 1] = '\0'; fprintf(stream, "typedef %s %s;\n", r, t); free(r); } else fprintf(stream, "typedef %s %s;\n", s, t); } else fprintf(stream, "/// Note: use wsdl2h option -g to generate this global element declaration.\n"); } else { const char *s = types.cname("_", (*schema)->targetNamespace, (*element).name); const char *t = types.deftypemap[s]; if (t && *t) { fprintf(stream, "/// Imported element %s from typemap %s.\n", s, mapfile?mapfile:""); types.format(t); } else fprintf(stream, "// '%s' element definition intentionally left blank.\n", types.cname("_", (*schema)->targetNamespace, (*element).name)); } } } if (vflag) fprintf(stderr, "\nGenerating attributes in %s\n", (*schema)->targetNamespace); for (vector<xs__attribute>::iterator attribute = (*schema)->attribute.begin(); attribute != (*schema)->attribute.end(); ++attribute) { if ((*attribute).name && (*attribute).type) { fprintf(stream, "\n/// Attribute \"%s\":%s of simpleType %s.\n", (*schema)->targetNamespace, (*attribute).name, (*attribute).type); types.document((*attribute).annotation); if (!types.is_defined("_", (*schema)->targetNamespace, (*attribute).name)) { const char *s = types.tname(NULL, (*schema)->targetNamespace, (*attribute).type); const char *t = types.deftname(TYPEDEF, NULL, false, "_", (*schema)->targetNamespace, (*attribute).name); if (gflag) { if (strncmp(s, "char", 4) && strchr(s, '*')) // don't want pointer typedef, unless char* { size_t n = strlen(s); char *r = (char*)malloc(n); strncpy(r, s, n - 1); r[n - 1] = '\0'; fprintf(stream, "typedef %s %s;\n", r, t); free(r); } else fprintf(stream, "typedef %s %s;\n", s, t); } else fprintf(stream, "/// Note: use wsdl2h option -g to generate this global attribute declaration.\n"); } else { const char *s = types.cname("_", (*schema)->targetNamespace, (*attribute).name); const char *t = types.deftypemap[s]; if (t && *t) { fprintf(stream, "/// Imported attribute %s from typemap %s.\n", s, mapfile?mapfile:""); types.format(t); } else fprintf(stream, "// '%s' attribute definition intentionally left blank.\n", types.cname("_", (*schema)->targetNamespace, (*attribute).name)); } } } } } if (vflag) fprintf(stderr, "\nCollecting service bindings"); collect(definitions); if (!services.empty()) { banner("Services"); for (MapOfStringToService::const_iterator service1 = services.begin(); service1 != services.end(); ++service1) { Service *sv = (*service1).second; if (sv && sv->prefix) { fprintf(stream, "\n"); if (sv->name) fprintf(stream, serviceformat, sv->prefix, "name", sv->name, ""); if (sv->type) fprintf(stream, serviceformat, sv->prefix, "type", sv->type, ""); for (SetOfString::const_iterator port = sv->location.begin(); port != sv->location.end(); ++port) fprintf(stream, serviceformat, sv->prefix, "port", (*port), ""); if (sv->URI) fprintf(stream, serviceformat, sv->prefix, "namespace", sv->URI, ""); if (sv->transport) fprintf(stream, serviceformat, sv->prefix, "transport", sv->transport, ""); } } fprintf(stream, "\n/** @mainpage %s Definitions\n", definitions.name?definitions.name:"Service"); if (definitions.version) { section(defs, "_version Version", NULL); text(definitions.version); } if (definitions.documentation) { section(defs, "_documentation Documentation", NULL); text(definitions.documentation); } if (definitions.types && definitions.types->documentation) { section(defs, "_types Types", NULL); text(definitions.types->documentation); } section(defs, "_bindings Bindings", NULL); for (MapOfStringToService::const_iterator service2 = services.begin(); service2 != services.end(); ++service2) { Service *sv = (*service2).second; if (sv && sv->name) fprintf(stream, " - @ref %s\n", sv->name); } fprintf(stream, "\n*/\n"); for (MapOfStringToService::const_iterator service3 = services.begin(); service3 != services.end(); ++service3) { Service *sv = (*service3).second; if (sv && sv->name) { fprintf(stream, "\n/**\n"); page(sv->name, " Binding", sv->name); for (MapOfStringToString::const_iterator service_doc = sv->service_documentation.begin(); service_doc != sv->service_documentation.end(); ++service_doc) { const char *name = types.aname(NULL, NULL, (*service_doc).first); section(name, "_service Service Documentation", (*service_doc).first); text((*service_doc).second); } for (MapOfStringToString::const_iterator port_doc = sv->port_documentation.begin(); port_doc != sv->port_documentation.end(); ++port_doc) { const char *name = types.aname(NULL, NULL, (*port_doc).first); section(name, "_port Port Documentation", (*port_doc).first); text((*port_doc).second); } for (MapOfStringToString::const_iterator binding_doc = sv->binding_documentation.begin(); binding_doc != sv->binding_documentation.end(); ++binding_doc) { const char *name = types.aname(NULL, NULL, (*binding_doc).first); section(name, "_binding Binding Documentation", (*binding_doc).first); text((*binding_doc).second); } section(sv->name, "_operations Operations of Binding ", sv->name); for (vector<Operation*>::const_iterator op = sv->operation.begin(); op != sv->operation.end(); ++op) { if (*op && (*op)->input_name) fprintf(stream, " - @ref %s\n", (*op)->input_name); } section((*sv).name, "_ports Endpoints of Binding ", sv->name); for (SetOfString::const_iterator port = sv->location.begin(); port != sv->location.end(); ++port) fprintf(stream, " - %s\n", *port); fprintf(stream, "\nNote: use wsdl2h option -N to change the service binding prefix name\n\n*/\n"); } } } generate(); if (cppnamespace) fprintf(stream, "\n} // namespace %s\n", cppnamespace); fprintf(stream, "\n/* End of %s */\n", outfile?outfile:"file");}void Definitions::generate(){ MapOfStringToMessage headers; MapOfStringToMessage faults; const char *t; for (MapOfStringToService::const_iterator service1 = services.begin(); service1 != services.end(); ++service1) { if ((*service1).second) { for (MapOfStringToMessage::const_iterator header = (*service1).second->header.begin(); header != (*service1).second->header.end(); ++header) headers[(*header).first] = (*header).second; for (MapOfStringToMessage::const_iterator fault = (*service1).second->fault.begin(); fault != (*service1).second->fault.end(); ++fault) faults[(*fault).first] = (*fault).second; } } // Generate SOAP Header definition t = types.deftypemap["SOAP_ENV__Header"]; if (t && *t) { banner("Custom SOAP Header"); types.format(t); } else if (!jflag && !headers.empty()) { banner("SOAP Header"); fprintf(stream, "/**\n\nThe SOAP Header is part of the gSOAP context and its content is accessed\nthrough the soap.header variable. You may have to set the soap.actor variable\nto serialize SOAP Headers with SOAP-ENV:actor or SOAP-ENV:role attributes.\nUse option -j to omit.\n\n*/\n"); fprintf(stream, "struct SOAP_ENV__Header\n{\n"); for (MapOfStringToMessage::const_iterator header = headers.begin(); header != headers.end(); ++header) { if ((*header).second->URI && !types.uris[(*header).second->URI]) fprintf(stream, schemaformat, types.nsprefix(NULL, (*header).second->URI), "namespace", (*header).second->URI); comment("Header", (*header).first, "WSDL", (*header).second->ext_documentation); comment("Header", (*header).first, "SOAP", (*header).second->documentation); fprintf(stream, elementformat, "mustUnderstand", "// must be understood by receiver"); fprintf(stream, "\n"); if ((*header).second->part && (*header).second->part->elementPtr()) { fprintf(stream, "/// \"%s\" SOAP Header part element\n", (*header).second->part->name); types.gen(NULL, *(*header).second->part->elementPtr()); } else if ((*header).second->part && (*header).second->part->type) { fprintf(stream, elementformat, types.pname(true, NULL, NULL, (*header).second->part->type), types.aname(NULL, (*header).second->URI, (*header).second->part->name)); fprintf(stream, ";\n"); } else { if ((*header).second->part && (*header).second->part->element) fprintf(stream, elementformat, types.pname(true, "_", NULL, (*header).second->part->element), (*header).first); else fprintf(stream, pointerformat, (*header).first, (*header).first); fprintf(stream, ";\t///< TODO: Please check element name and type (imported type)\n"); } } types.modify("SOAP_ENV__Header"); fprintf(stream, "\n};\n"); } // Generate Fault detail element definitions for (MapOfStringToMessage::const_iterator fault = faults.begin(); fault != faults.end(); ++fault) { if ((*fault).second->use == encoded) { banner("SOAP Fault Detail Message"); fprintf(stream, "/// SOAP Fault detail message \"%s:%s\"\n", (*fault).second->URI, (*fault).second->message->name); comment("Fault", (*fault).first, "WSDL", (*fault).second->ext_documentation); comment("Fault", (*fault).first, "SOAP", (*fault).second->documentation); if (cflag) fprintf(stream, "struct %s\n{", (*fault).first); else fprintf(stream, "class %s\n{ public:", (*fault).first); (*fault).second->generate(types, ";", false, true, false); if (!cflag) { fprintf(stream, "\n"); fprintf(stream, pointerformat, "struct soap", "soap"); fprintf(stream, ";"); } fprintf(stream, "\n};\n"); if (cflag) fprintf(stream, "typedef struct %s %s;\n", (*fault).first, (*fault).first); if ((*fault).second->URI && !types.uris[(*fault).second->URI]) fprintf(stream, schemaformat, types.nsprefix(NULL, (*fault).second->URI), "namespace", (*fault).second->URI); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -