Class: StompMessage::Message

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

Overview

basic stomp message class sent between clients and servers… subclasss and add instance variables.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from XmlHelper

#add_elements, #create_element, #load_instance_variables, #load_iv, #xml_instance_variable

Constructor Details

#initialize(cmd, bdy = nil) ⇒ Message

Returns a new instance of Message.



133
134
135
136
137
138
# File 'lib/stomp_message/message.rb', line 133

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.



132
133
134
# File 'lib/stomp_message/message.rb', line 132

def __stomp_msg_body
  @__stomp_msg_body
end

#__stomp_msg_commandObject

Returns the value of attribute __stomp_msg_command.



132
133
134
# File 'lib/stomp_message/message.rb', line 132

def __stomp_msg_command
  @__stomp_msg_command
end

Class Method Details

.load_xml(xml_string) ⇒ Object



159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/stomp_message/message.rb', line 159

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}"
  tt_sms=StompMessage::Message.new(command, body)
  rescue Exception => e
    puts "Exception in load xml:#{xml_string}"
    puts "message #{e.message}"
  end
  tt_sms
end

.load_xml_new(xml_string) ⇒ Object



173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/stomp_message/message.rb', line 173

def self.load_xml_new(xml_string)
  begin
 # doc=REXML::Document.new(xml_string)
  test= self.new('temp', 'temp')
  test.load_instance_variables(xml_string)
  #sms=StompMessage::Message.new(test.command, test.body)
  rescue Exception => e
    puts "Exception in load xml:#{xml_string}"
    puts "message #{e.message}"
  end
 test
end

Instance Method Details

#bodyObject



139
140
141
# File 'lib/stomp_message/message.rb', line 139

def body
 self.__stomp_msg_body
end

#commandObject



142
143
144
# File 'lib/stomp_message/message.rb', line 142

def command
 self.__stomp_msg_command
end

#to_xmlObject



146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/stomp_message/message.rb', line 146

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