Sha256: a56d9e7867b9f3dec8ee076ad6109cb71cc39a23d3a76356e70ad4faad6af440

Contents?: true

Size: 1.57 KB

Versions: 2

Compression:

Stored size: 1.57 KB

Contents

module Adaptation
#= Adaptation::Adaptor -- The message processor
#
#Adaptation::Adaptor is the base class for those classes containing the logic to be executed when a message is read through the mom. 
#
#Each class extending Adaptation::Adaptor must implement the _process_ function, using it as the main entry point for the logic to be executed when a message arrives. The name of the class extending Adaptation::Message associates the class with the one to be executed when a message arrives. Ie. if a message is received with a root element named <hello>, adaptation will search for a class extending Adaptation::Adaptor named _HelloAdaptor_. 
#
#<i>Adaptation::Adaptors</i> (classes extending Adaptation::Adaptor) must be stored under <i>app/adaptors_name</i> in the adaptation file tree. This is done automatically when an adaptor is generated using adaptation built-in generator:
#  script/generate adaptor hello
# 
  class Adaptor

    def logger
      Adaptation::Base.logger
    end
    
    def publish *options
      message_object = nil
      if options.first.is_a?(Message)
        message_object = options.first
      elsif options.first.is_a?(String)
        xml_message = options.first
        message_type = xml_message[1..(xml_message.index(/(>| )/) - 1)]
        message_class = get_class_object(message_type.capitalize)
        message_object = message_class.to_object(xml_message)
      end
      
      xml = message_object.to_xml
      unless system("#{$config["oappublish"]} '#{$config["application"]}' '#{xml}'")
        puts "Problem publishing: #{xml}"
      end
    end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
adaptation-0.0.9 lib/adaptation/adaptor.rb
adaptation-0.1.0 lib/adaptation/adaptor.rb