Class: StompMessage::Message

Inherits:
Object
  • Object
show all
Includes:
XmlHelper
Defined in:
lib/stomp_message/message.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from XmlHelper

#add_elements, #create_element, #xml_instance_variable

Constructor Details

#initialize(cmd, bdy = nil) ⇒ Message

Returns a new instance of Message.



56
57
58
59
60
61
# File 'lib/stomp_message/message.rb', line 56

def initialize(cmd, bdy=nil)
    raise 'command nil' if cmd==nil
    self.__stomp_msg_command =   cmd==nil ? '' : cmd.to_s
    self.__stomp_msg_body =   bdy==nil ? '' : bdy.to_s
   
end

Instance Attribute Details

#__stomp_msg_bodyObject

Returns the value of attribute __stomp_msg_body.



55
56
57
# File 'lib/stomp_message/message.rb', line 55

def __stomp_msg_body
  @__stomp_msg_body
end

#__stomp_msg_commandObject

Returns the value of attribute __stomp_msg_command.



55
56
57
# File 'lib/stomp_message/message.rb', line 55

def __stomp_msg_command
  @__stomp_msg_command
end

Class Method Details

.load_xml(xml_string) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/stomp_message/message.rb', line 82

def self.load_xml(xml_string)
  begin
  doc=REXML::Document.new(xml_string)
  command=REXML::XPath.first(doc, "//__stomp_msg_command").text
#  puts "load_xml command is #{command}"
  body=REXML::XPath.first(doc, "//__stomp_msg_body").text
#     puts "load_xml body is #{body}"
  sms=StompMessage::Message.new(command, body)
  rescue Exception => e
    puts "Exception in load xml:#{xml_string}"
    puts "message #{e.message}"
  end
  sms
end

Instance Method Details

#bodyObject



62
63
64
# File 'lib/stomp_message/message.rb', line 62

def body
 self.__stomp_msg_body
end

#commandObject



65
66
67
# File 'lib/stomp_message/message.rb', line 65

def command
 self.__stomp_msg_command
end

#to_xmlObject



69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/stomp_message/message.rb', line 69

def to_xml
  doc=REXML::Document.new()
  msg_xml = REXML::Element.new "stomp_msg_message"   
  doc.add_element(msg_xml)   
   msg3 = self.add_elements(REXML::Element.new("__instance_variables"))
   doc.root.add_element(msg3)
  output =""
  doc.write output
  output
 # doc= REXML::Document.new sms_xml.to_s
 # doc.to_s
end