How I might use mysterious mappingRegistry
In SOAP world, a data model called "SOAP Data Model" is defined. It's a graph of typed object. Type is Struct, Array and simple types like string, integer, datetime, etc.
SOAP spec defines SOAP Data Model <-> XML instance. No language mapping such as in CORBA world. So to define mapping between a language and SOAP Data Model is user's responsibility. Though SOAP4R defines default mapping for easy use, you can use custom mappingregistry to define your mapping.
For example, under SOAP4R's default mapping, Ruby's array is mapped to 'Array of anytype' in SOAP Data Model. Sending this array to remote endpoint, it will be mapped to Variant array under SOAP/COM mapping, or Vector under Java mapping.
Don't you want to map some array to 'Array of int' exactly, do you? Then, at first, define your own Array;
class IntArray < Array; end
Create your custom mappingRegistry;
map = SOAP::Mapping::Registry.new
map.add(
IntArray, SOAP::SOAPArray, SOAP::Mapping::Registry::TypedArrayFactory,
{
:type => XSD::QName.new(XSD::Namespace, XSD::IntLiteral)
}
)
Then, use this map in marshalling/unmarshalling Ruby's object like;
SOAP::Marshal.marshal(IntArray[1, 2, 3], map)
Other than Marshal interface, SOAP::Driver and SOAP::Server has mappingregistry attribute.
All example
cf. http://dev.ctor.org/soap4r/browser/trunk/sample/marshal/customregistry.rb
require 'soap/marshal'
class IntArray < Array; end
map = SOAP::Mapping::Registry.new
map.add(
IntArray, SOAP::SOAPArray, SOAP::Mapping::Registry::TypedArrayFactory,
{
:type => XSD::QName.new(XSD::Namespace, XSD::IntLiteral)
}
)
puts "== dumps anyType array =="
puts SOAP::Marshal.marshal(IntArray[1, 2, 3])
puts
puts "== dumps int array with custom registry =="
puts SOAP::Marshal.marshal(IntArray[1, 2, 3], map)
=>
== dumps anyType array ==
<?xml version="1.0" encoding="utf-8" ?>
<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<env:Body>
<IntArray xmlns:n1="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:n2="http://www.ruby-lang.org/xmlns/ruby/type-instance"
xsi:type="n1:Array"
n1:arrayType="xsd:anyType[3]"
n2:rubyType="IntArray"
env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<item xsi:type="xsd:int">1</item>
<item xsi:type="xsd:int">2</item>
<item xsi:type="xsd:int">3</item>
</IntArray>
</env:Body>
</env:Envelope>
== dumps int array with custom registry ==
<?xml version="1.0" encoding="utf-8" ?>
<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<env:Body>
<IntArray xmlns:n1="http://schemas.xmlsoap.org/soap/encoding/"
xsi:type="n1:Array"
n1:arrayType="xsd:int[3]"
env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<item>1</item>
<item>2</item>
<item>3</item>
</IntArray>
</env:Body>
</env:Envelope>