Class: SOAP::XSD::Element
Instance Method Summary collapse
- #display(types, args) ⇒ Object
- #getOccures(args) ⇒ Object
-
#initialize(type) ⇒ Element
constructor
A new instance of Element.
- #responseToHash(xml, types) ⇒ Object
Methods inherited from Hash
Constructor Details
#initialize(type) ⇒ Element
Returns a new instance of Element.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/wsdl-reader/xsd/element.rb', line 4 def initialize( type ) type.attributes.each { |name, value| self[name.to_sym] = value } type.find_all{ |e| e.class == REXML::Element }.each { |content| case content.name when "simpleType" raise SOAP::LCElementError, "Malformated element `#{type.attributes['name']}'" unless self[:type].nil? self[:type] = :simpleType ############################################################################### warn "xsd:simpleType in xsd:element is not yet supported!" ############################################################################### when "complexType" raise SOAP::LCElementError, "Malformated element `#{type.attributes['name']}'" unless self[:type].nil? self[:type] = :complexType self[:complexType] = SOAP::XSD::ComplexType.new( content ) when "unique" raise SOAP::LCElementError, "Malformated element `#{type.attributes['name']}'" unless self[:key].nil? self[:key] = :unique ############################################################################### warn "xsd:unique in xsd:element is not yet supported!" ############################################################################### when "key" raise SOAP::LCElementError, "Malformated element `#{type.attributes['name']}'" unless self[:key].nil? self[:key] = :key ############################################################################### warn "xsd:unique in xsd:element is not yet supported!" ############################################################################### when "keyref" raise SOAP::LCElementError, "Malformated element `#{type.attributes['name']}'" unless self[:key].nil? self[:key] = :keyref ############################################################################### warn "xsd:unique in xsd:element is not yet supported!" ############################################################################### when "annotation" ############################################################################### warn "xsd:annotation in xsd:complexType (global definition) (global definition) is not yet supported!" ############################################################################### else raise SOAP::LCElementError, "Invalid element `#{content.name}' in xsd:element `#{type.attributes['name']}'" end } end |
Instance Method Details
#display(types, args) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/wsdl-reader/xsd/element.rb', line 49 def display( types, args ) r = "" min, max = getOccures( args ) if self[:type].is_a?(String) && SOAP::XSD::ANY_SIMPLE_TYPE.include?( self[:type].nns ) r << SOAP::XSD.displayBuiltinType( self[:name], args, min, max ) else case types[self[:type].nns][:type] when :simpleType if args.keys.include?( self[:name].to_sym ) args[self[:name].to_sym] = [args[self[:name].to_sym]] unless args[self[:name].to_sym].class == Array if args[self[:name].to_sym].size < min or args[self[:name].to_sym].size > max raise SOAP::LCArgumentError, "Wrong number or values for parameter `#{name}'" end args[self[:name].to_sym].each { |v| r << "<#{self[:name]}>" r << "#{v}" ############ CHECK !!! r << "</#{self[:name]}>\n" } elsif min > 0 raise SOAP::LCArgumentError, "Missing parameter `#{name}'" if min > 0 end when :complexType if args.keys.include?( self[:name].to_sym ) if args.keys.include?( self[:name].to_sym ) args[self[:name].to_sym] = [args[self[:name].to_sym]] unless args[self[:name].to_sym].class == Array if args[self[:name].to_sym].size < min or args[self[:name].to_sym].size > max raise SOAP::LCArgumentError, "Wrong number or values for parameter `#{name}'" end args[self[:name].to_sym].each { |v| r << "<#{self[:name]}>" r << types[self[:type].nns][:value].display( types, v ) r << "</#{self[:name]}>\n" } elsif min > 0 raise SOAP::LCArgumentError, "Missing parameter `#{name}'" if min > 0 end else r << "<#{self[:name]}>\n" r << types[self[:type].nns][:value].display( types, args ) r << "</#{self[:name]}>\n" end else raise SOAL::LCWSDLError, "Malformated element `#{self[:name]}'" end end return r end |
#getOccures(args) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/wsdl-reader/xsd/element.rb', line 100 def getOccures( args ) element_min = self[:minOccurs].to_i || 1 element_max = self[:maxOccurs] || "1" if element_max == "unbounded" if args.keys.include?(self[:name].to_sym) if args[self[:name].to_sym].class == Array element_max = args[self[:name].to_sym].size else element_max = 1 end else element_max = 1 end else element_max = element_max.to_i end return( [element_min, element_max] ) end |
#responseToHash(xml, types) ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/wsdl-reader/xsd/element.rb', line 120 def responseToHash( xml, types ) r = {} if SOAP::XSD::ANY_SIMPLE_TYPE.include?( self[:type].to_s.nns ) xml.each { |e| if e.name == self[:name] r[self[:name]] = SOAP::XSD::Convert.to_ruby( self[:type].to_s, e.text ) end } else case self[:type] when :simpleType # **************************** TODO ************************************ when :complexType # **************************** NEED TO BE VERIFIED ************************************ r = self[:complexType].responseToHash( xml, types ) else xml.each { |e| if e.name == self[:name] case types[self[:type].to_s.nns][:type] when :simpleType if r.keys.include?(self[:name]) unless r[self[:name]].class == Array r[self[:name]] = [r[self[:name]]] end r[self[:name]] << types[self[:type].to_s.nns][:value].responseToHash( e.text, types ) else r[self[:name]] = types[self[:type].to_s.nns][:value].responseToHash( e.text, types ) end else if r.keys.include?(self[:name]) unless r[self[:name]].class == Array r[self[:name]] = [r[self[:name]]] end r[self[:name]] << types[self[:type].to_s.nns][:value].responseToHash( e, types ) else r[self[:name]] = types[self[:type].to_s.nns][:value].responseToHash( e, types ) end end end } end end return r end |