Class WSDL::XMLSchema::ComplexType
In: lib/wsdl/soap/complexType.rb
lib/wsdl/xmlSchema/complexType.rb
Parent: Info

Methods

Constants

AnyAsElement = Element.new(XSD::QName.new(nil, 'any'), XSD::AnyTypeName)

Attributes

attributes  [R] 
complexcontent  [RW] 
content  [R] 
final  [RW] 
mixed  [RW] 
name  [RW] 
simplecontent  [RW] 

Public Class methods

[Source]

    # File lib/wsdl/xmlSchema/complexType.rb, line 28
28:   def initialize(name = nil)
29:     super()
30:     @name = name
31:     @complexcontent = nil
32:     @simplecontent = nil
33:     @content = nil
34:     @final = nil
35:     @mixed = false
36:     @attributes = XSD::NamedElements.new
37:   end

Public Instance methods

[Source]

     # File lib/wsdl/xmlSchema/complexType.rb, line 95
 95:   def all_elements=(elements)
 96:     @content = All.new
 97:     elements.each do |element|
 98:       @content << element
 99:     end
100:   end

[Source]

    # File lib/wsdl/soap/complexType.rb, line 22
22:   def check_type
23:     if content
24:       if attributes.empty? and
25:           content.elements.size == 1 and content.elements[0].maxoccurs != '1'
26:         if name == ::SOAP::Mapping::MapQName
27:           :TYPE_MAP
28:         else
29:           :TYPE_ARRAY
30:         end
31:       else
32:         :TYPE_STRUCT
33:       end
34:     elsif complexcontent
35:       if complexcontent.base == ::SOAP::ValueArrayName
36:         :TYPE_ARRAY
37:       else
38:         complexcontent.basetype.check_type
39:       end
40:     elsif simplecontent
41:       :TYPE_SIMPLE
42:     elsif !attributes.empty?
43:       :TYPE_STRUCT
44:     else # empty complexType definition (seen in partner.wsdl of salesforce)
45:       :TYPE_EMPTY
46:     end
47:   end

[Source]

    # File lib/wsdl/soap/complexType.rb, line 74
74:   def child_defined_complextype(name)
75:     ele = nil
76:     case compoundtype
77:     when :TYPE_STRUCT, :TYPE_MAP
78:       unless ele = find_element(name)
79:         if name.namespace.nil?
80:           ele = find_element_by_name(name.name)
81:         end
82:       end
83:     when :TYPE_ARRAY
84:       if content.elements.size == 1
85:         ele = content.elements[0]
86:       else
87:         raise RuntimeError.new("Assert: must not reach.")
88:       end
89:     else
90:       raise RuntimeError.new("Assert: Not implemented.")
91:     end
92:     unless ele
93:       raise RuntimeError.new("Cannot find #{name} as a children of #{@name}.")
94:     end
95:     ele.local_complextype
96:   end

[Source]

    # File lib/wsdl/soap/complexType.rb, line 49
49:   def child_type(name = nil)
50:     case compoundtype
51:     when :TYPE_STRUCT
52:       if ele = find_element(name)
53:         ele.type
54:       elsif ele = find_element_by_name(name.name)
55:         ele.type
56:       end
57:     when :TYPE_ARRAY
58:       @contenttype ||= content_arytype
59:     when :TYPE_MAP
60:       item_ele = find_element_by_name("item") or
61:         raise RuntimeError.new("'item' element not found in Map definition.")
62:       content = item_ele.local_complextype or
63:         raise RuntimeError.new("No complexType definition for 'item'.")
64:       if ele = content.find_element(name)
65:         ele.type
66:       elsif ele = content.find_element_by_name(name.name)
67:         ele.type
68:       end
69:     else
70:       raise NotImplementedError.new("Unknown kind of complexType.")
71:     end
72:   end

[Source]

    # File lib/wsdl/soap/complexType.rb, line 18
18:   def compoundtype
19:     @compoundtype ||= check_type
20:   end

[Source]

    # File lib/wsdl/xmlSchema/complexType.rb, line 50
50:   def each_element
51:     if content
52:       content.elements.each do |element|
53:         if element.is_a?(Any)
54:           yield(AnyAsElement)
55:         else
56:           yield(element)
57:         end
58:       end
59:     end
60:   end

[Source]

    # File lib/wsdl/xmlSchema/complexType.rb, line 45
45:   def elementformdefault
46:     parent.elementformdefault
47:   end

[Source]

     # File lib/wsdl/soap/complexType.rb, line 117
117:   def find_aryelement
118:     unless compoundtype == :TYPE_ARRAY
119:       raise RuntimeError.new("Assert: not for array")
120:     end
121:     if complexcontent
122:       if check_array_content(complexcontent.content)
123:         return complexcontent.content.elements[0]
124:       end
125:     elsif check_array_content(content)
126:       return content.elements[0]
127:     end
128:     nil # use default item name
129:   end

[Source]

     # File lib/wsdl/soap/complexType.rb, line 98
 98:   def find_arytype
 99:     unless compoundtype == :TYPE_ARRAY
100:       raise RuntimeError.new("Assert: not for array")
101:     end
102:     if complexcontent
103:       complexcontent.attributes.each do |attribute|
104:         if attribute.ref == ::SOAP::AttrArrayTypeName
105:           return attribute.arytype
106:         end
107:       end
108:       if check_array_content(complexcontent.content)
109:         return element_simpletype(complexcontent.content.elements[0])
110:       end
111:     elsif check_array_content(content)
112:       return element_simpletype(content.elements[0])
113:     end
114:     raise RuntimeError.new("Assert: Unknown array definition.")
115:   end

[Source]

    # File lib/wsdl/xmlSchema/complexType.rb, line 62
62:   def find_element(name)
63:     if content
64:       content.elements.each do |element|
65:         if element.is_a?(Any)
66:           return AnyAsElement if name == AnyAsElement.name
67:         else
68:           return element if name == element.name
69:         end
70:       end
71:     end
72:     nil
73:   end

[Source]

    # File lib/wsdl/xmlSchema/complexType.rb, line 75
75:   def find_element_by_name(name)
76:     if content
77:       content.elements.each do |element|
78:         if element.is_a?(Any)
79:           return AnyAsElement if name == AnyAsElement.name.name
80:         else
81:           return element if name == element.name.name
82:         end
83:       end
84:     end
85:     nil
86:   end

[Source]

     # File lib/wsdl/xmlSchema/complexType.rb, line 123
123:   def parse_attr(attr, value)
124:     case attr
125:     when FinalAttrName
126:       @final = value.source
127:     when MixedAttrName
128:       @mixed = (value.source == 'true')
129:     when NameAttrName
130:       @name = XSD::QName.new(targetnamespace, value.source)
131:     else
132:       nil
133:     end
134:   end

[Source]

     # File lib/wsdl/xmlSchema/complexType.rb, line 102
102:   def parse_element(element)
103:     case element
104:     when AllName
105:       @content = All.new
106:     when SequenceName
107:       @content = Sequence.new
108:     when ChoiceName
109:       @content = Choice.new
110:     when ComplexContentName
111:       @complexcontent = ComplexContent.new
112:     when SimpleContentName
113:       @simplecontent = SimpleContent.new
114:     when AttributeName
115:       o = Attribute.new
116:       @attributes << o
117:       o
118:     else
119:       nil
120:     end
121:   end

[Source]

    # File lib/wsdl/xmlSchema/complexType.rb, line 88
88:   def sequence_elements=(elements)
89:     @content = Sequence.new
90:     elements.each do |element|
91:       @content << element
92:     end
93:   end

[Source]

    # File lib/wsdl/xmlSchema/complexType.rb, line 39
39:   def targetnamespace
40:     # inner elements can be qualified
41:     # parent.is_a?(WSDL::XMLSchema::Element) ? nil : parent.targetnamespace
42:     parent.targetnamespace
43:   end

Private Instance methods

[Source]

     # File lib/wsdl/soap/complexType.rb, line 143
143:   def check_array_content(content)
144:     content and content.elements.size == 1 and
145:       content.elements[0].maxoccurs != '1'
146:   end

[Source]

     # File lib/wsdl/soap/complexType.rb, line 148
148:   def content_arytype
149:     if arytype = find_arytype
150:       ns = arytype.namespace
151:       name = arytype.name.sub(/\[(?:,)*\]$/, '')
152:       XSD::QName.new(ns, name)
153:     else
154:       nil
155:     end
156:   end

[Source]

     # File lib/wsdl/soap/complexType.rb, line 133
133:   def element_simpletype(element)
134:     if element.type
135:       element.type 
136:     elsif element.local_simpletype
137:       element.local_simpletype.base
138:     else
139:       nil
140:     end
141:   end

[Validate]