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



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

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



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

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



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

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



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

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



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

def elename_schema_definition_from_class(klass)
  @class_elename_schema_definition[klass]
end

#find_node_definition(node) ⇒ Object



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

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



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

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



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

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



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

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

#is_stubobj_elements_for_array(vars) ⇒ Object



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

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

#register(definition) ⇒ Object



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

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



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

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

#schema_definition_from_elename(qname) ⇒ Object



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

def schema_definition_from_elename(qname)
  @elename_schema_definition[qname]
end

#schema_definition_from_type(type) ⇒ Object



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

def schema_definition_from_type(type)
  @type_schema_definition[type]
end