class SOAP::Mapping::Registry
Constants
- ArrayFactory
- Base64Factory
- BasetypeFactory
- DateTimeFactory
- FixnumFactory
- 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
Calls superclass method
SOAP::Mapping::RegistrySupport::new
# File lib/soap/mapping/encodedregistry.rb, line 270 def initialize(config = {}) super() @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
initial mapping interface new interface Registry#register
is defined in RegisterSupport
# File lib/soap/mapping/encodedregistry.rb, line 294 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/encodedregistry.rb, line 320 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/encodedregistry.rb, line 316 def find_mapped_soap_class(obj_class) @map.find_mapped_soap_class(obj_class) end
obj2soap(obj, type_qname = nil)
click to toggle source
# File lib/soap/mapping/encodedregistry.rb, line 299 def obj2soap(obj, type_qname = nil) soap = _obj2soap(obj, type_qname) if @allow_original_mapping addextend2soap(soap, obj) end soap end
soap2obj(node, klass = nil)
click to toggle source
# File lib/soap/mapping/encodedregistry.rb, line 307 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, type_qname = nil)
click to toggle source
# File lib/soap/mapping/encodedregistry.rb, line 326 def _obj2soap(obj, type_qname = nil) ret = nil if obj.is_a?(SOAPCompoundtype) obj.replace do |ele| Mapping._obj2soap(ele, self) end return obj elsif obj.is_a?(SOAPBasetype) return obj elsif type_qname && type = TypeMap[type_qname] return base2soap(obj, type) end cause = nil begin if definition = schema_definition_from_class(obj.class) return stubobj2soap(obj, definition) end ret = @map.obj2soap(obj) || @default_factory.obj2soap(nil, obj, nil, self) return ret if ret rescue MappingError cause = $! 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.", cause) end
_soap2obj(node, klass = nil)
click to toggle source
Might return nil as a mapping result.
# File lib/soap/mapping/encodedregistry.rb, line 359 def _soap2obj(node, klass = nil) definition = find_node_definition(node) if klass klass_definition = schema_definition_from_class(klass) if definition and (definition.class_for < klass) klass = definition.class_for else definition = klass_definition end else klass = definition.class_for if definition end if definition and node.is_a?(::SOAP::SOAPNameAccessible) return elesoap2stubobj(node, klass, definition) end if node.extraattr.key?(RubyTypeName) conv, obj = @rubytype_factory.soap2obj(nil, node, nil, self) return obj if conv end conv, obj = @map.soap2obj(node) return obj if conv conv, obj = @default_factory.soap2obj(nil, node, nil, self) return obj if conv cause = nil if @excn_handler_soap2obj begin return @excn_handler_soap2obj.call(node) { |yield_node| Mapping._soap2obj(yield_node, self) } rescue Exception cause = $! end end raise MappingError.new("Cannot map #{ node.type } to Ruby object.", cause) end
add_elesoap2stubobj(node, obj, definition)
click to toggle source
XXX consider to merge with the method in LiteralRegistry
# File lib/soap/mapping/encodedregistry.rb, line 496 def add_elesoap2stubobj(node, obj, definition) vars = {} node.each do |name, value| item = definition.elements.find_element(value.elename) if item child = soap2typedobj(value, item.mapped_class) else # unknown element is treated as anyType. child = Mapping._soap2obj(value, self) end if item and item.as_array? (vars[name] ||= []) << child elsif vars.key?(name) vars[name] = [vars[name], child].flatten else vars[name] = child end end if obj.is_a?(::Array) and is_stubobj_elements_for_array(vars) Array.instance_method(:replace).bind(obj).call(vars.values[0]) else Mapping.set_attributes(obj, vars) end end
addextend2obj(obj, attr)
click to toggle source
# File lib/soap/mapping/encodedregistry.rb, line 404 def addextend2obj(obj, attr) return unless attr attr.split(/ /).reverse_each do |mstr| ext_module = Mapping.module_from_name(mstr) return if ext_module.is_a?(Class) # RubyJedi: Apparently needed for Ruby 2.1 and above? obj.extend(ext_module) end end
addextend2soap(node, obj)
click to toggle source
# File lib/soap/mapping/encodedregistry.rb, line 413 def addextend2soap(node, obj) return if [Symbol, Fixnum, Bignum, Float].any?{ |c| obj.is_a?(c) } list = (class << obj; self; end).ancestors - obj.class.ancestors list = list.reject{|c| c.class == Class } ## As of Ruby 2.1 Singleton Classes are now included in the ancestry. Need to filter those out here. return if list.empty? extra_attrs = list.collect { |c| name = c.name if name.nil? or name.empty? raise TypeError.new("singleton can't be dumped #{ obj }") end name }.join(" ") node.extraattr[RubyExtendName] = extra_attrs end
addiv2obj(obj, attr)
click to toggle source
# File lib/soap/mapping/encodedregistry.rb, line 395 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
array2soap(obj, definition)
click to toggle source
# File lib/soap/mapping/encodedregistry.rb, line 438 def array2soap(obj, definition) return SOAPNil.new if obj.nil? # ToDo: check nillable. eledef = definition.elements[0] soap_obj = SOAPArray.new(ValueArrayName, 1, eledef.elename) mark_marshalled_obj(obj, soap_obj) obj.each do |item| soap_obj.add(typedobj2soap(item, eledef.mapped_class)) end soap_obj end
elesoap2stubobj(node, obj_class, definition)
click to toggle source
# File lib/soap/mapping/encodedregistry.rb, line 489 def elesoap2stubobj(node, obj_class, definition) obj = Mapping.create_empty_object(obj_class) add_elesoap2stubobj(node, obj, definition) obj end
soap2typedobj(value, klass)
click to toggle source
# File lib/soap/mapping/encodedregistry.rb, line 521 def soap2typedobj(value, klass) unless klass raise MappingError.new("unknown class: #{klass}") end if klass.include?(::SOAP::SOAPBasetype) obj = base2obj(value, klass) else obj = Mapping._soap2obj(value, self, klass) end obj end
stubobj2soap(obj, definition)
click to toggle source
# File lib/soap/mapping/encodedregistry.rb, line 429 def stubobj2soap(obj, definition) case obj when ::Array array2soap(obj, definition) else unknownstubobj2soap(obj, definition) end end
typedobj2soap(value, klass)
click to toggle source
# File lib/soap/mapping/encodedregistry.rb, line 481 def typedobj2soap(value, klass) if klass and klass.include?(::SOAP::SOAPBasetype) base2soap(value, klass) else Mapping._obj2soap(value, self) end end
unknownstubobj2soap(obj, definition)
click to toggle source
# File lib/soap/mapping/encodedregistry.rb, line 449 def unknownstubobj2soap(obj, definition) return SOAPNil.new if obj.nil? if definition.elements.size == 0 ele = Mapping.obj2soap(obj) ele.elename = definition.elename if definition.elename ele.extraattr[XSD::AttrTypeName] = definition.type if definition.type return ele else ele = SOAPStruct.new(definition.type) mark_marshalled_obj(obj, ele) end definition.elements.each do |eledef| name = eledef.elename.name if obj.respond_to?(:each) and eledef.as_array? obj.each do |item| ele.add(name, typedobj2soap(item, eledef.mapped_class)) end else child = Mapping.get_attribute(obj, eledef.varname) if child.respond_to?(:each) and eledef.as_array? child = child.lines if child.respond_to?(:lines) # RubyJedi: compatible with Ruby 1.8.6 and above child.each do |item| ele.add(name, typedobj2soap(item, eledef.mapped_class)) end else ele.add(name, typedobj2soap(child, eledef.mapped_class)) end end end ele end