Sha256: 859e8a678ab99a97a7c3a04e502d84b254f4a243a8fc9d76b72557e3d75ff64c

Contents?: true

Size: 1.89 KB

Versions: 7

Compression:

Stored size: 1.89 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("'", "\"")
      publish_method = $config["oappublish"] || "#{ADAPTOR_ROOT}/script/publish"
      topic = $config["application"] || "ADAPTATION"
      unless system("#{publish_method} '#{$config["application"]}' '#{xml}'")
        logger.error "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

7 entries across 7 versions & 1 rubygems

Version Path
adaptation-0.1.6 lib/adaptation/adaptor.rb
adaptation-0.1.7 lib/adaptation/adaptor.rb
adaptation-0.1.10 lib/adaptation/adaptor.rb
adaptation-0.1.4 lib/adaptation/adaptor.rb
adaptation-0.1.5 lib/adaptation/adaptor.rb
adaptation-0.1.8 lib/adaptation/adaptor.rb
adaptation-0.1.9 lib/adaptation/adaptor.rb