1 | # WSDL4R - Creating client skelton code from WSDL.
|
---|
2 | # Copyright (C) 2002, 2003 NAKAMURA, Hiroshi <[email protected]>.
|
---|
3 |
|
---|
4 | # This program is copyrighted free software by NAKAMURA, Hiroshi. You can
|
---|
5 | # redistribute it and/or modify it under the same terms of Ruby's license;
|
---|
6 | # either the dual license version in 2003, or any later version.
|
---|
7 |
|
---|
8 |
|
---|
9 | require 'wsdl/info'
|
---|
10 | require 'wsdl/soap/classDefCreatorSupport'
|
---|
11 |
|
---|
12 |
|
---|
13 | module WSDL
|
---|
14 | module SOAP
|
---|
15 |
|
---|
16 |
|
---|
17 | class ClientSkeltonCreator
|
---|
18 | include ClassDefCreatorSupport
|
---|
19 |
|
---|
20 | attr_reader :definitions
|
---|
21 |
|
---|
22 | def initialize(definitions)
|
---|
23 | @definitions = definitions
|
---|
24 | end
|
---|
25 |
|
---|
26 | def dump(service_name)
|
---|
27 | result = ""
|
---|
28 | @definitions.service(service_name).ports.each do |port|
|
---|
29 | result << dump_porttype(port.porttype.name)
|
---|
30 | result << "\n"
|
---|
31 | end
|
---|
32 | result
|
---|
33 | end
|
---|
34 |
|
---|
35 | private
|
---|
36 |
|
---|
37 | def dump_porttype(name)
|
---|
38 | drv_name = create_class_name(name)
|
---|
39 |
|
---|
40 | result = ""
|
---|
41 | result << <<__EOD__
|
---|
42 | endpoint_url = ARGV.shift
|
---|
43 | obj = #{ drv_name }.new(endpoint_url)
|
---|
44 |
|
---|
45 | # run ruby with -d to see SOAP wiredumps.
|
---|
46 | obj.wiredump_dev = STDERR if $DEBUG
|
---|
47 |
|
---|
48 | __EOD__
|
---|
49 | @definitions.porttype(name).operations.each do |operation|
|
---|
50 | result << dump_method_signature(operation)
|
---|
51 | result << dump_input_init(operation.input) << "\n"
|
---|
52 | result << dump_operation(operation) << "\n\n"
|
---|
53 | end
|
---|
54 | result
|
---|
55 | end
|
---|
56 |
|
---|
57 | def dump_operation(operation)
|
---|
58 | name = operation.name
|
---|
59 | input = operation.input
|
---|
60 | "puts obj.#{ safemethodname(name.name) }#{ dump_inputparam(input) }"
|
---|
61 | end
|
---|
62 |
|
---|
63 | def dump_input_init(input)
|
---|
64 | result = input.find_message.parts.collect { |part|
|
---|
65 | safevarname(part.name)
|
---|
66 | }.join(" = ")
|
---|
67 | if result.empty?
|
---|
68 | ""
|
---|
69 | else
|
---|
70 | result << " = nil"
|
---|
71 | end
|
---|
72 | result
|
---|
73 | end
|
---|
74 | end
|
---|
75 |
|
---|
76 |
|
---|
77 | end
|
---|
78 | end
|
---|