1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
|
# WSDL4R - WSDL operation definition.
# Copyright (C) 2000-2007 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
# This program is copyrighted free software by NAKAMURA, Hiroshi. You can
# redistribute it and/or modify it under the same terms of Ruby's license;
# either the dual license version in 2003, or any later version.
require 'wsdl/info'
module WSDL
class Operation < Info
attr_reader :name # required
attr_reader :parameter_order # optional
attr_reader :input
attr_reader :output
attr_reader :fault
attr_reader :type # required
def initialize
super
@name = nil
@type = nil
@parameter_order = nil
@input = nil
@output = nil
@fault = []
end
def targetnamespace
parent.targetnamespace
end
def operationname
as_operationname(@name)
end
EMPTY = [].freeze
# TODO: remove once after OperationInfo created
def inputparts
if message = input_message
sort_parts(message.parts)
else
EMPTY
end
end
def inputname
if input
as_operationname(input.name ? input.name.name : @name)
else
nil
end
end
# TODO: remove once after OperationInfo created
def outputparts
if message = output_message
sort_parts(message.parts)
else
EMPTY
end
end
def outputname
if output
as_operationname(output.name ? output.name.name : @name + 'Response')
else
nil
end
end
def parse_element(element)
case element
when InputName
o = Param.new
@input = o
o
when OutputName
o = Param.new
@output = o
o
when FaultName
o = Param.new
@fault << o
o
when DocumentationName
o = Documentation.new
o
else
nil
end
end
def parse_attr(attr, value)
case attr
when NameAttrName
@name = value.source
when TypeAttrName
@type = value
when ParameterOrderAttrName
@parameter_order = value.source.split(/\s+/)
else
nil
end
end
private
def input_message
if input and message = input.find_message
message
else
nil
end
end
def output_message
if output and message = output.find_message
message
else
nil
end
end
def sort_parts(parts)
return parts.dup unless parameter_order
result = []
parameter_order.each do |orderitem|
if (ele = parts.find { |part| part.name == orderitem })
result << ele
end
end
if result.length == 0
return parts.dup
end
# result length can be shorter than parts's.
# return part must not be a part of the parameterOrder.
result
end
def as_operationname(name)
XSD::QName.new(targetnamespace, name)
end
end
end
|