class SOAP::Mapping::Registry
Constants
- ArrayFactory
- Base64Factory
- BasetypeFactory
- DateTimeFactory
- HashFactory
- RubyOriginalMap
- SOAPBaseMap
- StringFactory
- TypedArrayFactory
- TypedStructFactory
- URIFactory
Attributes
default_factory[RW]
excn_handler_obj2soap[RW]
excn_handler_soap2obj[RW]
Public Class Methods
new(config = {})
click to toggle source
# File lib/soap/mapping/registry.rb, line 392 def initialize(config = {}) @config = config @map = Map.new(self) if @config[:allow_original_mapping] @allow_original_mapping = true @map.init(RubyOriginalMap) else @allow_original_mapping = false @map.init(SOAPBaseMap) end @allow_untyped_struct = @config.key?(:allow_untyped_struct) ? @config[:allow_untyped_struct] : true @rubytype_factory = RubytypeFactory.new( :allow_untyped_struct => @allow_untyped_struct, :allow_original_mapping => @allow_original_mapping ) @default_factory = @rubytype_factory @excn_handler_obj2soap = nil @excn_handler_soap2obj = nil end
Public Instance Methods
add(obj_class, soap_class, factory, info = nil)
click to toggle source
# File lib/soap/mapping/registry.rb, line 413 def add(obj_class, soap_class, factory, info = nil) @map.add(obj_class, soap_class, factory, info) end
Also aliased as: set
find_mapped_obj_class(soap_class)
click to toggle source
# File lib/soap/mapping/registry.rb, line 440 def find_mapped_obj_class(soap_class) @map.find_mapped_obj_class(soap_class) end
find_mapped_soap_class(obj_class)
click to toggle source
# File lib/soap/mapping/registry.rb, line 436 def find_mapped_soap_class(obj_class) @map.find_mapped_soap_class(obj_class) end
obj2soap(obj, type_qname = nil)
click to toggle source
general Registry
ignores type_qname
# File lib/soap/mapping/registry.rb, line 419 def obj2soap(obj, type_qname = nil) soap = _obj2soap(obj) if @allow_original_mapping addextend2soap(soap, obj) end soap end
soap2obj(node, klass = nil)
click to toggle source
# File lib/soap/mapping/registry.rb, line 427 def soap2obj(node, klass = nil) obj = _soap2obj(node, klass) if @allow_original_mapping addextend2obj(obj, node.extraattr[RubyExtendName]) addiv2obj(obj, node.extraattr[RubyIVarName]) end obj end
Private Instance Methods
_obj2soap(obj)
click to toggle source
# File lib/soap/mapping/registry.rb, line 446 def _obj2soap(obj) ret = nil if obj.is_a?(SOAPStruct) or obj.is_a?(SOAPArray) obj.replace do |ele| Mapping._obj2soap(ele, self) end return obj elsif obj.is_a?(SOAPBasetype) return obj end begin ret = @map.obj2soap(obj) || @default_factory.obj2soap(nil, obj, nil, self) return ret if ret rescue MappingError end if @excn_handler_obj2soap ret = @excn_handler_obj2soap.call(obj) { |yield_obj| Mapping._obj2soap(yield_obj, self) } return ret if ret end raise MappingError.new("Cannot map #{ obj.class.name } to SOAP/OM.") end
_soap2obj(node, klass = nil)
click to toggle source
Might return nil as a mapping result.
# File lib/soap/mapping/registry.rb, line 472 def _soap2obj(node, klass = nil) if node.extraattr.key?(RubyTypeName) conv, obj = @rubytype_factory.soap2obj(nil, node, nil, self) return obj if conv else conv, obj = @map.soap2obj(node, klass) return obj if conv conv, obj = @default_factory.soap2obj(nil, node, nil, self) return obj if conv end if @excn_handler_soap2obj begin return @excn_handler_soap2obj.call(node) { |yield_node| Mapping._soap2obj(yield_node, self) } rescue Exception end end raise MappingError.new("Cannot map #{ node.type.name } to Ruby object.") end
addextend2obj(obj, attr)
click to toggle source
# File lib/soap/mapping/registry.rb, line 503 def addextend2obj(obj, attr) return unless attr attr.split(/ /).reverse_each do |mstr| obj.extend(Mapping.module_from_name(mstr)) end end
addextend2soap(node, obj)
click to toggle source
# File lib/soap/mapping/registry.rb, line 520 def addextend2soap(node, obj) return if obj.is_a?(Symbol) or obj.is_a?(Fixnum) list = (class << obj; self; end).ancestors - obj.class.ancestors unless list.empty? node.extraattr[RubyExtendName] = list.collect { |c| if c.name.empty? raise TypeError.new("singleton can't be dumped #{ obj }") end c.name }.join(" ") end end
addiv2obj(obj, attr)
click to toggle source
# File lib/soap/mapping/registry.rb, line 493 def addiv2obj(obj, attr) return unless attr vars = {} attr.__getobj__.each do |name, value| vars[name] = Mapping._soap2obj(value, self) end Mapping.set_attributes(obj, vars) end