class SOAP::WSDLDriverFactory

Attributes

wsdl[R]

Public Class Methods

new(wsdl) click to toggle source
# File lib/soap/wsdlDriver.rb, line 31
def initialize(wsdl)
  @wsdl = import(wsdl)
  name_creator = WSDL::SOAP::ClassNameCreator.new
  @modulepath = 'WSDLDriverFactory'
  @methoddefcreator =
    WSDL::SOAP::MethodDefCreator.new(@wsdl, name_creator, @modulepath, {})
end

Public Instance Methods

createDriver(servicename = nil, portname = nil)

Backward compatibility.

Alias for: create_driver
create_driver(servicename = nil, portname = nil) click to toggle source

deprecated old interface

# File lib/soap/wsdlDriver.rb, line 52
def create_driver(servicename = nil, portname = nil)
  warn("WSDLDriverFactory#create_driver is deprecated.  Use create_rpc_driver instead.")
  port = find_port(servicename, portname)
  WSDLDriver.new(@wsdl, port, nil)
end
Also aliased as: createDriver
create_rpc_driver(servicename = nil, portname = nil) click to toggle source
# File lib/soap/wsdlDriver.rb, line 43
def create_rpc_driver(servicename = nil, portname = nil)
  port = find_port(servicename, portname)
  drv = SOAP::RPC::Driver.new(port.soap_address.location)
  init_driver(drv, port)
  add_operation(drv, port)
  drv
end
dump_method_signatures(servicename = nil, portname = nil) click to toggle source
# File lib/soap/wsdlDriver.rb, line 61
def dump_method_signatures(servicename = nil, portname = nil)
  targetservice = XSD::QName.new(@wsdl.targetnamespace, servicename) if servicename
  targetport = XSD::QName.new(@wsdl.targetnamespace, portname) if portname
  sig = []
  element_definitions = @wsdl.collect_elements
  @wsdl.services.each do |service|
    next if targetservice and service.name != targetservice
    service.ports.each do |port|
      next if targetport and port.name != targetport
      sig << port.porttype.operations.collect { |operation|
        dump_method_signature(operation, element_definitions).gsub(/^#/, ' ')
      }.join("\n")
    end
  end
  sig.join("\n")
end
inspect() click to toggle source
# File lib/soap/wsdlDriver.rb, line 39
def inspect
  sprintf("#<%s:%s:0x%x\n\n%s>", self.class.name, @wsdl.name, __id__, dump_method_signatures)
end

Private Instance Methods

add_operation(drv, port) click to toggle source
# File lib/soap/wsdlDriver.rb, line 119
def add_operation(drv, port)
  port.find_binding.operations.each do |op_bind|
    op_name = op_bind.soapoperation_name
    soapaction = op_bind.soapaction || ''
    orgname = op_name.name
    name = XSD::CodeGen::GenSupport.safemethodname(orgname)
    param_def = create_param_def(op_bind)
    opt = {
      :request_style => op_bind.soapoperation_style,
      :response_style => op_bind.soapoperation_style,
      :request_use => op_bind.soapbody_use_input,
      :response_use => op_bind.soapbody_use_output
    }
    if op_bind.soapoperation_style == :rpc
      drv.add_rpc_operation(op_name, soapaction, name, param_def, opt)
    else
      drv.add_document_operation(soapaction, name, param_def, opt)
    end
    if orgname != name and orgname.capitalize == name.capitalize
      ::SOAP::Mapping.define_singleton_method(drv, orgname) do |*arg|
        __send__(name, *arg)
      end
    end
  end
end
create_param_def(op_bind) click to toggle source
# File lib/soap/wsdlDriver.rb, line 149
def create_param_def(op_bind)
  op = op_bind.find_operation
  if op_bind.soapoperation_style == :rpc
    param_def = @methoddefcreator.collect_rpcparameter(op)
  else
    param_def = @methoddefcreator.collect_documentparameter(op)
  end
  # the first element of typedef in param_def is a String like
  # "::SOAP::SOAPStruct".  turn this String to a class.
  param_def.collect { |io_type, name, param_type|
    [io_type, name, ::SOAP::RPC::SOAPMethod.parse_param_type(param_type)]
  }
end
filter_parts(partsdef, partssource) click to toggle source
# File lib/soap/wsdlDriver.rb, line 175
def filter_parts(partsdef, partssource)
  parts = partsdef.split(/\s+/)
  partssource.find_all { |part| parts.include?(part.name) }
end
find_port(servicename = nil, portname = nil) click to toggle source
# File lib/soap/wsdlDriver.rb, line 80
def find_port(servicename = nil, portname = nil)
  service = port = nil
  if servicename
    service = @wsdl.service(
      XSD::QName.new(@wsdl.targetnamespace, servicename))
  else
    service = @wsdl.services[0]
  end
  if service.nil?
    raise FactoryError.new("service #{servicename} not found in WSDL")
  end
  if portname
    port = service.ports[XSD::QName.new(@wsdl.targetnamespace, portname)]
    if port.nil?
      raise FactoryError.new("port #{portname} not found in WSDL")
    end
  else
    port = service.ports.find { |port| !port.soap_address.nil? }
    if port.nil?
      raise FactoryError.new("no ports have soap:address")
    end
  end
  if port.soap_address.nil?
    raise FactoryError.new("soap:address element not found in WSDL")
  end
  port
end
import(location) click to toggle source
# File lib/soap/wsdlDriver.rb, line 145
def import(location)
  WSDL::Importer.import(location)
end
init_driver(drv, port) click to toggle source
# File lib/soap/wsdlDriver.rb, line 108
def init_driver(drv, port)
  wsdl_elements = @wsdl.collect_elements
  wsdl_types = @wsdl.collect_complextypes + @wsdl.collect_simpletypes
  rpc_decode_typemap = wsdl_types +
    @wsdl.soap_rpc_complextypes(port.find_binding)
  drv.proxy.mapping_registry =
    Mapping::WSDLEncodedRegistry.new(rpc_decode_typemap)
  drv.proxy.literal_mapping_registry =
    Mapping::WSDLLiteralRegistry.new(wsdl_types, wsdl_elements)
end
param_def(type, name, klass, partqname) click to toggle source
# File lib/soap/wsdlDriver.rb, line 171
def param_def(type, name, klass, partqname)
  [type, name, [klass, partqname.namespace, partqname.name]]
end
partqname(part) click to toggle source
# File lib/soap/wsdlDriver.rb, line 163
def partqname(part)
  if part.type
    part.type
  else
    part.element
  end
end