Class: SOAP::Mapping::WSDLLiteralRegistry

Inherits:
LiteralRegistry show all
Defined in:
lib/soap/mapping/wsdlliteralregistry.rb

Instance Attribute Summary collapse

Attributes inherited from LiteralRegistry

#excn_handler_obj2soap, #excn_handler_soap2obj

Instance Method Summary collapse

Methods included from RegistrySupport

#add_attributes2soap, #base2obj, #base2soap, #elename_schema_definition_from_class, #find_node_definition, #find_schema_definition, #get_xmlattr_value, #is_stubobj_elements_for_array, #register, #schema_definition_from_class, #schema_definition_from_elename, #schema_definition_from_type

Constructor Details

#initialize(definedtypes = XSD::NamedElements::Empty, definedelements = XSD::NamedElements::Empty) ⇒ WSDLLiteralRegistry

Returns a new instance of WSDLLiteralRegistry


25
26
27
28
29
30
# File 'lib/soap/mapping/wsdlliteralregistry.rb', line 25

def initialize(definedtypes = XSD::NamedElements::Empty,
    definedelements = XSD::NamedElements::Empty)
  super()
  @definedtypes = definedtypes
  @definedelements = definedelements
end

Instance Attribute Details

#definedelementsObject (readonly)

Returns the value of attribute definedelements


22
23
24
# File 'lib/soap/mapping/wsdlliteralregistry.rb', line 22

def definedelements
  @definedelements
end

#definedtypesObject (readonly)

Returns the value of attribute definedtypes


23
24
25
# File 'lib/soap/mapping/wsdlliteralregistry.rb', line 23

def definedtypes
  @definedtypes
end

Instance Method Details

#obj2soap(obj, qname, obj_class = nil) ⇒ Object

Raises:


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/soap/mapping/wsdlliteralregistry.rb', line 32

def obj2soap(obj, qname, obj_class = nil)
  soap_obj = nil
  if obj.is_a?(SOAPElement)
    soap_obj = obj
  elsif eledef = @definedelements[qname]
    soap_obj = obj2elesoap(obj, eledef)
  elsif type = @definedtypes[qname]
    soap_obj = obj2typesoap(obj, type)
  else
    soap_obj = any2soap(obj, qname, obj_class)
  end
  return soap_obj if soap_obj
  if @excn_handler_obj2soap
    soap_obj = @excn_handler_obj2soap.call(obj) { |yield_obj|
      Mapping.obj2soap(yield_obj, nil, nil, MAPPING_OPT)
    }
    return soap_obj if soap_obj
  end
  raise MappingError.new("cannot map #{obj.class.name} as #{qname}")
end

#soap2obj(node, obj_class = nil) ⇒ Object

node should be a SOAPElement


54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/soap/mapping/wsdlliteralregistry.rb', line 54

def soap2obj(node, obj_class = nil)
  cause = nil
  begin
    return any2obj(node, obj_class)
  rescue MappingError
    cause = $!
  end
  if @excn_handler_soap2obj
    begin
      return @excn_handler_soap2obj.call(node) { |yield_node|
   Mapping.soap2obj(yield_node, nil, nil, MAPPING_OPT)
 }
    rescue Exception
    end
  end
  if node.respond_to?(:type)
    raise MappingError.new("cannot map #{node.type.name} to Ruby object", cause)
  else
    raise MappingError.new("cannot map #{node.elename.name} to Ruby object", cause)
  end
end