Method: XmiModel#initialize

Defined in:
lib/xmimodel.rb

#initialize(model_file_name) ⇒ XmiModel

Constructor.

Parameters:

  • Path (String, #read)

    of model.



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
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/xmimodel.rb', line 33

def initialize(model_file_name)

  # Obtem a tag 'XMI.content' que contém todos os objetos que serão tratados
  f = File.open(model_file_name)   
  doc = Nokogiri::XML(f)
  @document = doc
  xmi_content = doc.at_xpath("./XMI/XMI.content")
  f.close

  # Header
  @exporter = XmiHelper.exporter(doc)
  @exporter_version = XmiHelper.exporter_version(doc)
  @metamodel_version = XmiHelper.metamodel_version(doc)

  # Constrói vetor de pacotes
  @packages = Array.new    
  XmiHelper.packages(xmi_content).each do |uml_package|
    if ! (uml_package.attribute('name').nil? || 
      uml_package.attribute('name').to_s.empty? || 
      uml_package.attribute('name').to_s.strip == "Component View" ||
      uml_package.attribute('name').to_s.strip == "Data types")
      p = Package.new(uml_package, nil)
      @packages << p
    end
  end

  # Constrói vetor de heranças
  @generalizations = Array.new
  XmiHelper.all_generalizations(xmi_content).each do |xml|
    g = Generalization.new(xml, self)
    
    g.child_obj.parent  = g.parent_obj unless g.child_obj.nil?
    g.parent_obj.children << g.child_obj unless g.parent_obj.nil?

    #puts "#{g.child_obj.full_name} - #{g.parent_obj.full_name}"
    @generalizations << g
  end

  @associations = Array.new
  XmiHelper.all_associations(xmi_content).each do |xml|
    @associations << Association.new(xml, self)
  end

  true
end