ServiceDeclaration.h
1/*
2 * Copyright (C) 2014 by Dr. Marc Boris Duerner
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * As a special exception, you may use this file as part of a free
10 * software library without restriction. Specifically, if other files
11 * instantiate templates or use macros or inline functions from this
12 * file, or you compile this file and link it with other files to
13 * produce an executable, this file does not by itself cause the
14 * resulting executable to be covered by the GNU General Public
15 * License. This exception does not however invalidate any other
16 * reasons why the executable file might be covered by the GNU Library
17 * General Public License.
18 *
19 * This library is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * Lesser General Public License for more details.
23 *
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
27 */
28
29#ifndef Pt_Soap_ServiceDeclaration_h
30#define Pt_Soap_ServiceDeclaration_h
31
32#include <Pt/Soap/Api.h>
33#include <Pt/NonCopyable.h>
34#include <Pt/String.h>
35#include <Pt/Types.h>
36#include <string>
37#include <vector>
38#include <map>
39
40namespace Pt {
41
42namespace Soap {
43
44class Parameter;
45
49class Type : private NonCopyable
50{
51 public:
52 enum TypeId
53 {
54 Array = 1,
55 Struct = 2,
56 Bool = 3,
57 Int = 4,
58 Float = 5,
59 String = 6,
60 Base64 = 7,
61 Dict = 8,
62 DictElement = 9
63 };
64
65 public:
66 explicit Type(TypeId typeId)
67 : _typeId(typeId)
68 {}
69
70 virtual ~Type()
71 {}
72
73 TypeId typeId() const
74 { return _typeId; }
75
76 virtual bool isSimple() const = 0;
77
78 virtual const Parameter* getParameter(std::size_t n) const = 0;
79
80 virtual const Parameter* getParameter(const std::string& name) const = 0;
81
82 virtual const char* name() const = 0;
83
84 virtual std::size_t size() const = 0;
85
86 private:
87 TypeId _typeId;
88};
89
90
91class SimpleType : public Type
92{
93 public:
94 explicit SimpleType(TypeId typeId)
95 : Type(typeId)
96 {
97 }
98
99 virtual ~SimpleType()
100 {}
101
102 virtual bool isSimple() const
103 {
104 return true;
105 }
106
107 virtual const Parameter* getParameter(std::size_t) const
108 { return 0; }
109
110 virtual const Parameter* getParameter(const std::string&) const
111 { return 0; }
112
113 std::size_t size() const
114 {
115 return 0;
116 }
117};
118
119
120class ComplexType : public Type
121{
122 public:
123 explicit ComplexType(TypeId typeId, const std::string& name)
124 : Type(typeId)
125 , _name(name)
126 {
127 }
128
129 virtual ~ComplexType()
130 {}
131
132 virtual bool isSimple() const
133 {
134 return false;
135 }
136
137 virtual const char* name() const
138 {
139 return _name.c_str();
140 }
141
142 private:
143 std::string _name;
144};
145
146
147class Parameter
148{
149 public:
150 Parameter()
151 : _type(0)
152 , _min(1)
153 , _max(1)
154 {}
155
156 Parameter(const std::string& name, const Type& t)
157 : _name(name)
158 , _type(&t)
159 , _min(1)
160 , _max(1)
161 { }
162
163 virtual ~Parameter()
164 {}
165
166 const Type* type() const
167 { return _type; }
168
169 const std::string& name() const
170 { return _name; }
171
172 void set(const std::string& name, const Type& t)
173 {
174 _name = name;
175 _type = &t;
176 }
177
178 int minOccurs() const
179 {
180 return _min;
181 }
182
183 int maxOccurs() const
184 {
185 return _max;
186 }
187
188 void setOccurrence(int min, int max)
189 {
190 _min = min;
191 _max= max;
192 }
193
194 private:
195 std::string _name;
196 const Type* _type;
197 int _min;
198 int _max;
199};
200
201
202class PT_SOAP_API BooleanType : public SimpleType
203{
204 public:
205 BooleanType();
206
207 virtual ~BooleanType();
208
209 virtual const char* name() const
210 {
211 return "boolean";
212 }
213};
214
215
216class PT_SOAP_API IntegerType : public SimpleType
217{
218 public:
219 IntegerType();
220
221 virtual ~IntegerType();
222
223 virtual const char* name() const
224 {
225 return "int";
226 }
227};
228
229
230class PT_SOAP_API FloatType : public SimpleType
231{
232 public:
233 FloatType();
234
235 virtual ~FloatType();
236
237 virtual const char* name() const
238 {
239 return "double";
240 }
241};
242
243
244class PT_SOAP_API StringType : public SimpleType
245{
246 public:
247 StringType();
248
249 virtual ~StringType();
250
251 virtual const char* name() const
252 {
253 return "string";
254 }
255};
256
257
258class PT_SOAP_API Base64Type : public SimpleType
259{
260 public:
261 Base64Type();
262
263 virtual ~Base64Type();
264
265 virtual const char* name() const
266 {
267 return "base64Binary";
268 }
269};
270
271
272class PT_SOAP_API StructType : public ComplexType
273{
274 public:
275 StructType(const std::string& name);
276
277 virtual ~StructType();
278
279 void addParameter(const std::string& name, const Type& param,
280 int minOccurence = 1, int maxOccurence = 1);
281
282 virtual const Parameter* getParameter(std::size_t n) const;
283
284 virtual const Parameter* getParameter(const std::string& name) const;
285
286 virtual std::size_t size() const
287 {
288 return _paramList.size();
289 }
290
291 private:
292 typedef std::vector<Parameter> ParameterList;
293 ParameterList _paramList;
294};
295
296
297class PT_SOAP_API ArrayType : public ComplexType
298{
299 public:
300 ArrayType(const std::string& name);
301
302 ArrayType(const std::string& name, const Type& elem, const std::string& elemName);
303
304 virtual ~ArrayType();
305
306 void setElement(const std::string& elemName, const Type& elem);
307
308 virtual const Parameter* getParameter(std::size_t n) const;
309
310 virtual const Parameter* getParameter(const std::string& name) const;
311
312 virtual std::size_t size() const
313 {
314 return 1;
315 }
316
317 private:
318 Parameter _elem;
319};
320
321
322class PT_SOAP_API DictElementType : public ComplexType
323{
324 public:
325 DictElementType(const std::string& name);
326
327 virtual ~DictElementType();
328
329 void setKey(const std::string& name, const Type& param);
330
331 void setValue(const std::string& name, const Type& param);
332
333 virtual const Parameter* getParameter(std::size_t n) const;
334
335 virtual const Parameter* getParameter(const std::string& name) const;
336
337 virtual std::size_t size() const
338 {
339 return 0;
340 }
341
342 private:
343 Parameter _key;
344 Parameter _value;
345};
346
347
348class PT_SOAP_API DictType : public ComplexType
349{
350 public:
351 DictType(const std::string& typeName, const std::string& elemTypeName);
352
353 virtual ~DictType();
354
355 void setElement(const std::string& elemName,
356 const std::string& keyname, const Type& keyType,
357 const std::string& valueName, const Type& valueType);
358
359 virtual const Parameter* getParameter(std::size_t n) const;
360
361 virtual const Parameter* getParameter(const std::string& name) const;
362
363 virtual std::size_t size() const
364 {
365 return 1;
366 }
367
368 private:
369 DictElementType _elemType;
370 Parameter _elem;
371};
372
373
374PT_SOAP_API const BooleanType& boolType();
375
376
377PT_SOAP_API const IntegerType& intType();
378
379
380PT_SOAP_API const FloatType& floatType();
381
382
383PT_SOAP_API const StringType& stringType();
384
385
386PT_SOAP_API const Base64Type& base64Type();
387
388
389class PT_SOAP_API Operation : private NonCopyable
390{
391 public:
392 typedef std::vector<Parameter> ParameterList;
393
394 Operation(const Pt::String& inputName, const Pt::String& outputName);
395
396 virtual ~Operation();
397
398 const Pt::String& inputName() const
399 { return _inputName; }
400
401 const Pt::String& outputName() const
402 { return _outputName; }
403
404 void addInput(const std::string& name, const Type& param);
405
406 const Parameter* getInput(const std::string& name) const;
407
408 const Parameter* getInput(std::size_t n) const;
409
410 void setOutput(const std::string& name, const Type& param);
411
412 const Parameter* getOutput() const;
413
414 const ParameterList& parameters() const
415 {
416 return _params;
417 }
418
419 private:
420 ParameterList _params;
421 Parameter _out;
422 Pt::String _inputName;
423 Pt::String _outputName;
424};
425
426
427class PT_SOAP_API ServiceDeclaration
428{
429 public:
430 ServiceDeclaration(const std::string& name);
431
432 virtual ~ServiceDeclaration();
433
434 const std::string& name() const
435 { return _name; }
436
437 const std::string& targetNamespace() const
438 { return _targetNamespace; }
439
440 void setTargetNamespace(const std::string& ns)
441 { _targetNamespace = ns; }
442
443 void addOperation(Operation& op);
444
445 const Operation* getOperation(const Pt::String& name) const;
446
447 void toWsdl(std::ostream& os) const;
448
449 public:
450 // deprecated
451 static const BooleanType& boolType();
452
453 // deprecated
454 static const IntegerType& intType();
455
456 // deprecated
457 static const FloatType& floatType();
458
459 // deprecated
460 static const StringType& stringType();
461
462 private:
463 static void createComplexTypeList(std::map<std::string,const Type*>& complexTypes, const Type* type);
464
465 private:
466 std::string _name;
467 std::string _targetNamespace;
468 typedef std::vector<Operation*> OperationList;
469 OperationList _operations;
470};
471
472
476
477// template <typename T>
478// class BasicParameter : public Type
479// {
480// public:
481// BasicParameter()
482// { }
483// };
484
485
486// template <>
487// class BasicParameter<int> : public IntegerType
488// {
489// public:
490// BasicParameter()
491// { }
492// };
493
494
495// template <typename T>
496// class BasicParameter< std::vector<T> > : public ArrayType
497// {
498// public:
499// BasicParameter()
500// {
501// setElement(_elem);
502// }
503
504// private:
505// BasicParameter<T> _elem;
506// };
507
508
509// template <typename R, typename A1, typename A2>
510// class BasicProcedureDefinition : public Operation
511// {
512// public:
513// BasicProcedureDefinition()
514// {}
515
516// private:
517// BasicParameter<R> _rDef;
518// BasicParameter<A1> _a1Def;
519// BasicParameter<A2> _a2Def;
520// };
521
522} // namespace Soap
523
524} // namespace Pt
525
526#endif // Pt_Soap_ServiceDefinition_h
NonCopyable()
Default constructor.
Definition NonCopyable.h:63
XML schema type for WSDLs.
Definition ServiceDeclaration.h:50
Unicode capable basic_string.
Definition Api-String.h:67
PT_MCP_API const Type & stringType()
Returns the process-wide JSON string schema type.
SOAP services and clients.
Core module.
Definition Allocator.h:33