Sha256: 30e4236c072bbd5cf67c0a8bbd6560ab2999a3a8a3e229c9abb4454d075c948e

Contents?: true

Size: 1.75 KB

Versions: 2

Compression:

Stored size: 1.75 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 process message
    end

    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 = Adaptation::Message.get_class_object(message_type.capitalize)
        message_object = message_class.to_object(xml_message)
      end
      
      xml = message_object.to_xml.to_s.gsub("'", "\"")
      unless system("#{$config["oappublish"]} '#{$config["application"]}' '#{xml}'")
        puts "Problem publishing: #{xml}"
      end
    end

    def self.get_class_object(adaptor_class) # nodoc
      Object.const_get(adaptor_class) rescue nil
    end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
adaptation-0.1.3 lib/adaptation/adaptor.rb
adaptation-0.1.2 lib/adaptation/adaptor.rb