Class: Clazz

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

Direct Known Subclasses

Enumeration

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(xml, parent_tag) ⇒ Clazz

Returns a new instance of Clazz.


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
# File 'lib/xmimodel/clazz.rb', line 40

def initialize(xml, parent_tag)		
	super(xml, parent_tag)

	@package = parent_tag.parent_tag
			
	@name = xml.attribute("name").to_s.strip
	
	@attributes = Array.new
	XmiHelper.attributes(xml).each do |uml_attribute|
		attribute = Attribute.new(uml_attribute, self)
		@attributes << attribute			
	end

	@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

	@operations = Array.new
	XmiHelper.operations(xml).each do |uml_operation|
		tagged_value = Operation.new(uml_operation, self)
		@operations << tagged_value
	end

	# SerĂ¡ povoado quando tratar dos objetos do tipo Genezalization
	@children = Array.new

	@associations = Array.new
	@associations_end = Array.new

end

Instance Attribute Details

#associationsArray<Association> (readonly)

Returns Class associations.

Returns:


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

def associations
  @associations
end

#associations_endArray<AssociationEnd> (readonly)

Returns Class associations end.

Returns:


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

def associations_end
  @associations_end
end

#attributesArray<Attribute> (readonly)

Returns Class attributes.

Returns:


18
19
20
# File 'lib/xmimodel/clazz.rb', line 18

def attributes
  @attributes
end

#childrenArray<Clazz>

Return the child classes when has inheritance.

Returns:

  • (Array<Clazz>)

    Return the child classes when has inheritance.


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

def children
  @children
end

#nameObject (readonly)

Returns the value of attribute name


12
13
14
# File 'lib/xmimodel/clazz.rb', line 12

def name
  @name
end

#operationsObject (readonly)

Returns the value of attribute operations


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

def operations
  @operations
end

#packageString (readonly)

Returns Full Package name of class.

Returns:

  • (String)

    Full Package name of class.


15
16
17
# File 'lib/xmimodel/clazz.rb', line 15

def package
  @package
end

#parentClazz

Return the parent class when has inheritance.

Returns:

  • (Clazz)

    Return the parent class when has inheritance.


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

def parent
  @parent
end

#stereotypesArray<Stereotype> (readonly)

Returns Class stereotypes.

Returns:


21
22
23
# File 'lib/xmimodel/clazz.rb', line 21

def stereotypes
  @stereotypes
end

#tagged_valuesArray<TaggedValue> (readonly)

Returns Class tagged values.

Returns:


24
25
26
# File 'lib/xmimodel/clazz.rb', line 24

def tagged_values
  @tagged_values
end

Instance Method Details

#<=>(obj) ⇒ Object


174
175
176
# File 'lib/xmimodel/clazz.rb', line 174

def <=>(obj)
   	full_name <=> obj.full_name
end

#==(obj) ⇒ Object


178
179
180
181
182
183
184
185
# File 'lib/xmimodel/clazz.rb', line 178

def ==(obj)
	return false if obj.nil?
	if String == obj.class
		full_name == obj
	else
   		full_name == obj.full_name
   	end
end

#add_xml_attribute(xml_attribute) ⇒ Object


85
86
87
88
89
90
91
92
93
94
# File 'lib/xmimodel/clazz.rb', line 85

def add_xml_attribute(xml_attribute)
	parent = self.xml.at_xpath('./UML:Classifier.feature')
	if parent.nil?
		parent = Nokogiri::XML::Node.new('Classifier.feature', self.xml.document)
		self.xml << parent
	end		
	parent.inner_html = parent.inner_html + xml_attribute.to_xml

	@attributes << Attribute.new(xml_attribute, self)		
end

#add_xml_stereotype(xml) ⇒ Object

Parameters:

  • xml (Nokogiri::XML::Element, #read)

108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/xmimodel/clazz.rb', line 108

def add_xml_stereotype(xml)		
	parent = self.xml.at_xpath('./UML:ModelElement.stereotype')
	if parent.nil?
		parent = Nokogiri::XML::Node.new('ModelElement.stereotype', self.xml.document)
		self.xml << parent
	end		
	parent.inner_html = parent.inner_html + xml.to_xml

	stereotype = Stereotype.new(xml, self)
	@stereotypes << stereotype
	return stereotype
end

#association_end_by_name_and_participant(associations_end_name, participant) ⇒ AssociationEnd

Parameters:

  • associations_end_name (String, #read)
  • participant (Clazz, #read)

Returns:


125
126
127
128
129
# File 'lib/xmimodel/clazz.rb', line 125

def association_end_by_name_and_participant(associations_end_name, participant)
	obj = @associations_end.select{|obj| obj.name == associations_end_name && obj.participant == participant}
	return obj[0] if !obj.nil? && obj.size > 0
	nil
end

#associations_end_by_participant(participant) ⇒ Array<AssociationEnd>

Parameters:

  • participant (Clazz, #read)

Returns:


134
135
136
# File 'lib/xmimodel/clazz.rb', line 134

def associations_end_by_participant(participant)
	obj = @associations_end.select{|obj| obj.participant == participant}
end

#attribute_by_id(attribute_id) ⇒ Object


138
139
140
141
142
# File 'lib/xmimodel/clazz.rb', line 138

def attribute_by_id(attribute_id)
	attribute = @attributes.select{|obj| obj.id == attribute_id}
	return attribute[0] if !attribute.nil? && attribute.size > 0
	nil
end

#attribute_by_name(attribute_name) ⇒ Object


144
145
146
147
148
# File 'lib/xmimodel/clazz.rb', line 144

def attribute_by_name(attribute_name)
	attribute = @attributes.select{|obj| obj.name == attribute_name}
	return attribute[0] if !attribute.nil? && attribute.size > 0
	nil
end

#full_nameObject


187
188
189
# File 'lib/xmimodel/clazz.rb', line 187

def full_name
	"#{package.full_name}.#{name}"
end

#operation_by_id(operation_id) ⇒ Object


150
151
152
153
154
# File 'lib/xmimodel/clazz.rb', line 150

def operation_by_id(operation_id)
	operation = @operations.select{|obj| obj.id == operation_id}
	return operation[0] if !operation.nil? && operation.size > 0
	nil
end

#operation_by_name(operation_name) ⇒ Object


156
157
158
159
160
# File 'lib/xmimodel/clazz.rb', line 156

def operation_by_name(operation_name)
	operation = @operations.select{|obj| obj.name == operation_name}
	return operation[0] if !operation.nil? && operation.size > 0
	nil
end

#remove_attribute(attribute) ⇒ Object

Parameters:

  • Attribute

98
99
100
101
102
103
104
# File 'lib/xmimodel/clazz.rb', line 98

def remove_attribute(attribute)		
	
	id = attribute.id
	xml_attribute = attribute.parent_tag.xml.at_xpath("//UML:Attribute[@xmi.id='#{id}']")
	xml_attribute.remove	#puts "xml: #{attribute.parent_tag.xml}"

end

#stereotype_by_name(name) ⇒ Object


162
163
164
165
166
# File 'lib/xmimodel/clazz.rb', line 162

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) ⇒ Object


168
169
170
171
172
# File 'lib/xmimodel/clazz.rb', line 168

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_sObject


191
192
193
# File 'lib/xmimodel/clazz.rb', line 191

def to_s
	"Clazz[#{full_name}]"
end