soap4r_es 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (165) hide show
  1. checksums.yaml +7 -0
  2. data/bin/wsdl2ruby.rb +140 -0
  3. data/bin/wsdl2ruby_rails.rb +140 -0
  4. data/bin/xsd2ruby.rb +92 -0
  5. data/lib/soap/attachment.rb +109 -0
  6. data/lib/soap/attrproxy.rb +35 -0
  7. data/lib/soap/baseData.rb +1095 -0
  8. data/lib/soap/element.rb +278 -0
  9. data/lib/soap/encodingstyle/aspDotNetHandler.rb +208 -0
  10. data/lib/soap/encodingstyle/handler.rb +121 -0
  11. data/lib/soap/encodingstyle/literalHandler.rb +196 -0
  12. data/lib/soap/encodingstyle/soapHandler.rb +560 -0
  13. data/lib/soap/filter/filterchain.rb +52 -0
  14. data/lib/soap/filter/handler.rb +32 -0
  15. data/lib/soap/filter/streamhandler.rb +30 -0
  16. data/lib/soap/filter.rb +14 -0
  17. data/lib/soap/generator.rb +299 -0
  18. data/lib/soap/header/handler.rb +64 -0
  19. data/lib/soap/header/handlerset.rb +78 -0
  20. data/lib/soap/header/mappinghandler.rb +48 -0
  21. data/lib/soap/header/simplehandler.rb +45 -0
  22. data/lib/soap/httpconfigloader.rb +140 -0
  23. data/lib/soap/mapping/encodedregistry.rb +541 -0
  24. data/lib/soap/mapping/factory.rb +389 -0
  25. data/lib/soap/mapping/literalregistry.rb +392 -0
  26. data/lib/soap/mapping/mapping.rb +577 -0
  27. data/lib/soap/mapping/registry.rb +297 -0
  28. data/lib/soap/mapping/rubytypeFactory.rb +446 -0
  29. data/lib/soap/mapping/schemadefinition.rb +171 -0
  30. data/lib/soap/mapping/typeMap.rb +107 -0
  31. data/lib/soap/mapping/wsdlencodedregistry.rb +212 -0
  32. data/lib/soap/mapping/wsdlliteralregistry.rb +249 -0
  33. data/lib/soap/mapping.rb +13 -0
  34. data/lib/soap/marshal.rb +60 -0
  35. data/lib/soap/mimemessage.rb +243 -0
  36. data/lib/soap/nestedexception.rb +43 -0
  37. data/lib/soap/netHttpClient.rb +242 -0
  38. data/lib/soap/ns.rb +39 -0
  39. data/lib/soap/parser.rb +253 -0
  40. data/lib/soap/processor.rb +67 -0
  41. data/lib/soap/property.rb +330 -0
  42. data/lib/soap/proxy.rb +15 -0
  43. data/lib/soap/rpc/cgistub.rb +249 -0
  44. data/lib/soap/rpc/driver.rb +222 -0
  45. data/lib/soap/rpc/element.rb +375 -0
  46. data/lib/soap/rpc/httpserver.rb +144 -0
  47. data/lib/soap/rpc/methodDef.rb +69 -0
  48. data/lib/soap/rpc/proxy.rb +573 -0
  49. data/lib/soap/rpc/router.rb +672 -0
  50. data/lib/soap/rpc/rpc.rb +26 -0
  51. data/lib/soap/rpc/soaplet.rb +201 -0
  52. data/lib/soap/rpc/standaloneServer.rb +44 -0
  53. data/lib/soap/soap.rb +163 -0
  54. data/lib/soap/streamHandler.rb +302 -0
  55. data/lib/soap/version.rb +12 -0
  56. data/lib/soap/wsdlDriver.rb +165 -0
  57. data/lib/wsdl/binding.rb +66 -0
  58. data/lib/wsdl/data.rb +65 -0
  59. data/lib/wsdl/definitions.rb +237 -0
  60. data/lib/wsdl/documentation.rb +33 -0
  61. data/lib/wsdl/import.rb +81 -0
  62. data/lib/wsdl/importer.rb +39 -0
  63. data/lib/wsdl/info.rb +51 -0
  64. data/lib/wsdl/message.rb +55 -0
  65. data/lib/wsdl/operation.rb +152 -0
  66. data/lib/wsdl/operationBinding.rb +241 -0
  67. data/lib/wsdl/param.rb +94 -0
  68. data/lib/wsdl/parser.rb +180 -0
  69. data/lib/wsdl/part.rb +53 -0
  70. data/lib/wsdl/port.rb +67 -0
  71. data/lib/wsdl/portType.rb +76 -0
  72. data/lib/wsdl/service.rb +62 -0
  73. data/lib/wsdl/soap/address.rb +41 -0
  74. data/lib/wsdl/soap/binding.rb +50 -0
  75. data/lib/wsdl/soap/body.rb +59 -0
  76. data/lib/wsdl/soap/cgiStubCreator.rb +93 -0
  77. data/lib/wsdl/soap/classDefCreator.rb +529 -0
  78. data/lib/wsdl/soap/classDefCreatorSupport.rb +242 -0
  79. data/lib/wsdl/soap/classNameCreator.rb +57 -0
  80. data/lib/wsdl/soap/clientSkeltonCreator.rb +107 -0
  81. data/lib/wsdl/soap/complexType.rb +174 -0
  82. data/lib/wsdl/soap/data.rb +43 -0
  83. data/lib/wsdl/soap/definitions.rb +201 -0
  84. data/lib/wsdl/soap/driverCreator.rb +121 -0
  85. data/lib/wsdl/soap/element.rb +34 -0
  86. data/lib/wsdl/soap/encodedMappingRegistryCreator.rb +74 -0
  87. data/lib/wsdl/soap/fault.rb +57 -0
  88. data/lib/wsdl/soap/header.rb +87 -0
  89. data/lib/wsdl/soap/headerfault.rb +57 -0
  90. data/lib/wsdl/soap/literalMappingRegistryCreator.rb +116 -0
  91. data/lib/wsdl/soap/mappingRegistryCreator.rb +59 -0
  92. data/lib/wsdl/soap/mappingRegistryCreatorSupport.rb +380 -0
  93. data/lib/wsdl/soap/methodDefCreator.rb +200 -0
  94. data/lib/wsdl/soap/operation.rb +113 -0
  95. data/lib/wsdl/soap/servantSkeltonCreator.rb +92 -0
  96. data/lib/wsdl/soap/servletStubCreator.rb +105 -0
  97. data/lib/wsdl/soap/standaloneServerStubCreator.rb +101 -0
  98. data/lib/wsdl/soap/wsdl2ruby.rb +249 -0
  99. data/lib/wsdl/types.rb +45 -0
  100. data/lib/wsdl/wsdl.rb +25 -0
  101. data/lib/wsdl/xmlSchema/all.rb +25 -0
  102. data/lib/wsdl/xmlSchema/annotation.rb +35 -0
  103. data/lib/wsdl/xmlSchema/any.rb +62 -0
  104. data/lib/wsdl/xmlSchema/anyAttribute.rb +49 -0
  105. data/lib/wsdl/xmlSchema/attribute.rb +105 -0
  106. data/lib/wsdl/xmlSchema/attributeGroup.rb +69 -0
  107. data/lib/wsdl/xmlSchema/choice.rb +59 -0
  108. data/lib/wsdl/xmlSchema/complexContent.rb +98 -0
  109. data/lib/wsdl/xmlSchema/complexExtension.rb +120 -0
  110. data/lib/wsdl/xmlSchema/complexRestriction.rb +105 -0
  111. data/lib/wsdl/xmlSchema/complexType.rb +194 -0
  112. data/lib/wsdl/xmlSchema/content.rb +96 -0
  113. data/lib/wsdl/xmlSchema/data.rb +117 -0
  114. data/lib/wsdl/xmlSchema/element.rb +154 -0
  115. data/lib/wsdl/xmlSchema/enumeration.rb +37 -0
  116. data/lib/wsdl/xmlSchema/fractiondigits.rb +38 -0
  117. data/lib/wsdl/xmlSchema/group.rb +101 -0
  118. data/lib/wsdl/xmlSchema/import.rb +53 -0
  119. data/lib/wsdl/xmlSchema/importHandler.rb +45 -0
  120. data/lib/wsdl/xmlSchema/importer.rb +103 -0
  121. data/lib/wsdl/xmlSchema/include.rb +48 -0
  122. data/lib/wsdl/xmlSchema/length.rb +38 -0
  123. data/lib/wsdl/xmlSchema/list.rb +49 -0
  124. data/lib/wsdl/xmlSchema/maxexclusive.rb +38 -0
  125. data/lib/wsdl/xmlSchema/maxinclusive.rb +38 -0
  126. data/lib/wsdl/xmlSchema/maxlength.rb +38 -0
  127. data/lib/wsdl/xmlSchema/minexclusive.rb +38 -0
  128. data/lib/wsdl/xmlSchema/mininclusive.rb +38 -0
  129. data/lib/wsdl/xmlSchema/minlength.rb +38 -0
  130. data/lib/wsdl/xmlSchema/parser.rb +168 -0
  131. data/lib/wsdl/xmlSchema/pattern.rb +37 -0
  132. data/lib/wsdl/xmlSchema/ref.rb +34 -0
  133. data/lib/wsdl/xmlSchema/schema.rb +179 -0
  134. data/lib/wsdl/xmlSchema/sequence.rb +55 -0
  135. data/lib/wsdl/xmlSchema/simpleContent.rb +70 -0
  136. data/lib/wsdl/xmlSchema/simpleExtension.rb +63 -0
  137. data/lib/wsdl/xmlSchema/simpleRestriction.rb +133 -0
  138. data/lib/wsdl/xmlSchema/simpleType.rb +88 -0
  139. data/lib/wsdl/xmlSchema/totaldigits.rb +38 -0
  140. data/lib/wsdl/xmlSchema/union.rb +36 -0
  141. data/lib/wsdl/xmlSchema/unique.rb +35 -0
  142. data/lib/wsdl/xmlSchema/whitespace.rb +38 -0
  143. data/lib/wsdl/xmlSchema/xsd2ruby.rb +177 -0
  144. data/lib/xsd/charset.rb +190 -0
  145. data/lib/xsd/codegen/classdef.rb +230 -0
  146. data/lib/xsd/codegen/commentdef.rb +35 -0
  147. data/lib/xsd/codegen/gensupport.rb +277 -0
  148. data/lib/xsd/codegen/methoddef.rb +71 -0
  149. data/lib/xsd/codegen/moduledef.rb +209 -0
  150. data/lib/xsd/codegen.rb +13 -0
  151. data/lib/xsd/datatypes.rb +1465 -0
  152. data/lib/xsd/datatypes1999.rb +21 -0
  153. data/lib/xsd/iconvcharset.rb +33 -0
  154. data/lib/xsd/mapping.rb +69 -0
  155. data/lib/xsd/namedelements.rb +133 -0
  156. data/lib/xsd/ns.rb +183 -0
  157. data/lib/xsd/qname.rb +80 -0
  158. data/lib/xsd/xmlparser/libxmlparser.rb +136 -0
  159. data/lib/xsd/xmlparser/nokogiriparser.rb +63 -0
  160. data/lib/xsd/xmlparser/ogaparser.rb +53 -0
  161. data/lib/xsd/xmlparser/oxparser.rb +97 -0
  162. data/lib/xsd/xmlparser/parser.rb +101 -0
  163. data/lib/xsd/xmlparser/rexmlparser.rb +54 -0
  164. data/lib/xsd/xmlparser.rb +81 -0
  165. metadata +240 -0
@@ -0,0 +1,529 @@
1
+ # encoding: UTF-8
2
+ # WSDL4R - Creating class definition from WSDL
3
+ # Copyright (C) 2000-2007 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
4
+
5
+ # This program is copyrighted free software by NAKAMURA, Hiroshi. You can
6
+ # redistribute it and/or modify it under the same terms of Ruby's license;
7
+ # either the dual license version in 2003, or any later version.
8
+
9
+
10
+ require 'wsdl/data'
11
+ require 'wsdl/soap/classDefCreatorSupport'
12
+ require 'xsd/codegen'
13
+ require 'set'
14
+ require 'byebug'
15
+
16
+ #uso il metodo di rails per convertire il nome della classe da camel case a snake case
17
+ class String
18
+ def underscore
19
+ self.gsub(/::/, '/').gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').gsub(/([a-z\d])([A-Z])/,'\1_\2').tr("-", "_").downcase
20
+ end
21
+ end
22
+
23
+
24
+
25
+ module WSDL
26
+ module SOAP
27
+
28
+
29
+ class ClassDefCreator
30
+ include ClassDefCreatorSupport
31
+ include XSD::CodeGen
32
+
33
+ def initialize(definitions, name_creator, modulepath = nil)
34
+ @definitions = definitions
35
+ @name_creator = name_creator
36
+ @modulepath = modulepath
37
+ @elements = definitions.collect_elements
38
+ @elements.uniq!
39
+ @attributes = definitions.collect_attributes
40
+ @attributes.uniq!
41
+ @simpletypes = definitions.collect_simpletypes
42
+ @simpletypes.uniq!
43
+ @complextypes = definitions.collect_complextypes
44
+ @complextypes.uniq!
45
+ @modelgroups = definitions.collect_modelgroups
46
+ @modelgroups.uniq!
47
+ @faulttypes = nil
48
+ if definitions.respond_to?(:collect_faulttypes)
49
+ @faulttypes = definitions.collect_faulttypes
50
+ end
51
+ @defined_const = {}
52
+ @logger = Logger.new(STDERR)
53
+ end
54
+
55
+ def dump(type = nil)
56
+ result = "require 'xsd/qname'\n"
57
+ # cannot use @modulepath because of multiple classes
58
+ if @modulepath
59
+ result << "\n"
60
+ result << modulepath_split(@modulepath).collect { |ele| "module #{ele}" }.join("; ")
61
+ result << "\n\n"
62
+ end
63
+ str = dump_group(type)
64
+ unless str.empty?
65
+ result << "\n" unless result.empty?
66
+ result << str
67
+ end
68
+ str = dump_complextype(type)
69
+ unless str.empty?
70
+ result << "\n" unless result.empty?
71
+ result << str
72
+ end
73
+ str = dump_simpletype(type)
74
+ unless str.empty?
75
+ result << "\n" unless result.empty?
76
+ result << str
77
+ end
78
+ str = dump_element(type)
79
+ unless str.empty?
80
+ result << "\n" unless result.empty?
81
+ result << str
82
+ end
83
+ str = dump_attribute(type)
84
+ unless str.empty?
85
+ result << "\n" unless result.empty?
86
+ result << str
87
+ end
88
+ if @modulepath
89
+ result << "\n\n"
90
+ result << modulepath_split(@modulepath).collect { |ele| "end" }.join("; ")
91
+ result << "\n"
92
+ end
93
+ result
94
+ end
95
+
96
+ private
97
+
98
+ def dump_element(target = nil)
99
+ @elements.collect { |ele|
100
+ next if @complextypes[ele.name]
101
+ next if target and target != ele.name
102
+ c = create_elementdef(@modulepath, ele)
103
+ c ? c.dump : nil
104
+ }.compact.join("\n")
105
+ end
106
+
107
+ def dump_attribute(target = nil)
108
+ @attributes.collect { |attribute|
109
+ next if target and target != attribute.name
110
+ if attribute.local_simpletype
111
+ c = create_simpletypedef(@modulepath, attribute.name, attribute.local_simpletype)
112
+ end
113
+ c ? c.dump : nil
114
+ }.compact.join("\n")
115
+ end
116
+
117
+ def dump_simpletype(target = nil)
118
+ @simpletypes.collect { |type|
119
+ next if target and target != type.name
120
+ c = create_simpletypedef(@modulepath, type.name, type)
121
+ c ? c.dump : nil
122
+ }.compact.join("\n")
123
+ end
124
+
125
+ def dump_complextype(target = nil)
126
+ definitions = sort_dependency(@complextypes).collect { |type|
127
+ next if target and target != type.name
128
+ c = create_complextypedef(@modulepath, type.name, type)
129
+ c ? c.dump : nil
130
+ }.compact.join("\n")
131
+ end
132
+
133
+ def dump_group(target = nil)
134
+ definitions = @modelgroups.collect { |group|
135
+ # TODO: not dumped for now but may be useful in the future
136
+ }.compact.join("\n")
137
+ end
138
+
139
+ def create_elementdef(mpath, ele)
140
+ qualified = (ele.elementform == 'qualified')
141
+ if ele.local_complextype
142
+ create_complextypedef(mpath, ele.name, ele.local_complextype, qualified)
143
+ elsif ele.local_simpletype
144
+ create_simpletypedef(mpath, ele.name, ele.local_simpletype, qualified)
145
+ elsif ele.empty?
146
+ create_simpleclassdef(mpath, ele.name, nil)
147
+ else
148
+ # ignores type only element
149
+ nil
150
+ end
151
+ end
152
+
153
+ def create_simpletypedef(mpath, qname, simpletype, qualified = false)
154
+ if simpletype.restriction
155
+ create_simpletypedef_restriction(mpath, qname, simpletype, qualified)
156
+ elsif simpletype.list
157
+ create_simpletypedef_list(mpath, qname, simpletype, qualified)
158
+ elsif simpletype.union
159
+ create_simpletypedef_union(mpath, qname, simpletype, qualified)
160
+ else
161
+ raise RuntimeError.new("unknown kind of simpletype: #{simpletype}")
162
+ end
163
+ end
164
+
165
+ def create_simpletypedef_restriction(mpath, qname, typedef, qualified)
166
+ restriction = typedef.restriction
167
+ #MODIFICATO
168
+ # unless restriction.enumeration?
169
+ # # not supported. minlength?
170
+ # return nil
171
+ # end
172
+ classname = mapped_class_basename(qname, mpath)
173
+ c = ClassDef.new(classname, '::String')
174
+ c.comment = "#{qname}"
175
+ define_classenum_restriction(c, classname, restriction.enumeration)
176
+ #SCRIVO UN FILE PER OGNI CLASSE
177
+ write_file(c.name+".rb", 'models_pagopa') do |f|
178
+ f.puts "# encoding: UTF-8"
179
+ f.puts "# Generated by wsdl2ruby (#{::SOAP::VERSION::FORK_STRING})\n"
180
+ f << c.dump
181
+ end
182
+ c
183
+ end
184
+
185
+ def create_simpletypedef_list(mpath, qname, typedef, qualified)
186
+ list = typedef.list
187
+ classname = mapped_class_basename(qname, mpath)
188
+ c = ClassDef.new(classname, '::Array')
189
+ c.comment = "#{qname}"
190
+ if simpletype = list.local_simpletype
191
+ if simpletype.restriction.nil?
192
+ raise RuntimeError.new(
193
+ "unknown kind of simpletype: #{simpletype}")
194
+ end
195
+ define_stringenum_restriction(c, simpletype.restriction.enumeration)
196
+ c.comment << "\n contains list of #{classname}::*"
197
+ elsif list.itemtype
198
+ c.comment << "\n contains list of #{mapped_class_basename(list.itemtype, mpath)}::*"
199
+ else
200
+ raise RuntimeError.new("unknown kind of list: #{list}")
201
+ end
202
+ #SCRIVO UN FILE PER OGNI CLASSE
203
+ write_file(c.name+".rb", 'models_pagopa') do |f|
204
+ f.puts "# encoding: UTF-8"
205
+ f.puts "# Generated by wsdl2ruby (#{::SOAP::VERSION::FORK_STRING})\n"
206
+ f << c.dump
207
+ end
208
+ c
209
+ end
210
+
211
+ def create_simpletypedef_union(mpath, qname, typedef, qualified)
212
+ union = typedef.union
213
+ classname = mapped_class_basename(qname, mpath)
214
+ c = ClassDef.new(classname, '::String')
215
+ c.comment = "#{qname}"
216
+ if union.member_types
217
+ # fixme
218
+ c.comment << "\n any of #{union.member_types}"
219
+ end
220
+ #SCRIVO UN FILE PER OGNI CLASSE
221
+ write_file(c.name+".rb", 'models_pagopa') do |f|
222
+ f.puts "# encoding: UTF-8"
223
+ f.puts "# Generated by wsdl2ruby (#{::SOAP::VERSION::FORK_STRING})\n"
224
+ f << c.dump
225
+ end
226
+ c
227
+ end
228
+
229
+ def define_stringenum_restriction(c, enumeration)
230
+ const = {}
231
+ enumeration.each do |value|
232
+ constname = safeconstname(value)
233
+ const[constname] ||= 0
234
+ if (const[constname] += 1) > 1
235
+ constname += "_#{const[constname]}"
236
+ end
237
+ c.def_const(constname, ndq(value))
238
+ end
239
+ end
240
+
241
+ def define_classenum_restriction(c, classname, enumeration)
242
+ const = {}
243
+ enumeration.each do |value|
244
+ constname = safeconstname(value)
245
+ const[constname] ||= 0
246
+ if (const[constname] += 1) > 1
247
+ constname += "_#{const[constname]}"
248
+ end
249
+ c.def_const(constname, "new(#{ndq(value)})")
250
+ end
251
+ end
252
+
253
+ def create_simpleclassdef(mpath, qname, type_or_element)
254
+ classname = mapped_class_basename(qname, mpath)
255
+ c = ClassDef.new(classname, '::String')
256
+ c.comment = "#{qname}"
257
+ init_lines = []
258
+ if type_or_element and !type_or_element.attributes.empty?
259
+ define_attribute(c, type_or_element.attributes)
260
+ init_lines << "@__xmlattr = {}"
261
+ end
262
+ #TOLTO INITIALIZE PER AVERE CONVENZIONE RAILS DI COSTRUTTORE CON HASH
263
+ # c.def_method('initialize', '*arg') do
264
+ # "super\n" + init_lines.join("\n")
265
+ # end
266
+ #SCRIVO UN FILE PER OGNI CLASSE
267
+ write_file(c.name+".rb", 'models_pagopa') do |f|
268
+ f.puts "# encoding: UTF-8"
269
+ f.puts "# Generated by wsdl2ruby (#{::SOAP::VERSION::FORK_STRING})\n"
270
+ f << c.dump
271
+ end
272
+
273
+ c
274
+ end
275
+
276
+ def create_complextypedef(mpath, qname, type, qualified = false)
277
+ case type.compoundtype
278
+ when :TYPE_STRUCT, :TYPE_EMPTY
279
+ create_structdef(mpath, qname, type, qualified)
280
+ when :TYPE_ARRAY
281
+ create_arraydef(mpath, qname, type)
282
+ when :TYPE_SIMPLE
283
+ create_simpleclassdef(mpath, qname, type)
284
+ when :TYPE_MAP
285
+ # mapped as a general Hash
286
+ nil
287
+ else
288
+ raise RuntimeError.new(
289
+ "unknown kind of complexContent: #{type.compoundtype}")
290
+ end
291
+ end
292
+
293
+ #MODIFICATO
294
+
295
+ def write_file(filename, basedir)
296
+ if basedir
297
+ basedir = "../../"+basedir
298
+ Dir.mkdir(basedir) unless Dir.exist?(basedir)
299
+ filename = File.join(basedir, filename.underscore)
300
+ end
301
+ File.open(filename, "w") do |f|
302
+ yield f
303
+ end
304
+ @logger.info { "created file #{filename}" }
305
+ end
306
+
307
+ def create_structdef(mpath, qname, typedef, qualified = false)
308
+ classname = mapped_class_basename(qname, mpath)
309
+ baseclassname = nil
310
+ if typedef.complexcontent
311
+ if base = typedef.complexcontent.base
312
+ # :TYPE_ARRAY must not be derived (#424)
313
+ basedef = @complextypes[base]
314
+ if basedef and basedef.compoundtype != :TYPE_ARRAY
315
+ # baseclass should be a toplevel complexType
316
+ baseclassname = mapped_class_basename(base, @modulepath)
317
+ end
318
+ end
319
+ end
320
+ if @faulttypes and @faulttypes.index(qname)
321
+ c = ClassDef.new(classname, '::StandardError')
322
+ else
323
+ c = ClassDef.new(classname, baseclassname)
324
+ end
325
+ c.comment = "#{qname}"
326
+ c.comment << "\nabstract" if typedef.abstract
327
+ parentmodule = mapped_class_name(qname, mpath)
328
+ init_lines, init_params =
329
+ parse_elements(c, typedef.elements, qname.namespace, parentmodule)
330
+
331
+ c.include_files_in_class("ActiveModel::Model")
332
+ c.include_files_in_class("AttributesHash")
333
+
334
+ unless typedef.attributes.empty?
335
+ define_attribute(c, typedef.attributes)
336
+ init_lines << "@__xmlattr = {}"
337
+ end
338
+ #DA AGGIUNGERE VALIDAZIONI RESTRICTION
339
+ unless typedef.elements.empty?
340
+ define_validations(c, typedef.elements)
341
+ end
342
+
343
+ #TOLTO INITIALIZE PER AVERE CONVENZIONE RAILS DI COSTRUTTORE CON HASH
344
+ # c.def_method('initialize', *init_params) do
345
+ # init_lines.join("\n")
346
+ # end
347
+
348
+ #SCRIVO UN FILE PER OGNI CLASSE
349
+ write_file(c.name+".rb", 'models_pagopa') do |f|
350
+ f.puts "# encoding: UTF-8"
351
+ f.puts "# Generated by wsdl2ruby (#{::SOAP::VERSION::FORK_STRING})\n"
352
+ f << c.dump
353
+ end
354
+
355
+ c
356
+ end
357
+
358
+ def parse_elements(c, elements, base_namespace, mpath, as_array = false)
359
+ init_lines = []
360
+ init_params = []
361
+ any = false
362
+ elements.each do |element|
363
+ case element
364
+ when XMLSchema::Any
365
+ # only 1 <any/> is allowed for now.
366
+ raise RuntimeError.new("duplicated 'any'") if any
367
+ any = true
368
+ attrname = '__xmlele_any'
369
+ c.def_attr(attrname, false, attrname)
370
+ c.def_method('set_any', 'elements') do
371
+ '@__xmlele_any = elements'
372
+ end
373
+ init_lines << "@__xmlele_any = nil"
374
+ when XMLSchema::Element
375
+ next if element.ref == SchemaName
376
+ name = name_element(element).name
377
+ typebase = @modulepath
378
+ if element.anonymous_type?
379
+ inner = create_elementdef(mpath, element)
380
+ unless as_array
381
+ inner.comment = "inner class for member: #{name}\n" + inner.comment
382
+ end
383
+ c.innermodule << inner
384
+ typebase = mpath
385
+ end
386
+ unless as_array
387
+ attrname = safemethodname(name)
388
+ varname = safevarname(name)
389
+ c.def_attr(attrname, true, varname)
390
+ init_lines << "@#{varname} = #{varname}"
391
+ if element.map_as_array?
392
+ init_params << "#{varname} = []"
393
+ else
394
+ init_params << "#{varname} = nil"
395
+ end
396
+ c.comment << "\n #{attrname} - #{create_type_name(typebase, element) || '(any)'}"
397
+ end
398
+ when WSDL::XMLSchema::Sequence
399
+ child_init_lines, child_init_params =
400
+ parse_elements(c, element.elements, base_namespace, mpath, as_array)
401
+ init_lines.concat(child_init_lines)
402
+ init_params.concat(child_init_params)
403
+ when WSDL::XMLSchema::Choice
404
+ child_init_lines, child_init_params =
405
+ parse_elements(c, element.elements, base_namespace, mpath, as_array)
406
+ init_lines.concat(child_init_lines)
407
+ init_params.concat(child_init_params)
408
+ when WSDL::XMLSchema::Group
409
+ if element.content.nil?
410
+ warn("no group definition found: #{element}")
411
+ next
412
+ end
413
+ child_init_lines, child_init_params =
414
+ parse_elements(c, element.content.elements, base_namespace, mpath, as_array)
415
+ init_lines.concat(child_init_lines)
416
+ init_params.concat(child_init_params)
417
+ else
418
+ raise RuntimeError.new("unknown type: #{element}")
419
+ end
420
+ end
421
+ [init_lines, init_params]
422
+ end
423
+
424
+ def define_attribute(c, attributes)
425
+ const = {}
426
+ unless attributes.empty?
427
+ c.def_method("__xmlattr") do <<-__EOD__
428
+ @__xmlattr ||= {}
429
+ __EOD__
430
+ end
431
+ end
432
+ attributes.each do |attribute|
433
+ name = name_attribute(attribute)
434
+ methodname = safemethodname('xmlattr_' + name.name)
435
+ constname = 'Attr' + safeconstname(name.name)
436
+ const[constname] ||= 0
437
+ if (const[constname] += 1) > 1
438
+ constname += "_#{const[constname]}"
439
+ end
440
+ c.def_const(constname, dqname(name))
441
+ c.def_method(methodname) do <<-__EOD__
442
+ __xmlattr[#{constname}]
443
+ __EOD__
444
+ end
445
+ c.def_method(methodname + '=', 'value') do <<-__EOD__
446
+ __xmlattr[#{constname}] = value
447
+ __EOD__
448
+ end
449
+ c.comment << "\n #{methodname} - #{attribute_basetype(attribute) || '(any)'}"
450
+ end
451
+ end
452
+
453
+ #AGGIUNTO
454
+ #aggiunge la validazione rails sulla lunghezza del campo se compare una restrictions sull'elemento
455
+ def define_validations(c,elements)
456
+ elements.each do |element|
457
+ if element.respond_to?(:type)
458
+ element_type = @simpletypes[element.type]
459
+ unless element_type.nil?
460
+ minlength = element_type.restriction.minlength
461
+ maxlength = element_type.restriction.maxlength
462
+ if minlength != nil && maxlength != nil
463
+ #ricavo ilnome dell'elemento
464
+ element_name = name_element(element).name
465
+ c.def_code("\n validates_length_of :#{element_name}, :in => #{minlength}..#{maxlength}")
466
+ end
467
+ end
468
+ end
469
+ end
470
+ end
471
+
472
+
473
+ def create_arraydef(mpath, qname, typedef)
474
+ classname = mapped_class_basename(qname, mpath)
475
+ c = ClassDef.new(classname, '::Array')
476
+ c.comment = "#{qname}"
477
+ parentmodule = mapped_class_name(qname, mpath)
478
+ parse_elements(c, typedef.elements, qname.namespace, parentmodule, true)
479
+ #SCRIVO UN FILE PER OGNI CLASSE
480
+ write_file(c.name+".rb", 'models_pagopa') do |f|
481
+ f.puts "# encoding: UTF-8"
482
+ f.puts "# Generated by wsdl2ruby (#{::SOAP::VERSION::FORK_STRING})\n"
483
+ f << c.dump
484
+ end
485
+ c
486
+ end
487
+
488
+ def sort_dependency(types)
489
+ dep = {}
490
+ root = []
491
+ types.each do |type|
492
+ if type.complexcontent and (base = type.complexcontent.base)
493
+ dep[base] ||= []
494
+ dep[base] << type
495
+ else
496
+ root << type
497
+ end
498
+ end
499
+ sorted = []
500
+ root.each do |type|
501
+ sorted.concat(collect_dependency(type, dep))
502
+ end
503
+ sorted.concat(dep.values.flatten)
504
+ sorted
505
+ end
506
+
507
+ # removes collected key from dep
508
+ def collect_dependency(type, dep)
509
+ result = [type]
510
+ return result unless dep.key?(type.name)
511
+ dep[type.name].each do |deptype|
512
+ result.concat(collect_dependency(deptype, dep))
513
+ end
514
+ dep.delete(type.name)
515
+ result
516
+ end
517
+
518
+ def modulepath_split(modulepath)
519
+ if modulepath.is_a?(::Array)
520
+ modulepath
521
+ else
522
+ modulepath.to_s.split('::')
523
+ end
524
+ end
525
+ end
526
+
527
+
528
+ end
529
+ end