Class: SOAP::Mapping::Registry::Map

Inherits:
Object
  • Object
show all
Defined in:
lib/action_web_service/soap/mapping/registry.rb

Instance Method Summary collapse

Constructor Details

#initialize(registry) ⇒ Map

Returns a new instance of Map.



178
179
180
181
182
# File 'lib/action_web_service/soap/mapping/registry.rb', line 178

def initialize(registry)
  @obj2soap = {}
  @soap2obj = {}
  @registry = registry
end

Instance Method Details

#add(obj_class, soap_class, factory, info) ⇒ Object

Give priority to latter entry.



229
230
231
232
233
# File 'lib/action_web_service/soap/mapping/registry.rb', line 229

def add(obj_class, soap_class, factory, info)
  info ||= {}
  (@obj2soap[obj_class] ||= []).unshift([soap_class, factory, info])
  (@soap2obj[soap_class] ||= []).unshift([obj_class, factory, info])
end

#clearObject



235
236
237
238
# File 'lib/action_web_service/soap/mapping/registry.rb', line 235

def clear
  @obj2soap.clear
  @soap2obj.clear
end

#find_mapped_obj_class(target_soap_class) ⇒ Object



245
246
247
248
# File 'lib/action_web_service/soap/mapping/registry.rb', line 245

def find_mapped_obj_class(target_soap_class)
  map = @soap2obj[target_soap_class]
  map.empty? ? nil : map[0][0]
end

#find_mapped_soap_class(target_obj_class) ⇒ Object



240
241
242
243
# File 'lib/action_web_service/soap/mapping/registry.rb', line 240

def find_mapped_soap_class(target_obj_class)
  map = @obj2soap[target_obj_class]
  map.empty? ? nil : map[0][1]
end

#init(init_map = []) ⇒ Object

Give priority to former entry.



221
222
223
224
225
226
# File 'lib/action_web_service/soap/mapping/registry.rb', line 221

def init(init_map = [])
  clear
  init_map.reverse_each do |obj_class, soap_class, factory, info|
    add(obj_class, soap_class, factory, info)
  end
end

#obj2soap(obj) ⇒ Object



184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# File 'lib/action_web_service/soap/mapping/registry.rb', line 184

def obj2soap(obj)
  klass = obj.class
  if map = @obj2soap[klass]
    map.each do |soap_class, factory, info|
      ret = factory.obj2soap(soap_class, obj, info, @registry)
      return ret if ret
    end
  end
  ancestors = klass.ancestors
  ancestors.delete(klass)
  ancestors.delete(::Object)
  ancestors.delete(::Kernel)
  ancestors.each do |klass|
    if map = @obj2soap[klass]
      map.each do |soap_class, factory, info|
        if info[:derived_class]
          ret = factory.obj2soap(soap_class, obj, info, @registry)
          return ret if ret
        end
      end
    end
  end
  nil
end

#soap2obj(node, klass = nil) ⇒ Object



209
210
211
212
213
214
215
216
217
218
# File 'lib/action_web_service/soap/mapping/registry.rb', line 209

def soap2obj(node, klass = nil)
  if map = @soap2obj[node.class]
    map.each do |obj_class, factory, info|
      next if klass and obj_class != klass
      conv, obj = factory.soap2obj(obj_class, node, info, @registry)
      return true, obj if conv
    end
  end
  return false, nil
end