File: uml13_to_uml13_ea.rb

package info (click to toggle)
ruby-rgen 0.10.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 2,428 kB
  • sloc: ruby: 11,344; xml: 1,368; yacc: 72; makefile: 10
file content (89 lines) | stat: -rw-r--r-- 3,119 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
require 'rgen/transformer'
require 'metamodels/uml13_metamodel'
require 'ea_support/uml13_ea_metamodel'
require 'ea_support/uml13_ea_metamodel_ext'

class UML13ToUML13EA < RGen::Transformer
  include UML13
  
  def transform
    trans(:class => Package)
    trans(:class => Class)
  end
  
  copy_all UML13, :to => UML13EA, :except => %w(
    ActivityGraph 
    CompositeState SimpleState
    Class 
    Association AssociationEnd AssociationEndRole
    Generalization
    Pseudostate    
    Attribute
  )  
  
  copy ActivityGraph, :to => UML13EA::ActivityModel
  
  copy Pseudostate, :to => UML13EA::PseudoState
  
  transform CompositeState, :to => UML13EA::CompositeState do
    copy_features :except => [:subvertex] do
      { :substate => trans(subvertex) }
    end
  end
  
  transform SimpleState, :to => UML13EA::SimpleState do
    copy_features :except => [:container] do
      { :taggedValue => trans(taggedValue) + 
        [@env_out.new(UML13EA::TaggedValue, :tag => "ea_stype", :value => "State")] +
        (container ? [ @env_out.new(UML13EA::TaggedValue, :tag => "owner", :value => trans(container)._xmi_id)] : []) }
    end
  end
  
  transform Class, :to => UML13EA::Class do
    copy_features do
      { :taggedValue => trans(taggedValue) + [@env_out.new(UML13EA::TaggedValue, :tag => "ea_stype", :value => "Class")]}
    end
  end
  
  transform Association, :to => UML13EA::Association do
    copy_features do
      { :connection => trans(connection[1].isNavigable ? [connection[0], connection[1]] : [connection[1], connection[0]]),
        :taggedValue => trans(taggedValue) + [
          @env_out.new(UML13EA::TaggedValue, :tag => "ea_type", :value => "Association"),
          @env_out.new(UML13EA::TaggedValue, :tag => "direction", :value => 
            connection.all?{|c| c.isNavigable} ? "Bi-Directional" : "Source -&gt; Destination")] }
    end
  end
  
  transform AssociationEnd, :to => UML13EA::AssociationEnd do 
    copyAssociationEnd
  end
  
  transform AssociationEndRole, :to => UML13EA::AssociationEndRole do 
    copyAssociationEnd
  end
  
  def copyAssociationEnd
    _lower = multiplicity && multiplicity.range.first.lower
    _upper = multiplicity && multiplicity.range.first.upper
    copy_features :except => [:multiplicity, :ordering, :changeability] do
      { :multiplicity => _lower == _upper ? _lower : "#{_lower}..#{_upper}",
        :isOrdered => ordering == :ordered,
        :changeable => :none } #{:frozen => :none}[changeability] || changeability}
    end
  end

  transform Attribute, :to => UML13EA::Attribute do
    copy_features :except => [:changeability] do
      { :changeable => {:frozen => :none}[changeability] }
    end
  end

  transform Generalization, :to => UML13EA::Generalization do
    copy_features :except => [:child, :parent] do
      { :taggedValue => trans(taggedValue) + [@env_out.new(UML13EA::TaggedValue, :tag => "ea_type", :value => "Generalization")],
        :subtype => trans(child),
        :supertype => trans(parent)}
    end
  end
end