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


225
226
227
228
229
230
231
232
233
234
235
236
237
# File 'lib/soap/mapping/registry.rb', line 225

def add_attributes2soap(obj, ele)
  definition = Mapping.schema_definition_classdef(obj.class)
  if definition && attributes = definition.attributes
    attributes.each do |qname, param|
      at = Mapping.get_attribute(obj, XSD::CodeGen::GenSupport.safemethodname('xmlattr_' + qname.name))
      ele.extraattr[qname] = at
    end
  elsif obj.respond_to?(:__xmlattr)
    obj.__xmlattr.each do |key, value|
      ele.extraattr[key] = value
    end
  end
end

#base2obj(value, klass) ⇒ Object


253
254
255
256
257
258
259
260
261
262
263
264
265
266
# File 'lib/soap/mapping/registry.rb', line 253

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.new(v).data
  end
end

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


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

def base2soap(obj, type, qualified = nil)
  soap_obj = nil
  if type <= XSD::XSDString
    str = XSD::Charset.encoding_conv(obj.to_s,
      Thread.current[:SOAPMapping][:ExternalCES],
      XSD::Charset.encoding)
    soap_obj = type.new(str)
  else
    soap_obj = type.new(obj)
  end
  soap_obj.qualified = qualified
  soap_obj
end

#find_node_definition(node) ⇒ Object


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

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


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

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

#initializeObject


178
179
180
181
182
183
# File 'lib/soap/mapping/registry.rb', line 178

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

#is_stubobj_elements_for_array(vars) ⇒ Object


268
269
270
# File 'lib/soap/mapping/registry.rb', line 268

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

#register(definition) ⇒ Object


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

def register(definition)
  obj_class = definition[:class]
  definition = Mapping.create_schema_definition(obj_class, definition)
  @class_schema_definition[obj_class] = definition
  if definition.elename
    @elename_schema_definition[definition.elename] = definition
  end
  if definition.type
    @type_schema_definition[definition.type] = definition
  end
end

#schema_definition_from_class(klass) ⇒ Object


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

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

#schema_definition_from_elename(qname) ⇒ Object


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

def schema_definition_from_elename(qname)
  @elename_schema_definition[qname]
end

#schema_definition_from_type(type) ⇒ Object


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

def schema_definition_from_type(type)
  @type_schema_definition[type]
end