rrt_ruby 0.2.1-mswin32 → 0.3.0-mswin32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/rrt_ruby/classes.rb +879 -0
- data/lib/rrt_ruby/finder.rb +264 -0
- data/lib/rrt_ruby/writer.rb +166 -0
- data/lib/rrt_ruby.rb +161 -18
- metadata +5 -6
- data/lib/rrt_ruby/rrt_component.rb +0 -177
- data/lib/rrt_ruby/rrt_deployment.rb +0 -96
- data/lib/rrt_ruby/rrt_generic.rb +0 -229
- data/lib/rrt_ruby/rrt_logical.rb +0 -314
data/lib/rrt_ruby/rrt_logical.rb
DELETED
@@ -1,314 +0,0 @@
|
|
1
|
-
#Contains the Logical View corresponding elements and Finder functionality.
|
2
|
-
#See RRT_RUBY::RRTLogical
|
3
|
-
|
4
|
-
#
|
5
|
-
RRT_DIR="rrt_ruby/" unless defined?(::RRT_DIR)
|
6
|
-
require RRT_DIR+'rrt_generic'
|
7
|
-
module RRT_RUBY
|
8
|
-
#Adds functionality for accessing the Logical View of
|
9
|
-
#a RoseRT model.
|
10
|
-
module RRT_RUBY::RRTLogical
|
11
|
-
class LogicalPackage<RRTGeneric::Element
|
12
|
-
attr_reader :capsules,:classes,:packages,:protocols,:parent
|
13
|
-
def initialize element
|
14
|
-
begin
|
15
|
-
super(element)
|
16
|
-
@capsules=extract_capsules(element.Capsules)
|
17
|
-
@classes=extract_classes(element.Classes)
|
18
|
-
@packages=extract_packages(element.LogicalPackages)
|
19
|
-
@protocols=extract_protocols(element.Protocols)
|
20
|
-
@parent=element.ParentLogicalPackage.GetQualifiedName
|
21
|
-
end
|
22
|
-
end
|
23
|
-
def to_s
|
24
|
-
return "#{@name}, #{@packages.size} packages, #{@capsules.size} capsules, #{@classes.size} classes, #{@protocols.size} protocols"
|
25
|
-
end
|
26
|
-
private
|
27
|
-
def extract_classes col
|
28
|
-
ar=Array.new
|
29
|
-
count=col.Count
|
30
|
-
1.upto(count){|i|
|
31
|
-
ar<<RRTLogical::Class.new(col.GetAt(i))
|
32
|
-
}
|
33
|
-
return ar
|
34
|
-
end
|
35
|
-
def extract_capsules col
|
36
|
-
ar=Array.new
|
37
|
-
count=col.Count
|
38
|
-
1.upto(count){|i|
|
39
|
-
ar<<Capsule.new(col.GetAt(i))
|
40
|
-
}
|
41
|
-
return ar
|
42
|
-
end
|
43
|
-
def extract_protocols col
|
44
|
-
ar=Array.new
|
45
|
-
count=col.Count
|
46
|
-
1.upto(count){|i|
|
47
|
-
ar<<Protocol.new(col.GetAt(i))
|
48
|
-
}
|
49
|
-
return ar
|
50
|
-
end
|
51
|
-
def extract_packages col
|
52
|
-
ar=Array.new
|
53
|
-
count=col.Count
|
54
|
-
1.upto(count){|i|
|
55
|
-
ar<<LogicalPackage.new(col.GetAt(i))
|
56
|
-
}
|
57
|
-
return ar
|
58
|
-
end
|
59
|
-
end
|
60
|
-
class Capsule<RRTGeneric::Element
|
61
|
-
attr_reader :roles,:connectors,:dependencies
|
62
|
-
def initialize element
|
63
|
-
begin
|
64
|
-
super(element)
|
65
|
-
#get the roles out of the element
|
66
|
-
@roles=extract_roles(element.Structure.ClassifierRoles)
|
67
|
-
@connectors=extract_connectors(element.Structure.Connectors)
|
68
|
-
@dependencies=extract_dependencies(element.GetClassDependencies)
|
69
|
-
rescue
|
70
|
-
raise RRTGeneric::ElementException.new(element),"error while initialising element: #{$!}"
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
def to_s
|
75
|
-
return "#{@name}, #{@roles.size} roles, #{@dependencies.size} dependencies"
|
76
|
-
end
|
77
|
-
|
78
|
-
private
|
79
|
-
#extracts information out of the OLE element to construct the list of Roles contained in the capsule
|
80
|
-
def extract_roles col
|
81
|
-
ar=Array.new
|
82
|
-
count=col.Count
|
83
|
-
1.upto(count){|i|
|
84
|
-
ar<<Role.new(col.GetAt(i))
|
85
|
-
}
|
86
|
-
return ar
|
87
|
-
end
|
88
|
-
#extracts information out of the OLE element to construct the list of Connectors contained in the capsule
|
89
|
-
def extract_connectors col
|
90
|
-
ar=Array.new
|
91
|
-
count=col.Count
|
92
|
-
1.upto(count){|i|
|
93
|
-
ar<<Connector.new(col.GetAt(i))
|
94
|
-
}
|
95
|
-
return ar
|
96
|
-
end
|
97
|
-
#extracts the classes with which this capsule has a dependency
|
98
|
-
def extract_dependencies col
|
99
|
-
ar=Array.new
|
100
|
-
count=col.Count
|
101
|
-
1.upto(count){|i|
|
102
|
-
ar<<RRTLogical::Class.new(col.GetAt(i).GetSupplierClassifier)
|
103
|
-
}
|
104
|
-
return ar
|
105
|
-
end
|
106
|
-
|
107
|
-
end
|
108
|
-
|
109
|
-
class Role<RRTGeneric::Element
|
110
|
-
attr_reader :class_name, :cardinality, :capsule, :parent
|
111
|
-
def initialize element
|
112
|
-
begin
|
113
|
-
super(element)
|
114
|
-
#name for the class and cardinality
|
115
|
-
@class_name=element.ClassifierName
|
116
|
-
@cardinality=element.multiplicity
|
117
|
-
#get the name of the capsule containing the role
|
118
|
-
@parent=element.ParentCollaboration.ParentClassifier.Name
|
119
|
-
#get the capsule for the role
|
120
|
-
@capsule=nil
|
121
|
-
#checking against the name of the parent ensures that we avoid endless loops
|
122
|
-
@capsule=Capsule.new(element.Classifier) if element.Classifier.IsClass("Capsule") && element.Classifier.name==@parent
|
123
|
-
rescue
|
124
|
-
raise RRTGeneric::ElementException.new(element),"error while initialising element: #{$!}"
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
def to_s
|
129
|
-
return "#{@name}/#{@class_name}"
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
|
134
|
-
class Connector<RRTGeneric::Element
|
135
|
-
attr_reader :connects_to,:cardinality
|
136
|
-
def initialize element
|
137
|
-
begin
|
138
|
-
super(element)
|
139
|
-
@connects_to=Array.new
|
140
|
-
#this gets name of the capsule containing the port this connector connects to.
|
141
|
-
#with this configuration the Connector is only to be used as a member of a capsule (so this defines one end of the connection and the parent object defines the other end)
|
142
|
-
@connects_to<<element.PortRole1.ParentCapsuleRole.Name if element.PortRole1
|
143
|
-
@connects_to<<element.PortRole2.ParentCapsuleRole.Name if element.PortRole2
|
144
|
-
@cardinality=element.Cardinality
|
145
|
-
rescue
|
146
|
-
raise RRTGeneric::ElementException.new(element),"error while initialising element:#{$!}"
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
def to_s
|
151
|
-
super()
|
152
|
-
end
|
153
|
-
end
|
154
|
-
class Class<RRTGeneric::Element
|
155
|
-
attr_reader :attributes
|
156
|
-
def initialize element
|
157
|
-
begin
|
158
|
-
super(element)
|
159
|
-
@attributes=extract_attributes(element)
|
160
|
-
rescue
|
161
|
-
raise RRTGeneric::ElementException.new(element),"error while initialising element: #{$!}"
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
|
-
def to_s
|
166
|
-
super()+", #{@attributes.size} attributes"
|
167
|
-
end
|
168
|
-
|
169
|
-
private
|
170
|
-
#extracts the attributes of this class
|
171
|
-
def extract_attributes element
|
172
|
-
ar=Hash.new
|
173
|
-
col=element.Attributes
|
174
|
-
count=col.Count
|
175
|
-
1.upto(count){|i|
|
176
|
-
a=Attribute.new(col.GetAt(i))
|
177
|
-
ar[a.name]=a
|
178
|
-
}
|
179
|
-
return ar
|
180
|
-
end
|
181
|
-
end
|
182
|
-
|
183
|
-
class Attribute<RRTGeneric::Element
|
184
|
-
attr_reader :init_value, :type
|
185
|
-
|
186
|
-
def initialize element
|
187
|
-
begin
|
188
|
-
super(element)
|
189
|
-
@init_value=element.InitValue
|
190
|
-
@type=element.Type
|
191
|
-
rescue
|
192
|
-
raise RRTGeneric::ElementException.new(element),"error while initialising element: #{$!}"
|
193
|
-
end
|
194
|
-
end
|
195
|
-
|
196
|
-
def to_s
|
197
|
-
return "#{@name}=#{@init_value}/#{@type}"
|
198
|
-
end
|
199
|
-
end
|
200
|
-
class Protocol<RRTGeneric::Element
|
201
|
-
def initialize element
|
202
|
-
begin
|
203
|
-
super(element)
|
204
|
-
rescue
|
205
|
-
raise RRTGeneric::ElementException.new(element),"error while initialising element: #{$!}"
|
206
|
-
end
|
207
|
-
end
|
208
|
-
|
209
|
-
def to_s
|
210
|
-
super()
|
211
|
-
end
|
212
|
-
end
|
213
|
-
|
214
|
-
#Adds functionlaity for querying component view elements.
|
215
|
-
module LogicalFinderModule
|
216
|
-
LOGICAL_PACKAGE='LogicalPackage'
|
217
|
-
#delivers all fully qualified capsule names under the defined package.
|
218
|
-
#If the parameter does not correspond to a logical view package it will return an empty array
|
219
|
-
#It will not recurse.
|
220
|
-
def capsule_names root_package,debug=false
|
221
|
-
raise RRTGeneric::FinderException.new(@modelname),"This Finder instance is invalid" unless @model
|
222
|
-
capsules=Array.new
|
223
|
-
#first of all find the package in the model
|
224
|
-
pkg= find_logical_package(root_package,debug)
|
225
|
-
begin
|
226
|
-
caps=pkg.capsules
|
227
|
-
@logger.debug("There are #{caps.size} capsules under #{pkg.qualifiedname}")
|
228
|
-
caps.each{|i|
|
229
|
-
capsules<<caps.qualifiedname
|
230
|
-
}
|
231
|
-
end if pkg
|
232
|
-
return capsules
|
233
|
-
end
|
234
|
-
#delivers all fully qualified package names under the defined package.
|
235
|
-
#If the parameter does not correspond to a logical view package it will return an empty array
|
236
|
-
#It will not recurse.
|
237
|
-
def package_names root_package,debug=false
|
238
|
-
raise RRTGeneric::FinderException.new(@modelname),"This Finder instance is invalid" unless @model
|
239
|
-
packages=Array.new
|
240
|
-
#first of all find the package in the model
|
241
|
-
pkg= find_logical_package(root_package,debug)
|
242
|
-
begin
|
243
|
-
caps=pkg.LogicalPackages
|
244
|
-
@logger.debug("There are #{caps.Count} packages under #{pkg.GetQualifiedName}")
|
245
|
-
cnt=caps.Count
|
246
|
-
1.upto(cnt){|i|
|
247
|
-
packages<<caps.GetAt(i).GetQualifiedName
|
248
|
-
}
|
249
|
-
end if pkg
|
250
|
-
return packages
|
251
|
-
end
|
252
|
-
|
253
|
-
#This will return the first logical view package matching the name or
|
254
|
-
#nil if no package is found
|
255
|
-
#if no fully qualified name is provided, then the first match is returned
|
256
|
-
def find_logical_package package_name,debug=false
|
257
|
-
ret=nil
|
258
|
-
raise RRTGeneric::FinderException.new(@modelname),"This Finder instance is invalid" unless @model
|
259
|
-
#get the simple package name
|
260
|
-
splitted=package_name.split("::")
|
261
|
-
simple_name=splitted[splitted.size-1] unless splitted.size==0
|
262
|
-
#get a collection with all the packages with the same name
|
263
|
-
col=@model.FindModelElements(simple_name)
|
264
|
-
count=col.Count
|
265
|
-
@logger.debug("There are #{count} packages named #{simple_name}")
|
266
|
-
1.upto(count){|i|
|
267
|
-
obj=col.GetAt(i)
|
268
|
-
#match the first if no qualified name is given
|
269
|
-
ret=LogicalPackage.new(obj) if obj&&package_name==simple_name&&obj.Name==simple_name && obj.IsClass(LOGICAL_PACKAGE)
|
270
|
-
#match the qualified name
|
271
|
-
ret=LogicalPackage.new(obj) if obj&&obj.GetQualifiedName==package_name && obj.IsClass(LOGICAL_PACKAGE)
|
272
|
-
}
|
273
|
-
col=nil
|
274
|
-
count=0
|
275
|
-
return ret
|
276
|
-
end
|
277
|
-
|
278
|
-
def find_capsule capsule_name
|
279
|
-
raise RRTGeneric::FinderException.new(@modelname),"This Finder instance is invalid" unless @model
|
280
|
-
#get the simple capsule name
|
281
|
-
splitted=capsule_name.split("::")
|
282
|
-
simple_name=splitted[splitted.size-1] unless splitted.size==0
|
283
|
-
#find it
|
284
|
-
col=@model.FindModelElements(simple_name)
|
285
|
-
count=col.Count
|
286
|
-
1.upto(count){|i|
|
287
|
-
it=col.GetAt(i)
|
288
|
-
#match the first if no qualified name is given
|
289
|
-
return Capsule.new(it) if it &&capsule_name==simple_name&&it.Name==capsule_name && it.IsClass("Capsule")
|
290
|
-
#match the qualified name
|
291
|
-
return Capsule.new(it) if it&&it.GetQualifiedName==capsule_name&& it.IsClass("Capsule")
|
292
|
-
}
|
293
|
-
@logger.debug("Capsule #{capsule_name} not found in #{@modelname}")
|
294
|
-
return nil
|
295
|
-
end
|
296
|
-
#returns the RRTLogical::Class instance of the first class with the provided name.
|
297
|
-
#nil if nothing is found
|
298
|
-
def find_class name
|
299
|
-
raise RRTGeneric::FinderException.new(@modelname) unless @model
|
300
|
-
col=@model.FindModelElements(name)
|
301
|
-
count=col.Count
|
302
|
-
1.upto(count){|i|
|
303
|
-
it=col.GetAt(i)
|
304
|
-
return Class.new(it) if it && it.Name==name && it.IsClass("Class")
|
305
|
-
}
|
306
|
-
return nil
|
307
|
-
end
|
308
|
-
end
|
309
|
-
#This is just for compatibility with the older scripts. The RRTFinder should be used instead.
|
310
|
-
class LogicalFinder<RRTGeneric::Finder
|
311
|
-
include RRTLogical::LogicalFinderModule
|
312
|
-
end
|
313
|
-
end
|
314
|
-
end
|