Skip to content

Commit 3fef307

Browse files
committed
* clean up unused codes in MethodDefCreator.
git-svn-id: http://dev.ctor.org/svn/soap4r/trunk@2007 23c4dcf6-64ea-0310-84d7-d424c7495ec0
1 parent 5692e62 commit 3fef307

File tree

6 files changed

+38
-79
lines changed

6 files changed

+38
-79
lines changed

lib/soap/wsdlDriver.rb

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ class FactoryError < StandardError; end
3131

3232
def initialize(wsdl)
3333
@wsdl = import(wsdl)
34-
name_creator = WSDL::SOAP::ClassNameCreator.new
35-
@modulepath = 'WSDLDriverFactory'
36-
@methoddefcreator =
37-
WSDL::SOAP::MethodDefCreator.new(@wsdl, name_creator, @modulepath, {})
3834
end
3935

4036
def inspect
@@ -44,8 +40,10 @@ def inspect
4440
def create_rpc_driver(servicename = nil, portname = nil)
4541
port = find_port(servicename, portname)
4642
drv = SOAP::RPC::Driver.new(port.soap_address.location)
47-
init_driver(drv, port)
48-
add_operation(drv, port)
43+
if binding = port.find_binding
44+
init_driver(drv, binding)
45+
add_operation(drv, binding)
46+
end
4947
drv
5048
end
5149

@@ -113,20 +111,27 @@ def find_port(servicename = nil, portname = nil)
113111
port
114112
end
115113

116-
def init_driver(drv, port)
114+
def init_driver(drv, binding)
117115
wsdl_elements = @wsdl.collect_elements
118116
wsdl_types = @wsdl.collect_complextypes + @wsdl.collect_simpletypes
119117
rpc_decode_typemap = wsdl_types +
120-
@wsdl.soap_rpc_complextypes(port.find_binding)
118+
@wsdl.soap_rpc_complextypes(binding)
121119
drv.proxy.mapping_registry =
122120
Mapping::WSDLEncodedRegistry.new(rpc_decode_typemap)
123121
drv.proxy.literal_mapping_registry =
124122
Mapping::WSDLLiteralRegistry.new(wsdl_types, wsdl_elements)
125123
end
126124

127-
def add_operation(drv, port)
128-
port.find_binding.operations.each do |op_bind|
129-
mdef = @methoddefcreator.create_methoddef(op_bind)
125+
def add_operation(drv, binding)
126+
name_creator = WSDL::SOAP::ClassNameCreator.new
127+
modulepath = 'WSDLDriverFactory'
128+
methoddefcreator =
129+
WSDL::SOAP::MethodDefCreator.new(@wsdl, name_creator, modulepath, {})
130+
mdefs = methoddefcreator.create(binding.name)
131+
if mdefs.nil?
132+
raise FactoryError.new("no method definition found in WSDL")
133+
end
134+
mdefs.each do |mdef|
130135
opt = {
131136
:request_style => mdef.style,
132137
:response_style => mdef.style,

lib/wsdl/soap/cgiStubCreator.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ def dump(service_name)
4949
def dump_porttype(porttype)
5050
class_name = mapped_class_name(porttype.name, @modulepath)
5151
defined_const = {}
52-
result = MethodDefCreator.new(@definitions, @name_creator, @modulepath, defined_const).dump(porttype.name)
53-
methoddef = result[:methoddef]
52+
methoddef = MethodDefCreator.new(@definitions, @name_creator, @modulepath, defined_const).dump(porttype.name)
5453
wsdl_name = @definitions.name ? @definitions.name.name : 'default'
5554
mrname = safeconstname(wsdl_name + 'MappingRegistry')
5655
c1 = XSD::CodeGen::ClassDef.new(class_name)

lib/wsdl/soap/driverCreator.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ def dump_porttype(porttype)
6363
class_name = mapped_class_basename(qname, @modulepath)
6464
defined_const = {}
6565
mdcreator = MethodDefCreator.new(@definitions, @name_creator, @modulepath, defined_const)
66-
result = mdcreator.dump(porttype)
67-
methoddef = result[:methoddef]
66+
methoddef = mdcreator.dump(porttype)
6867
binding = @definitions.bindings.find { |item| item.type == porttype }
6968
if binding.nil? or binding.soapbinding.nil?
7069
# not bound or not a SOAP binding

lib/wsdl/soap/methodDefCreator.rb

Lines changed: 18 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -31,49 +31,44 @@ def initialize(definitions, name_creator, modulepath, defined_const)
3131
@simpletypes = @definitions.collect_simpletypes
3232
@complextypes = @definitions.collect_complextypes
3333
@elements = @definitions.collect_elements
34-
@types = []
35-
@encoded = false
36-
@literal = false
3734
@defined_const = defined_const
3835
@assigned_method = {}
3936
end
4037

4138
def dump(name)
42-
@types.clear
43-
@encoded = false
44-
@literal = false
4539
methoddef = ""
4640
porttype = @definitions.porttype(name)
4741
binding = porttype.find_binding
4842
if binding
49-
binding.operations.each do |op_bind|
50-
next unless op_bind # no binding is defined
51-
next unless op_bind.soapoperation # not a SOAP operation binding
43+
create(binding.name).each do |mdef|
5244
methoddef << ",\n" unless methoddef.empty?
53-
methoddef << dump_method(op_bind).chomp
45+
methoddef << dump_method(mdef).chomp
5446
end
5547
end
56-
result = {
57-
:methoddef => methoddef,
58-
:types => @types,
59-
:encoded => @encoded,
60-
:literal => @literal
61-
}
62-
result
48+
methoddef
49+
end
50+
51+
def create(bindingname)
52+
binding = @definitions.binding(bindingname)
53+
if binding
54+
return binding.operations.collect { |op_bind|
55+
next unless op_bind.soapoperation # not a SOAP operation binding
56+
create_methoddef(op_bind)
57+
}
58+
end
59+
nil
6360
end
6461

62+
private
63+
6564
def create_methoddef(op_bind)
6665
op_info = op_bind.operation_info
6766
name = assign_method_name(op_bind)
6867
soapaction = op_info.boundid.soapaction
6968
qname = op_bind.soapoperation_name
70-
style = op_info.style
71-
inputuse = op_info.inputuse
72-
outputuse = op_info.outputuse
7369
mdef = ::SOAP::RPC::MethodDef.new(name, soapaction, qname)
7470
op_info.parts.each do |part|
75-
if style == :rpc
76-
collect_type(part.type)
71+
if op_info.style == :rpc
7772
mapped_class, qname = rpcdefinedtype(part)
7873
else
7974
mapped_class, qname = documentdefinedtype(part)
@@ -90,10 +85,7 @@ def create_methoddef(op_bind)
9085
mdef
9186
end
9287

93-
private
94-
95-
def dump_method(op_bind)
96-
mdef = create_methoddef(op_bind)
88+
def dump_method(mdef)
9789
style = mdef.style
9890
inputuse = mdef.inputuse
9991
outputuse = mdef.outputuse
@@ -111,12 +103,6 @@ def dump_method(op_bind)
111103
:response_style => #{nsym(style)}, :response_use => #{nsym(outputuse)},
112104
:faults => #{mdef.faults.inspect} }
113105
__EOD__
114-
if inputuse == :encoded or outputuse == :encoded
115-
@encoded = true
116-
end
117-
if inputuse == :literal or outputuse == :literal
118-
@literal = true
119-
end
120106
if style == :rpc
121107
assign_const(mdef.qname.namespace, 'Ns')
122108
return <<__EOD__
@@ -183,30 +169,6 @@ def documentdefinedtype(part)
183169
end
184170
end
185171

186-
def collect_type(type)
187-
# ignore inline type definition.
188-
return if type.nil?
189-
return if @types.include?(type)
190-
@types << type
191-
return unless @complextypes[type]
192-
collect_elements_type(@complextypes[type].elements)
193-
end
194-
195-
def collect_elements_type(elements)
196-
elements.each do |element|
197-
case element
198-
when WSDL::XMLSchema::Any
199-
# nothing to do
200-
when WSDL::XMLSchema::Element
201-
collect_type(element.type)
202-
when WSDL::XMLSchema::Sequence, WSDL::XMLSchema::Choice
203-
collect_elements_type(element.elements)
204-
else
205-
raise RuntimeError.new("unknown type: #{element}")
206-
end
207-
end
208-
end
209-
210172
def param2str(params)
211173
params.collect { |param|
212174
mappingstr = mapping_info2str(param.mapped_class, param.qname)

lib/wsdl/soap/servletStubCreator.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,9 @@ def dump(service_name)
4949
def dump_porttype(porttype)
5050
class_name = mapped_class_name(porttype.name, @modulepath)
5151
defined_const = {}
52-
result = MethodDefCreator.new(@definitions, @name_creator, @modulepath, defined_const).dump(porttype.name)
53-
methoddef = result[:methoddef]
54-
52+
methoddef = MethodDefCreator.new(@definitions, @name_creator, @modulepath, defined_const).dump(porttype.name)
5553
wsdl_name = @definitions.name ? @definitions.name.name : 'default'
5654
mrname = safeconstname(wsdl_name + 'MappingRegistry')
57-
5855
c1 = XSD::CodeGen::ClassDef.new(class_name)
5956
c1.def_require("soap/rpc/soaplet")
6057
c1.def_code <<-EOD

lib/wsdl/soap/standaloneServerStubCreator.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,9 @@ def dump(service_name)
5050
def dump_porttype(porttype)
5151
class_name = mapped_class_name(porttype.name, @modulepath)
5252
defined_const = {}
53-
result = MethodDefCreator.new(@definitions, @name_creator, @modulepath, defined_const).dump(porttype.name)
54-
methoddef = result[:methoddef]
55-
53+
methoddef = MethodDefCreator.new(@definitions, @name_creator, @modulepath, defined_const).dump(porttype.name)
5654
wsdl_name = @definitions.name ? @definitions.name.name : 'default'
5755
mrname = safeconstname(wsdl_name + 'MappingRegistry')
58-
5956
c1 = XSD::CodeGen::ClassDef.new(class_name)
6057
c1.def_require("soap/rpc/standaloneServer")
6158
c1.def_code <<-EOD

0 commit comments

Comments
 (0)