Class: State

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

Direct Known Subclasses

ActionState, FinalState, PseudoState

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

Returns a new instance of State.


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

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

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

	if @name.nil? || @name.empty?
		
		if xml.name == "Pseudostate"
			if xml.attribute("kind").to_s == "initial"
				@name = "Initial State" 
				@type = :initial_state
			else
				@name = "Decision Point" 
				@type = :decision_point
			end
		end
		@name = "Final State" if xml.name == "FinalState"
	elsif xml.name == "FinalState"
		@name = "#{@name}"
		@type = :final_state
	end

	@stereotypes = Array.new
	stereotype_id = xml.attribute("stereotype").to_s
	if !stereotype_id.empty?
		uml_stereotype = XmiHelper.stereotype_by_id(xml, stereotype_id)
		stereotype = Stereotype.new(uml_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

	# SerĂ£o povoados em ActivityGraph
	@transitions = Array.new
	@from_transitions = Array.new
	@targets = Array.new		
end

Instance Attribute Details

#activity_graphObject (readonly)

Returns the value of attribute activity_graph


7
8
9
# File 'lib/xmimodel/state.rb', line 7

def activity_graph
  @activity_graph
end

#from_transitionsArray<Transition>

Returns:


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

def from_transitions
  @from_transitions
end

#nameObject (readonly)

Returns the value of attribute name


9
10
11
# File 'lib/xmimodel/state.rb', line 9

def name
  @name
end

#stereotypesObject (readonly)

Returns the value of attribute stereotypes


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

def stereotypes
  @stereotypes
end

#tagged_valuesObject (readonly)

Returns the value of attribute tagged_values


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

def tagged_values
  @tagged_values
end

#targetsArray<State>

Returns:


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

def targets
  @targets
end

#transitionsArray<Transition>

Returns:


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

def transitions
  @transitions
end

Instance Method Details

#full_nameObject


117
118
119
# File 'lib/xmimodel/state.rb', line 117

def full_name
	"#{@activity_graph.full_name} {'#{@name}'}"
end

#is_action_state?Boolean

Returns:

  • (Boolean)

83
84
85
# File 'lib/xmimodel/state.rb', line 83

def is_action_state?
	@type == :action_state
end

#is_decision_point?Boolean

Returns:

  • (Boolean)

75
76
77
# File 'lib/xmimodel/state.rb', line 75

def is_decision_point?
	@type == :decision_point
end

#is_final_state?Boolean

Returns:

  • (Boolean)

79
80
81
# File 'lib/xmimodel/state.rb', line 79

def is_final_state?
	@type == :final_state
end

#is_initial_state?Boolean

Returns:

  • (Boolean)

71
72
73
# File 'lib/xmimodel/state.rb', line 71

def is_initial_state?
	@type == :initial_state
end

#pathObject


87
88
89
90
91
92
93
# File 'lib/xmimodel/state.rb', line 87

def path
	if !source().nil?
		source().path + ":" + name
	else
		name
	end
end

#sourcesArray<State>

Returns:


96
97
98
99
100
101
102
103
# File 'lib/xmimodel/state.rb', line 96

def sources
	return @sources unless @sources.nil?
	@sources = Array.new
	@from_transitions.each do |t|
		@sources << t.source
	end
	@sources		
end

#stereotype_by_name(name) ⇒ Object


105
106
107
108
109
# File 'lib/xmimodel/state.rb', line 105

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

#tagged_value_by_name(tagged_value_name) ⇒ Object


111
112
113
114
115
# File 'lib/xmimodel/state.rb', line 111

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


121
122
123
# File 'lib/xmimodel/state.rb', line 121

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