-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathUtilities.tcl
5196 lines (5016 loc) · 204 KB
/
Utilities.tcl
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
###############################################################################
## ##
## Copyright (c) 2006-2013, Gerald W. Lester ##
## Copyright (c) 2008, Georgios Petasis ##
## Copyright (c) 2006, Visiprise Software, Inc ##
## Copyright (c) 2006, Arnulf Wiedemann ##
## Copyright (c) 2006, Colin McCormack ##
## Copyright (c) 2006, Rolf Ade ##
## Copyright (c) 2001-2006, Pat Thoyts ##
## All rights reserved. ##
## ##
## Redistribution and use in source and binary forms, with or without ##
## modification, are permitted provided that the following conditions ##
## are met: ##
## ##
## * Redistributions of source code must retain the above copyright ##
## notice, this list of conditions and the following disclaimer. ##
## * Redistributions in binary form must reproduce the above ##
## copyright notice, this list of conditions and the following ##
## disclaimer in the documentation and/or other materials provided ##
## with the distribution. ##
## * Neither the name of the Visiprise Software, Inc nor the names ##
## of its contributors may be used to endorse or promote products ##
## derived from this software without specific prior written ##
## permission. ##
## ##
## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ##
## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT ##
## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS ##
## FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ##
## COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, ##
## INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, ##
## BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; ##
## LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ##
## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT ##
## LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ##
## ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE ##
## POSSIBILITY OF SUCH DAMAGE. ##
## ##
###############################################################################
package require Tcl 8.6-
package require log
# Emulate the log::logsubst command introduced in log 1.4
if {![llength [info command ::log::logsubst]]} {
proc ::log::logsubst {level text} {
if {[::log::lvIsSuppressed $level]} {
return
}
::log::log $level [uplevel 1 [list subst $text]]
}
}
package require tdom 0.8-
package require struct::set
package provide WS::Utils 3.2.0
namespace eval ::WS {}
namespace eval ::WS::Utils {
set ::WS::Utils::typeInfo {}
set ::WS::Utils::currentSchema {}
array set ::WS::Utils::importedXref {}
variable redirectArray
array set redirectArray {}
set nsList {
w http://schemas.xmlsoap.org/wsdl/
d http://schemas.xmlsoap.org/wsdl/soap/
xs http://www.w3.org/2001/XMLSchema
}
# mapping of how the simple SOAP types should be serialized using YAJL into JSON.
array set ::WS::Utils::simpleTypesJson {
boolean "bool"
float "number"
double "double"
integer "integer"
int "integer"
long "integer"
short "integer"
byte "integer"
nonPositiveInteger "integer"
negativeInteger "integer"
nonNegativeInteger "integer"
unsignedLong "integer"
unsignedInt "integer"
unsignedShort "integer"
unsignedByte "integer"
positiveInteger "integer"
decimal "number"
}
array set ::WS::Utils::simpleTypes {
anyType 1
string 1
boolean 1
decimal 1
float 1
double 1
duration 1
dateTime 1
time 1
date 1
gYearMonth 1
gYear 1
gMonthDay 1
gDay 1
gMonth 1
hexBinary 1
base64Binary 1
anyURI 1
QName 1
NOTATION 1
normalizedString 1
token 1
language 1
NMTOKEN 1
NMTOKENS 1
Name 1
NCName 1
ID 1
IDREF 1
IDREFS 1
ENTITY 1
ENTITIES 1
integer 1
nonPositiveInteger 1
negativeInteger 1
long 1
int 1
short 1
byte 1
nonNegativeInteger 1
unsignedLong 1
unsignedInt 1
unsignedShort 1
unsignedByte 1
positiveInteger 1
}
array set ::WS::Utils::options {
UseNS 1
StrictMode error
parseInAttr 0
genOutAttr 0
valueAttrCompatiblityMode 1
includeDirectory {}
suppressNS {}
useTypeNs 0
nsOnChangeOnly 0
anyType string
queryTimeout 60000
}
set ::WS::Utils::standardAttributes {
baseType
comment
example
pattern
length
fixed
maxLength
minLength
minInclusive
maxInclusive
enumeration
type
}
dom parse {
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
version="1.0">
<xsl:template priority="1" match="comment()"/>
<xsl:template match="xs:choice">
<xsl:apply-templates/>
</xsl:template>
<!-- Copy all the attributes and other nodes -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
} ::WS::Utils::xsltSchemaDom
set currentNs {}
}
###########################################################################
#
# Public Procedure Header - as this procedure is modified, please be sure
# that you update this header block. Thanks.
#
#>>BEGIN PUBLIC<<
#
# Procedure Name : ::WS::Utils::GetCrossreference
#
# Description : Get the type cross reference information for a service.
#
# Arguments :
# mode - Client|Server
# service - The name of the service
#
# Returns : A dictionary of cross reference information
#
# Side-Effects : None
#
# Exception Conditions : None
#
# Pre-requisite Conditions : None
#
# Original Author : Gerald W. Lester
#
#>>END PUBLIC<<
#
# Maintenance History - as this file is modified, please be sure that you
# update this segment of the file header block by
# adding a complete entry at the bottom of the list.
#
# Version Date Programmer Comments / Changes / Reasons
# ------- ---------- ---------- -------------------------------------------
# 1 07/06/2006 G.Lester Initial version
#
#
###########################################################################
proc ::WS::Utils::GetCrossreference {mode service} {
variable typeInfo
array set crossreference {}
dict for {type typeDict} [dict get $typeInfo $mode $service] {
foreach {field fieldDict} [dict get $typeDict definition] {
set fieldType [string trimright [dict get $fieldDict type] {()?}]
incr crossreference($fieldType,count)
lappend crossreference($fieldType,usedBy) $type.$field
}
if {![info exists crossreference($type,count) ]} {
set crossreference($type,count) 0
set crossreference($type,usedBy) {}
}
}
return [array get crossreference]
}
###########################################################################
#
# Public Procedure Header - as this procedure is modified, please be sure
# that you update this header block. Thanks.
#
#>>BEGIN PUBLIC<<
#
# Procedure Name : ::WS::Utils::SetOption
#
# Description : Define a type for a service.
#
# Arguments :
# option - option
# value - value (optional)
#
# Returns : Nothing
#
# Side-Effects : None
#
# Exception Conditions : None
#
# Pre-requisite Conditions : None
#
# Original Author : Gerald W. Lester
#
#>>END PUBLIC<<
#
# Maintenance History - as this file is modified, please be sure that you
# update this segment of the file header block by
# adding a complete entry at the bottom of the list.
#
# Version Date Programmer Comments / Changes / Reasons
# ------- ---------- ---------- -------------------------------------------
# 1 07/06/2006 G.Lester Initial version
#
#
###########################################################################
proc ::WS::Utils::SetOption {args} {
variable options
if {[llength $args] == 0} {
::log::log debug {Return all options}
return [array get options]
} elseif {[llength $args] == 1} {
set opt [lindex $args 0]
::log::logsubst debug {One Option {$opt}}
if {[info exists options($opt)]} {
return $options($opt)
} else {
::log::logsubst debug {Unknown option {$opt}}
return \
-code error \
-errorcode [list WS CLIENT UNKOPTION $opt] \
"Unknown option'$opt'"
}
} elseif {([llength $args] % 2) == 0} {
::log::log debug {Multiple option pairs}
foreach {opt value} $args {
if {[info exists options($opt)]} {
::log::logsubst debug {Setting Option {$opt} to {$value}}
set options($opt) $value
} else {
::log::logsubst debug {Unknown option {$opt}}
return \
-code error \
-errorcode [list WS CLIENT UNKOPTION $opt] \
"Unknown option'$opt'"
}
}
} else {
::log::logsubst debug {Bad number of arguments {$args}}
return \
-code error \
-errorcode [list WS CLIENT INVARGCNT $args] \
"Invalid argument count'$args'"
}
return
}
###########################################################################
#
# Public Procedure Header - as this procedure is modified, please be sure
# that you update this header block. Thanks.
#
#>>BEGIN PUBLIC<<
#
# Procedure Name : ::WS::Utils::ServiceTypeDef
#
# Description : Define a type for a service.
#
# Arguments :
# mode - Client|Server
# service - The name of the service this type definition is for
# type - The type to be defined/redefined
# definition - The definition of the type's fields. This consist of one
# or more occurence of a field definition. Each field definition
# consist of: fieldName fieldInfo
# Where field info is: {type typeName comment commentString}
# typeName can be any simple or defined type.
# commentString is a quoted string describing the field.
# xns - The namespace
# abstract - Boolean indicating if this is an abstract, and hence mutable type
# version - Version code for the custom type
#
# Returns : Nothing
#
# Side-Effects : None
#
# Exception Conditions : None
#
# Pre-requisite Conditions : None
#
# Original Author : Gerald W. Lester
#
#>>END PUBLIC<<
#
# Maintenance History - as this file is modified, please be sure that you
# update this segment of the file header block by
# adding a complete entry at the bottom of the list.
#
# Version Date Programmer Comments / Changes / Reasons
# ------- ---------- ---------- -------------------------------------------
# 1 07/06/2006 G.Lester Initial version
# 2 11/13/2018 J.Cone Version support
#
#
###########################################################################
proc ::WS::Utils::ServiceTypeDef {mode service type definition {xns {}} {abstract {false}} {version {}}} {
::log::logsubst debug {Entering [info level 0]}
variable typeInfo
if {![string length $xns]} {
set xns $service
}
if {[llength [split $type {:}]] == 1} {
set type $xns:$type
}
dict set typeInfo $mode $service $type definition $definition
dict set typeInfo $mode $service $type xns $xns
dict set typeInfo $mode $service $type abstract $abstract
if {$version ne {}} {
dict set typeInfo $mode $service $type version $version
}
return
}
###########################################################################
#
# Public Procedure Header - as this procedure is modified, please be sure
# that you update this header block. Thanks.
#
#>>BEGIN PUBLIC<<
#
# Procedure Name : ::WS::Utils::MutableTypeDef
#
# Description : Define a mutable type for a service.
#
# Arguments :
# mode - Client|Server
# service - The name of the service this type definition is for
# type - The type to be defined/redefined
# fromSwitchCmd - The cmd to determine the actaul type when converting
# from DOM to a dictionary. The actual call will have
# the following arguments appended to the command:
# mode service type xns DOMnode
# toSwitchCmd - The cmd to determine the actual type when converting
# from a dictionary to a DOM. The actual call will have
# the following arguments appended to the command:
# mode service type xns remainingDictionaryTree
# xns - The namespace
#
# Returns : Nothing
#
# Side-Effects : None
#
# Exception Conditions : None
#
# Pre-requisite Conditions : None
#
# Original Author : Gerald W. Lester
#
#>>END PUBLIC<<
#
# Maintenance History - as this file is modified, please be sure that you
# update this segment of the file header block by
# adding a complete entry at the bottom of the list.
#
# Version Date Programmer Comments / Changes / Reasons
# ------- ---------- ---------- -------------------------------------------
# 1 02/15/2008 G.Lester Initial version
#
#
###########################################################################
proc ::WS::Utils::MutableTypeDef {mode service type fromSwitchCmd toSwitchCmd {xns {}}} {
variable mutableTypeInfo
if {![string length $xns]} {
set xns $service
}
set mutableTypeInfo([list $mode $service $type]) \
[list $fromSwitchCmd $toSwitchCmd]
return
}
###########################################################################
#
# Public Procedure Header - as this procedure is modified, please be sure
# that you update this header block. Thanks.
#
#>>BEGIN PUBLIC<<
#
# Procedure Name : ::WS::Utils::ServiceSimpleTypeDef
#
# Description : Define a type for a service.
#
# Arguments :
# mode - Client|Server
# service - The name of the service this type definition is for
# type - The type to be defined/redefined
# definition - The definition of the type's fields. This consist of one
# or more occurance of a field definition. Each field definition
# consist of: fieldName fieldInfo
# Where field info is list of name value:
# basetype typeName - any simple or defined type.
# comment commentString - a quoted string describing the field.
# pattern value
# length value
# fixed "true"|"false"
# maxLength value
# minLength value
# minInclusive value
# maxInclusive value
# enumeration value
#
# xns - The namespace
#
# Returns : Nothing
#
# Side-Effects : None
#
# Exception Conditions : None
#
# Pre-requisite Conditions : None
#
# Original Author : Gerald W. Lester
#
#>>END PUBLIC<<
#
# Maintenance History - as this file is modified, please be sure that you
# update this segment of the file header block by
# adding a complete entry at the bottom of the list.
#
# Version Date Programmer Comments / Changes / Reasons
# ------- ---------- ---------- -------------------------------------------
# 1 07/06/2006 G.Lester Initial version
#
#
###########################################################################
proc ::WS::Utils::ServiceSimpleTypeDef {mode service type definition {xns {tns1}}} {
variable simpleTypes
variable typeInfo
::log::logsubst debug {Entering [info level 0]}
if {![dict exists $definition xns]} {
set simpleTypes($mode,$service,$type) [concat $definition xns $xns]
} else {
set simpleTypes($mode,$service,$type) $definition
}
if {[dict exists $typeInfo $mode $service $type]} {
::log::logsubst debug {\t Unsetting typeInfo $mode $service $type}
::log::logsubst debug {\t Was [dict get $typeInfo $mode $service $type]}
dict unset typeInfo $mode $service $type
}
return
}
###########################################################################
#
# Public Procedure Header - as this procedure is modified, please be sure
# that you update this header block. Thanks.
#
#>>BEGIN PUBLIC<<
#
# Procedure Name : ::WS::Utils::GetServiceTypeDef
#
# Description : Query for type definitions.
#
# Arguments :
# mode - Client|Server
# service - The name of the service this query is for
# type - The type to be retrieved (optional)
#
# Returns :
# If type not provided, a dictionary object describing all of the complex types
# for the service.
# If type provided, a dictionary object describing the type.
# A definition consist of a dictionary object with the following key/values:
# xns - The namespace for this type.
# definition - The definition of the type's fields. This consist of one
# or more occurance of a field definition. Each field definition
# consist of: fieldName fieldInfo
# Where field info is: {type typeName comment commentString}
# Where field info is list of name value:
# basetype typeName - any simple or defined type.
# comment commentString - a quoted string describing the field.
# pattern value
# length value
# fixed "true"|"false"
# maxLength value
# minLength value
# minInclusive value
# maxInclusive value
# enumeration value
#
# Side-Effects : None
#
# Exception Conditions : None
#
# Pre-requisite Conditions : The service must be defined.
#
# Original Author : Gerald W. Lester
#
#>>END PUBLIC<<
#
# Maintenance History - as this file is modified, please be sure that you
# update this segment of the file header block by
# adding a complete entry at the bottom of the list.
#
# Version Date Programmer Comments / Changes / Reasons
# ------- ---------- ---------- -------------------------------------------
# 1 07/06/2006 G.Lester Initial version
#
#
###########################################################################
proc ::WS::Utils::GetServiceTypeDef {mode service {type {}}} {
variable typeInfo
variable simpleTypes
set type [string trimright $type {()?}]
set results {}
if {[string equal $type {}]} {
::log::log debug "@1"
set results [dict get $typeInfo $mode $service]
} else {
set typeInfoList [TypeInfo $mode $service $type]
if {[string equal -nocase -length 3 $type {xs:}]} {
set type [string range $type 3 end]
}
::log::logsubst debug {Type = {$type} typeInfoList = {$typeInfoList}}
if {[info exists simpleTypes($mode,$service,$type)]} {
::log::log debug "@2"
set results $simpleTypes($mode,$service,$type)
} elseif {[info exists simpleTypes($type)]} {
::log::log debug "@3"
set results [list type xs:$type xns xs]
} elseif {[dict exists $typeInfo $mode $service $service:$type]} {
::log::log debug "@5"
set results [dict get $typeInfo $mode $service $service:$type]
} elseif {[dict exists $typeInfo $mode $service $type]} {
::log::log debug "@6"
set results [dict get $typeInfo $mode $service $type]
}
}
return $results
}
###########################################################################
#
# Public Procedure Header - as this procedure is modified, please be sure
# that you update this header block. Thanks.
#
#>>BEGIN PUBLIC<<
#
# Procedure Name : ::WS::Utils::GetServiceSimpleTypeDef
#
# Description : Query for type definitions.
#
# Arguments :
# mode - Client|Server
# service - The name of the service this query is for
# type - The type to be retrieved (optional)
#
# Returns :
# If type not provided, a dictionary object describing all of the simple types
# for the service.
# If type provided, a dictionary object describing the type.
# A definition consist of a dictionary object with the following key/values:
# xns - The namespace for this type.
# definition - The definition of the type's fields. This consist of one
# or more occurance of a field definition. Each field definition
# consist of: fieldName fieldInfo
# Where field info is: {type typeName comment commentString}
# Where field info is list of name value and any restrictions:
# basetype typeName - any simple or defined type.
# comment commentString - a quoted string describing the field.
# pattern value
# length value
# fixed "true"|"false"
# maxLength value
# minLength value
# minInclusive value
# maxInclusive value
# enumeration value
#
# Side-Effects : None
#
# Exception Conditions : None
#
# Pre-requisite Conditions : The service must be defined.
#
# Original Author : Gerald W. Lester
#
#>>END PUBLIC<<
#
# Maintenance History - as this file is modified, please be sure that you
# update this segment of the file header block by
# adding a complete entry at the bottom of the list.
#
# Version Date Programmer Comments / Changes / Reasons
# ------- ---------- ---------- -------------------------------------------
# 1 07/06/2006 G.Lester Initial version
#
#
###########################################################################
proc ::WS::Utils::GetServiceSimpleTypeDef {mode service {type {}}} {
variable simpleTypes
set type [string trimright $type {()?}]
if {[string equal -nocase -length 3 $type {xs:}]} {
return [::WS::Utils::GetServiceTypeDef $mode $service $type]
}
if {[string equal $type {}]} {
set results {}
foreach {key value} [array get simpleTypes $mode,$service,*] {
lappend results [list [lindex [split $key {,}] end] $simpleTypes($key)]
}
} else {
if {[info exists simpleTypes($mode,$service,$type)]} {
set results $simpleTypes($mode,$service,$type)
} elseif {[info exists simpleTypes($type)]} {
set results [list type $type xns xs]
} else {
return \
-code error \
-errorcode [list WS CLIENT UNKSMPTYP $type] \
"Unknown simple type '$type'"
}
}
return $results
}
###########################################################################
#
# Private Procedure Header - as this procedure is modified, please be sure
# that you update this header block. Thanks.
#
#>>BEGIN PUBLIC<<
#
# Procedure Name : ::WS::Utils::ProcessImportXml
#
# Description : Parse the bindings for a service from a WSDL into our
# internal representation
#
# Arguments :
# mode - The mode, Client or Server
# baseUrl - The URL we are processing
# xml - The XML string to parse
# serviceName - The name service.
# serviceInfoVar - The name of the dictionary containing the partially
# parsed service.
# tnsCountVar - The name of the variable containing the count of the
# namespace.
#
# Returns : Nothing
#
# Side-Effects : Defines Client mode types for the service as specified by the WSDL
#
# Exception Conditions : None
#
# Pre-requisite Conditions : None
#
# Original Author : Gerald W. Lester
#
#>>END PRIVATE<<
#
# Maintenance History - as this file is modified, please be sure that you
# update this segment of the file header block by
# adding a complete entry at the bottom of the list.
#
# Version Date Programmer Comments / Changes / Reasons
# ------- ---------- ---------- -------------------------------------------
# 1 08/06/2006 G.Lester Initial version
# 2.6.1 07/20/2018 A.Goth Correct variable access problems. Ticket [7bb1cd7b43]
# Corrected access of right document. Ticket [61fd346dc3]
# Bugs introduced 2015-05-24 Checkin [9c7e118edb]
# 2018-09-03 H.Oehlmann Replaced stderr error print by error log.
#
###########################################################################
proc ::WS::Utils::ProcessImportXml {mode baseUrl xml serviceName serviceInfoVar tnsCountVar} {
::log::logsubst debug {Entering [info level 0]}
upvar 1 $serviceInfoVar serviceInfo
upvar 1 $tnsCountVar tnsCount
variable currentSchema
variable nsList
variable xsltSchemaDom
set first [string first {<} $xml]
if {$first > 0} {
set xml [string range $xml $first end]
}
if {[catch {dom parse $xml tmpdoc}]} {
set first [string first {?>} $xml]
incr first 2
set xml [string range $xml $first end]
dom parse $xml tmpdoc
}
$tmpdoc xslt $xsltSchemaDom doc
$tmpdoc delete
$doc selectNodesNamespaces {
w http://schemas.xmlsoap.org/wsdl/
d http://schemas.xmlsoap.org/wsdl/soap/
xs http://www.w3.org/2001/XMLSchema
}
$doc documentElement schema
if {[catch {ProcessIncludes $schema $baseUrl} errMsg]} {
::log::log error "Error processing include $schema $baseUrl: $errMsg"
}
set prevSchema $currentSchema
set nodeList [$doc selectNodes -namespaces $nsList descendant::xs:schema]
foreach node $nodeList {
set currentSchema $node
parseScheme $mode $baseUrl $node $serviceName serviceInfo tnsCount
}
set currentSchema $prevSchema
$doc delete
}
###########################################################################
#
# Private Procedure Header - as this procedure is modified, please be sure
# that you update this header block. Thanks.
#
#>>BEGIN PUBLIC<<
#
# Procedure Name : ::WS::Utils::ProcessIncludes
#
# Description : Replace all include nodes with the contents of the included url.
#
# Arguments :
# rootNode - the root node of the document
# baseUrl - The URL being processed
#
# Returns : nothing
#
# Side-Effects : None
#
# Exception Conditions : None
#
# Pre-requisite Conditions : None
#
# Original Author : Gerald W. Lester
#
#>>END PUBLIC<<
#
# Maintenance History - as this file is modified, please be sure that you
# update this segment of the file header block by
# adding a complete entry at the bottom of the list.
#
# Version Date Programmer Comments / Changes / Reasons
# ------- ---------- ---------- -------------------------------------------
# 1 25/05/2006 G.Lester Initial version
#
#
###########################################################################
proc ::WS::Utils::ProcessIncludes {rootNode baseUrl {includePath {}}} {
variable xsltSchemaDom
variable nsList
variable options
variable includeArr
::log::logsubst debug {Entering [info level 0]}
set includeNodeList [concat \
[$rootNode selectNodes -namespaces $nsList descendant::xs:include] \
[$rootNode selectNodes -namespaces $nsList descendant::w:include] \
[$rootNode selectNodes -namespaces $nsList descendant::w:import] \
]
set inXml [$rootNode asXML]
set included 0
foreach includeNode $includeNodeList {
::log::logsubst debug {\t Processing Include [$includeNode asXML]}
if {[$includeNode hasAttribute schemaLocation]} {
set urlTail [$includeNode getAttribute schemaLocation]
set url [::uri::resolve $baseUrl $urlTail]
} elseif {[$includeNode hasAttribute location]} {
set url [$includeNode getAttribute location]
set urlTail [file tail [dict get [::uri::split $url] path]]
} else {
continue
}
if {[lsearch -exact $includePath $url] != -1} {
log::logsubst warning {Include loop detected: [join $includePath { -> }]}
continue
} elseif {[info exists includeArr($url)]} {
continue
} else {
set includeArr($url) 1
}
incr included
::log::logsubst info {\t Including {$url} from base {$baseUrl}}
switch -exact -- [dict get [::uri::split $url] scheme] {
file {
upvar #0 [::uri::geturl $url] token
set xml $token(data)
unset token
}
https -
http {
set ncode -1
catch {
::log::logsubst info {[list ::http::geturl $url\
-timeout $options(queryTimeout)]}
set token [::http::geturl $url -timeout $options(queryTimeout)]
set ncode [::http::ncode $token]
set xml [::http::data $token]
::log::logsubst info {Received Ncode = ($ncode), $xml}
::http::cleanup $token
}
if {($ncode != 200) && [string equal $options(includeDirectory) {}]} {
return \
-code error \
-errorcode [list WS CLIENT HTTPFAIL $url $ncode] \
"HTTP get of import file failed '$url'"
} elseif {($ncode != 200) && ![string equal $options(includeDirectory) {}]} {
set fn [file join $options(includeDirectory) $urlTail]
set ifd [open $fn r]
set xml [read $ifd]
close $ifd
}
}
default {
return \
-code error \
-errorcode [list WS CLIENT UNKURLTYP $url] \
"Unknown URL type '$url'"
}
}
set parentNode [$includeNode parentNode]
set nextSibling [$includeNode nextSibling]
set first [string first {<} $xml]
if {$first > 0} {
set xml [string range $xml $first end]
}
dom parse $xml tmpdoc
$tmpdoc xslt $xsltSchemaDom doc
$tmpdoc delete
set children 0
set top [$doc documentElement]
::WS::Utils::ProcessIncludes $top $url [concat $includePath $baseUrl]
foreach childNode [$top childNodes] {
if {[catch {
#set newNode [$parentNode appendXML [$childNode asXML]]
#$parentNode removeChild $newNode
#$parentNode insertBefore $newNode $includeNode
$parentNode insertBefore $childNode $includeNode
}]} {
continue
}
incr children
}
$doc delete
$includeNode delete
}
}
###########################################################################
#
# Private Procedure Header - as this procedure is modified, please be sure
# that you update this header block. Thanks.
#
#>>BEGIN PUBLIC<<
#
# Procedure Name : ::WS::Utils::TypeInfo
#
# Description : Return a list indicating if the type is simple or complex
# and if it is a scalar or an array. Also if it is optional
#
# Arguments :
# type - the type name, possibly with a () to specify it is an array
#
# Returns : A list of two elements, as follows:
# 0|1 - 0 means a simple type, 1 means a complex type
# 0|1 - 0 means a scalar, 1 means an array
#
# Side-Effects : None
#
# Exception Conditions : None
#
# Pre-requisite Conditions : None
#
# Original Author : Gerald W. Lester
#
#>>END PUBLIC<<
#
# Maintenance History - as this file is modified, please be sure that you
# update this segment of the file header block by
# adding a complete entry at the bottom of the list.
#
# Version Date Programmer Comments / Changes / Reasons
# ------- ---------- ---------- -------------------------------------------
# 1 07/06/2006 G.Lester Initial version
# 2.3.0 10/16/2012 G. Lester Corrected detection of service specific simple type.
# 2.3.0 10/31/2012 G. Lester Corrected missing newline.
#
###########################################################################
proc ::WS::Utils::TypeInfo {mode service type {findOptional 0}} {
variable simpleTypes
variable typeInfo
set type [string trim $type]
set isOptional 0
if {[string equal [string index $type end] {?}]} {
set isOptional 1
set type [string trimright $type {?}]
}
if {[string equal [string range $type end-1 end] {()}]} {
set isArray 1
set type [string range $type 0 end-2]
} elseif {[string equal $type {array}]} {
set isArray 1
} else {
set isArray 0
}
#set isNotSimple [dict exists $typeInfo $mode $service $type]
#set isNotSimple [expr {$isNotSimple || [dict exists $typeInfo $mode $service $service:$type]}]
lassign [split $type {:}] tns baseType
set isNotSimple [expr {!([info exist simpleTypes($type)] || [info exist simpleTypes($baseType)] || [info exist simpleTypes($mode,$service,$type)] || [info exist simpleTypes($mode,$service,$baseType)] )}]
if {$findOptional} {