1 | # WSDL4R - Creating class code support from WSDL.
|
---|
2 | # Copyright (C) 2004 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 'soap/mapping'
|
---|
11 | require 'soap/mapping/typeMap'
|
---|
12 | require 'xsd/codegen/gensupport'
|
---|
13 |
|
---|
14 |
|
---|
15 | module WSDL
|
---|
16 | module SOAP
|
---|
17 |
|
---|
18 |
|
---|
19 | module ClassDefCreatorSupport
|
---|
20 | include XSD::CodeGen::GenSupport
|
---|
21 |
|
---|
22 | def create_class_name(qname)
|
---|
23 | if klass = basetype_mapped_class(qname)
|
---|
24 | ::SOAP::Mapping::DefaultRegistry.find_mapped_obj_class(klass).name
|
---|
25 | else
|
---|
26 | safeconstname(qname.name)
|
---|
27 | end
|
---|
28 | end
|
---|
29 |
|
---|
30 | def basetype_mapped_class(name)
|
---|
31 | ::SOAP::TypeMap[name]
|
---|
32 | end
|
---|
33 |
|
---|
34 | def dump_method_signature(operation)
|
---|
35 | name = operation.name.name
|
---|
36 | input = operation.input
|
---|
37 | output = operation.output
|
---|
38 | fault = operation.fault
|
---|
39 | signature = "#{ name }#{ dump_inputparam(input) }"
|
---|
40 | str = <<__EOD__
|
---|
41 | # SYNOPSIS
|
---|
42 | # #{name}#{dump_inputparam(input)}
|
---|
43 | #
|
---|
44 | # ARGS
|
---|
45 | #{dump_inout_type(input).chomp}
|
---|
46 | #
|
---|
47 | # RETURNS
|
---|
48 | #{dump_inout_type(output).chomp}
|
---|
49 | #
|
---|
50 | __EOD__
|
---|
51 | unless fault.empty?
|
---|
52 | faultstr = (fault.collect { |f| dump_inout_type(f).chomp }).join(', ')
|
---|
53 | str <<<<__EOD__
|
---|
54 | # RAISES
|
---|
55 | # #{faultstr}
|
---|
56 | #
|
---|
57 | __EOD__
|
---|
58 | end
|
---|
59 | str
|
---|
60 | end
|
---|
61 |
|
---|
62 | def dq(ele)
|
---|
63 | ele.dump
|
---|
64 | end
|
---|
65 |
|
---|
66 | def ndq(ele)
|
---|
67 | ele.nil? ? 'nil' : dq(ele)
|
---|
68 | end
|
---|
69 |
|
---|
70 | def sym(ele)
|
---|
71 | ':' + ele
|
---|
72 | end
|
---|
73 |
|
---|
74 | def dqname(qname)
|
---|
75 | qname.dump
|
---|
76 | end
|
---|
77 |
|
---|
78 | private
|
---|
79 |
|
---|
80 | def dump_inout_type(param)
|
---|
81 | if param
|
---|
82 | message = param.find_message
|
---|
83 | params = ""
|
---|
84 | message.parts.each do |part|
|
---|
85 | name = safevarname(part.name)
|
---|
86 | if part.type
|
---|
87 | typename = safeconstname(part.type.name)
|
---|
88 | params << add_at("# #{name}", "#{typename} - #{part.type}\n", 20)
|
---|
89 | elsif part.element
|
---|
90 | typename = safeconstname(part.element.name)
|
---|
91 | params << add_at("# #{name}", "#{typename} - #{part.element}\n", 20)
|
---|
92 | end
|
---|
93 | end
|
---|
94 | unless params.empty?
|
---|
95 | return params
|
---|
96 | end
|
---|
97 | end
|
---|
98 | "# N/A\n"
|
---|
99 | end
|
---|
100 |
|
---|
101 | def dump_inputparam(input)
|
---|
102 | message = input.find_message
|
---|
103 | params = ""
|
---|
104 | message.parts.each do |part|
|
---|
105 | params << ", " unless params.empty?
|
---|
106 | params << safevarname(part.name)
|
---|
107 | end
|
---|
108 | if params.empty?
|
---|
109 | ""
|
---|
110 | else
|
---|
111 | "(#{ params })"
|
---|
112 | end
|
---|
113 | end
|
---|
114 |
|
---|
115 | def add_at(base, str, pos)
|
---|
116 | if base.size >= pos
|
---|
117 | base + ' ' + str
|
---|
118 | else
|
---|
119 | base + ' ' * (pos - base.size) + str
|
---|
120 | end
|
---|
121 | end
|
---|
122 | end
|
---|
123 |
|
---|
124 |
|
---|
125 | end
|
---|
126 | end
|
---|