Class: MINT::MappingParser

Inherits:
Object
  • Object
show all
Includes:
REXML, StreamListener
Defined in:
lib/MINT-core/manager/mapping_parser.rb

Instance Method Summary collapse

Constructor Details

#initializeMappingParser

Returns a new instance of MappingParser.



10
11
12
13
14
15
16
# File 'lib/MINT-core/manager/mapping_parser.rb', line 10

def initialize()
  @mapping_name  #actual name of the mapping
  @mapping_type  #type of the mapping: complementary, sequential, ...
  @observations = Array.new #will store the observations
  @actions = Array.new #will store the actions
  @mapping #actual mapping
end

Instance Method Details

#build_from_scxml(filename) ⇒ Object

This function parses scxml from a file



19
20
21
22
23
# File 'lib/MINT-core/manager/mapping_parser.rb', line 19

def build_from_scxml(filename)
  source = File.new filename
  Document.parse_stream(source, self)
  @mapping
end

#build_from_scxml_string(stringbuffer) ⇒ Object

This function parses scxml directly from the string parameter “stringbuffer”



26
27
28
29
# File 'lib/MINT-core/manager/mapping_parser.rb', line 26

def build_from_scxml_string(stringbuffer)
  Document.parse_stream(stringbuffer, self)
  @mapping
end

#tag_end(name) ⇒ Object

This function defines the actions to be taken for each different tag when the tag is closed



69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/MINT-core/manager/mapping_parser.rb', line 69

def tag_end(name)
  case name
    when 'operator'
      case @mapping_type
        when 'complementary'
          @mapping = ComplementaryMapping.new(:id => @mapping_id, :name => @mapping_name, :observations => @observations, :actions => @actions)
        when 'sequential'
          @mapping = SequentialMapping.new(:id => @mapping_id, :name => @mapping_name, :observations => @observations, :actions => @actions)
        else
      end
    else
  end
end

#tag_start(name, attributes) ⇒ Object

This function defines the actions to be taken for each different tag when the tag is opened



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/MINT-core/manager/mapping_parser.rb', line 32

def tag_start(name, attributes)
  case name
    when 'mapping'
      @mapping_name = attributes['name']
    when 'operator'
      @mapping_type = attributes['type']
      @mapping_id = attributes['id']
    when 'observation'
      observation_states = Array.new
      observation_hash = Hash.new
      observation_hash[:element] = attributes['interactor']
      observation_hash[:name] = attributes['name']
      observation_hash[:id] = attributes['id']
      attributes['states'].split("|").each do |s| observation_states << s.to_sym end   if attributes['states']
      observation_hash[:states] = observation_states
      observation_hash[:process] = attributes['process'].to_s.to_sym if attributes['process']
      observation_hash[:result] = attributes['result'] if attributes['result']

      if attributes['type'] and attributes['type'].eql? "negation"
        @observations << NegationObservation.new(observation_hash)
      else
        @observations << Observation.new(observation_hash)
      end
    when 'backend'
      backend_call = MINT::const_get(attributes['class']).method(attributes['call'].to_sym) # TODO figure out a way that this can work
      @actions << BackendAction.new(:call => backend_call,:parameter => attributes['parameter'], :id => attributes['id'])
    when 'bind'
      backend_call = MINT::const_get(attributes['class']).method(attributes['transformation'].to_sym) if attributes['transformation']
      @actions << BindAction.new(:id => attributes['id'], :elementIn => attributes['interactor_in'], :nameIn => attributes['name_in'], :attrIn => attributes['attr_in'],
                                 :elementOut => attributes['interactor_out'], :nameOut => attributes['name_out'], :attrOut => attributes['attr_out'],:transform => backend_call)
    when 'event'
      @actions << EventAction.new(:id => attributes['id'], :event => attributes['type'].to_sym, :target => attributes['target'])
    else
  end
end

#text(text) ⇒ Object



83
84
# File 'lib/MINT-core/manager/mapping_parser.rb', line 83

def text(text)
end

#xmldecl(version, encoding, standalone) ⇒ Object



86
87
# File 'lib/MINT-core/manager/mapping_parser.rb', line 86

def xmldecl(version, encoding, standalone)
end