Class: SOAP::SOAPBody

Inherits:
SOAPStruct show all
Includes:
SOAPEnvelopeElement
Defined in:
lib/soap/rpc/element.rb,
lib/soap/element.rb

Overview

Add method definitions for RPC to common definition in element.rb

Constant Summary

Constant Summary

Constants included from SOAP

AttrActor, AttrActorName, AttrArrayType, AttrArrayTypeName, AttrEncodingStyle, AttrEncodingStyleName, AttrHref, AttrHrefName, AttrId, AttrIdName, AttrMustUnderstand, AttrMustUnderstandName, AttrOffset, AttrOffsetName, AttrPosition, AttrPositionName, AttrRoot, AttrRootName, Base64Literal, EleBody, EleBodyName, EleEnvelope, EleEnvelopeName, EleFault, EleFaultActor, EleFaultActorName, EleFaultCode, EleFaultCodeName, EleFaultDetail, EleFaultDetailName, EleFaultName, EleFaultString, EleFaultStringName, EleHeader, EleHeaderName, EncodingNamespace, EnvelopeNamespace, LiteralNamespace, MediaType, NextActor, PropertyName, SOAPProxy, TypeMap, VERSION, ValueArray, ValueArrayName

Instance Attribute Summary collapse

Attributes included from SOAPCompoundtype

#qualified

Attributes included from SOAPType

#definedtype, #elename, #encodingstyle, #extraattr, #force_typed, #id, #parent, #position, #precedents, #root

Attributes inherited from XSD::NSDBase

#type

Instance Method Summary collapse

Methods inherited from SOAPStruct

#[], #[]=, #add, decode, #each, #have_member, #key?, #members, #replace, #to_obj, #to_s

Methods included from SOAPType

#inspect, #rootnode

Methods included from Enumerable

#inject

Methods inherited from XSD::NSDBase

inherited, #init, types

Constructor Details

#initialize(data = nil, is_fault = false) ⇒ SOAPBody

Returns a new instance of SOAPBody



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/soap/element.rb', line 99

def initialize(data = nil, is_fault = false)
  super(nil)
  @elename = EleBodyName
  @encodingstyle = nil
  if data
    if data.respond_to?(:to_xmlpart)
      data = SOAP::SOAPRawData.new(data)
    elsif defined?(::REXML) and data.is_a?(::REXML::Element)
      data = SOAP::SOAPRawData.new(SOAP::SOAPREXMLElementWrap.new(data))
    end
    if data.respond_to?(:elename)
      add(data.elename.name, data)
    else
      data.to_a.each do |datum|
        add(datum.elename.name, datum)
      end
    end
  end
  @is_fault = is_fault
end

Instance Attribute Details

#is_faultObject (readonly)

Returns the value of attribute is_fault



97
98
99
# File 'lib/soap/element.rb', line 97

def is_fault
  @is_fault
end

Instance Method Details

#encode(generator, ns, attrs = {}) ⇒ Object



120
121
122
123
124
125
126
127
# File 'lib/soap/element.rb', line 120

def encode(generator, ns, attrs = {})
  name = ns.name(@elename)
  generator.encode_tag(name, attrs)
  @data.each do |data|
    yield(data)
  end
  generator.encode_tag_end(name, @data.size > 0)
end

#faultObject



50
51
52
53
54
55
56
# File 'lib/soap/rpc/element.rb', line 50

def fault
  if @is_fault
    self['fault']
  else
    nil
  end
end

#fault=(fault) ⇒ Object



58
59
60
61
# File 'lib/soap/rpc/element.rb', line 58

def fault=(fault)
  @is_fault = true
  add('fault', fault)
end

#outparamsObject



39
40
41
42
43
44
45
46
47
48
# File 'lib/soap/rpc/element.rb', line 39

def outparams
  root = root_node
  if !@is_fault and !root.nil? and !root.is_a?(SOAPBasetype)
    op = root[1..-1]
    op = nil if op && op.empty?
    op
  else
    nil
  end
end

#requestObject



19
20
21
# File 'lib/soap/rpc/element.rb', line 19

def request
  root_node
end

#responseObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/soap/rpc/element.rb', line 23

def response
  root = root_node
  if !@is_fault
    if root.nil?
      nil
    elsif root.is_a?(SOAPBasetype)
      root
    else
      # Initial element is [retval].
      root[0]
    end
  else
    root
  end
end

#root_nodeObject



129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/soap/element.rb', line 129

def root_node
  @data.each do |node|
    if node.root == 1
	return node
    end
  end
  # No specified root...
  @data.each do |node|
    if node.root != 0
	return node
    end
  end
  raise Parser::FormatDecodeError.new('no root element')
end