forked from vpulim/node-soap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwsdl.js
1673 lines (1452 loc) · 47.2 KB
/
wsdl.js
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) 2011 Vinay Pulim <[email protected]>
* MIT Licensed
*
*/
/*jshint proto:true*/
"use strict";
var sax = require('sax');
var inherits = require('util').inherits;
var http = require('./http');
var fs = require('fs');
var url = require('url');
var path = require('path');
var assert = require('assert').ok;
var Primitives = {
string: 1,
boolean: 1,
decimal: 1,
float: 1,
double: 1,
anyType: 1,
byte: 1,
int: 1,
long: 1,
short: 1,
unsignedByte: 1,
unsignedInt: 1,
unsignedLong: 1,
unsignedShort: 1,
duration: 0,
dateTime: 0,
time: 0,
date: 0,
gYearMonth: 0,
gYear: 0,
gMonthDay: 0,
gDay: 0,
gMonth: 0,
hexBinary: 0,
base64Binary: 0,
anyURI: 0,
QName: 0,
NOTATION: 0
};
function splitNSName(nsName) {
var i = typeof nsName === 'string' ? nsName.indexOf(':') : -1;
return i < 0 ? {namespace: 'xmlns', name: nsName} : {namespace: nsName.substring(0, i), name: nsName.substring(i + 1)};
}
function pad(number) {
return ('00' + number).slice(-2);
}
function padOffset(offset) {
if(offset < 0) {
offset = offset * -1;
return '-' + ('00' + offset).slice(-2);
}
return '+' + ('00' + offset).slice(-2);
}
function toSoapDate(obj) {
obj.setDate(obj.getDate() + 1);
var tzOffset = (obj.getTimezoneOffset() / -60);
return obj.getUTCFullYear() +
'-' + pad(obj.getUTCMonth() + 1) +
'-' + pad(obj.getUTCDate()) +
padOffset(tzOffset) + ':00';
}
function xmlEscape(obj) {
if (typeof (obj) === 'string') {
return obj
.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/"/g, '"')
.replace(/'/g, ''');
}
if (obj instanceof Date) {
return toSoapDate(obj);
}
return obj;
}
var trimLeft = /^[\s\xA0]+/;
var trimRight = /[\s\xA0]+$/;
function trim(text) {
return text.replace(trimLeft, '').replace(trimRight, '');
}
function extend(base, obj) {
for (var key in obj) {
if (!obj.hasOwnProperty(key)) {
base[key] = obj[key];
}
}
return base;
}
function findKey(obj, val) {
for (var n in obj)
if (obj[n] === val)
return n;
}
var Element = function(nsName, attrs, ignoredNamespaces) {
var parts = splitNSName(nsName);
this.nsName = nsName;
this.namespace = parts.namespace;
this.ignoredNamespaces = ignoredNamespaces;
this.name = parts.name;
this.children = [];
this.xmlns = {};
for (var key in attrs) {
var match = /^xmlns:?(.*)$/.exec(key);
if (match) {
this.xmlns[match[1] ? match[1] : 'xmlns'] = attrs[key];
}
else {
this['$' + key] = attrs[key];
}
}
};
Element.prototype.deleteFixedAttrs = function() {
this.children && this.children.length === 0 && delete this.children;
this.xmlns && Object.keys(this.xmlns).length === 0 && delete this.xmlns;
delete this.nsName;
delete this.namespace;
delete this.name;
};
Element.prototype.allowedChildren = [];
Element.prototype.startElement = function(stack, nsName, attrs, ignoredNamespaces) {
if (!this.allowedChildren)
return;
var ChildClass = this.allowedChildren[splitNSName(nsName).name],
element = null;
if (ChildClass) {
stack.push(new ChildClass(nsName, attrs, ignoredNamespaces));
}
else {
this.unexpected(nsName);
}
};
Element.prototype.endElement = function(stack, nsName) {
if (this.nsName === nsName) {
if (stack.length < 2)
return;
var parent = stack[stack.length - 2];
if (this !== stack[0]) {
extend(stack[0].xmlns, this.xmlns);
// delete this.xmlns;
parent.children.push(this);
parent.addChild(this);
}
stack.pop();
}
};
Element.prototype.addChild = function(child) {
return;
};
Element.prototype.unexpected = function(name) {
throw new Error('Found unexpected element (' + name + ') inside ' + this.nsName);
};
Element.prototype.description = function(definitions) {
return this.$name || this.name;
};
Element.prototype.init = function() {
};
Element.createSubClass = function() {
var root = this;
var subElement = function() {
root.apply(this, arguments);
this.init();
};
// inherits(subElement, root);
subElement.prototype.__proto__ = root.prototype;
return subElement;
};
var ElementElement = Element.createSubClass();
var AnyElement = Element.createSubClass();
var InputElement = Element.createSubClass();
var OutputElement = Element.createSubClass();
var SimpleTypeElement = Element.createSubClass();
var RestrictionElement = Element.createSubClass();
var ExtensionElement = Element.createSubClass();
var ChoiceElement = Element.createSubClass();
var EnumerationElement = Element.createSubClass();
var ComplexTypeElement = Element.createSubClass();
var ComplexContentElement = Element.createSubClass();
var SimpleContentElement = Element.createSubClass();
var SequenceElement = Element.createSubClass();
var AllElement = Element.createSubClass();
var MessageElement = Element.createSubClass();
var DocumentationElement = Element.createSubClass();
var SchemaElement = Element.createSubClass();
var TypesElement = Element.createSubClass();
var OperationElement = Element.createSubClass();
var PortTypeElement = Element.createSubClass();
var BindingElement = Element.createSubClass();
var PortElement = Element.createSubClass();
var ServiceElement = Element.createSubClass();
var DefinitionsElement = Element.createSubClass();
var ElementTypeMap = {
types: [TypesElement, 'schema documentation'],
schema: [SchemaElement, 'element complexType simpleType include import'],
element: [ElementElement, 'annotation complexType'],
any: [AnyElement, ''],
simpleType: [SimpleTypeElement, 'restriction'],
restriction: [RestrictionElement, 'enumeration choice sequence'],
extension: [ExtensionElement, 'sequence choice'],
choice: [ChoiceElement, 'element choice'],
// group: [GroupElement, 'element group'],
enumeration: [EnumerationElement, ''],
complexType: [ComplexTypeElement, 'annotation sequence all complexContent simpleContent choice'],
complexContent: [ComplexContentElement, 'extension'],
simpleContent: [SimpleContentElement, 'extension'],
sequence: [SequenceElement, 'element choice any'],
all: [AllElement, 'element choice'],
service: [ServiceElement, 'port documentation'],
port: [PortElement, 'address documentation'],
binding: [BindingElement, '_binding SecuritySpec operation documentation'],
portType: [PortTypeElement, 'operation documentation'],
message: [MessageElement, 'part documentation'],
operation: [OperationElement, 'documentation input output fault _operation'],
input: [InputElement, 'body SecuritySpecRef documentation header'],
output: [OutputElement, 'body SecuritySpecRef documentation header'],
fault: [Element, '_fault documentation'],
definitions: [DefinitionsElement, 'types message portType binding service import documentation'],
documentation: [DocumentationElement, '']
};
function mapElementTypes(types) {
var rtn = {};
types = types.split(' ');
types.forEach(function(type) {
rtn[type.replace(/^_/, '')] = (ElementTypeMap[type] || [Element]) [0];
});
return rtn;
}
for (var n in ElementTypeMap) {
var v = ElementTypeMap[n];
v[0].prototype.allowedChildren = mapElementTypes(v[1]);
}
MessageElement.prototype.init = function() {
this.element = null;
this.parts = null;
};
SchemaElement.prototype.init = function() {
this.complexTypes = {};
this.types = {};
this.elements = {};
this.includes = [];
};
TypesElement.prototype.init = function() {
this.schemas = {};
};
OperationElement.prototype.init = function() {
this.input = null;
this.output = null;
this.inputSoap = null;
this.outputSoap = null;
this.style = '';
this.soapAction = '';
};
PortTypeElement.prototype.init = function() {
this.methods = {};
};
BindingElement.prototype.init = function() {
this.transport = '';
this.style = '';
this.methods = {};
};
PortElement.prototype.init = function() {
this.location = null;
};
ServiceElement.prototype.init = function() {
this.ports = {};
};
DefinitionsElement.prototype.init = function() {
if (this.name !== 'definitions')this.unexpected(this.nsName);
this.messages = {};
this.portTypes = {};
this.bindings = {};
this.services = {};
this.schemas = {};
};
DocumentationElement.prototype.init = function() {
};
SchemaElement.prototype.addChild = function(child) {
if (child.$name in Primitives)
return;
if (child.name === 'include' || child.name === 'import') {
var location = child.$schemaLocation || child.$location;
if (location) {
this.includes.push({
namespace: child.$namespace || child.$targetNamespace || this.$targetNamespace,
location: location
});
}
}
else if (child.name === 'complexType') {
this.complexTypes[child.$name] = child;
}
else if (child.name === 'element') {
this.elements[child.$name] = child;
}
else if (child.$name) {
this.types[child.$name] = child;
}
this.children.pop();
// child.deleteFixedAttrs();
};
//fix#325
TypesElement.prototype.addChild = function (child) {
assert(child instanceof SchemaElement);
var targetNamespace = child.$targetNamespace;
if(!targetNamespace) {
if(child.includes && (child.includes instanceof Array) && child.includes.length > 0) {
targetNamespace = child.includes[0].namespace;
}
}
if(!this.schemas.hasOwnProperty(targetNamespace)) {
this.schemas[targetNamespace] = child;
} else {
console.error('Target-Namespace "'+ targetNamespace +'" already in use by another Schema!');
}
};
InputElement.prototype.addChild = function(child) {
if (child.name === 'body') {
this.use = child.$use;
if (this.use === 'encoded') {
this.encodingStyle = child.$encodingStyle;
}
this.children.pop();
}
};
OutputElement.prototype.addChild = function(child) {
if (child.name === 'body') {
this.use = child.$use;
if (this.use === 'encoded') {
this.encodingStyle = child.$encodingStyle;
}
this.children.pop();
}
};
OperationElement.prototype.addChild = function(child) {
if (child.name === 'operation') {
this.soapAction = child.$soapAction || '';
this.style = child.$style || '';
this.children.pop();
}
};
BindingElement.prototype.addChild = function(child) {
if (child.name === 'binding') {
this.transport = child.$transport;
this.style = child.$style;
this.children.pop();
}
};
PortElement.prototype.addChild = function(child) {
if (child.name === 'address' && typeof (child.$location) !== 'undefined') {
this.location = child.$location;
}
};
DefinitionsElement.prototype.addChild = function(child) {
var self = this;
if (child instanceof TypesElement) {
self.schemas = child.schemas;
}
else if (child instanceof MessageElement) {
self.messages[child.$name] = child;
}
else if (child.name === 'import') {
self.schemas[child.$namespace] = new SchemaElement(child.$namespace, {});
self.schemas[child.$namespace].addChild(child);
}
else if (child instanceof PortTypeElement) {
self.portTypes[child.$name] = child;
}
else if (child instanceof BindingElement) {
if (child.transport === 'http://schemas.xmlsoap.org/soap/http' ||
child.transport === 'http://www.w3.org/2003/05/soap/bindings/HTTP/')
self.bindings[child.$name] = child;
}
else if (child instanceof ServiceElement) {
self.services[child.$name] = child;
}
else if (child instanceof DocumentationElement) {
}
this.children.pop();
};
MessageElement.prototype.postProcess = function(definitions) {
var part = null;
var child;
var children = this.children || [];
var ns;
var nsName;
var i;
var type;
for (i in children) {
if ((child = children[i]).name === 'part') {
part = child;
break;
}
}
if (!part) {
return;
}
if (part.$element) {
var lookupTypes = [],
elementChildren ;
delete this.parts;
nsName = splitNSName(part.$element);
ns = nsName.namespace;
var schema = definitions.schemas[definitions.xmlns[ns]];
this.element = schema.elements[nsName.name];
this.element.targetNSAlias = ns;
this.element.targetNamespace = definitions.xmlns[ns];
// set the optional $lookupType to be used within `client#_invoke()` when
// calling `wsdl#objectToDocumentXML()
this.element.$lookupType = part.$name;
elementChildren = this.element.children;
// get all nested lookup types (only complex types are followed)
if (elementChildren.length > 0) {
for (i = 0; i < elementChildren.length; i++) {
lookupTypes.push(this._getNestedLookupTypeString(elementChildren[i]));
}
}
// if nested lookup types where found, prepare them for furter usage
if (lookupTypes.length > 0) {
lookupTypes = lookupTypes.
join('_').
split('_').
filter(function removeEmptyLookupTypes (type) {
return type !== '^';
});
var schemaXmlns = definitions.schemas[this.element.targetNamespace].xmlns;
for (i = 0; i < lookupTypes.length; i++) {
lookupTypes[i] = this._createLookupTypeObject(lookupTypes[i], schemaXmlns);
}
}
this.element.$lookupTypes = lookupTypes;
if (this.element.$type) {
type = splitNSName(this.element.$type);
var typeNs = schema.xmlns && schema.xmlns[type.namespace] || definitions.xmlns[type.namespace];
if (typeNs) {
if (type.name in Primitives) {
// this.element = this.element.$type;
}
else {
// first check local mapping of ns alias to namespace
schema = definitions.schemas[typeNs];
var ctype = schema.complexTypes[type.name] || schema.types[type.name] || schema.elements[type.name];
if (ctype) {
this.parts = ctype.description(definitions, schema.xmlns);
}
}
}
}
else {
var method = this.element.description(definitions, schema.xmlns);
this.parts = method[nsName.name];
}
this.children.splice(0, 1);
} else {
// rpc encoding
this.parts = {};
delete this.element;
for (i = 0; part = this.children[i]; i++) {
assert(part.name === 'part', 'Expected part element');
nsName = splitNSName(part.$type);
ns = definitions.xmlns[nsName.namespace];
type = nsName.name;
var schemaDefinition = definitions.schemas[ns];
if (typeof schemaDefinition !== 'undefined') {
this.parts[part.$name] = definitions.schemas[ns].types[type] || definitions.schemas[ns].complexTypes[type];
} else {
this.parts[part.$name] = part.$type;
}
this.parts[part.$name].namespace = nsName.namespace;
this.parts[part.$name].xmlns = ns;
this.children.splice(i--, 1);
}
}
this.deleteFixedAttrs();
};
/**
* Takes a given namespaced String(for example: 'alias:property') and creates a lookupType
* object for further use in as first (lookup) `parameterTypeObj` within the `objectToXML`
* method and provides an entry point for the already existing code in `findChildParameterObject`.
*
* @method _createLookupTypeObject
* @param {String} nsString The NS String (for example "alias:type").
* @param {Object} xmlns The fully parsed `wsdl` definitions object (including all schemas).
* @returns {Object}
* @private
*/
MessageElement.prototype._createLookupTypeObject = function (nsString, xmlns) {
var splittedNSString = splitNSName(nsString),
nsAlias = splittedNSString.namespace,
splittedName = splittedNSString.name.split('#'),
type = splittedName[0],
name = splittedName[1],
lookupTypeObj = {};
lookupTypeObj.$namespace = xmlns[nsAlias];
lookupTypeObj.$type = nsAlias + ':' + type;
lookupTypeObj.$name = name;
return lookupTypeObj;
};
/**
* Iterates through the element and every nested child to find any defined `$type`
* property and returns it in a underscore ('_') separated String (using '^' as default
* value if no `$type` property was found).
*
* @method _getNestedLookupTypeString
* @param {Object} element The element which (probably) contains nested `$type` values.
* @returns {String}
* @private
*/
MessageElement.prototype._getNestedLookupTypeString = function (element) {
var resolvedType = '^',
excluded = this.ignoredNamespaces.concat('xs'); // do not process $type values wich start with
if (element.hasOwnProperty('$type') && typeof element.$type === 'string') {
if (excluded.indexOf(element.$type.split(':')[0]) === -1) {
resolvedType += ('_' + element.$type + '#' + element.$name);
}
}
if (element.children.length > 0) {
var self = this;
element.children.forEach(function (child) {
var resolvedChildType = self._getNestedLookupTypeString(child).replace(/\^_/, '');
if (resolvedChildType && typeof resolvedChildType === 'string') {
resolvedType += ('_' + resolvedChildType);
}
});
}
return resolvedType;
};
OperationElement.prototype.postProcess = function(definitions, tag) {
var children = this.children;
for (var i = 0, child; child = children[i]; i++) {
if (child.name !== 'input' && child.name !== 'output')
continue;
if (tag === 'binding') {
this[child.name] = child;
children.splice(i--, 1);
continue;
}
var messageName = splitNSName(child.$message).name;
var message = definitions.messages[messageName];
message.postProcess(definitions);
if (message.element) {
definitions.messages[message.element.$name] = message;
this[child.name] = message.element;
}
else {
this[child.name] = message;
}
children.splice(i--, 1);
}
this.deleteFixedAttrs();
};
PortTypeElement.prototype.postProcess = function(definitions) {
var children = this.children;
if (typeof children === 'undefined')
return;
for (var i = 0, child; child = children[i]; i++) {
if (child.name !== 'operation')
continue;
child.postProcess(definitions, 'portType');
this.methods[child.$name] = child;
children.splice(i--, 1);
}
delete this.$name;
this.deleteFixedAttrs();
};
BindingElement.prototype.postProcess = function(definitions) {
var type = splitNSName(this.$type).name,
portType = definitions.portTypes[type],
style = this.style,
children = this.children;
if (portType){
portType.postProcess(definitions);
this.methods = portType.methods;
for (var i = 0, child; child = children[i]; i++) {
if (child.name !== 'operation')
continue;
child.postProcess(definitions, 'binding');
children.splice(i--, 1);
child.style || (child.style = style);
var method = this.methods[child.$name];
if (method) {
method.style = child.style;
method.soapAction = child.soapAction;
method.inputSoap = child.input || null;
method.outputSoap = child.output || null;
method.inputSoap && method.inputSoap.deleteFixedAttrs();
method.outputSoap && method.outputSoap.deleteFixedAttrs();
}
}
}
delete this.$name;
delete this.$type;
this.deleteFixedAttrs();
};
ServiceElement.prototype.postProcess = function(definitions) {
var children = this.children,
bindings = definitions.bindings;
for (var i = 0, child; child = children[i]; i++) {
if (child.name !== 'port')
continue;
var bindingName = splitNSName(child.$binding).name;
var binding = bindings[bindingName];
if (binding) {
binding.postProcess(definitions);
this.ports[child.$name] = {
location: child.location,
binding: binding
};
children.splice(i--, 1);
}
}
delete this.$name;
this.deleteFixedAttrs();
};
SimpleTypeElement.prototype.description = function(definitions) {
var children = this.children;
for (var i = 0, child; child = children[i]; i++) {
if (child instanceof RestrictionElement)
return this.$name + "|" + child.description();
}
return {};
};
RestrictionElement.prototype.description = function(definitions, xmlns) {
var children = this.children;
var desc;
for (var i=0, child; child=children[i]; i++) {
if (child instanceof SequenceElement ||
child instanceof ChoiceElement) {
desc = child.description(definitions);
break;
}
}
if (desc && this.$base) {
var type = splitNSName(this.$base),
typeName = type.name,
ns = xmlns && xmlns[type.namespace] || definitions.xmlns[type.namespace],
schema = definitions.schemas[ns],
typeElement = schema && ( schema.complexTypes[typeName] || schema.types[typeName] || schema.elements[typeName] );
desc.getBase = function() {
return typeElement.description(definitions, xmlns);
};
return desc;
}
// then simple element
var base = this.$base ? this.$base + "|" : "";
return base + this.children.map(function(child) {
return child.description();
}).join(",");
};
ExtensionElement.prototype.description = function(definitions, xmlns) {
var children = this.children;
var desc = {};
for (var i=0, child; child=children[i]; i++) {
if (child instanceof SequenceElement ||
child instanceof ChoiceElement) {
desc = child.description(definitions);
}
}
if (this.$base) {
var type = splitNSName(this.$base),
typeName = type.name,
ns = xmlns && xmlns[type.namespace] || definitions.xmlns[type.namespace],
schema = definitions.schemas[ns];
if (typeName in Primitives) {
return this.$base;
}
else {
var typeElement = schema && ( schema.complexTypes[typeName] ||
schema.types[typeName] || schema.elements[typeName] );
var base = typeElement.description(definitions, xmlns);
extend(desc, base);
}
}
return desc;
};
EnumerationElement.prototype.description = function() {
return this.$value;
};
ComplexTypeElement.prototype.description = function(definitions, xmlns) {
var children = this.children || [];
for (var i=0, child; child=children[i]; i++) {
if (child instanceof ChoiceElement ||
child instanceof SequenceElement ||
child instanceof AllElement ||
child instanceof SimpleContentElement ||
child instanceof ComplexContentElement) {
return child.description(definitions, xmlns);
}
}
return {};
};
ComplexContentElement.prototype.description = function(definitions, xmlns) {
var children = this.children;
for (var i = 0, child; child = children[i]; i++) {
if (child instanceof ExtensionElement) {
return child.description(definitions, xmlns);
}
}
return {};
};
SimpleContentElement.prototype.description = function(definitions, xmlns) {
var children = this.children;
for (var i = 0, child; child = children[i]; i++) {
if (child instanceof ExtensionElement) {
return child.description(definitions, xmlns);
}
}
return {};
};
ElementElement.prototype.description = function(definitions, xmlns) {
var element = {},
name = this.$name;
var isMany = !this.$maxOccurs ? false : (isNaN(this.$maxOccurs) ? (this.$maxOccurs === 'unbounded') : (this.$maxOccurs > 1));
if (this.$minOccurs !== this.$maxOccurs && isMany) {
name += '[]';
}
var type = this.$type || this.$ref;
if (type) {
type = splitNSName(type);
var typeName = type.name,
ns = xmlns && xmlns[type.namespace] || definitions.xmlns[type.namespace],
schema = definitions.schemas[ns],
typeElement = schema && ( schema.complexTypes[typeName] || schema.types[typeName] || schema.elements[typeName] );
if (typeElement && !(typeName in Primitives)) {
if (!(typeName in definitions.descriptions.types)) {
var elem = {};
definitions.descriptions.types[typeName] = elem;
if (this.$ref) {
elem = element = typeElement.description(definitions, xmlns);
}
else {
elem = element[name] = typeElement.description(definitions, xmlns);
}
if (typeof elem === 'object') {
elem.targetNSAlias = type.namespace;
elem.targetNamespace = ns;
}
definitions.descriptions.types[typeName] = elem;
}
else {
if (this.$ref) {
element = definitions.descriptions.types[typeName];
}
else {
element[name] = definitions.descriptions.types[typeName];
}
}
}
else {
element[name] = this.$type;
}
}
else {
var children = this.children;
element[name] = {};
for (var i = 0, child; child = children[i]; i++) {
if (child instanceof ComplexTypeElement) {
element[name] = child.description(definitions, xmlns);
}
}
}
return element;
};
AllElement.prototype.description =
SequenceElement.prototype.description = function(definitions, xmlns) {
var children = this.children;
var sequence = {};
for (var i = 0, child; child = children[i]; i++) {
if (child instanceof AnyElement) {
continue;
}
var description = child.description(definitions, xmlns);
for (var key in description) {
sequence[key] = description[key];
}
}
return sequence;
};
ChoiceElement.prototype.description = function(definitions, xmlns) {
var children = this.children;
var choice = {};
for (var i=0, child; child=children[i]; i++) {
var description = child.description(definitions, xmlns);
for (var key in description) {
choice[key] = description[key];
}
}
return choice;
};
MessageElement.prototype.description = function(definitions) {
if (this.element) {
return this.element && this.element.description(definitions);
}
var desc = {};
desc[this.$name] = this.parts;
return desc;
};
PortTypeElement.prototype.description = function(definitions) {
var methods = {};
for (var name in this.methods) {
var method = this.methods[name];
methods[name] = method.description(definitions);
}
return methods;
};
OperationElement.prototype.description = function(definitions) {
var inputDesc = this.input ? this.input.description(definitions) : null;
var outputDesc = this.output ? this.output.description(definitions) : null;
return {
input: inputDesc && inputDesc[Object.keys(inputDesc)[0]],
output: outputDesc && outputDesc[Object.keys(outputDesc)[0]]
};
};
BindingElement.prototype.description = function(definitions) {
var methods = {};
for (var name in this.methods) {
var method = this.methods[name];
methods[name] = method.description(definitions);
}
return methods;
};
ServiceElement.prototype.description = function(definitions) {
var ports = {};
for (var name in this.ports) {
var port = this.ports[name];
ports[name] = port.binding.description(definitions);
}
return ports;
};
var WSDL = function(definition, uri, options) {
var self = this,
fromFunc,
ignoredNamespaces;
this.uri = uri;
this.callback = function() {
};
this.options = options || {};
ignoredNamespaces = this.options.ignoredNamespaces;
if (ignoredNamespaces &&
(Array.isArray(ignoredNamespaces.namespaces) || typeof ignoredNamespaces.namespaces === 'string')) {
if (ignoredNamespaces.override) {
this.ignoredNamespaces = ignoredNamespaces.namespaces;
} else {
this.ignoredNamespaces.concat(ignoredNamespaces.namespaces);
}
}
if (typeof definition === 'string') {
fromFunc = this._fromXML;
}
else if (typeof definition === 'object') {
fromFunc = this._fromServices;
}
else {
throw new Error('WSDL constructor takes either an XML string or service definition');
}
process.nextTick(function() {
try {
fromFunc.call(self, definition);
} catch (e) {
return self.callback(e.message);
}
self.processIncludes(function(err) {
var name;
if (err) {
return self.callback(err);
}
self.definitions.deleteFixedAttrs();
var services = self.services = self.definitions.services;
if (services) {
for (name in services) {
services[name].postProcess(self.definitions);
}