source: extensions/gsdl-video/trunk/installed/cmdline/lib/ruby/1.8/wsdl/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: 5.2 KB
Line 
1# WSDL4R - WSDL definitions.
2# Copyright (C) 2002, 2003 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'
11
12
13module WSDL
14
15
16class 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 result = XSD::NamedElements.new
55 if @types
56 @types.schemas.each do |schema|
57 result.concat(schema.collect_attributes)
58 end
59 end
60 @imports.each do |import|
61 result.concat(import.content.collect_attributes)
62 end
63 result
64 end
65
66 def collect_elements
67 result = XSD::NamedElements.new
68 if @types
69 @types.schemas.each do |schema|
70 result.concat(schema.collect_elements)
71 end
72 end
73 @imports.each do |import|
74 result.concat(import.content.collect_elements)
75 end
76 result
77 end
78
79 def collect_complextypes
80 result = @anontypes.dup
81 if @types
82 @types.schemas.each do |schema|
83 result.concat(schema.collect_complextypes)
84 end
85 end
86 @imports.each do |import|
87 result.concat(import.content.collect_complextypes)
88 end
89 result
90 end
91
92 def collect_simpletypes
93 result = XSD::NamedElements.new
94 if @types
95 @types.schemas.each do |schema|
96 result.concat(schema.collect_simpletypes)
97 end
98 end
99 @imports.each do |import|
100 result.concat(import.content.collect_simpletypes)
101 end
102 result
103 end
104
105 # ToDo: simpletype must be accepted...
106 def add_type(complextype)
107 @anontypes << complextype
108 end
109
110 def messages
111 result = @messages.dup
112 @imports.each do |import|
113 result.concat(import.content.messages) if self.class === import.content
114 end
115 result
116 end
117
118 def porttypes
119 result = @porttypes.dup
120 @imports.each do |import|
121 result.concat(import.content.porttypes) if self.class === import.content
122 end
123 result
124 end
125
126 def bindings
127 result = @bindings.dup
128 @imports.each do |import|
129 result.concat(import.content.bindings) if self.class === import.content
130 end
131 result
132 end
133
134 def services
135 result = @services.dup
136 @imports.each do |import|
137 result.concat(import.content.services) if self.class === import.content
138 end
139 result
140 end
141
142 def message(name)
143 message = @messages[name]
144 return message if message
145 @imports.each do |import|
146 message = import.content.message(name) if self.class === import.content
147 return message if message
148 end
149 nil
150 end
151
152 def porttype(name)
153 porttype = @porttypes[name]
154 return porttype if porttype
155 @imports.each do |import|
156 porttype = import.content.porttype(name) if self.class === import.content
157 return porttype if porttype
158 end
159 nil
160 end
161
162 def binding(name)
163 binding = @bindings[name]
164 return binding if binding
165 @imports.each do |import|
166 binding = import.content.binding(name) if self.class === import.content
167 return binding if binding
168 end
169 nil
170 end
171
172 def service(name)
173 service = @services[name]
174 return service if service
175 @imports.each do |import|
176 service = import.content.service(name) if self.class === import.content
177 return service if service
178 end
179 nil
180 end
181
182 def porttype_binding(name)
183 binding = @bindings.find { |item| item.type == name }
184 return binding if binding
185 @imports.each do |import|
186 binding = import.content.porttype_binding(name) if self.class === import.content
187 return binding if binding
188 end
189 nil
190 end
191
192 def parse_element(element)
193 case element
194 when ImportName
195 o = Import.new
196 @imports << o
197 o
198 when TypesName
199 o = Types.new
200 @types = o
201 o
202 when MessageName
203 o = Message.new
204 @messages << o
205 o
206 when PortTypeName
207 o = PortType.new
208 @porttypes << o
209 o
210 when BindingName
211 o = Binding.new
212 @bindings << o
213 o
214 when ServiceName
215 o = Service.new
216 @services << o
217 o
218 when DocumentationName
219 o = Documentation.new
220 o
221 else
222 nil
223 end
224 end
225
226 def parse_attr(attr, value)
227 case attr
228 when NameAttrName
229 @name = XSD::QName.new(targetnamespace, value.source)
230 when TargetNamespaceAttrName
231 self.targetnamespace = value.source
232 else
233 nil
234 end
235 end
236
237 def self.parse_element(element)
238 if element == DefinitionsName
239 Definitions.new
240 else
241 nil
242 end
243 end
244
245private
246
247end
248
249
250end
Note: See TracBrowser for help on using the repository browser.