| 1 |
# WSDL4R - WSDL definitions. |
|---|
| 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 |
require 'xsd/namedelements' |
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
module WSDL |
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
class Definitions < Info |
|---|
| 17 |
attr_reader :name |
|---|
| 18 |
attr_reader :targetnamespace |
|---|
| 19 |
attr_reader :imports |
|---|
| 20 |
|
|---|
| 21 |
attr_accessor :location |
|---|
| 22 |
attr_reader :importedschema |
|---|
| 23 |
|
|---|
| 24 |
def initialize |
|---|
| 25 |
super |
|---|
| 26 |
@name = nil |
|---|
| 27 |
@targetnamespace = nil |
|---|
| 28 |
@location = nil |
|---|
| 29 |
@importedschema = {} |
|---|
| 30 |
|
|---|
| 31 |
@types = nil |
|---|
| 32 |
@imports = [] |
|---|
| 33 |
@messages = XSD::NamedElements.new |
|---|
| 34 |
@porttypes = XSD::NamedElements.new |
|---|
| 35 |
@bindings = XSD::NamedElements.new |
|---|
| 36 |
@services = XSD::NamedElements.new |
|---|
| 37 |
|
|---|
| 38 |
@anontypes = XSD::NamedElements.new |
|---|
| 39 |
@root = self |
|---|
| 40 |
end |
|---|
| 41 |
|
|---|
| 42 |
def inspect |
|---|
| 43 |
sprintf("#<%s:0x%x %s>", self.class.name, __id__, @name || '(unnamed)') |
|---|
| 44 |
end |
|---|
| 45 |
|
|---|
| 46 |
def targetnamespace=(targetnamespace) |
|---|
| 47 |
@targetnamespace = targetnamespace |
|---|
| 48 |
if @name |
|---|
| 49 |
@name = XSD::QName.new(@targetnamespace, @name.name) |
|---|
| 50 |
end |
|---|
| 51 |
end |
|---|
| 52 |
|
|---|
| 53 |
def collect_attributes |
|---|
| 54 |
collect_imports(:collect_attributes) |
|---|
| 55 |
end |
|---|
| 56 |
|
|---|
| 57 |
def collect_modelgroups |
|---|
| 58 |
collect_imports(:collect_modelgroups) |
|---|
| 59 |
end |
|---|
| 60 |
|
|---|
| 61 |
def collect_attributegroups |
|---|
| 62 |
collect_imports(:collect_attributegroups) |
|---|
| 63 |
end |
|---|
| 64 |
|
|---|
| 65 |
def collect_elements |
|---|
| 66 |
collect_imports(:collect_elements) |
|---|
| 67 |
end |
|---|
| 68 |
|
|---|
| 69 |
def collect_complextypes |
|---|
| 70 |
result = collect_imports(:collect_complextypes) |
|---|
| 71 |
@anontypes.dup.concat(result) |
|---|
| 72 |
end |
|---|
| 73 |
|
|---|
| 74 |
def collect_simpletypes |
|---|
| 75 |
collect_imports(:collect_simpletypes) |
|---|
| 76 |
end |
|---|
| 77 |
|
|---|
| 78 |
# ToDo: simpletype must be accepted... |
|---|
| 79 |
def add_type(complextype) |
|---|
| 80 |
@anontypes << complextype |
|---|
| 81 |
end |
|---|
| 82 |
|
|---|
| 83 |
def messages |
|---|
| 84 |
result = @messages.dup |
|---|
| 85 |
@imports.each do |import| |
|---|
| 86 |
result.concat(import.content.messages) if self.class === import.content |
|---|
| 87 |
end |
|---|
| 88 |
result |
|---|
| 89 |
end |
|---|
| 90 |
|
|---|
| 91 |
def porttypes |
|---|
| 92 |
result = @porttypes.dup |
|---|
| 93 |
@imports.each do |import| |
|---|
| 94 |
result.concat(import.content.porttypes) if self.class === import.content |
|---|
| 95 |
end |
|---|
| 96 |
result |
|---|
| 97 |
end |
|---|
| 98 |
|
|---|
| 99 |
def bindings |
|---|
| 100 |
result = @bindings.dup |
|---|
| 101 |
@imports.each do |import| |
|---|
| 102 |
result.concat(import.content.bindings) if self.class === import.content |
|---|
| 103 |
end |
|---|
| 104 |
result |
|---|
| 105 |
end |
|---|
| 106 |
|
|---|
| 107 |
def services |
|---|
| 108 |
result = @services.dup |
|---|
| 109 |
@imports.each do |import| |
|---|
| 110 |
result.concat(import.content.services) if self.class === import.content |
|---|
| 111 |
end |
|---|
| 112 |
result |
|---|
| 113 |
end |
|---|
| 114 |
|
|---|
| 115 |
def message(name) |
|---|
| 116 |
message = @messages[name] |
|---|
| 117 |
return message if message |
|---|
| 118 |
@imports.each do |import| |
|---|
| 119 |
message = import.content.message(name) if self.class === import.content |
|---|
| 120 |
return message if message |
|---|
| 121 |
end |
|---|
| 122 |
nil |
|---|
| 123 |
end |
|---|
| 124 |
|
|---|
| 125 |
def porttype(name) |
|---|
| 126 |
porttype = @porttypes[name] |
|---|
| 127 |
return porttype if porttype |
|---|
| 128 |
@imports.each do |import| |
|---|
| 129 |
porttype = import.content.porttype(name) if self.class === import.content |
|---|
| 130 |
return porttype if porttype |
|---|
| 131 |
end |
|---|
| 132 |
nil |
|---|
| 133 |
end |
|---|
| 134 |
|
|---|
| 135 |
def binding(name) |
|---|
| 136 |
binding = @bindings[name] |
|---|
| 137 |
return binding if binding |
|---|
| 138 |
@imports.each do |import| |
|---|
| 139 |
binding = import.content.binding(name) if self.class === import.content |
|---|
| 140 |
return binding if binding |
|---|
| 141 |
end |
|---|
| 142 |
nil |
|---|
| 143 |
end |
|---|
| 144 |
|
|---|
| 145 |
def service(name) |
|---|
| 146 |
service = @services[name] |
|---|
| 147 |
return service if service |
|---|
| 148 |
@imports.each do |import| |
|---|
| 149 |
service = import.content.service(name) if self.class === import.content |
|---|
| 150 |
return service if service |
|---|
| 151 |
end |
|---|
| 152 |
nil |
|---|
| 153 |
end |
|---|
| 154 |
|
|---|
| 155 |
def porttype_binding(name) |
|---|
| 156 |
binding = @bindings.find { |item| item.type == name } |
|---|
| 157 |
return binding if binding |
|---|
| 158 |
@imports.each do |import| |
|---|
| 159 |
binding = import.content.porttype_binding(name) if self.class === import.content |
|---|
| 160 |
return binding if binding |
|---|
| 161 |
end |
|---|
| 162 |
nil |
|---|
| 163 |
end |
|---|
| 164 |
|
|---|
| 165 |
def parse_element(element) |
|---|
| 166 |
case element |
|---|
| 167 |
when ImportName |
|---|
| 168 |
o = Import.new |
|---|
| 169 |
@imports << o |
|---|
| 170 |
o |
|---|
| 171 |
when TypesName |
|---|
| 172 |
o = Types.new |
|---|
| 173 |
@types = o |
|---|
| 174 |
o |
|---|
| 175 |
when MessageName |
|---|
| 176 |
o = Message.new |
|---|
| 177 |
@messages << o |
|---|
| 178 |
o |
|---|
| 179 |
when PortTypeName |
|---|
| 180 |
o = PortType.new |
|---|
| 181 |
@porttypes << o |
|---|
| 182 |
o |
|---|
| 183 |
when BindingName |
|---|
| 184 |
o = Binding.new |
|---|
| 185 |
@bindings << o |
|---|
| 186 |
o |
|---|
| 187 |
when ServiceName |
|---|
| 188 |
o = Service.new |
|---|
| 189 |
@services << o |
|---|
| 190 |
o |
|---|
| 191 |
when DocumentationName |
|---|
| 192 |
o = Documentation.new |
|---|
| 193 |
o |
|---|
| 194 |
else |
|---|
| 195 |
nil |
|---|
| 196 |
end |
|---|
| 197 |
end |
|---|
| 198 |
|
|---|
| 199 |
def parse_attr(attr, value) |
|---|
| 200 |
case attr |
|---|
| 201 |
when NameAttrName |
|---|
| 202 |
@name = XSD::QName.new(targetnamespace, value.source) |
|---|
| 203 |
when TargetNamespaceAttrName |
|---|
| 204 |
self.targetnamespace = value.source |
|---|
| 205 |
else |
|---|
| 206 |
nil |
|---|
| 207 |
end |
|---|
| 208 |
end |
|---|
| 209 |
|
|---|
| 210 |
def self.parse_element(element) |
|---|
| 211 |
if element == DefinitionsName |
|---|
| 212 |
Definitions.new |
|---|
| 213 |
else |
|---|
| 214 |
nil |
|---|
| 215 |
end |
|---|
| 216 |
end |
|---|
| 217 |
|
|---|
| 218 |
private |
|---|
| 219 |
|
|---|
| 220 |
def collect_imports(method) |
|---|
| 221 |
result = XSD::NamedElements.new |
|---|
| 222 |
if @types |
|---|
| 223 |
@types.schemas.each do |schema| |
|---|
| 224 |
result.concat(schema.send(method)) |
|---|
| 225 |
end |
|---|
| 226 |
end |
|---|
| 227 |
@imports.each do |import| |
|---|
| 228 |
result.concat(import.content.send(method)) |
|---|
| 229 |
end |
|---|
| 230 |
result |
|---|
| 231 |
end |
|---|
| 232 |
|
|---|
| 233 |
end |
|---|
| 234 |
|
|---|
| 235 |
|
|---|
| 236 |
end |
|---|