Class: AssociationEnd

Inherits:
Tag
  • Object
show all
Defined in:
lib/xmimodel/association_end.rb

Instance Attribute Summary collapse

Attributes inherited from Tag

#id, #parent_tag, #xml

Instance Method Summary collapse

Methods inherited from Tag

#xml_root

Constructor Details

#initialize(xmls, index, parent_tag) ⇒ AssociationEnd

Returns a new instance of AssociationEnd.


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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/xmimodel/association_end.rb', line 49

def initialize(xmls, index, parent_tag)		
	super(xmls[index], parent_tag)

	@is_first = index == 0

	@xml_a = xmls[0]
	@xml_b = xmls[1]

	@tag = xmls[index]

	@xmi_model = parent_tag.parent_tag
	@association = parent_tag

	@participant_id = @xml.attribute("participant").to_s
	
	if @participant_id.nil? or @participant_id.empty?

		# argoUML
		c = @xml.at_xpath("./UML:AssociationEnd.participant/UML:Class")			
		@participant_id = c.attribute("xmi.idref").to_s unless c.nil?

		classifier = @xml.at_xpath("./UML:AssociationEnd.participant/UML:Classifier")
		if !classifier.nil?
			classifier_href = classifier.attribute("href").to_s
			paramns = classifier_href.split("|")
			puts "TODO: Read id #{paramns[1]} from the model #{paramns[0]}"
		end
		
	end

	@name = @xml.attribute("name").to_s

	if @name.empty?
		@name = index == 0 ? "EndA" : "EndB"
	end

	@visibility = @xml.attribute("visibility").to_s
	@is_navigable = @xml.attribute("isNavigable").to_s
	if "true" == @is_navigable
		@is_navigable = true 
	else
		@is_navigable = false
	end		

	@is_specification = @xml.attribute("isSpecification").to_s

	@ordering = @xml.attribute("ordering").to_s
	@aggregation = @xml.attribute("aggregation").to_s
	@target_scope = @xml.attribute("targetScope").to_s
	@changeability = @xml.attribute("changeability").to_s

	@multiplicity_range = XmiHelper.multiplicity_range(@xml)

	@stereotypes = Array.new
	stereotype_id = @xml.attribute("stereotype").to_s
	if !stereotype_id.empty?
		stereotype = XmiHelper.stereotype_by_id(@xml, stereotype_id)
		stereotype = Stereotype.new(stereotype, self)
		@stereotypes << stereotype			
	end
	XmiHelper.stereotypes(@xml).each do |uml_stereotype|
		stereotype = Stereotype.new(uml_stereotype, self)
		@stereotypes << stereotype
	end	

	@tagged_values = Array.new
	XmiHelper.tagged_values(@xml).each do |uml_tagged_value|
		tagged_value = TaggedValue.new(uml_tagged_value, self)
		@tagged_values << tagged_value
	end		
end

Instance Attribute Details

#aggregationString (readonly)

Returns:

  • (String)

26
27
28
# File 'lib/xmimodel/association_end.rb', line 26

def aggregation
  @aggregation
end

#associationAssociation (readonly)

Return the parent association of this association end

Returns:

  • (Association)

    Return the parent association of this association end


41
42
43
# File 'lib/xmimodel/association_end.rb', line 41

def association
  @association
end

#changeabilityString (readonly)

Returns:

  • (String)

32
33
34
# File 'lib/xmimodel/association_end.rb', line 32

def changeability
  @changeability
end

#is_firstBoolean (readonly)

Returns:

  • (Boolean)

47
48
49
# File 'lib/xmimodel/association_end.rb', line 47

def is_first
  @is_first
end

#is_navigableString (readonly)

Returns:

  • (String)

14
15
16
# File 'lib/xmimodel/association_end.rb', line 14

def is_navigable
  @is_navigable
end

#is_specificationString (readonly)

Returns:

  • (String)

17
18
19
# File 'lib/xmimodel/association_end.rb', line 17

def is_specification
  @is_specification
end

#multiplicity_rangeString (readonly)

Returns:

  • (String)

20
21
22
# File 'lib/xmimodel/association_end.rb', line 20

def multiplicity_range
  @multiplicity_range
end

#nameString (readonly)

Returns:

  • (String)

8
9
10
# File 'lib/xmimodel/association_end.rb', line 8

def name
  @name
end

#orderingString (readonly)

Returns:

  • (String)

23
24
25
# File 'lib/xmimodel/association_end.rb', line 23

def ordering
  @ordering
end

#other_endAssociationEnb

Return the other end of the association

Returns:

  • (AssociationEnb)

    Return the other end of the association


44
45
46
# File 'lib/xmimodel/association_end.rb', line 44

def other_end
  @other_end
end

#stereotypesArray<Stereotype> (readonly)

Returns Association end stereotypes.

Returns:

  • (Array<Stereotype>)

    Association end stereotypes.


35
36
37
# File 'lib/xmimodel/association_end.rb', line 35

def stereotypes
  @stereotypes
end

#tagged_valuesArray<TaggedValue> (readonly)

Returns Association end tagged values.

Returns:

  • (Array<TaggedValue>)

    Association end tagged values.


38
39
40
# File 'lib/xmimodel/association_end.rb', line 38

def tagged_values
  @tagged_values
end

#target_scopeString (readonly)

Returns:

  • (String)

29
30
31
# File 'lib/xmimodel/association_end.rb', line 29

def target_scope
  @target_scope
end

#visibilityString (readonly)

Returns:

  • (String)

11
12
13
# File 'lib/xmimodel/association_end.rb', line 11

def visibility
  @visibility
end

Instance Method Details

#==(obj) ⇒ Object


128
129
130
131
132
133
134
135
136
137
# File 'lib/xmimodel/association_end.rb', line 128

def ==(obj)
	return false if obj.nil?
	if String == obj.class
		@name == obj
	elsif AssociationEnd == obj.class
   		@name == obj.name && participant.full_name == obj.participant.full_name
   	else
   		return false
   	end
end

#full_nameString

Returns:

  • (String)

154
155
156
# File 'lib/xmimodel/association_end.rb', line 154

def full_name
	"#{@parent_tag.full_name}::#{@name}"
end

#participantClazz

Returns:


122
123
124
125
126
# File 'lib/xmimodel/association_end.rb', line 122

def participant
	return nil if @participant_id.nil? or @participant_id.empty?
	participant = @xmi_model.class_by_id(@participant_id)		
	return participant
end

#stereotype_by_name(name) ⇒ Stereotype

Returns:


140
141
142
143
144
# File 'lib/xmimodel/association_end.rb', line 140

def stereotype_by_name(name)
	stereotype = @stereotypes.select{|obj| obj == name}
	return stereotype[0] if !stereotype.nil? && stereotype.size > 0
	nil		
end

#tagged_value_by_name(tagged_value_name) ⇒ TaggedValue

Returns:


147
148
149
150
151
# File 'lib/xmimodel/association_end.rb', line 147

def tagged_value_by_name(tagged_value_name)
	tagged_value = @tagged_values.select{|obj| obj.name == tagged_value_name}
	return tagged_value[0] if !tagged_value.nil? && tagged_value.size > 0
	nil
end

#to_sString

Returns:

  • (String)

159
160
161
162
163
164
165
# File 'lib/xmimodel/association_end.rb', line 159

def to_s
	if participant.nil?
		return "AssociationEnd[#{name}]"
	else
		return "AssociationEnd[#{name} (#{participant.full_name}])" 
	end
end