Class: SOAP::EncodingStyle::SOAPHandler

Inherits:
Handler show all
Defined in:
lib/action_web_service/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_epilogue, #encode_prologue, handler, uri

Constructor Details

#initialize(charset = nil) ⇒ SOAPHandler

Returns a new instance of SOAPHandler.



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

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

Instance Method Details

#decode_epilogueObject



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

def decode_epilogue
  decode_resolve_id
end

#decode_parent(parent, node) ⇒ Object



215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
# File 'lib/action_web_service/soap/encodingstyle/soapHandler.rb', line 215

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



205
206
207
208
209
# File 'lib/action_web_service/soap/encodingstyle/soapHandler.rb', line 205

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

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



145
146
147
148
149
150
151
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
# File 'lib/action_web_service/soap/encodingstyle/soapHandler.rb', line 145

def decode_tag(ns, elename, attrs, parent)
  @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

#decode_tag_end(ns, node) ⇒ Object



182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/action_web_service/soap/encodingstyle/soapHandler.rb', line 182

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
  decode_textbuf(o)
  # unlink definedtype
  o.definedtype = nil
end

#decode_text(ns, text) ⇒ Object



201
202
203
# File 'lib/action_web_service/soap/encodingstyle/soapHandler.rb', line 201

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

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

encode interface.



32
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
# File 'lib/action_web_service/soap/encodingstyle/soapHandler.rb', line 32

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



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

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