Module: WSDL::SOAP::MappingRegistryCreatorSupport

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

Constant Summary

Constants included from XSD::CodeGen

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

Instance Method Summary collapse

Methods included from ClassDefCreatorSupport

#basetype_mapped_class, #create_class_name, #dq, #dqname, #dump_method_signature, #ndq, #nsym, #sym

Methods included from XSD::CodeGen::GenSupport

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

Instance Method Details

#attribute_basetype(attr) ⇒ Object


138
139
140
141
142
143
144
145
146
# File 'lib/wsdl/soap/mappingRegistryCreatorSupport.rb', line 138

def attribute_basetype(attr)
  if klass = basetype_class(attr.type)
    klass
  elsif attr.local_simpletype
    basetype_class(attr.local_simpletype.base)
  else
    nil
  end
end

#basetype_class(type) ⇒ Object


148
149
150
151
152
153
154
155
# File 'lib/wsdl/soap/mappingRegistryCreatorSupport.rb', line 148

def basetype_class(type)
  return nil if type.nil?
  if simpletype = @simpletypes[type]
    basetype_mapped_class(simpletype.base)
  else
    basetype_mapped_class(type)
  end
end

#define_attribute(attributes) ⇒ Object


157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/wsdl/soap/mappingRegistryCreatorSupport.rb', line 157

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|
      dqname(name) + ' => ' + ndq(type)
    }.join(",\n    ") +
  "\n  }"
end

#dump_entry(regname, var) ⇒ Object


188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/wsdl/soap/mappingRegistryCreatorSupport.rb', line 188

def dump_entry(regname, var)
  "#{regname}.register(\n  " +
    [
      dump_entry_item(var, :class),
      dump_entry_item(var, :soap_class),
      dump_entry_item(var, :schema_ns, true),
      dump_entry_item(var, :schema_name, true),
      dump_entry_item(var, :schema_type, true),
      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, as_string = false) ⇒ Object


203
204
205
206
207
208
209
210
211
212
213
# File 'lib/wsdl/soap/mappingRegistryCreatorSupport.rb', line 203

def dump_entry_item(var, key, as_string = false)
  if var.key?(key)
    if as_string
      ":#{key} => #{ndq(var[key])}"
    else
      ":#{key} => #{var[key]}"
    end
  else
    nil
  end
end

#dump_occurrence(occurrence) ⇒ Object


56
57
58
59
60
61
62
# File 'lib/wsdl/soap/mappingRegistryCreatorSupport.rb', line 56

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


40
41
42
43
44
45
46
# File 'lib/wsdl/soap/mappingRegistryCreatorSupport.rb', line 40

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


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/wsdl/soap/mappingRegistryCreatorSupport.rb', line 20

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_simpletypedef(qname, simpletype, as_element = nil, qualified = false) ⇒ Object


215
216
217
218
219
220
221
222
223
224
225
# File 'lib/wsdl/soap/mappingRegistryCreatorSupport.rb', line 215

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

#dump_simpletypedef_list(qname, typedef, as_element, qualified) ⇒ Object


248
249
250
# File 'lib/wsdl/soap/mappingRegistryCreatorSupport.rb', line 248

def dump_simpletypedef_list(qname, typedef, as_element, qualified)
  nil
end

#dump_simpletypedef_restriction(qname, typedef, as_element, qualified) ⇒ Object


227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
# File 'lib/wsdl/soap/mappingRegistryCreatorSupport.rb', line 227

def dump_simpletypedef_restriction(qname, typedef, as_element, qualified)
  restriction = typedef.restriction
  if restriction.enumeration.empty?
    # not supported.  minlength?
    return nil
  end
  var = {}
  var[:class] = create_class_name(qname, @modulepath)
  if as_element
    var[:schema_type] = nil
    var[:schema_ns] = as_element.namespace
  elsif typedef.name.nil?
    var[:schema_type] = nil
    var[:schema_ns] = qname.namespace
  else
    var[:schema_type] = qname.name
    var[:schema_ns] = qname.namespace
  end
  dump_entry(@varname, var)
end

#dump_simpletypedef_union(qname, typedef, as_element, qualified) ⇒ Object


252
253
254
# File 'lib/wsdl/soap/mappingRegistryCreatorSupport.rb', line 252

def dump_simpletypedef_union(qname, typedef, as_element, qualified)
  nil
end

#dump_type(name, type) ⇒ Object


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

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

#element_basetype(ele) ⇒ Object


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

def element_basetype(ele)
  if klass = basetype_class(ele.type)
    klass
  elsif ele.local_simpletype
    basetype_class(ele.local_simpletype.base)
  else
    nil
  end
end

#name_attribute(attribute) ⇒ Object

Raises:

  • (RuntimeError)

182
183
184
185
186
# File 'lib/wsdl/soap/mappingRegistryCreatorSupport.rb', line 182

def name_attribute(attribute)
  return attribute.name if attribute.name 
  return attribute.ref if attribute.ref
  raise RuntimeError.new("cannot define name of #{attribute}")
end

#name_element(element) ⇒ Object

Raises:

  • (RuntimeError)

176
177
178
179
180
# File 'lib/wsdl/soap/mappingRegistryCreatorSupport.rb', line 176

def name_element(element)
  return element.name if element.name 
  return element.ref if element.ref
  raise RuntimeError.new("cannot define name of #{element}")
end

#parse_elements(elements, base_namespace) ⇒ Object


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

def parse_elements(elements, base_namespace)
  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
      if element.type == XSD::AnyTypeName
        type = nil
      elsif klass = element_basetype(element)
        type = klass.name
      elsif element.type
        type = create_class_name(element.type, @modulepath)
      elsif element.ref
        next if element.ref == SchemaName
        type = create_class_name(element.ref, @modulepath)
      else
        type = nil      # means anyType.
        # do we define a class for local complexType from it's name?
        #   type = create_class_name(element.name, @modulepath)
        # <element>
        #   <complexType>
        #     <seq...>
        #   </complexType>
        # </element>
      end
      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)
      schema_element << child_schema_element
    when WSDL::XMLSchema::Choice
      child_schema_element = parse_elements(element.elements, base_namespace)
      child_schema_element.unshift(:choice)
      schema_element << child_schema_element
    else
      raise RuntimeError.new("unknown type: #{element}")
    end
  end
  schema_element
end