Module: SOAP::Mapping::RegistrySupport

Included in:
EncodedRegistry, LiteralRegistry
Defined in:
lib/soap/mapping/registry.rb

Instance Method Summary collapse

Instance Method Details

#add_attributes2soap(obj, ele) ⇒ Object



230
231
232
233
234
235
236
237
238
# File 'lib/soap/mapping/registry.rb', line 230

def add_attributes2soap(obj, ele)
  if definition = Mapping.schema_definition_classdef(obj.class)
    add_definedattributes2soap(obj, ele, definition)
  elsif obj.respond_to?(:__xmlattr)
    obj.__xmlattr.each do |key, value|
      ele.extraattr[key] = value
    end
  end
end

#add_definedattributes2soap(obj, ele, typedef) ⇒ Object



240
241
242
243
244
245
246
247
# File 'lib/soap/mapping/registry.rb', line 240

def add_definedattributes2soap(obj, ele, typedef)
  if typedef.attributes
    typedef.attributes.each do |qname, param|
      value = get_xmlattr_value(obj, qname)
      ele.extraattr[qname] = value unless value.nil?
    end
  end
end

#base2obj(value, klass) ⇒ Object



273
274
275
276
277
278
279
280
281
282
283
284
285
286
# File 'lib/soap/mapping/registry.rb', line 273

def base2obj(value, klass)
  v = if value.respond_to?(:data)
        value.data
      elsif value.respond_to?(:text)
        value.text
      else
        nil
      end
  if value.is_a?(klass)
    v
  else
    klass.to_data(v)
  end
end

#base2soap(obj, type, qualified = nil) ⇒ Object



259
260
261
262
263
264
265
266
267
268
269
270
271
# File 'lib/soap/mapping/registry.rb', line 259

def base2soap(obj, type, qualified = nil)
  return SOAPNil.new if obj.nil?
  soap_obj = nil
  if type <= XSD::XSDString
    str = XSD::Charset.encoding_conv(obj.to_s, Mapping.external_ces,
      XSD::Charset.encoding)
    soap_obj = type.new(str)
  else
    soap_obj = type.new(obj)
  end
  soap_obj.qualified = qualified
  soap_obj
end

#elename_schema_definition_from_class(klass) ⇒ Object



202
203
204
# File 'lib/soap/mapping/registry.rb', line 202

def elename_schema_definition_from_class(klass)
  @class_elename_schema_definition[klass]
end

#find_node_definition(node) ⇒ Object



214
215
216
217
218
219
# File 'lib/soap/mapping/registry.rb', line 214

def find_node_definition(node)
  schema_definition_from_type(node.type) ||
    schema_definition_from_elename(node.elename) ||
    find_schema_definition(node.elename.name) ||
    find_schema_definition(node.type.name)
end

#find_schema_definition(name) ⇒ Object



221
222
223
224
225
226
227
228
# File 'lib/soap/mapping/registry.rb', line 221

def find_schema_definition(name)
  return nil unless name
  typestr = Mapping.safeconstname(name)
  obj_class = Mapping.class_from_name(typestr)
  if obj_class
    schema_definition_from_class(obj_class)
  end
end

#get_xmlattr_value(obj, qname) ⇒ Object



249
250
251
252
253
254
255
256
257
# File 'lib/soap/mapping/registry.rb', line 249

def get_xmlattr_value(obj, qname)
  attrname = 'xmlattr_' + qname.name
  value = Mapping.get_attribute(obj, attrname)
  if value.nil?
    attrname = Mapping.safemethodname('xmlattr_' + qname.name)
    value = Mapping.get_attribute(obj, attrname)
  end
  value
end

#initializeObject



174
175
176
177
178
179
180
# File 'lib/soap/mapping/registry.rb', line 174

def initialize
  super()
  @class_schema_definition = {}
  @class_elename_schema_definition = {}
  @elename_schema_definition = {}
  @type_schema_definition = {}
end

#is_stubobj_elements_for_array(vars) ⇒ Object



288
289
290
# File 'lib/soap/mapping/registry.rb', line 288

def is_stubobj_elements_for_array(vars)
  vars.keys.size == 1 and vars.values[0].is_a?(::Array)
end

#register(definition) ⇒ Object



182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/soap/mapping/registry.rb', line 182

def register(definition)
  obj_class = definition[:class]
  definition = Mapping.create_schema_definition(obj_class, definition)
  # give complexType definition a priority explicitly
  if !@class_schema_definition[obj_class] or definition.type
    @class_schema_definition[obj_class] = definition
  end
  if definition.elename and !definition.is_anonymous?
    @class_elename_schema_definition[obj_class] = definition
    @elename_schema_definition[definition.elename] = definition
  end
  if definition.type
    @type_schema_definition[definition.type] = definition
  end
end

#schema_definition_from_class(klass) ⇒ Object



198
199
200
# File 'lib/soap/mapping/registry.rb', line 198

def schema_definition_from_class(klass)
  @class_schema_definition[klass] || Mapping.schema_definition_classdef(klass)
end

#schema_definition_from_elename(qname) ⇒ Object



206
207
208
# File 'lib/soap/mapping/registry.rb', line 206

def schema_definition_from_elename(qname)
  @elename_schema_definition[qname]
end

#schema_definition_from_type(type) ⇒ Object



210
211
212
# File 'lib/soap/mapping/registry.rb', line 210

def schema_definition_from_type(type)
  @type_schema_definition[type]
end