source: extensions/gsdl-video/trunk/installed/cmdline/lib/ruby/1.8/wsdl/soap/definitions.rb@ 18425

Last change on this file since 18425 was 18425, checked in by davidb, 15 years ago

Video extension to Greenstone

File size: 4.4 KB
Line 
1# WSDL4R - WSDL additional definitions for SOAP.
2# Copyright (C) 2002-2005 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
9require 'wsdl/info'
10require 'xsd/namedelements'
11require 'soap/mapping'
12
13
14module WSDL
15
16
17class Definitions < Info
18 def self.soap_rpc_complextypes
19 types = XSD::NamedElements.new
20 types << array_complextype
21 types << fault_complextype
22 types << exception_complextype
23 types
24 end
25
26 def self.array_complextype
27 type = XMLSchema::ComplexType.new(::SOAP::ValueArrayName)
28 type.complexcontent = XMLSchema::ComplexContent.new
29 type.complexcontent.base = ::SOAP::ValueArrayName
30 attr = XMLSchema::Attribute.new
31 attr.ref = ::SOAP::AttrArrayTypeName
32 anytype = XSD::AnyTypeName.dup
33 anytype.name += '[]'
34 attr.arytype = anytype
35 type.complexcontent.attributes << attr
36 type
37 end
38
39=begin
40<xs:complexType name="Fault" final="extension">
41 <xs:sequence>
42 <xs:element name="faultcode" type="xs:QName" />
43 <xs:element name="faultstring" type="xs:string" />
44 <xs:element name="faultactor" type="xs:anyURI" minOccurs="0" />
45 <xs:element name="detail" type="tns:detail" minOccurs="0" />
46 </xs:sequence>
47</xs:complexType>
48=end
49 def self.fault_complextype
50 type = XMLSchema::ComplexType.new(::SOAP::EleFaultName)
51 faultcode = XMLSchema::Element.new(::SOAP::EleFaultCodeName, XSD::XSDQName::Type)
52 faultstring = XMLSchema::Element.new(::SOAP::EleFaultStringName, XSD::XSDString::Type)
53 faultactor = XMLSchema::Element.new(::SOAP::EleFaultActorName, XSD::XSDAnyURI::Type)
54 faultactor.minoccurs = 0
55 detail = XMLSchema::Element.new(::SOAP::EleFaultDetailName, XSD::AnyTypeName)
56 detail.minoccurs = 0
57 type.all_elements = [faultcode, faultstring, faultactor, detail]
58 type.final = 'extension'
59 type
60 end
61
62 def self.exception_complextype
63 type = XMLSchema::ComplexType.new(XSD::QName.new(
64 ::SOAP::Mapping::RubyCustomTypeNamespace, 'SOAPException'))
65 excn_name = XMLSchema::Element.new(XSD::QName.new(nil, 'excn_type_name'), XSD::XSDString::Type)
66 cause = XMLSchema::Element.new(XSD::QName.new(nil, 'cause'), XSD::AnyTypeName)
67 backtrace = XMLSchema::Element.new(XSD::QName.new(nil, 'backtrace'), ::SOAP::ValueArrayName)
68 message = XMLSchema::Element.new(XSD::QName.new(nil, 'message'), XSD::XSDString::Type)
69 type.all_elements = [excn_name, cause, backtrace, message]
70 type
71 end
72
73 def soap_rpc_complextypes(binding)
74 types = rpc_operation_complextypes(binding)
75 types + self.class.soap_rpc_complextypes
76 end
77
78 def collect_faulttypes
79 result = []
80 collect_fault_messages.each do |name|
81 faultparts = message(name).parts
82 if faultparts.size != 1
83 raise RuntimeError.new("expecting fault message to have only 1 part")
84 end
85 if result.index(faultparts[0].type).nil?
86 result << faultparts[0].type
87 end
88 end
89 result
90 end
91
92private
93
94 def collect_fault_messages
95 result = []
96 porttypes.each do |porttype|
97 porttype.operations.each do |operation|
98 operation.fault.each do |fault|
99 if result.index(fault.message).nil?
100 result << fault.message
101 end
102 end
103 end
104 end
105 result
106 end
107
108 def rpc_operation_complextypes(binding)
109 types = XSD::NamedElements.new
110 binding.operations.each do |op_bind|
111 if op_bind_rpc?(op_bind)
112 operation = op_bind.find_operation
113 if op_bind.input
114 type = XMLSchema::ComplexType.new(op_bind.soapoperation_name)
115 message = messages[operation.input.message]
116 type.sequence_elements = elements_from_message(message)
117 types << type
118 end
119 if op_bind.output
120 type = XMLSchema::ComplexType.new(operation.outputname)
121 message = messages[operation.output.message]
122 type.sequence_elements = elements_from_message(message)
123 types << type
124 end
125 end
126 end
127 types
128 end
129
130 def op_bind_rpc?(op_bind)
131 op_bind.soapoperation_style == :rpc
132 end
133
134 def elements_from_message(message)
135 message.parts.collect { |part|
136 if part.element
137 collect_elements[part.element]
138 elsif part.name.nil? or part.type.nil?
139 raise RuntimeError.new("part of a message must be an element or typed")
140 else
141 qname = XSD::QName.new(nil, part.name)
142 XMLSchema::Element.new(qname, part.type)
143 end
144 }
145 end
146end
147
148
149end
Note: See TracBrowser for help on using the repository browser.