Class: SOAP::EncodingStyle::SOAPHandler

Inherits:
Handler show all
Defined in:
lib/soap/encodingstyle/soapHandler.rb

Defined Under Namespace

Classes: SOAPTemporalObject, SOAPUnknown

Constant Summary collapse

Namespace =
SOAP::EncodingNamespace

Instance Attribute Summary

Attributes inherited from Handler

#charset, #generate_explicit_type

Instance Method Summary collapse

Methods inherited from Handler

#decode_typemap=, each, #encode_attr_key, #encode_epilogue, #encode_prologue, #encode_qname, handler, uri

Constructor Details

#initialize(charset = nil) ⇒ SOAPHandler

Returns a new instance of SOAPHandler.



21
22
23
24
25
26
27
# File 'lib/soap/encodingstyle/soapHandler.rb', line 21

def initialize(charset = nil)
  super(charset)
  @refpool = []
  @idpool = []
  @textbuf = []
  @is_first_top_ele = true
end

Instance Method Details

#decode_epilogueObject



220
221
222
# File 'lib/soap/encodingstyle/soapHandler.rb', line 220

def decode_epilogue
  decode_resolve_id
end

#decode_parent(parent, node) ⇒ Object



224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# File 'lib/soap/encodingstyle/soapHandler.rb', line 224

def decode_parent(parent, node)
  return unless 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
  else
    raise EncodingStyleError.new("illegal parent: #{parent.node}")
  end
end

#decode_prologueObject



214
215
216
217
218
# File 'lib/soap/encodingstyle/soapHandler.rb', line 214

def decode_prologue
  @refpool.clear
  @idpool.clear
  @is_first_top_ele = true
end

#decode_tag(ns, elename, attrs, parent) ⇒ Object



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/soap/encodingstyle/soapHandler.rb', line 152

def decode_tag(ns, elename, attrs, parent)
  @textbuf.clear
  is_nil, type, arytype, root, offset, position, href, id =
    extract_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, attrs)
  else
    o = decode_tag_by_type(ns, elename, type, parent.node, arytype, attrs)
  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

#decode_tag_end(ns, node) ⇒ Object



189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/soap/encodingstyle/soapHandler.rb', line 189

def decode_tag_end(ns, node)
  textbufstr = @textbuf.join
  @textbuf.clear
  o = node.node
  if o.is_a?(SOAPUnknown)
    newnode = if /\A\s*\z/ =~ textbufstr
	o.as_struct
    else
	o.as_string
    end
    if newnode.id
	@idpool << newnode
    end
    node.replace_node(newnode)
    o = node.node
  end
  decode_textbuf(o, textbufstr)
  # unlink definedtype
  o.definedtype = nil
end

#decode_text(ns, text) ⇒ Object



210
211
212
# File 'lib/soap/encodingstyle/soapHandler.rb', line 210

def decode_text(ns, text)
  @textbuf << text
end

#encode_data(generator, ns, data, parent) ⇒ Object

encode interface.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/soap/encodingstyle/soapHandler.rb', line 33

def encode_data(generator, ns, 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 = generator.encode_name(ns, data, attrs)
  case data
  when SOAPReference
    attrs['href'] = data.refidstr
    generator.encode_tag(name, attrs)
  when SOAPExternalReference
    data.referred
    attrs['href'] = data.refidstr
    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|
      generator.encode_child(ns, value, data)
    end
  when SOAPArray
    generator.encode_tag(name, attrs)
    data.traverse do |child, *rank|
	data.position = data.sparse ? rank : nil
      generator.encode_child(ns, child, data)
    end
  else
    raise EncodingStyleError.new(
	"unknown object:#{data} in this encodingStyle")
  end
end

#encode_data_end(generator, ns, data, parent) ⇒ Object



74
75
76
77
78
# File 'lib/soap/encodingstyle/soapHandler.rb', line 74

def encode_data_end(generator, ns, data, parent)
  name = generator.encode_name_end(ns, data)
  cr = (data.is_a?(SOAPCompoundtype) and data.have_member)
  generator.encode_tag_end(name, cr)
end