-
Notifications
You must be signed in to change notification settings - Fork 37
/
wsdl2aws-generator.adb
3200 lines (2658 loc) · 108 KB
/
wsdl2aws-generator.adb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
------------------------------------------------------------------------------
-- Ada Web Server --
-- --
-- Copyright (C) 2003-2022, AdaCore --
-- --
-- This library is free software; you can redistribute it and/or modify --
-- it under terms of the GNU General Public License as published by the --
-- Free Software Foundation; either version 3, or (at your option) any --
-- later version. This library is distributed in the hope that it will be --
-- useful, but WITHOUT ANY WARRANTY; without even the implied warranty of --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are --
-- granted additional permissions described in the GCC Runtime Library --
-- Exception, version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- As a special exception, if other files instantiate generics from this --
-- unit, or you link this unit with other files to produce an executable, --
-- this unit does not by itself cause the resulting executable to be --
-- covered by the GNU General Public License. This exception does not --
-- however invalidate any other reasons why the executable file might be --
-- covered by the GNU Public License. --
------------------------------------------------------------------------------
with Ada.Characters.Handling;
with Ada.Containers.Indefinite_Ordered_Sets;
with Ada.Directories;
with Ada.Environment_Variables;
with Ada.Strings.Fixed;
with Ada.Strings.Maps.Constants;
with Ada.Text_IO;
with AWS.Containers.Key_Value;
with AWS.Utils;
with SOAP.Types;
with SOAP.Utils;
with SOAP.WSDL.Name_Spaces;
with SOAP.WSDL.Schema;
with WSDL2AWS.WSDL.Types;
with wsdl2aws_templates;
pragma Unreferenced (wsdl2aws_templates);
package body WSDL2AWS.Generator is
use Ada;
use type Templates.Tag;
-- All the templates files used to generate the type code
Template_Enum_Ads : constant String := "s-type-enum.tads";
Template_Enum_Adb : constant String := "s-type-enum.tadb";
Template_Enum_Types : constant String := "s-type-enum-types.tads";
Template_Derived_Ads : constant String := "s-type-derived.tads";
Template_Derived_Types : constant String := "s-type-derived-types.tads";
Template_Array_Ads : constant String := "s-type-array.tads";
Template_Array_Types : constant String := "s-type-array-types.tads";
Template_Record_Ads : constant String := "s-type-record.tads";
Template_Record_Adb : constant String := "s-type-record.tadb";
Template_Record_Types : constant String := "s-type-record-types.tads";
Template_Types_Ads : constant String := "s-types.tads";
Template_Types_Adb : constant String := "s-types.tadb";
Template_Stub_Types_Ads : constant String := "s-stub-types.tads";
Template_Main_Adb : constant String := "s-main.tadb";
Template_Root_Ads : constant String := "s-root.tads";
Template_NS_Pkg_Ads : constant String := "s-name-space-pkg.tads";
procedure Generate
(O : Object;
Filename : String;
Template : String;
Translations : Templates.Translate_Set);
-- Render a template with associated translations into Filename
procedure Generate
(O : Object;
File : Text_IO.File_Type;
Template : String;
Translations : Templates.Translate_Set);
-- Render a template with associated translations into File
procedure Insert_Types_Def
(O : in out Object;
Template : String;
Translations : Templates.Translate_Set);
-- Insert a type chunk into the global types definitions
procedure Generate_Params
(O : Object;
N : WSDL.Parameters.P_Set;
P_Decl : in out Templates.Tag;
P_Name : in out Templates.Tag;
P_Kind : in out Templates.Tag;
P_Min : in out Templates.Tag;
P_Max : in out Templates.Tag;
P_Compound_Size : in out Templates.Tag;
P_Type : in out Templates.Tag;
P_Base_Type : in out Templates.Tag;
P_Root_Type : in out Templates.Tag;
P_Root_Type_Kind : in out Templates.Tag;
P_Type_Name : in out Templates.Tag;
P_Type_Kind : in out Templates.Tag;
P_Ada_Type : in out Templates.Tag;
P_Q_Name : in out Templates.Tag;
P_NS_Name : in out Templates.Tag;
P_NS_Value : in out Templates.Tag;
P_Elt_NS_Name : in out Templates.Tag;
P_Elt_NS_Value : in out Templates.Tag);
-- Generate all tag information for the parameters pointed to by N
function Type_Name
(O : Object;
N : WSDL.Parameters.P_Set) return String;
-- Returns the name of the type for parameter on node N
package String_Store is
new Ada.Containers.Indefinite_Ordered_Sets (String);
function Format_Name (O : Object; Name : String) return String;
-- Returns Name formated with the Ada style if O.Ada_Style is true and
-- Name unchanged otherwise.
procedure Put_Types
(O : in out Object;
Proc : String;
SOAPAction : String;
Input : WSDL.Parameters.P_Set;
Output : WSDL.Parameters.P_Set);
-- This must be called to create the data types for composite objects
function Result_Type
(O : Object;
Proc : String;
Output : WSDL.Parameters.P_Set) return String;
-- Returns the result type given the output parameters
function Is_Simple_Wrapped_Parameter
(O : Object;
P : WSDL.Parameters.P_Set) return Boolean;
-- Returns True if P is a record with a least one field and we are in
-- Document style binding.
function To_Unit_Name (Filename : String) return String;
-- Returns the unit name given a filename following the GNAT
-- naming scheme.
procedure Output_Schema_Definition
(O : in out Object;
Key, Value : String);
-- This is just a key/value pair to record schema definitions for the
-- runtime. The information format is:
--
-- proc.param -> type_name
-- record.field -> type_name
-- type_name -> type_name | @enum
--
-- The special tag @enum above is to be able to differentiate between
-- xsd:string and enumeration literal.
--
-- And some special keys:
--
-- @binding.style -> [rcp|document]
-- @<proc>.encoding -> [literal/encoded] (encoding for proc name)
-- @param1[:param_n] -> operation (operation for signature)
function Is_String (N : WSDL.Parameters.P_Set) return Boolean;
-- Returns True is N is a string
S_Gen : SOAP.WSDL.Schema.Definition;
-- Keep record of generated schema definitions to avoid dupliace
NS_Generated : String_Store.Set;
-- Keep record generated name-space renaming in types package to avoid
-- duplicate.
Types_Gen : String_Store.Set;
-- Stub generator routines
package Stub is
procedure Start_Service
(O : in out Object;
Name : String;
Root_Documentation : String;
Documentation : String;
Location : String);
procedure End_Service
(O : in out Object;
Name : String);
procedure New_Procedure
(O : in out Object;
Proc : String;
Documentation : String;
SOAPAction : String;
Wrapper_Name : String;
Namespace : SOAP.Name_Space.Object;
Input : WSDL.Parameters.P_Set;
Output : WSDL.Parameters.P_Set;
Fault : WSDL.Parameters.P_Set);
end Stub;
-- Skeleton generator routines
package Skel is
procedure Start_Service
(O : in out Object;
Name : String;
Root_Documentation : String;
Documentation : String;
Location : String);
procedure End_Service
(O : in out Object;
Name : String);
procedure New_Procedure
(O : in out Object;
Proc : String;
Documentation : String;
SOAPAction : String;
Wrapper_Name : String;
Namespace : SOAP.Name_Space.Object;
Input : WSDL.Parameters.P_Set;
Output : WSDL.Parameters.P_Set;
Fault : WSDL.Parameters.P_Set);
end Skel;
-- Callback generator routines
package CB is
procedure Start_Service
(O : in out Object;
Name : String;
Root_Documentation : String;
Documentation : String;
Location : String);
procedure End_Service
(O : in out Object;
Name : String);
procedure New_Procedure
(O : in out Object;
Proc : String;
Documentation : String;
SOAPAction : String;
Wrapper_Name : String;
Namespace : SOAP.Name_Space.Object;
Input : WSDL.Parameters.P_Set;
Output : WSDL.Parameters.P_Set;
Fault : WSDL.Parameters.P_Set);
end CB;
-- Simple name set used to keep record of all generated types
package Name_Set is
procedure Add (Name : String);
-- Add new name into the set
function Exists (Name : String) return Boolean;
-- Returns true if Name is in the set
end Name_Set;
---------------
-- Ada_Style --
---------------
procedure Ada_Style (O : in out Object) is
begin
O.Ada_Style := True;
end Ada_Style;
--------------
-- Add_TagV --
--------------
procedure Add_TagV
(Set : in out Templates.Translate_Set;
Assoc_Name, Tag_Name : String)
is
T : Templates.Tag;
begin
if Templates.Exists (Set, Assoc_Name) then
T := Templates.Get (Templates.Get (Set, Assoc_Name));
end if;
T := T & Tag_Name;
Templates.Insert (Set, Templates.Assoc (Assoc_Name, T));
end Add_TagV;
procedure Add_TagV
(Set : in out Templates.Translate_Set;
Assoc_Name : String;
Value : Boolean)
is
T : Templates.Tag;
begin
if Templates.Exists (Set, Assoc_Name) then
T := Templates.Get (Templates.Get (Set, Assoc_Name));
end if;
T := T & Value;
Templates.Insert (Set, Templates.Assoc (Assoc_Name, T));
end Add_TagV;
procedure Add_TagV
(Set : in out Templates.Translate_Set;
Assoc_Name : String;
Tag : Templates.Tag)
is
R : Templates.Tag;
begin
if Templates.Exists (Set, Assoc_Name) then
declare
T : constant Templates.Tag :=
Templates.Get (Templates.Get (Set, Assoc_Name));
begin
R := T & Tag;
end;
else
R := +Tag;
end if;
Templates.Insert (Set, Templates.Assoc (Assoc_Name, R));
end Add_TagV;
--------
-- CB --
--------
package body CB is separate;
-------------
-- CVS_Tag --
-------------
procedure CVS_Tag (O : in out Object) is
begin
O.CVS_Tag := True;
end CVS_Tag;
-----------
-- Debug --
-----------
procedure Debug (O : in out Object) is
begin
O.Debug := True;
end Debug;
------------------------
-- Disable_Time_Stamp --
------------------------
procedure Disable_Time_Stamp (O : in out Object) is
begin
O.Stamp := False;
end Disable_Time_Stamp;
-----------------
-- End_Service --
-----------------
overriding procedure End_Service
(O : in out Object;
Name : String) is
begin
-- Generate binding style information
Output_Schema_Definition
(O,
Key => "@binding.style",
Value => SOAP.WSDL.Schema.Binding_Style'Image (O.Style));
-- Generate the Schema information
for C in WSDL.Types.Get_Schema_Definition.Iterate loop
Output_Schema_Definition
(O,
Key => AWS.Containers.Key_Value.Key (C),
Value => AWS.Containers.Key_Value.Element (C));
end loop;
Generate
(O,
Characters.Handling.To_Lower (Format_Name (O, Name)) & "-types.ads",
Template_Types_Ads, O.Type_S_Trans);
Generate
(O,
Characters.Handling.To_Lower (Format_Name (O, Name)) & "-types.adb",
Template_Types_Adb, O.Type_B_Trans);
-- Stub
if O.Gen_Stub then
Stub.End_Service (O, Name);
end if;
-- Skeleton
if O.Gen_Skel then
Skel.End_Service (O, Name);
end if;
-- Callbacks
if O.Gen_CB then
CB.End_Service (O, Name);
end if;
end End_Service;
--------------
-- Endpoint --
--------------
procedure Endpoint (O : in out Object; URL : String) is
begin
O.Endpoint := To_Unbounded_String (URL);
end Endpoint;
-----------------
-- Format_Name --
-----------------
function Format_Name (O : Object; Name : String) return String is
function Ada_Format (Name : String) return String;
-- Returns Name with the Ada style
----------------
-- Ada_Format --
----------------
function Ada_Format (Name : String) return String is
Result : Unbounded_String;
begin
if not O.Ada_Style then
-- No need to reformat this name
return Name;
end if;
for K in Name'Range loop
if K = Name'First then
Append (Result, Characters.Handling.To_Upper (Name (K)));
elsif Characters.Handling.Is_Upper (Name (K))
and then not Characters.Handling.Is_Upper (Name (K - 1))
and then K > Name'First
and then Name (K - 1) not in '_' | '.' | '-'
and then K < Name'Last
and then Name (K + 1) not in '_' | '.' | '-'
then
Append (Result, "_" & Name (K));
else
Append (Result, Name (K));
end if;
end loop;
return To_String (Result);
end Ada_Format;
Ada_Name : constant String := Ada_Format (Name);
begin
if SOAP.Utils.Is_Ada_Reserved_Word (Name) then
return "v_" & Ada_Name;
else
return Ada_Name;
end if;
end Format_Name;
------------
-- Gen_CB --
------------
procedure Gen_CB (O : in out Object) is
begin
O.Gen_CB := True;
end Gen_CB;
----------------------
-- Gen_Safe_Pointer --
----------------------
procedure Gen_Safe_Pointer (O : in out Object) is
begin
O.Sp := True;
end Gen_Safe_Pointer;
--------------
-- Generate --
--------------
procedure Generate
(O : Object;
File : Text_IO.File_Type;
Template : String;
Translations : Templates.Translate_Set)
is
use type Templates.Translate_Set;
use type SOAP.WSDL.Schema.Binding_Style;
Template_Dir : constant String :=
Environment_Variables.Value
("AWS_TEMPLATE_FILES", Default => "./");
Template_File : constant String :=
Directories.Compose (Template_Dir, Template);
Final_T : Templates.Translate_Set := Translations;
begin
Final_T := Final_T
& Templates.Assoc ("AWS_VERSION", AWS.Version)
& Templates.Assoc ("SOAP_VERSION", SOAP.Version)
& Templates.Assoc ("OPTIONS", To_String (O.Options))
& Templates.Assoc ("WSDL2AWS_VERSION", WSDL2AWS.Version)
& Templates.Assoc
("HTTP_VERSION", HTTP_Protocol'Image (O.HTTP_Version))
& Templates.Assoc ("HTTP_PROXY", O.Proxy)
& Templates.Assoc ("HTTP_PROXY_USER", O.P_User)
& Templates.Assoc ("HTTP_PROXY_PASSWORD", O.P_Pwd)
& Templates.Assoc ("IS_RPC", O.Style = SOAP.WSDL.Schema.RPC)
& Templates.Assoc ("DEBUG", O.Debug)
& Templates.Assoc ("TRACE", O.Traces)
& Templates.Assoc ("SERVICE_NAME", O.Unit)
& Templates.Assoc ("SAFE_POINTER", O.Sp);
if Types_Spec (O) /= "" then
Add_TagV (Final_T, "USER_UNITS", Types_Spec (O, With_Clause => True));
end if;
if Procs_Spec (O) /= "" and then Procs_Spec (O) /= Types_Spec (O) then
Add_TagV (Final_T, "USER_UNITS", Types_Spec (O, With_Clause => True));
end if;
if Directories.Exists (Template_File) then
Text_IO.Put (File, Templates.Parse (Template_File, Final_T));
else
Text_IO.Put (File, Templates.Parse (Template, Final_T));
end if;
end Generate;
procedure Generate
(O : Object;
Filename : String;
Template : String;
Translations : Templates.Translate_Set)
is
File : Text_IO.File_Type;
begin
Text_IO.Create (File, Text_IO.Out_File, Filename);
Generate (O, File, Template, Translations);
Text_IO.Close (File);
end Generate;
---------------------
-- Generate_Params --
---------------------
procedure Generate_Params
(O : Object;
N : WSDL.Parameters.P_Set;
P_Decl : in out Templates.Tag;
P_Name : in out Templates.Tag;
P_Kind : in out Templates.Tag;
P_Min : in out Templates.Tag;
P_Max : in out Templates.Tag;
P_Compound_Size : in out Templates.Tag;
P_Type : in out Templates.Tag;
P_Base_Type : in out Templates.Tag;
P_Root_Type : in out Templates.Tag;
P_Root_Type_Kind : in out Templates.Tag;
P_Type_Name : in out Templates.Tag;
P_Type_Kind : in out Templates.Tag;
P_Ada_Type : in out Templates.Tag;
P_Q_Name : in out Templates.Tag;
P_NS_Name : in out Templates.Tag;
P_NS_Value : in out Templates.Tag;
P_Elt_NS_Name : in out Templates.Tag;
P_Elt_NS_Value : in out Templates.Tag)
is
use type WSDL.Types.Kind;
begin
P_Decl := P_Decl & Format_Name (O, To_String (N.Name));
P_Name := P_Name & To_String (N.Name);
P_Kind := P_Kind & WSDL.Types.Kind'Image (N.Mode);
P_Min := P_Min & N.Min;
P_Max := P_Max & N.Max;
P_Type := P_Type & WSDL.Types.Name (N.Typ, True);
P_Type_Name := P_Type_Name
& Format_Name
(O, WSDL.Types.Name (N.Typ, False));
P_Q_Name := P_Q_Name
& SOAP.Utils.To_Name (WSDL.Types.Name (N.Typ, True));
P_Ada_Type := P_Ada_Type & Type_Name (O, N);
if N.Mode = WSDL.Types.K_Simple then
P_Type_Kind := P_Type_Kind
& SOAP.WSDL.To_Type (WSDL.Types.Name (N.Typ))'Image;
else
P_Type_Kind := P_Type_Kind & "";
end if;
if N.Mode /= WSDL.Types.K_Derived then
P_Base_Type := P_Base_Type & "";
P_Root_Type_Kind := P_Root_Type_Kind & "";
end if;
if N.Mode in WSDL.Types.Compound_Type then
P_Compound_Size := P_Compound_Size & WSDL.Parameters.Length (N);
else
P_Compound_Size := P_Compound_Size & 0;
end if;
declare
Def : constant WSDL.Types.Definition :=
WSDL.Types.Find (N.Typ);
T_Name : constant String := WSDL.Types.Name (Def.Ref);
begin
case N.Mode is
when WSDL.Types.K_Simple =>
P_Root_Type := P_Root_Type
& SOAP.WSDL.Set_Type (SOAP.WSDL.To_Type (T_Name));
when WSDL.Types.K_Derived =>
P_Root_Type := P_Root_Type
& SOAP.WSDL.Set_Type
(SOAP.WSDL.To_Type
(WSDL.Types.Root_Type_For (Def)));
declare
P_Name : constant String :=
WSDL.Types.Name (Def.Parent, True);
B_Name : constant String :=
(if SOAP.WSDL.Is_Standard (P_Name)
then WSDL.Types.Name (N.Typ, True)
else SOAP.Utils.To_Name (P_Name));
begin
P_Base_Type := P_Base_Type & B_Name;
P_Root_Type_Kind := P_Root_Type_Kind
& SOAP.WSDL.To_Type
(WSDL.Types.Root_Type_For (Def))'Image;
end;
when WSDL.Types.K_Enumeration =>
P_Root_Type := P_Root_Type & "SOAP.Types.SOAP_Enumeration";
when WSDL.Types.K_Array =>
P_Root_Type := P_Root_Type & "SOAP.Types.SOAP_Array";
when WSDL.Types.K_Record =>
P_Root_Type := P_Root_Type & "SOAP.Types.SOAP_Record";
end case;
end;
declare
NS : constant SOAP.Name_Space.Object :=
SOAP.WSDL.Name_Spaces.Get
(SOAP.Utils.NS (To_String (N.Elmt_Name)));
begin
P_Elt_NS_Name := P_Elt_NS_Name & SOAP.Name_Space.Name (NS);
P_Elt_NS_Value := P_Elt_NS_Value & SOAP.Name_Space.Value (NS);
end;
declare
NS : constant SOAP.Name_Space.Object :=
WSDL.Types.NS (N.Typ);
begin
P_NS_Name := P_NS_Name & SOAP.Name_Space.Name (NS);
P_NS_Value := P_NS_Value & SOAP.Name_Space.Value (NS);
end;
end Generate_Params;
------------------
-- HTTP_Version --
------------------
procedure HTTP_Version
(O : in out Object;
Protocol_Version : HTTP_Protocol) is
begin
O.HTTP_Version := Protocol_Version;
end HTTP_Version;
----------------------
-- Insert_Types_Def --
----------------------
procedure Insert_Types_Def
(O : in out Object;
Template : String;
Translations : Templates.Translate_Set)
is
Template_Dir : constant String :=
Environment_Variables.Value
("AWS_TEMPLATE_FILES", Default => "./");
Template_File : constant String :=
Directories.Compose (Template_Dir, Template);
T_Name : constant String :=
Templates.Get
(if Templates.Exists (Translations, "TYPE_NAME")
then Templates.Get (Translations, "TYPE_NAME")
else Templates.Get (Translations, "PROC"));
Key : constant String := T_Name & '@' & Template;
begin
if not Types_Gen.Contains (Key) then
if Directories.Exists (Template_File) then
Add_TagV
(O.Type_S_Trans,
"TYPE_DECLS",
Templates.Parse (Template_File, Translations));
else
Add_TagV
(O.Type_S_Trans,
"TYPE_DECLS",
Templates.Parse (Template, Translations));
end if;
Types_Gen.Insert (Key);
end if;
end Insert_Types_Def;
---------------------------------
-- Is_Simple_Wrapped_Parameter --
---------------------------------
function Is_Simple_Wrapped_Parameter
(O : Object;
P : WSDL.Parameters.P_Set) return Boolean
is
use type SOAP.WSDL.Schema.Binding_Style;
use type WSDL.Parameters.P_Set;
use type WSDL.Types.Kind;
begin
return P /= null
and then P.Mode = WSDL.Types.K_Record
and then O.Style = SOAP.WSDL.Schema.Document
and then WSDL.Parameters.Length (P.P) >= 1;
end Is_Simple_Wrapped_Parameter;
---------------
-- Is_String --
---------------
function Is_String (N : WSDL.Parameters.P_Set) return Boolean is
use all type SOAP.WSDL.Parameter_Type;
use type WSDL.Types.Kind;
begin
return N.Mode = WSDL.Types.K_Simple
and then SOAP.WSDL.To_Type (WSDL.Types.Name (N.Typ)) = P_String;
end Is_String;
----------
-- Main --
----------
procedure Main (O : in out Object; Name : String) is
begin
O.Main := To_Unbounded_String (Name);
end Main;
--------------
-- Name_Set --
--------------
package body Name_Set is separate;
-------------------
-- New_Procedure --
-------------------
overriding procedure New_Procedure
(O : in out Object;
Proc : String;
Documentation : String;
SOAPAction : String;
Wrapper_Name : String;
Namespace : SOAP.Name_Space.Object;
Input : WSDL.Parameters.P_Set;
Output : WSDL.Parameters.P_Set;
Fault : WSDL.Parameters.P_Set)
is
use type SOAP.WSDL.Schema.Binding_Style;
use type WSDL.Parameters.P_Set;
procedure Generate_Call_Signature (P : WSDL.Parameters.P_Set);
-- Generate a call signature for Proc. This is needed to be able to map
-- this signature to the corresponding SOAP operation when using the
-- Document style binding. The signature is the key with the following
-- format: '@' & <param1> & [:<param2>]
procedure Generate_Schema (Prefix : String; P : WSDL.Parameters.P_Set);
-- Generate the fully qualified name for the parameters. This is needed
-- for the document/literal binding to match the payload with the
-- corresponding data type.
procedure Add_Proc_Tag
(Tag_Name : String;
Value : String);
procedure Add_Proc_Tag
(Tag_Name : String;
Value : Boolean);
procedure Add_Proc_Tag
(Tag_Name : String;
Value : Templates.Tag);
-- Add a tag for all procedure templates
procedure Generate_Input_Params
(O : in out Object;
Input : WSDL.Parameters.P_Set);
-- Generate the input parameters NAME / TYPE
procedure Generate_Output_Params
(O : in out Object;
Proc : String;
Output : WSDL.Parameters.P_Set);
-- Output procedure header into File. The terminating ';' or
-- 'is' is outputed depending on Spec value. If Mode is in
-- Con_Stub_Header the connection based spec is generated,
-- otherwise it is the endpoint based.
------------------
-- Add_Proc_Tag --
------------------
procedure Add_Proc_Tag
(Tag_Name : String;
Value : String) is
begin
Add_TagV (O.Stub_S_Trans, Tag_Name, Value);
Add_TagV (O.Stub_B_Trans, Tag_Name, Value);
Add_TagV (O.Skel_S_Trans, Tag_Name, Value);
Add_TagV (O.Skel_B_Trans, Tag_Name, Value);
end Add_Proc_Tag;
procedure Add_Proc_Tag
(Tag_Name : String;
Value : Boolean) is
begin
Add_TagV (O.Stub_S_Trans, Tag_Name, Value);
Add_TagV (O.Stub_B_Trans, Tag_Name, Value);
Add_TagV (O.Skel_S_Trans, Tag_Name, Value);
Add_TagV (O.Skel_B_Trans, Tag_Name, Value);
end Add_Proc_Tag;
procedure Add_Proc_Tag
(Tag_Name : String;
Value : Templates.Tag) is
begin
Add_TagV (O.Stub_S_Trans, Tag_Name, Value);
Add_TagV (O.Stub_B_Trans, Tag_Name, Value);
Add_TagV (O.Skel_S_Trans, Tag_Name, Value);
Add_TagV (O.Skel_B_Trans, Tag_Name, Value);
end Add_Proc_Tag;
-----------------------------
-- Generate_Call_Signature --
-----------------------------
procedure Generate_Call_Signature (P : WSDL.Parameters.P_Set) is
Sig : Unbounded_String;
N : WSDL.Parameters.P_Set := P;
begin
while N /= null loop
if Sig = Null_Unbounded_String then
Append (Sig, "@");
else
Append (Sig, ":");
end if;
Append (Sig, SOAP.Utils.No_NS (To_String (N.Elmt_Name)));
N := N.Next;
end loop;
Output_Schema_Definition
(O, To_String (Sig), To_String (O.Prefix) & Proc);
end Generate_Call_Signature;
---------------------------
-- Generate_Input_Params --
---------------------------
procedure Generate_Input_Params
(O : in out Object;
Input : WSDL.Parameters.P_Set)
is
use type WSDL.Types.Kind;
Parameter_Name : Templates.Tag;
Parameter_Type : Templates.Tag;
P_Decl : Templates.Tag;
P_Name : Templates.Tag;
P_Kind : Templates.Tag;
P_Min : Templates.Tag;
P_Max : Templates.Tag;
P_Compound_Size : Templates.Tag;
P_Type : Templates.Tag;
P_Base_Type : Templates.Tag;
P_Root_Type : Templates.Tag;
P_Root_Type_Kind : Templates.Tag;
P_Type_Name : Templates.Tag;
P_Type_Kind : Templates.Tag;
P_Ada_Type : Templates.Tag;
P_Q_Name : Templates.Tag;
P_NS_Name : Templates.Tag;
P_NS_Value : Templates.Tag;
P_Elt_NS_Name : Templates.Tag;
P_Elt_NS_Value : Templates.Tag;
N : WSDL.Parameters.P_Set;
begin
if Is_Simple_Wrapped_Parameter (O, Input) then
N := Input.P;
else
N := Input;
end if;
while N /= null loop
declare
Q_Name : constant String :=
SOAP.Utils.To_Name
(WSDL.Types.Name (N.Typ, NS => True));
T_Name : constant String := WSDL.Types.Name (N.Typ);
begin
Parameter_Name := Parameter_Name
& Format_Name (O, To_String (N.Name));
case N.Mode is
when WSDL.Types.K_Simple =>
Parameter_Type := Parameter_Type
& SOAP.WSDL.To_Ada (SOAP.WSDL.To_Type (T_Name));
when WSDL.Types.K_Enumeration =>
Parameter_Type := Parameter_Type
& (T_Name & "_Type");
when WSDL.Types.K_Derived =>
Parameter_Type := Parameter_Type
& (Q_Name & "_Type");
when WSDL.Types.K_Array =>
Parameter_Type := Parameter_Type
& (Format_Name (O, T_Name) & "_Type");
when WSDL.Types.K_Record =>
Parameter_Type := Parameter_Type
& (Format_Name (O, T_Name) & "_Type");
end case;
N := N.Next;
end;
end loop;
Add_Proc_Tag ("PARAMETER_NAME", Parameter_Name);
Add_Proc_Tag ("PARAMETER_TYPE", Parameter_Type);
-- Parameters
N := Input;
while N /= null loop
Generate_Params
(O, N, P_Decl, P_Name, P_Kind, P_Min, P_Max, P_Compound_Size,
P_Type, P_Base_Type, P_Root_Type, P_Root_Type_Kind,
P_Type_Name, P_Type_Kind, P_Ada_Type, P_Q_Name,
P_NS_Name, P_NS_Value, P_Elt_NS_Name, P_Elt_NS_Value);
N := N.Next;
end loop;
Add_TagV (O.Stub_B_Trans, "IP_DECL_NAME", P_Decl);
Add_TagV (O.Stub_B_Trans, "IP_NAME", P_Name);
Add_TagV (O.Stub_B_Trans, "IP_KIND", P_Kind);
Add_TagV (O.Stub_B_Trans, "IP_MIN", P_Min);
Add_TagV (O.Stub_B_Trans, "IP_MAX", P_Max);
Add_TagV (O.Stub_B_Trans, "IP_COMPOUND_SIZE", P_Compound_Size);