Class: Xumlidot::Diagram::Xmi

Inherits:
Object
  • Object
show all
Includes:
REXML
Defined in:
lib/xumlidot/diagram/xmi.rb,
lib/xumlidot/diagram/xmi/id.rb,
lib/xumlidot/diagram/xmi/klass.rb,
lib/xumlidot/diagram/xmi/method.rb,
lib/xumlidot/diagram/xmi/argument.rb,
lib/xumlidot/diagram/xmi/constant.rb,
lib/xumlidot/diagram/xmi/attribute.rb,
lib/xumlidot/diagram/xmi/superklass.rb

Defined Under Namespace

Modules: Argument, Attribute, Constant, ID, Klass, MethodSignature, Superklass Classes: DiagramAssociationElements, DiagramElements, Elements, ModelAssociationElements, ModelElements, NamespaceToId

Instance Method Summary collapse

Constructor Details

#initialize(stack, options = nil) ⇒ Xmi

Returns a new instance of Xmi.



97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/xumlidot/diagram/xmi.rb', line 97

def initialize(stack, options = nil)
  @stack = stack
  @options = options

  @namespace_to_id = NamespaceToId.new

  @model = ModelElements.new(options)
  @diagram = DiagramElements.new(options)

  @model_associations = ModelAssociationElements.new(options)
  @diagram_associations = DiagramAssociationElements.new(options)
end

Instance Method Details

#drawObject



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/xumlidot/diagram/xmi.rb', line 110

def draw
  # First traversal we're just assigning ids to everything so that when
  # we come to draw things we can do a lookup on the ids for any composition
  # aggregation or subclass relationships.
  @stack.traverse do |klass|
    klass.extend(::Xumlidot::Diagram::Xmi::Klass)
    klass.superklass.extend(::Xumlidot::Diagram::Xmi::Superklass) unless klass.superklass.name.nil?

    klass.definition.inherited_modules.each do |m|
      next if m.empty?
      m.extend(::Xumlidot::Diagram::Xmi::Superklass)
    end #unless klass.definition.inherited_modules.empty?

    next if @namespace_to_id.has?(klass.draw_identifier)
    @namespace_to_id[klass.draw_identifier] = klass.id
  end

  # Second traversal we are drawing everything
  @stack.traverse do |klass|
    # resolve the superclass id to that of an existing class with an id
    # we do this in the second loop so that all the classes are present
    unless klass.superklass.name.nil?
      id = @namespace_to_id[klass.superklass.draw_identifier]
      klass.superklass.force_id(id)
    end

    # do the same with the inherited modules
    klass.definition.inherited_modules.each do |m|
      next if m.empty?
      id = @namespace_to_id[m.draw_identifier]
      m.force_id(id)
    end #unless klass.definition.inherited_modules.empty?

    # if we have not added an id for this element it is likely a duplicate
    # so do not draw it.
    next unless @namespace_to_id.has_value?(klass.id)

    @model << klass.draw_klass(@options)
    @diagram << klass.draw_diagram(@options)

    if @options.composition
      klass.constants.each do |k|
        # Likewise to the above, unless we have an id for the class
        # we don't want to draw the relationships
        next unless @namespace_to_id.has_value?(k.id)
        @model_associations << klass.draw_model_composition(k)
        @diagram_associations << klass.draw_diagram_composition(k)
      end
    end
  end

  xml = header
  xml += @model.draw { @model_associations.draw }
  xml += @diagram.draw { @diagram_associations.draw }
  xml += footer

  pretty_print(xml)
end