Class: WSDL::Definitions

Inherits:
Info show all
Defined in:
lib/wsdl/definitions.rb,
lib/wsdl/soap/definitions.rb

Instance Attribute Summary collapse

Attributes inherited from Info

#id, #parent, #root

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Info

#parse_epilogue

Constructor Details

#initializeDefinitions

Returns a new instance of Definitions.


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/wsdl/definitions.rb', line 25

def initialize
  super
  @name = nil
  @targetnamespace = nil
  @location = nil
  @importedschema = {}

  @types = nil
  @imports = []
  @messages = XSD::NamedElements.new
  @porttypes = XSD::NamedElements.new
  @bindings = XSD::NamedElements.new
  @services = XSD::NamedElements.new

  @anontypes = XSD::NamedElements.new
  @root = self
end

Instance Attribute Details

#importedschemaObject (readonly)

Returns the value of attribute importedschema


23
24
25
# File 'lib/wsdl/definitions.rb', line 23

def importedschema
  @importedschema
end

#importsObject (readonly)

Returns the value of attribute imports


20
21
22
# File 'lib/wsdl/definitions.rb', line 20

def imports
  @imports
end

#locationObject

Returns the value of attribute location


22
23
24
# File 'lib/wsdl/definitions.rb', line 22

def location
  @location
end

#nameObject (readonly)

Returns the value of attribute name


18
19
20
# File 'lib/wsdl/definitions.rb', line 18

def name
  @name
end

#targetnamespaceObject

Returns the value of attribute targetnamespace


19
20
21
# File 'lib/wsdl/definitions.rb', line 19

def targetnamespace
  @targetnamespace
end

Class Method Details

.array_complextypeObject


27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/wsdl/soap/definitions.rb', line 27

def self.array_complextype
  type = XMLSchema::ComplexType.new(::SOAP::ValueArrayName)
  type.complexcontent = XMLSchema::ComplexContent.new
  type.complexcontent.restriction = XMLSchema::ComplexRestriction.new
  type.complexcontent.restriction.base = ::SOAP::ValueArrayName
  attr = XMLSchema::Attribute.new
  attr.ref = ::SOAP::AttrArrayTypeName
  anyarray = XSD::QName.new(
    XSD::AnyTypeName.namespace,
    XSD::AnyTypeName.name + '[]')
  attr.arytype = anyarray
  type.complexcontent.restriction.attributes << attr
  type
end

.exception_complextypeObject


65
66
67
68
69
70
71
72
73
74
# File 'lib/wsdl/soap/definitions.rb', line 65

def self.exception_complextype
  type = XMLSchema::ComplexType.new(XSD::QName.new(
	::SOAP::Mapping::RubyCustomTypeNamespace, 'SOAPException'))
  excn_name = XMLSchema::Element.new(XSD::QName.new(nil, 'excn_type_name'), XSD::XSDString::Type)
  cause = XMLSchema::Element.new(XSD::QName.new(nil, 'cause'), XSD::AnyTypeName)
  backtrace = XMLSchema::Element.new(XSD::QName.new(nil, 'backtrace'), ::SOAP::ValueArrayName)
  message = XMLSchema::Element.new(XSD::QName.new(nil, 'message'), XSD::XSDString::Type)
  type.all_elements = [excn_name, cause, backtrace, message]
  type
end

.fault_complextypeObject

<xs:complexType name=“Fault” final=“extension”>

<xs:sequence>
  <xs:element name="faultcode" type="xs:QName" /> 
  <xs:element name="faultstring" type="xs:string" /> 
  <xs:element name="faultactor" type="xs:anyURI" minOccurs="0" /> 
  <xs:element name="detail" type="tns:detail" minOccurs="0" /> 
</xs:sequence>

</xs:complexType>


52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/wsdl/soap/definitions.rb', line 52

def self.fault_complextype
  type = XMLSchema::ComplexType.new(::SOAP::EleFaultName)
  faultcode = XMLSchema::Element.new(::SOAP::EleFaultCodeName, XSD::XSDQName::Type)
  faultstring = XMLSchema::Element.new(::SOAP::EleFaultStringName, XSD::XSDString::Type)
  faultactor = XMLSchema::Element.new(::SOAP::EleFaultActorName, XSD::XSDAnyURI::Type)
  faultactor.minoccurs = 0
  detail = XMLSchema::Element.new(::SOAP::EleFaultDetailName, XSD::AnyTypeName)
  detail.minoccurs = 0
  type.all_elements = [faultcode, faultstring, faultactor, detail]
  type.final = 'extension'
  type
end

.parse_element(element) ⇒ Object


211
212
213
214
215
216
217
# File 'lib/wsdl/definitions.rb', line 211

def self.parse_element(element)
  if element == DefinitionsName
    Definitions.new
  else
    nil
  end
end

.soap_rpc_complextypesObject


19
20
21
22
23
24
25
# File 'lib/wsdl/soap/definitions.rb', line 19

def self.soap_rpc_complextypes
  types = XSD::NamedElements.new
  types << array_complextype
  types << fault_complextype
  types << exception_complextype
  types
end

Instance Method Details

#add_type(complextype) ⇒ Object

ToDo: simpletype must be accepted…


80
81
82
# File 'lib/wsdl/definitions.rb', line 80

def add_type(complextype)
  @anontypes << complextype
end

#binding(name) ⇒ Object


136
137
138
139
140
141
142
143
144
# File 'lib/wsdl/definitions.rb', line 136

def binding(name)
  binding = @bindings[name]
  return binding if binding
  @imports.each do |import|
    binding = import.content.binding(name) if self.class === import.content
    return binding if binding
  end
  nil
end

#bindingsObject


100
101
102
103
104
105
106
# File 'lib/wsdl/definitions.rb', line 100

def bindings
  result = @bindings.dup
  @imports.each do |import|
    result.concat(import.content.bindings) if self.class === import.content
  end
  result
end

#collect_attributegroupsObject


62
63
64
# File 'lib/wsdl/definitions.rb', line 62

def collect_attributegroups
  collect_imports(:collect_attributegroups)
end

#collect_attributesObject


54
55
56
# File 'lib/wsdl/definitions.rb', line 54

def collect_attributes
  collect_imports(:collect_attributes)
end

#collect_complextypesObject


70
71
72
73
# File 'lib/wsdl/definitions.rb', line 70

def collect_complextypes
  result = collect_imports(:collect_complextypes)
  @anontypes.dup.concat(result)
end

#collect_elementsObject


66
67
68
# File 'lib/wsdl/definitions.rb', line 66

def collect_elements
  collect_imports(:collect_elements)
end

#collect_faulttypesObject


81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/wsdl/soap/definitions.rb', line 81

def collect_faulttypes
  result = []
  collect_fault_messages.each do |name|
    faultparts = message(name).parts
    if faultparts.size != 1
	raise RuntimeError.new("Expecting fault message \"#{name}\" to have ONE part")
    end
    fault_part = faultparts[0]    # WS-I Basic Profile Version 1.1 (R2205) requires fault message parts 
    # to refer to elements rather than types

    faulttype = fault_part.element
    if not faulttype
	warn("Fault message \"#{name}\" part \"#{fault_part.name}\" must specify an \"element\" attribute")
      faulttype = fault_part.type
    end
    if faulttype and result.index(faulttype).nil?
	result << faulttype
    end
  end
  result
end

#collect_modelgroupsObject


58
59
60
# File 'lib/wsdl/definitions.rb', line 58

def collect_modelgroups
  collect_imports(:collect_modelgroups)
end

#collect_simpletypesObject


75
76
77
# File 'lib/wsdl/definitions.rb', line 75

def collect_simpletypes
  collect_imports(:collect_simpletypes)
end

#inspectObject


43
44
45
# File 'lib/wsdl/definitions.rb', line 43

def inspect
  sprintf("#<%s:0x%x %s>", self.class.name, __id__, @name || '(unnamed)')
end

#message(name) ⇒ Object


116
117
118
119
120
121
122
123
124
# File 'lib/wsdl/definitions.rb', line 116

def message(name)
  message = @messages[name]
  return message if message
  @imports.each do |import|
    message = import.content.message(name) if self.class === import.content
    return message if message
  end
  nil
end

#messagesObject


84
85
86
87
88
89
90
# File 'lib/wsdl/definitions.rb', line 84

def messages
  result = @messages.dup
  @imports.each do |import|
    result.concat(import.content.messages) if self.class === import.content
  end
  result
end

#parse_attr(attr, value) ⇒ Object


200
201
202
203
204
205
206
207
208
209
# File 'lib/wsdl/definitions.rb', line 200

def parse_attr(attr, value)
  case attr
  when NameAttrName
    @name = XSD::QName.new(targetnamespace, value.source)
  when TargetNamespaceAttrName
    self.targetnamespace = value.source
  else
    nil
  end
end

#parse_element(element) ⇒ Object


166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/wsdl/definitions.rb', line 166

def parse_element(element)
  case element
  when ImportName
    o = Import.new
    @imports << o
    o
  when TypesName
    o = Types.new
    @types = o
    o
  when MessageName
    o = Message.new
    @messages << o
    o
  when PortTypeName
    o = PortType.new
    @porttypes << o
    o
  when BindingName
    o = Binding.new
    @bindings << o
    o
  when ServiceName
    o = Service.new
    @services << o
    o
  when DocumentationName
    o = Documentation.new
    o
  else
    nil
  end
end

#porttype(name) ⇒ Object


126
127
128
129
130
131
132
133
134
# File 'lib/wsdl/definitions.rb', line 126

def porttype(name)
  porttype = @porttypes[name]
  return porttype if porttype
  @imports.each do |import|
    porttype = import.content.porttype(name) if self.class === import.content
    return porttype if porttype
  end
  nil
end

#porttype_binding(name) ⇒ Object


156
157
158
159
160
161
162
163
164
# File 'lib/wsdl/definitions.rb', line 156

def porttype_binding(name)
  binding = @bindings.find { |item| item.type == name }
  return binding if binding
  @imports.each do |import|
    binding = import.content.porttype_binding(name) if self.class === import.content
    return binding if binding
  end
  nil
end

#porttypesObject


92
93
94
95
96
97
98
# File 'lib/wsdl/definitions.rb', line 92

def porttypes
  result = @porttypes.dup
  @imports.each do |import|
    result.concat(import.content.porttypes) if self.class === import.content
  end
  result
end

#service(name) ⇒ Object


146
147
148
149
150
151
152
153
154
# File 'lib/wsdl/definitions.rb', line 146

def service(name)
  service = @services[name]
  return service if service
  @imports.each do |import|
    service = import.content.service(name) if self.class === import.content
    return service if service
  end
  nil
end

#servicesObject


108
109
110
111
112
113
114
# File 'lib/wsdl/definitions.rb', line 108

def services
  result = @services.dup
  @imports.each do |import|
    result.concat(import.content.services) if self.class === import.content
  end
  result
end

#soap_rpc_complextypes(binding) ⇒ Object


76
77
78
79
# File 'lib/wsdl/soap/definitions.rb', line 76

def soap_rpc_complextypes(binding)
  types = rpc_operation_complextypes(binding)
  types + self.class.soap_rpc_complextypes
end