In: |
soap/encodingstyle/soapHandler.rb
|
Parent: | Handler |
Namespace | = | SOAP::EncodingNamespace |
NilLiteralMap | = | { 'true' => true, '1' => true, 'false' => false, '0' => false |
RootLiteralMap | = | { '1' => 1, '0' => 0 |
# File soap/encodingstyle/soapHandler.rb, line 20 def initialize(charset = nil) super(charset) @refpool = [] @idpool = [] @textbuf = '' @is_first_top_ele = true end
# File soap/encodingstyle/soapHandler.rb, line 228 def decode_parent(parent, node) case parent.node when SOAPUnknown newparent = parent.node.as_struct node.parent = newparent if newparent.id @idpool << newparent end parent.replace_node(newparent) decode_parent(parent, node) when SOAPStruct parent.node.add(node.elename.name, node) node.parent = parent.node when SOAPArray if node.position parent.node[*(decode_arypos(node.position))] = node parent.node.sparse = true else parent.node.add(node) end node.parent = parent.node when SOAPBasetype raise EncodingStyleError.new("SOAP base type must not have a child.") else raise EncodingStyleError.new("Illegal parent: #{ parent.node }.") end end
# File soap/encodingstyle/soapHandler.rb, line 218 def decode_prologue @refpool.clear @idpool.clear @is_first_top_ele = true end
# File soap/encodingstyle/soapHandler.rb, line 153 def decode_tag(ns, elename, attrs, parent) # ToDo: check if @textbuf is empty... @textbuf = '' is_nil, type, arytype, root, offset, position, href, id, extraattr = decode_attrs(ns, attrs) o = nil if is_nil o = SOAPNil.decode(elename) elsif href o = SOAPReference.decode(elename, href) @refpool << o elsif @decode_typemap o = decode_tag_by_wsdl(ns, elename, type, parent.node, arytype, extraattr) else o = decode_tag_by_type(ns, elename, type, parent.node, arytype, extraattr) end if o.is_a?(SOAPArray) if offset o.offset = decode_arypos(offset) o.sparse = true else o.sparse = false end end o.parent = parent o.id = id o.root = root o.position = position unless o.is_a?(SOAPTemporalObject) @idpool << o if o.id decode_parent(parent, o) end o end
# File soap/encodingstyle/soapHandler.rb, line 191 def decode_tag_end(ns, node) o = node.node if o.is_a?(SOAPUnknown) newnode = if /\A\s*\z/ =~ @textbuf o.as_struct else o.as_string end if newnode.id @idpool << newnode end node.replace_node(newnode) o = node.node end if o.is_a?(SOAPCompoundtype) o.definedtype = nil end decode_textbuf(o) @textbuf = '' end
# File soap/encodingstyle/soapHandler.rb, line 213 def decode_text(ns, text) # @textbuf is set at decode_tag_end. @textbuf << text end
encode interface.
# File soap/encodingstyle/soapHandler.rb, line 32 def encode_data(generator, ns, qualified, data, parent) attrs = encode_attrs(generator, ns, data, parent) if parent && parent.is_a?(SOAPArray) && parent.position attrs[ns.name(AttrPositionName)] = '[' << parent.position.join(',') << ']' end name = nil if qualified and data.elename.namespace SOAPGenerator.assign_ns(attrs, ns, data.elename.namespace) name = ns.name(data.elename) else name = data.elename.name end case data when SOAPReference attrs['href'] = '#' << data.refid generator.encode_tag(name, attrs) when SOAPRawString generator.encode_tag(name, attrs) generator.encode_rawstring(data.to_s) when XSD::XSDString generator.encode_tag(name, attrs) generator.encode_string(@charset ? XSD::Charset.encoding_to_xml(data.to_s, @charset) : data.to_s) when XSD::XSDAnySimpleType generator.encode_tag(name, attrs) generator.encode_string(data.to_s) when SOAPStruct generator.encode_tag(name, attrs) data.each do |key, value| yield(value, false) end when SOAPArray generator.encode_tag(name, attrs) data.traverse do |child, *rank| data.position = data.sparse ? rank : nil yield(child, false) end else raise EncodingStyleError.new( "Unknown object:#{ data } in this encodingStyle.") end end