class Mexico::FileSystem::FiestaDocument

FiESTA Document

Attributes

resource[RW]

Public Class Methods

check_watch(needed_id, needed_object) click to toggle source

Checks whether the given id/object pair is watched, and takes appropriate action if this is the case. @param (String) needed_id The XML ID that might be watched. @param (Object) needed_object The ruby object that might be watched. @return (void)

# File lib/mexico/file_system/fiesta_document.rb, line 113
def self.check_watch(needed_id, needed_object)
  if defined?(@@WATCHLIST)
    if @@WATCHLIST.has_key?("#{Thread.current.__id__}.#{needed_id}")
      @@WATCHLIST["#{Thread.current.__id__}.#{needed_id}"].each do |entry|
        entry[0].send(entry[1], needed_object)
      end
      @@WATCHLIST.delete("#{Thread.current.__id__}.#{needed_id}")
    end
  end
end
knows?(xml_id) click to toggle source

Retrieves a stored object from the temporary import cache. @param (String) xml_id The xml id of the needed object. @return (Boolean) true if there is an entry for the given id, false otherwise.

# File lib/mexico/file_system/fiesta_document.rb, line 87
def self.knows?(xml_id)
  @@CACHE.has_key?("#{Thread.current.__id__}.#{xml_id}")
end
new() click to toggle source

Creates a new, empty instance of a FiESTA document. @todo Check if all standard or default values are set correctly.

Calls superclass method
# File lib/mexico/file_system/fiesta_document.rb, line 133
def initialize
  super
  @head = Mexico::FileSystem::Head.new
  @scales_container = []
  @layers_container = []
  @layer_connectors = []
  @items_container  = []
  link_document
end
open(filename) click to toggle source

Opens the document at the given location. @param (String) filename The path that points to the file to be opened. @return (Mexico::FileSystem::FiestaDocument) a toe document with that file's contents.

# File lib/mexico/file_system/fiesta_document.rb, line 127
def self.open(filename)
  self.from_xml(File.open(filename))
end
resolve(xml_id) click to toggle source

Retrieves a stored object from the temporary import cache. @param (String) xml_id The xml id of the needed object. @return (Object) The needed object, or nil if nothing could be found.

# File lib/mexico/file_system/fiesta_document.rb, line 80
def self.resolve(xml_id)
  @@CACHE["#{Thread.current.__id__}.#{xml_id}"]
end
store(xml_id, ruby_object) click to toggle source

Retrieves a stored object from the temporary import cache. @param (String) xml_id The xml id of the needed object. @param (String) ruby_object The ruby object to be stored. @return (void)

# File lib/mexico/file_system/fiesta_document.rb, line 95
def self.store(xml_id, ruby_object)
  @@CACHE = {} unless defined?(@@CACHE)
  @@CACHE["#{Thread.current.__id__}.#{xml_id}"] = ruby_object
  ::Mexico::FileSystem::FiestaDocument.check_watch(xml_id, ruby_object)
end
watch(needed_id, object, method) click to toggle source

Put an xml id into the watch list, along with an object and a method

# File lib/mexico/file_system/fiesta_document.rb, line 102
def self.watch(needed_id, object, method)
  @@WATCHLIST = {} unless defined?(@@WATCHLIST)
  @@WATCHLIST["#{Thread.current.__id__}.#{needed_id}"] = [] unless @@WATCHLIST.has_key?("#{Thread.current.__id__}.#{needed_id}")
  @@WATCHLIST["#{Thread.current.__id__}.#{needed_id}"] << [object, method]
end

Public Instance Methods

add_item(item=nil) { |new_item| ... } click to toggle source
# File lib/mexico/file_system/fiesta_document.rb, line 214
def add_item(item=nil)
  if item.nil?
    new_item = Mexico::FileSystem::Item.new(identifier: "item#{rand(2**16)}")
    # @TODO check if that random ID is still available!
  end
  if item.is_a?(Hash)
    new_item = Mexico::FileSystem::Item.new(item.merge({document: self}))
  end
  if item.is_a?(Mexico::FileSystem::Item)
    new_item = item
  end
  # @TODO catch error if parameter has wrong object type
  if block_given?
    yield new_item
  end
  # check if item is not in the array already
  @items_container << new_item
  new_item
end
add_layer(args) click to toggle source
# File lib/mexico/file_system/fiesta_document.rb, line 152
def add_layer(args)
  if args.is_a?(Hash)
    new_layer = Mexico::FileSystem::Layer.new(args.merge({document: self}))
    @layers_container << new_layer
    return new_layer
  end
  if args.is_a?(Mexico::FileSystem::Layer)
    @layers_container << args
    return args
  end
  # @TODO catch error if parameter has wrong object type
  return nil
end
add_layer_connector(layer_connector) click to toggle source
# File lib/mexico/file_system/fiesta_document.rb, line 234
def add_layer_connector(layer_connector)
  @layer_connectors << layer_connector
end
add_scale(args) click to toggle source
# File lib/mexico/file_system/fiesta_document.rb, line 166
def add_scale(args)
  if args.is_a?(Hash)
    new_layer = Mexico::FileSystem::Scale.new(args.merge({document: self}))
    @scales_container << new_layer
    return new_layer
  end
  if args.is_a?(Mexico::FileSystem::Scale)
    @scales_container << args
    return args
  end
  # @TODO catch error if parameter has wrong object type
  return nil
end
add_standard_timeline(unit="ms") click to toggle source

Adds a standard timeline scale to the document. @param unit [String] The unit to be used for this timeline. @return [Scale] The created timeline scale object.

# File lib/mexico/file_system/fiesta_document.rb, line 146
def add_standard_timeline(unit="ms")
  @scales_container << Mexico::FileSystem::Scale.new(identifier: 'timeline01', name: 'Timeline', unit: unit, dimension: Mexico::FileSystem::Scale::DIM_TIME)
  @scales_container.last.document = self
  @scales_container.last
end
after_parse() click to toggle source

This method attempts to link objects from other locations of the XML/object tree into position inside this object, by following the xml ids given in the appropriate fields of this class.

# File lib/mexico/file_system/fiesta_document.rb, line 183
def after_parse
  link_document
  # then clear cache
  @@CACHE.clear
end
get_layer_by_id(id) click to toggle source
# File lib/mexico/file_system/fiesta_document.rb, line 238
def get_layer_by_id(id)
  matches = layers.select{|l| l.identifier == id}
  return matches[0] if matches.size>0
  return nil
end
identifier=(new_id) click to toggle source
# File lib/mexico/file_system/fiesta_document.rb, line 358
def identifier=(new_id)
  @identifier = Mexico::Util::to_xml_id(new_id)
end
inter_layer_graph(layer1, layer2) click to toggle source
# File lib/mexico/file_system/fiesta_document.rb, line 282
def inter_layer_graph(layer1, layer2)
  # 0: source items, 1: target items, 2: links
  result_graph = {
      sources:    Set.new,
      sinks:      Set.new,
      links:      Set.new,
      source_map: Hash.new,
      sink_map:   Hash.new
  }

  result_graph[:sources].merge layer1.items
  result_graph[:sinks].merge layer2.items

  links = result_graph[:sources].collect{|i| i.item_links }.flatten
  links = links.select{|l| l.target_object.layers.include?(layer2) }
  result_graph[:links] = links

  # fill the source and target maps with data
  result_graph[:sources].each do |node|
    result_graph[:source_map][node] = Set.new
  end
  result_graph[:sinks].each do |node|
    result_graph[:sink_map][node] = Set.new
  end

  result_graph[:links].each do |link|
    source = link.item
    sink = link.target_item
    result_graph[:source_map][source] << sink
    result_graph[:sink_map][sink] << source
  end

  result_graph
end
inter_layer_graph_list() click to toggle source
# File lib/mexico/file_system/fiesta_document.rb, line 317
def inter_layer_graph_list
  # collect all parent child pairs of layers
  # calculate layer graphs for all of them
  ilg_list = Hash.new
  layers.each do |parent_layer|
    parent_layer.successor_layers.each do |child_layer|
      ilg_list[ [parent_layer, child_layer[0]] ] = inter_layer_graph(parent_layer, child_layer[0])
    end
  end
  ilg_list
end
inter_layer_sink_cardinality() click to toggle source

Cardinality of source elements: how many links are connected to the source nodes?

# File lib/mexico/file_system/fiesta_document.rb, line 349
def inter_layer_sink_cardinality
  card = 0
  inter_layer_graph_list.each do |k,v|
    graph_card = v[:source_map].values.collect{|m| m.size}.max
    card = [card,graph_card].max
  end
  card
end
inter_layer_source_cardinality() click to toggle source

Cardinality of source elements: how many links are connected to the source nodes?

# File lib/mexico/file_system/fiesta_document.rb, line 339
def inter_layer_source_cardinality
  card = 0
  inter_layer_graph_list.each do |k,v|
    graph_card = v[:sink_map].values.collect{|m| m.size}.max
    card = [card,graph_card].max
  end
  card
end
layers_form_a_cdag?() click to toggle source
# File lib/mexico/file_system/fiesta_document.rb, line 252
def layers_form_a_cdag?
  raise Mexico::NotYetImplementedError.new('This method has not been implemented yet.')
end
layers_form_a_dag?() click to toggle source
# File lib/mexico/file_system/fiesta_document.rb, line 248
def layers_form_a_dag?
  raise Mexico::NotYetImplementedError.new('This method has not been implemented yet.')
end
layers_form_a_forest?() click to toggle source
# File lib/mexico/file_system/fiesta_document.rb, line 256
def layers_form_a_forest?
  # check whether all layers have at most one parent layer
  self.layers.each do |layer|
    return false if layer.predecessor_layers.size > 1
  end
  return true
end
layers_form_a_graph?() click to toggle source
# File lib/mexico/file_system/fiesta_document.rb, line 244
def layers_form_a_graph?
  true
end
layers_form_a_tree?() click to toggle source
# File lib/mexico/file_system/fiesta_document.rb, line 264
def layers_form_a_tree?
  # check whether all layers but one have exactly one parent layer
  other_than_ones = []
  self.layers.each do |layer|
    s = layer.predecessor_layers.size
    other_than_ones << s if s != 1
  end
  true if s.size == 1 && s.first==0
end
layers_form_an_edgeless_graph?() click to toggle source
# File lib/mexico/file_system/fiesta_document.rb, line 274
def layers_form_an_edgeless_graph?
  @layer_connectors.empty?
end
layers_form_an_empty_graph?() click to toggle source
# File lib/mexico/file_system/fiesta_document.rb, line 278
def layers_form_an_empty_graph?
 layers.empty?
end
sink_cardinality_for_layer(layer1, layer2) click to toggle source
# File lib/mexico/file_system/fiesta_document.rb, line 333
def sink_cardinality_for_layer(layer1, layer2)
  inter_layer_graph_list[[layer1,layer2]][:source_map].values.collect{|m| m.size}.max
end
source_cardinality_for_layer(layer1, layer2) click to toggle source
# File lib/mexico/file_system/fiesta_document.rb, line 329
def source_cardinality_for_layer(layer1, layer2)
  inter_layer_graph_list[[layer1,layer2]][:sink_map].values.collect{|m| m.size}.max
end