Module: WSDL::SOAP::MappingRegistryCreatorSupport

Includes:
ClassDefCreatorSupport, XSD::CodeGen
Included in:
EncodedMappingRegistryCreator, LiteralMappingRegistryCreator
Defined in:
lib/wsdl/soap/mappingRegistryCreatorSupport.rb

Overview

requires @defined_const = {}, @dump_with_inner, @modulepath

Constant Summary collapse

DEFAULT_ITEM_NAME =
XSD::QName.new(nil, 'item')

Constants included from XSD::CodeGen

XSD::CodeGen::CONSTANTS, XSD::CodeGen::KEYWORDS

Instance Method Summary collapse

Methods included from ClassDefCreatorSupport

#assign_const, #basetype_mapped_class, #create_type_name, #dq, #dqname, #dump_method_signature, #mapped_class_basename, #mapped_class_name, #ndq, #nsym, #sym

Methods included from XSD::CodeGen::GenSupport

capitalize, constant?, #format, keyword?, safeconstname, safeconstname?, safemethodname, safemethodname?, safevarname, safevarname?, uncapitalize

Instance Method Details

#create_array_element_definition(typedef, mpath) ⇒ Object

used when “soapenc:arrayType” definition



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
# File 'lib/wsdl/soap/mappingRegistryCreatorSupport.rb', line 328

def create_array_element_definition(typedef, mpath)
  child_type = typedef.child_type
  child_element = typedef.find_aryelement
  if child_type == XSD::AnyTypeName
    type = nil
  elsif child_element
    if klass = element_basetype(child_element)
      type = klass.name
    else
      typename = child_element.type || child_element.name
      type = mapped_class_name(typename, mpath)
    end
  elsif child_type
    type = mapped_class_name(child_type, mpath)
  else
    type = nil
  end
  occurrence = [0, nil]
  if child_element and child_element.name
    if child_element.map_as_array?
      type << '[]' if type
      occurrence = [child_element.minoccurs, child_element.maxoccurs]
    end
    child_element_name = child_element.name
  else
    child_element_name = DEFAULT_ITEM_NAME
  end
  [child_element_name.name, child_element_name, type, occurrence]
end

#define_attribute(attributes) ⇒ Object



204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
# File 'lib/wsdl/soap/mappingRegistryCreatorSupport.rb', line 204

def define_attribute(attributes)
  schema_attribute = []
  attributes.each do |attribute|
    name = name_attribute(attribute)
    if klass = attribute_basetype(attribute)
      type = klass.name
    else
      warn("unresolved attribute type #{attribute.type} for #{name}")
      type = nil
    end
    schema_attribute << [name, type]
  end
  "{\n    " +
    schema_attribute.collect { |name, type|
      assign_const(name.namespace, 'Ns')
      dqname(name) + ' => ' + ndq(type)
    }.join(",\n    ") +
  "\n  }"
end

#define_dump_class(var, mpath, qname, typedef, as_element, opt) ⇒ Object



358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
# File 'lib/wsdl/soap/mappingRegistryCreatorSupport.rb', line 358

def define_dump_class(var, mpath, qname, typedef, as_element, opt)
  var[:class] = mapped_class_name(qname, mpath)
  if as_element
    var[:schema_name] = as_element
    schema_ns = as_element.namespace
  elsif typedef.name.nil?
    var[:schema_name] = qname
    schema_ns = qname.namespace
  else
    var[:schema_type] = qname
    schema_ns = qname.namespace
  end
  var[:is_anonymous] = opt[:is_anonymous] if opt.key?(:is_anonymous)
  # true, false, or nil
  if opt.key?(:qualified)
    var[:schema_qualified] = opt[:qualified].to_s
  end
end

#dump_array_typemap(mpath, qname, typedef, as_element, opt) ⇒ Object



46
47
48
49
50
51
52
53
54
# File 'lib/wsdl/soap/mappingRegistryCreatorSupport.rb', line 46

def dump_array_typemap(mpath, qname, typedef, as_element, opt)
  if typedef.find_soapenc_arytype
    if opt[:encoded]
      dump_encoded_array_typemap(mpath, qname, typedef, as_element, opt)
    end
  else
    dump_literal_array_typemap(mpath, qname, typedef, as_element, opt)
  end
end

#dump_complex_typemap(mpath, qname, typedef, as_element, opt) ⇒ Object

mappa il complex type



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/wsdl/soap/mappingRegistryCreatorSupport.rb', line 57

def dump_complex_typemap(mpath, qname, typedef, as_element, opt)
  var = {}
  define_dump_class(var, mpath, qname, typedef, as_element, opt)
  schema_ns = (var[:schema_name] || var[:schema_type]).namespace
  if var[:schema_type] and typedef.base
    var[:schema_basetype] = typedef.base
  end
  parentmodule = var[:class]
  parsed_element =
    parse_elements(typedef.elements, qname.namespace, parentmodule, opt)
  if typedef.choice?
    parsed_element.unshift(:choice)
  end
  var[:schema_element] = dump_schema_element_definition(parsed_element, 2)
  unless typedef.attributes.empty?
    var[:schema_attribute] = define_attribute(typedef.attributes)
  end
  assign_const(schema_ns, 'Ns')
  dump_entry(@varname, var)
end

#dump_complextypedef(mpath, qname, typedef, as_element = nil, opt = {}) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/wsdl/soap/mappingRegistryCreatorSupport.rb', line 29

def dump_complextypedef(mpath, qname, typedef, as_element = nil, opt = {})
  case typedef.compoundtype
  when :TYPE_STRUCT, :TYPE_EMPTY
    dump_complex_typemap(mpath, qname, typedef, as_element, opt)
  when :TYPE_ARRAY
    dump_array_typemap(mpath, qname, typedef, as_element, opt)
  when :TYPE_SIMPLE
    dump_simple_typemap(mpath, qname, typedef, as_element, opt)
  when :TYPE_MAP
    # mapped as a general Hash
    nil
  else
    raise RuntimeError.new(
      "unknown kind of complexContent: #{typedef.compoundtype}")
  end
end

#dump_encoded_array_typemap(mpath, qname, typedef, as_element, opt) ⇒ Object



314
315
316
317
318
319
320
321
322
323
324
325
# File 'lib/wsdl/soap/mappingRegistryCreatorSupport.rb', line 314

def dump_encoded_array_typemap(mpath, qname, typedef, as_element, opt)
  arytype = typedef.find_arytype || XSD::AnyTypeName
  type = XSD::QName.new(arytype.namespace, arytype.name.sub(/\[(?:,)*\]$/, ''))
  return <<__EOD__
#{@varname}.set(
#{mapped_class_name(qname, mpath)},
::SOAP::SOAPArray,
::SOAP::Mapping::EncodedRegistry::TypedArrayFactory,
{ :type => #{dqname(type)} }
)
__EOD__
end

#dump_entry(regname, var) ⇒ Object



224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# File 'lib/wsdl/soap/mappingRegistryCreatorSupport.rb', line 224

def dump_entry(regname, var)
  "#{regname}.register(\n  " +
    [
      dump_entry_item(var, :class),
      dump_entry_item(var, :soap_class),
      dump_entry_item(var, :schema_name, :qname),
      dump_entry_item(var, :schema_type, :qname),
      dump_entry_item(var, :is_anonymous),
      dump_entry_item(var, :schema_basetype, :qname),
      dump_entry_item(var, :schema_qualified),
      dump_entry_item(var, :schema_element),
      dump_entry_item(var, :schema_attribute)
    ].compact.join(",\n  ") +
  "\n)\n"
end

#dump_entry_item(var, key, dump_type = :none) ⇒ Object



240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
# File 'lib/wsdl/soap/mappingRegistryCreatorSupport.rb', line 240

def dump_entry_item(var, key, dump_type = :none)
  if var.key?(key)
    case dump_type
    when :none
      ":#{key} => #{var[key]}"
    when :string
      if @defined_const.key?(var[key])
        ":#{key} => #{@defined_const[var[key]]}"
      else
        ":#{key} => #{ndq(var[key])}"
      end
    when :qname
      qname = var[key]
      if @defined_const.key?(qname.namespace)
        ns = @defined_const[qname.namespace]
      else
        ns = ndq(qname.namespace)
      end
      ":#{key} => XSD::QName.new(#{ns}, #{ndq(qname.name)})"
    else
      raise "Unknown dump type: #{dump_type}"
    end
  end
end

#dump_literal_array_typemap(mpath, qname, typedef, as_element, opt) ⇒ Object



300
301
302
303
304
305
306
307
308
309
310
311
312
# File 'lib/wsdl/soap/mappingRegistryCreatorSupport.rb', line 300

def dump_literal_array_typemap(mpath, qname, typedef, as_element, opt)
  var = {}
  define_dump_class(var, mpath, qname, typedef, as_element, opt)
  schema_ns = (var[:schema_name] || var[:schema_type]).namespace
  parsed_element =
    parse_elements(typedef.elements, qname.namespace, var[:class], opt)
  if parsed_element.empty?
    parsed_element = [create_array_element_definition(typedef, mpath)]
  end
  var[:schema_element] = dump_schema_element_definition(parsed_element, 2)
  assign_const(schema_ns, 'Ns')
  dump_entry(@varname, var)
end

#dump_occurrence(occurrence) ⇒ Object



127
128
129
130
131
132
133
# File 'lib/wsdl/soap/mappingRegistryCreatorSupport.rb', line 127

def dump_occurrence(occurrence)
  if occurrence and occurrence != [1, 1] # default
    minoccurs, maxoccurs = occurrence
    maxoccurs ||= 'nil'
    "[#{minoccurs}, #{maxoccurs}]"
  end
end

#dump_schema_element(schema_element, indent = 0) ⇒ Object



110
111
112
113
114
115
116
# File 'lib/wsdl/soap/mappingRegistryCreatorSupport.rb', line 110

def dump_schema_element(schema_element, indent = 0)
  sp = ' ' * indent
  delimiter = ",\n" + sp
  sp + schema_element.collect { |definition|
    dump_schema_element_definition(definition, indent)
  }.join(delimiter)
end

#dump_schema_element_definition(definition, indent = 0) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/wsdl/soap/mappingRegistryCreatorSupport.rb', line 90

def dump_schema_element_definition(definition, indent = 0)
  return '[]' if definition.empty?
  sp = ' ' * indent
  if definition[0] == :choice
    definition.shift
    "[ :choice,\n" +
      dump_schema_element(definition, indent + 2) + "\n" + sp + "]"
  elsif definition[0].is_a?(::Array)
    "[\n" +
      dump_schema_element(definition, indent + 2) + "\n" + sp + "]"
  else
    varname, name, type, occurrence = definition
    '[' + [
      varname.dump,
      dump_type(name, type),
      dump_occurrence(occurrence)
    ].compact.join(', ') + ']'
  end
end

#dump_simple_typemap(mpath, qname, typedef, as_element, opt) ⇒ Object

mappa il simple type



79
80
81
82
83
84
85
86
87
88
# File 'lib/wsdl/soap/mappingRegistryCreatorSupport.rb', line 79

def dump_simple_typemap(mpath, qname, typedef, as_element, opt)
  var = {}
  define_dump_class(var, mpath, qname, typedef, as_element, opt)
  schema_ns = (var[:schema_name] || var[:schema_type]).namespace
  unless typedef.attributes.empty?
    var[:schema_attribute] = define_attribute(typedef.attributes)
  end
  assign_const(schema_ns, 'Ns')
  dump_entry(@varname, var)
end

#dump_simpletypedef(mpath, qname, simpletype, as_element = nil, opt = {}) ⇒ Object



265
266
267
268
269
270
271
272
273
274
275
# File 'lib/wsdl/soap/mappingRegistryCreatorSupport.rb', line 265

def dump_simpletypedef(mpath, qname, simpletype, as_element = nil, opt = {})
  if simpletype.restriction
    dump_simpletypedef_restriction(mpath, qname, simpletype, as_element, opt)
  elsif simpletype.list
    dump_simpletypedef_list(mpath, qname, simpletype, as_element, opt)
  elsif simpletype.union
    dump_simpletypedef_union(mpath, qname, simpletype, as_element, opt)
  else
    raise RuntimeError.new("unknown kind of simpletype: #{simpletype}")
  end
end

#dump_simpletypedef_list(mpath, qname, typedef, as_element, opt) ⇒ Object



290
291
292
# File 'lib/wsdl/soap/mappingRegistryCreatorSupport.rb', line 290

def dump_simpletypedef_list(mpath, qname, typedef, as_element, opt)
  nil
end

#dump_simpletypedef_restriction(mpath, qname, typedef, as_element, opt) ⇒ Object



277
278
279
280
281
282
283
284
285
286
287
288
# File 'lib/wsdl/soap/mappingRegistryCreatorSupport.rb', line 277

def dump_simpletypedef_restriction(mpath, qname, typedef, as_element, opt)
  restriction = typedef.restriction
  # unless restriction.enumeration?
  #   # not supported.  minlength?
  #   return nil
  # end
  var = {}
  define_dump_class(var, mpath, qname, typedef, as_element, opt)
  schema_ns = (var[:schema_name] || var[:schema_type]).namespace
  assign_const(schema_ns, 'Ns')
  dump_entry(@varname, var)
end

#dump_simpletypedef_union(mpath, qname, typedef, as_element, opt) ⇒ Object



294
295
296
# File 'lib/wsdl/soap/mappingRegistryCreatorSupport.rb', line 294

def dump_simpletypedef_union(mpath, qname, typedef, as_element, opt)
  nil
end

#dump_type(name, type) ⇒ Object



118
119
120
121
122
123
124
125
# File 'lib/wsdl/soap/mappingRegistryCreatorSupport.rb', line 118

def dump_type(name, type)
  if name
    assign_const(name.namespace, 'Ns')
    '[' + ndq(type) + ', ' + dqname(name) + ']'
  else
    ndq(type)
  end
end

#dump_with_innerObject



23
24
25
26
27
# File 'lib/wsdl/soap/mappingRegistryCreatorSupport.rb', line 23

def dump_with_inner
  @dump_with_inner = []
  @dump_with_inner.unshift(yield)
  @dump_with_inner.join("\n")
end

#parse_elements(elements, base_namespace, mpath, opt) ⇒ Object



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
# File 'lib/wsdl/soap/mappingRegistryCreatorSupport.rb', line 135

def parse_elements(elements, base_namespace, mpath, opt)
  schema_element = []
  any = false
  elements.each do |element|
    case element
    when XMLSchema::Any
      # only 1 <any/> is allowed for now.
      raise RuntimeError.new("duplicated 'any'") if any
      any = true
      varname = 'any' # not used
      eleqname = XSD::AnyTypeName
      type = nil
      occurrence = nil
      schema_element << [varname, eleqname, type, occurrence]
    when XMLSchema::Element
      next if element.ref == SchemaName
      typebase = @modulepath
      if element.anonymous_type?
        child_opt = {
          :qualified => (element.elementform == 'qualified'),
          :is_anonymous => true
        }
        @dump_with_inner << dump_complextypedef(mpath, element.name, element.local_complextype, nil, child_opt)
        typebase = mpath
      end
      type = create_type_name(typebase, element)
      name = name_element(element).name
      varname = safevarname(name)
      if element.map_as_array?
        if type
          type += '[]'
        else
          type = '[]'
        end
      end
      # nil means @@schema_ns + varname
      eleqname = element.name || element.ref
      if eleqname && varname == name && eleqname.namespace == base_namespace
        eleqname = nil
      end
      occurrence = [element.minoccurs, element.maxoccurs]
      schema_element << [varname, eleqname, type, occurrence]
    when WSDL::XMLSchema::Sequence
      child_schema_element =
        parse_elements(element.elements, base_namespace, mpath, opt)
      schema_element << child_schema_element
    when WSDL::XMLSchema::Choice
      child_schema_element =
        parse_elements(element.elements, base_namespace, mpath, opt)
      if !element.map_as_array?
        # choice + maxOccurs="unbounded" is treated just as 'all' now.
        child_schema_element.unshift(:choice)
      end
      schema_element << child_schema_element
    when WSDL::XMLSchema::Group
      if element.content.nil?
        warn("no group definition found: #{element}")
        next
      end
      child_schema_element =
        parse_elements(element.content.elements, base_namespace, mpath, opt)
      schema_element.concat(child_schema_element)
    else
      raise RuntimeError.new("unknown type: #{element}")
    end
  end
  schema_element
end