Welcome to the "trac"-ing site of soap4r!
[soap4r] [httpclient] [openpgp4u] [pkcs1] [logger] [csv] [vtr]

root/trunk/lib/wsdl/operation.rb

Revision 2005, 2.7 kB (checked in by nahi, 1 year ago)
  • introduce SOAP::RPC::MethodDef? and use it instead of complex Array structure.
  • param type 'in', 'out', 'retval' -> :in, :out, :retval
  • Property svn:eol-style set to native
  • Property svn:keywords set to author date id revision
Line 
1 # WSDL4R - WSDL operation definition.
2 # Copyright (C) 2000-2007  NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
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
11
12 module WSDL
13
14
15 class Operation < Info
16   attr_reader :name             # required
17   attr_reader :parameter_order  # optional
18   attr_reader :input
19   attr_reader :output
20   attr_reader :fault
21   attr_reader :type             # required
22
23   def initialize
24     super
25     @name = nil
26     @type = nil
27     @parameter_order = nil
28     @input = nil
29     @output = nil
30     @fault = []
31   end
32
33   def targetnamespace
34     parent.targetnamespace
35   end
36
37   def operationname
38     as_operationname(@name)
39   end
40
41   EMPTY = [].freeze
42   # TODO: remove once after OperationInfo created
43   def inputparts
44     if message = input_message
45       sort_parts(message.parts)
46     else
47       EMPTY
48     end
49   end
50
51   def inputname
52     if input
53       as_operationname(input.name ? input.name.name : @name)
54     else
55       nil
56     end
57   end
58
59   # TODO: remove once after OperationInfo created
60   def outputparts
61     if message = output_message
62       sort_parts(message.parts)
63     else
64       EMPTY
65     end
66   end
67
68   def outputname
69     if output
70       as_operationname(output.name ? output.name.name : @name + 'Response')
71     else
72       nil
73     end
74   end
75
76   def parse_element(element)
77     case element
78     when InputName
79       o = Param.new
80       @input = o
81       o
82     when OutputName
83       o = Param.new
84       @output = o
85       o
86     when FaultName
87       o = Param.new
88       @fault << o
89       o
90     when DocumentationName
91       o = Documentation.new
92       o
93     else
94       nil
95     end
96   end
97
98   def parse_attr(attr, value)
99     case attr
100     when NameAttrName
101       @name = value.source
102     when TypeAttrName
103       @type = value
104     when ParameterOrderAttrName
105       @parameter_order = value.source.split(/\s+/)
106     else
107       nil
108     end
109   end
110
111 private
112
113   def input_message
114     if input and message = input.find_message
115       message
116     else
117       nil
118     end
119   end
120
121   def output_message
122     if output and message = output.find_message
123       message
124     else
125       nil
126     end
127   end
128
129   def sort_parts(parts)
130     return parts.dup unless parameter_order
131     result = []
132     parameter_order.each do |orderitem|
133       if (ele = parts.find { |part| part.name == orderitem })
134         result << ele
135       end
136     end
137     if result.length == 0
138       return parts.dup
139     end
140     # result length can be shorter than parts's.
141     # return part must not be a part of the parameterOrder.
142     result
143   end
144
145   def as_operationname(name)
146     XSD::QName.new(targetnamespace, name)
147   end
148 end
149
150
151 end
Note: See TracBrowser for help on using the browser.