Welcome to the "trac"-ing site of soap4r!
[soap4r] [httpclient] [openpgp4u] [pkcs1] [logger] [csv] [vtr]

root/branches/1_5/lib/wsdl/soap/complexType.rb

Revision 1994, 3.9 kB (checked in by nahi, 1 year ago)
  • avoid NameError? if an Array definition has soapenc:Array as a restriction base and no soapenc:arrayType inside. closes #441.
  • Property svn:eol-style set to native
  • Property svn:keywords set to author date id revision
Line 
1 # WSDL4R - SOAP complexType definition for WSDL.
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/xmlSchema/complexType'
10 require 'soap/mapping'
11
12
13 module WSDL
14 module XMLSchema
15
16
17 class ComplexType < Info
18   def compoundtype
19     @compoundtype ||= check_type
20   end
21
22   def check_type
23     if have_any?
24       :TYPE_STRUCT
25     elsif content
26       if attributes.empty? and map_as_array?
27         if name == ::SOAP::Mapping::MapQName
28           :TYPE_MAP
29         else
30           :TYPE_ARRAY
31         end
32       else
33         :TYPE_STRUCT
34       end
35     elsif complexcontent
36       complexcontent.check_type
37     elsif simplecontent
38       :TYPE_SIMPLE
39     elsif !attributes.empty?
40       :TYPE_STRUCT
41     else # empty complexType definition (seen in partner.wsdl of salesforce)
42       :TYPE_EMPTY
43     end
44   end
45
46   def child_type(name = nil)
47     case compoundtype
48     when :TYPE_STRUCT
49       if ele = find_element(name)
50         ele.type
51       elsif ele = find_element_by_name(name.name)
52         ele.type
53       end
54     when :TYPE_ARRAY
55       @contenttype ||= content_arytype
56     when :TYPE_MAP
57       item_ele = find_element_by_name("item") or
58         raise RuntimeError.new("'item' element not found in Map definition.")
59       content = item_ele.local_complextype or
60         raise RuntimeError.new("No complexType definition for 'item'.")
61       if ele = content.find_element(name)
62         ele.type
63       elsif ele = content.find_element_by_name(name.name)
64         ele.type
65       end
66     else
67       raise NotImplementedError.new("Unknown kind of complexType.")
68     end
69   end
70
71   def child_defined_complextype(name)
72     ele = nil
73     case compoundtype
74     when :TYPE_STRUCT, :TYPE_MAP
75       unless ele = find_element(name)
76         if name.namespace.nil?
77           ele = find_element_by_name(name.name)
78         end
79       end
80     when :TYPE_ARRAY
81       e = elements
82       if e.size == 1
83         ele = e[0]
84       else
85         raise RuntimeError.new("Assert: must not reach.")
86       end
87     else
88       raise RuntimeError.new("Assert: Not implemented.")
89     end
90     unless ele
91       raise RuntimeError.new("Cannot find #{name} as a children of #{@name}.")
92     end
93     ele.local_complextype
94   end
95
96   def find_soapenc_arytype
97     unless compoundtype == :TYPE_ARRAY
98       raise RuntimeError.new("Assert: not for array")
99     end
100     if complexcontent
101       if complexcontent.restriction
102         complexcontent.restriction.attributes.each do |attribute|
103           if attribute.ref == ::SOAP::AttrArrayTypeName
104             return attribute.arytype
105           end
106         end
107       end
108     end
109     nil
110   end
111
112   def find_arytype
113     unless compoundtype == :TYPE_ARRAY
114       raise RuntimeError.new("Assert: not for array")
115     end
116     if arytype = find_soapenc_arytype
117       return arytype
118     end
119     if map_as_array?
120       return element_simpletype(elements[0])
121     end
122     raise RuntimeError.new("Assert: Unknown array definition.")
123   end
124
125   def find_aryelement
126     unless compoundtype == :TYPE_ARRAY
127       raise RuntimeError.new("Assert: not for array")
128     end
129     if map_as_array?
130       return nested_elements[0]
131     end
132     nil # use default item name
133   end
134
135 private
136
137   def element_simpletype(element)
138     case element
139     when XMLSchema::Element
140       if element.type
141         element.type
142       elsif element.local_simpletype
143         element.local_simpletype.base
144       else
145         # element definition
146         nil
147       end
148     when XMLSchema::Any
149       XSD::AnyTypeName
150     else
151       nil
152     end
153   end
154
155   def map_as_array?
156     e = nested_elements
157     e.size == 1 and e[0].map_as_array?
158   end
159
160   def content_arytype
161     if arytype = find_arytype
162       ns = arytype.namespace
163       name = arytype.name.sub(/\[(?:,)*\]$/, '')
164       XSD::QName.new(ns, name)
165     else
166       nil
167     end
168   end
169 end
170
171
172 end
173 end
Note: See TracBrowser for help on using the browser.