sptk2 logo
SPTK Home Page
WSParser.h
1/*
2╔══════════════════════════════════════════════════════════════════════════════╗
3║ SIMPLY POWERFUL TOOLKIT (SPTK) ║
4╟──────────────────────────────────────────────────────────────────────────────╢
5║ copyright © 1999-2022 Alexey Parshin. All rights reserved. ║
6║ email alexeyp@gmail.com ║
7╚══════════════════════════════════════════════════════════════════════════════╝
8┌──────────────────────────────────────────────────────────────────────────────┐
9│ This library is free software; you can redistribute it and/or modify it │
10│ under the terms of the GNU Library General Public License as published by │
11│ the Free Software Foundation; either version 2 of the License, or (at your │
12│ option) any later version. │
13│ │
14│ This library is distributed in the hope that it will be useful, but │
15│ WITHOUT ANY WARRANTY; without even the implied warranty of │
16│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library │
17│ General Public License for more details. │
18│ │
19│ You should have received a copy of the GNU Library General Public License │
20│ along with this library; if not, write to the Free Software Foundation, │
21│ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. │
22│ │
23│ Please report all bugs and problems to alexeyp@gmail.com. │
24└──────────────────────────────────────────────────────────────────────────────┘
25*/
26
27#pragma once
28
29#include <sptk5/wsdl/OpenApiGenerator.h>
30#include <sptk5/wsdl/WSOperation.h>
31#include <sptk5/wsdl/WSParserComplexType.h>
32
33namespace sptk {
34
47class SP_EXPORT WSParser
48{
49public:
53 using ElementMap = std::map<String, const WSParserElement*>;
54
56 {
57 public:
58 void addType(const sptk::String& elementName, const SWSParserComplexType& complexType)
59 {
60 m_complexTypes[elementName] = complexType;
61 }
62
63 void add(const sptk::String& elementName, const SWSParserComplexType& complexType)
64 {
65 m_complexTypes[elementName] = complexType;
66 m_elements[elementName] = complexType.get();
67 }
68
69 void clear()
70 {
71 m_complexTypes.clear();
72 m_elements.clear();
73 }
74
75 [[nodiscard]] const WSParserElement* element(const sptk::String& elementName, const sptk::String& context) const
76 {
77 auto itor = m_elements.find(elementName);
78 if (itor == m_elements.end())
79 {
80 throw Exception(context + ": Element '" + elementName + "' not found");
81 }
82 return itor->second;
83 }
84
85 [[nodiscard]] const ElementMap& elements() const
86 {
87 return m_elements;
88 }
89
90 [[nodiscard]] SWSParserComplexType complexType(const sptk::String& elementName,
91 const sptk::String& context) const
92 {
93 auto itor = m_complexTypes.find(elementName);
94 if (itor == m_complexTypes.end())
95 {
96 throw Exception(context + ": Complex type '" + elementName + "' not found");
97 }
98 return itor->second;
99 }
100
101 [[nodiscard]] const WSComplexTypeMap& complexTypes() const
102 {
103 return m_complexTypes;
104 }
105
106 private:
107 ElementMap m_elements;
108 WSComplexTypeMap m_complexTypes;
109 };
110
114 using XmlTypeMap = std::map<String, const xdoc::Node*>;
115
119 using DocumentationMap = std::map<String, String>;
120
124 WSParser() = default;
125
126 WSParser(const WSParser& other) = delete;
127
128 WSParser(WSParser&& other) = delete;
129
133 virtual ~WSParser() = default;
134
135 WSParser& operator=(const WSParser& other) = delete;
136
137 WSParser& operator=(WSParser&& other) = delete;
138
142 void clear();
143
148 void parse(const fs::path& wsdlFile);
149
155 void generate(const String& sourceDirectory = ".", const String& headerFile = "",
156 const OpenApiGenerator::Options& options = OpenApiGenerator::Options(), bool verbose = false,
157 const String& serviceNamespace = "");
158
165 void generateWsdlCxx(const String& sourceDirectory, const String& headerFile, const fs::path& wsdlFileName) const;
166
171 static String strip_namespace(const String& name);
172
177 static String get_namespace(const String& name);
178
179 const String& description() const;
180
181protected:
186 void parseElement(const xdoc::SNode& elementNode);
187
192 static void parseSimpleType(const xdoc::SNode& simpleTypeElement);
193
198 void parseComplexType(xdoc::SNode& complexTypeElement);
199
204 void parseOperation(const xdoc::SNode& operationNode);
205
210 void parseSchema(const xdoc::SNode& schemaElement);
211
217 void generateDefinition(const Strings& usedClasses, std::ostream& output);
218
223 void generateImplementation(std::ostream& output) const;
224
225private:
226 String m_serviceName;
227 String m_serviceNamespace;
228 String m_description;
229 String m_location;
230 String m_wsdlFile;
231 ComplexTypeIndex m_complexTypeIndex;
232 WSOperationMap m_operations;
233 DocumentationMap m_documentation;
234};
235
240} // namespace sptk
SPTK generic exception class.
Definition: Exception.h:56
Definition: String.h:49
Definition: Strings.h:52
Definition: WSParserComplexType.h:118
Definition: WSParser.h:56
Definition: WSParser.h:48
std::map< String, const xdoc::Node * > XmlTypeMap
Definition: WSParser.h:114
static String strip_namespace(const String &name)
void parseComplexType(xdoc::SNode &complexTypeElement)
void parseOperation(const xdoc::SNode &operationNode)
void generateWsdlCxx(const String &sourceDirectory, const String &headerFile, const fs::path &wsdlFileName) const
std::map< String, String > DocumentationMap
Definition: WSParser.h:119
void generateDefinition(const Strings &usedClasses, std::ostream &output)
static void parseSimpleType(const xdoc::SNode &simpleTypeElement)
std::map< String, const WSParserElement * > ElementMap
Definition: WSParser.h:53
static String get_namespace(const String &name)
void parse(const fs::path &wsdlFile)
void parseElement(const xdoc::SNode &elementNode)
void generate(const String &sourceDirectory=".", const String &headerFile="", const OpenApiGenerator::Options &options=OpenApiGenerator::Options(), bool verbose=false, const String &serviceNamespace="")
virtual ~WSParser()=default
void generateImplementation(std::ostream &output) const
void parseSchema(const xdoc::SNode &schemaElement)
WSParser()=default
std::map< String, SWSParserComplexType > WSComplexTypeMap
Definition: WSParserComplexType.h:302
std::map< String, WSOperation > WSOperationMap
Definition: WSOperation.h:56
Definition: OpenApiGenerator.h:56

Fri Oct 14 2022 09:58:32: SPTK 5.4.1