class WSDL::SOAP::MethodDefCreator

Attributes

assigned_method[R]

TODO: should not export this kind of stateful information. will be rewwritten in 1.6.1

definitions[R]

Public Class Methods

new(definitions, name_creator, modulepath, defined_const) click to toggle source
# File lib/wsdl/soap/methodDefCreator.rb, line 27
def initialize(definitions, name_creator, modulepath, defined_const)
  @definitions = definitions
  @name_creator = name_creator
  @modulepath = modulepath
  @simpletypes = @definitions.collect_simpletypes
  @complextypes = @definitions.collect_complextypes
  @elements = @definitions.collect_elements
  @defined_const = defined_const
  @assigned_method = {}
end

Public Instance Methods

create(bindingname) click to toggle source
# File lib/wsdl/soap/methodDefCreator.rb, line 51
def create(bindingname)
  binding = @definitions.binding(bindingname)
  if binding
    return binding.operations.collect { |op_bind|
      next unless op_bind.soapoperation # not a SOAP operation binding
      create_methoddef(op_bind)
    }
  end
  nil
end
dump(name) click to toggle source
# File lib/wsdl/soap/methodDefCreator.rb, line 38
def dump(name)
  methoddef = ""
  porttype = @definitions.porttype(name)
  binding = porttype.find_binding
  if binding
    create(binding.name).each do |mdef|
      methoddef << ",\n" unless methoddef.empty?
      methoddef << dump_method(mdef).chomp
    end
  end
  methoddef
end

Private Instance Methods

assign_method_name(op_bind) click to toggle source
# File lib/wsdl/soap/methodDefCreator.rb, line 119
def assign_method_name(op_bind)
  method_name = safemethodname(op_bind.name)
  i = 1 # starts from _2
  while @assigned_method.value?(method_name)
    i += 1
    method_name = safemethodname("#{op_bind.name}_#{i}")
  end
  @assigned_method[op_bind.boundid] = method_name
  method_name
end
create_methoddef(op_bind) click to toggle source
# File lib/wsdl/soap/methodDefCreator.rb, line 64
def create_methoddef(op_bind)
  op_info = op_bind.operation_info
  name = assign_method_name(op_bind)
  soapaction = op_info.boundid.soapaction
  qname = op_bind.soapoperation_name
  mdef = ::SOAP::RPC::MethodDef.new(name, soapaction, qname)
  op_info.parts.each do |part|
    if op_info.style == :rpc
      mapped_class, qname = rpcdefinedtype(part)
    else
      mapped_class, qname = documentdefinedtype(part)
    end
    mdef.add_parameter(part.io_type, part.name, qname, mapped_class)
  end
  op_info.faults.each do |name, faultinfo|
    faultclass = mapped_class_name(name, @modulepath)
    mdef.faults[faultclass] = faultinfo
  end
  mdef.style = op_info.style
  mdef.inputuse = op_info.inputuse
  mdef.outputuse = op_info.outputuse
  mdef
end
documentdefinedtype(part) click to toggle source
# File lib/wsdl/soap/methodDefCreator.rb, line 154
def documentdefinedtype(part)
  if mapped = basetype_mapped_class(part.type)
    return ['::' + mapped.name, XSD::QName.new(nil, part.name)]
  elsif definedtype = @simpletypes[part.type]
    if definedtype.base
      return ['::' + basetype_mapped_class(definedtype.base).name, XSD::QName.new(nil, part.name)]
    else
      raise RuntimeError.new("unsupported simpleType: #{definedtype}")
    end
  elsif definedtype = @elements[part.element]
    return ['::SOAP::SOAPElement', part.element]
  elsif definedtype = @complextypes[part.type]
    return ['::SOAP::SOAPElement', part.type]
  else
    raise RuntimeError.new("part: #{part.name} cannot be resolved")
  end
end
dump_method(mdef) click to toggle source
# File lib/wsdl/soap/methodDefCreator.rb, line 88
  def dump_method(mdef)
    style = mdef.style
    inputuse = mdef.inputuse
    outputuse = mdef.outputuse
    paramstr = param2str(mdef.parameters)
    if paramstr.empty?
      paramstr = '[]'
    else
      paramstr = "[ " << paramstr.split(/\r?\n/).join("\n    ") << " ]"
    end
    definitions = <<__EOD__
#{ndq(mdef.soapaction)},
  #{dq(mdef.name)},
  #{paramstr},
  { :request_style =>  #{nsym(style)}, :request_use =>  #{nsym(inputuse)},
    :response_style => #{nsym(style)}, :response_use => #{nsym(outputuse)},
    :faults => #{mdef.faults.inspect} }
__EOD__
    if style == :rpc
      assign_const(mdef.qname.namespace, 'Ns')
      return <<__EOD__
[ #{dqname(mdef.qname)},
  #{definitions}]
__EOD__
    else
      return <<__EOD__
[ #{definitions}]
__EOD__
    end
  end
ele2str(ele) click to toggle source
# File lib/wsdl/soap/methodDefCreator.rb, line 187
def ele2str(ele)
  qualified = ele
  if qualified
    "true"
  else
    "false"
  end
end
mapping_info2str(mapped_class, qname) click to toggle source
# File lib/wsdl/soap/methodDefCreator.rb, line 179
def mapping_info2str(mapped_class, qname)
  if qname.nil?
    "[#{ndq(mapped_class)}]" 
  else
    "[#{ndq(mapped_class)}, #{ndq(qname.namespace)}, #{dq(qname.name)}]" 
  end
end
param2str(params) click to toggle source
# File lib/wsdl/soap/methodDefCreator.rb, line 172
def param2str(params)
  params.collect { |param|
    mappingstr = mapping_info2str(param.mapped_class, param.qname)
    "[:#{param.io_type.id2name}, #{dq(param.name)}, #{mappingstr}]"
  }.join(",\n")
end
rpcdefinedtype(part) click to toggle source
# File lib/wsdl/soap/methodDefCreator.rb, line 130
def rpcdefinedtype(part)
  if mapped = basetype_mapped_class(part.type)
    return ['::' + mapped.name, nil]
  elsif definedtype = @simpletypes[part.type]
    return [nil, definedtype.name]
  elsif definedtype = @elements[part.element]
    return [nil, part.element]
  elsif definedtype = @complextypes[part.type]
    case definedtype.compoundtype
    when :TYPE_STRUCT, :TYPE_EMPTY, :TYPE_ARRAY, :TYPE_SIMPLE
      type = mapped_class_name(part.type, @modulepath)
      return [type, part.type]
    when :TYPE_MAP
      return [Hash.name, part.type]
    else
      raise NotImplementedError.new("must not reach here: #{definedtype.compoundtype}")
    end
  elsif part.type == XSD::AnyTypeName
    return [nil, nil]
  else
    raise RuntimeError.new("part: #{part.name} cannot be resolved")
  end
end