Class: ActionService::Protocol::Soap::SoapMapper
- Inherits:
-
Object
- Object
- ActionService::Protocol::Soap::SoapMapper
- Defined in:
- lib/action_service/protocol/soap.rb
Instance Attribute Summary collapse
-
#custom_namespace ⇒ Object
readonly
Returns the value of attribute custom_namespace.
-
#custom_types ⇒ Object
readonly
Returns the value of attribute custom_types.
-
#registry ⇒ Object
readonly
Returns the value of attribute registry.
Instance Method Summary collapse
-
#initialize(custom_namespace) ⇒ SoapMapper
constructor
A new instance of SoapMapper.
- #lookup(klass) ⇒ Object (also: #map)
- #map_container_services(container, &block) ⇒ Object
Constructor Details
#initialize(custom_namespace) ⇒ SoapMapper
Returns a new instance of SoapMapper.
173 174 175 176 177 178 |
# File 'lib/action_service/protocol/soap.rb', line 173 def initialize(custom_namespace) @custom_namespace = custom_namespace @registry = SOAP::Mapping::Registry.new @klass2map = {} @custom_types = {} end |
Instance Attribute Details
#custom_namespace ⇒ Object (readonly)
Returns the value of attribute custom_namespace.
170 171 172 |
# File 'lib/action_service/protocol/soap.rb', line 170 def custom_namespace @custom_namespace end |
#custom_types ⇒ Object (readonly)
Returns the value of attribute custom_types.
171 172 173 |
# File 'lib/action_service/protocol/soap.rb', line 171 def custom_types @custom_types end |
#registry ⇒ Object (readonly)
Returns the value of attribute registry.
169 170 171 |
# File 'lib/action_service/protocol/soap.rb', line 169 def registry @registry end |
Instance Method Details
#lookup(klass) ⇒ Object Also known as: map
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 |
# File 'lib/action_service/protocol/soap.rb', line 180 def lookup(klass) return @klass2map[klass] if @klass2map.has_key?(klass) custom_type = false ruby_klass = select_class(klass.is_a?(Array) ? klass[0] : klass) type_name = Inflector.camelize(ruby_klass.name.split(/::/)[-1]) # Array signatures generate a double-mapping and require generation # of an Array subclass to represent the mapping in the SOAP # registry array_klass = nil if klass.is_a?(Array) array_klass = Class.new(Array) do module_eval <<-END def self.name "#{type_name}Array" end END end end mapping = @registry.find_mapped_soap_class(ruby_klass) rescue nil unless mapping # Custom structured type, generate a mapping info = { :type => XSD::QName.new(@custom_namespace, type_name) } @registry.add(ruby_klass, SOAP::SOAPStruct, SOAP::Mapping::Registry::TypedStructFactory, info) mapping = ensure_mapped(ruby_klass) custom_type = true end array_mapping = nil if array_klass # Typed array always requires a custom type. The info of the array # is the info of its element type (in mapping[2]), falling back # to SOAP base types. info = mapping[2] info ||= {} info[:type] ||= soap_base_type_qname(mapping[0]) @registry.add(array_klass, SOAP::SOAPArray, SOAP::Mapping::Registry::TypedArrayFactory, info) array_mapping = ensure_mapped(array_klass) end if array_mapping @klass2map[ruby_klass] = SoapMapping.new(self, type_name, ruby_klass, mapping[0], mapping, custom_type) @klass2map[klass] = SoapArrayMapping.new(self, type_name, array_klass, array_mapping[0], array_mapping, @klass2map[ruby_klass]) @custom_types[klass] = @klass2map[klass] @custom_types[ruby_klass] = @klass2map[ruby_klass] if custom_type else @klass2map[klass] = SoapMapping.new(self, type_name, ruby_klass, mapping[0], mapping, custom_type) @custom_types[klass] = @klass2map[klass] if custom_type end @klass2map[klass] end |
#map_container_services(container, &block) ⇒ Object
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 |
# File 'lib/action_service/protocol/soap.rb', line 258 def map_container_services(container, &block) container.class.services.each do |service_name, service_info| object = container.service_object(service_name) service_klass = object.class service_exports = {} object.class.exports.each do |export_name, export_info| expects = export_info[:expects] lookup_proc = lambda do |klass| mapping = lookup(klass) custom_mapping = nil if mapping.respond_to?(:element_mapping) custom_mapping = mapping.element_mapping else custom_mapping = mapping end if custom_mapping && custom_mapping.custom_type? # What gives? This is required so that structure types # referenced only by structures (and not signatures) still # have a custom type mapping in the registry (needed for WSDL # generation). custom_mapping.each_attribute{} end mapping end expects_signature = expects ? expects.map{|klass| lookup_proc.call(klass)} : nil returns = export_info[:returns] returns_signature = returns ? returns.map{|klass| lookup_proc.call(klass)} : nil service_exports[export_name] = { :expects => expects_signature, :returns => returns_signature } end yield service_name, service_klass, service_exports if block_given? end end |