rrt_ruby 0.2.1-mswin32 → 0.3.0-mswin32

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,879 @@
1
+ RRT_DIR="rrt_ruby/" unless defined?(::RRT_DIR)
2
+ module RRT_RUBY
3
+ #This module is included by all elements that contain relations to other elements.
4
+ module HasRelations
5
+ #Adds a new Relation instance.
6
+ #
7
+ #Notice that it is possible to add a Relation that makes no sense , i.e.
8
+ #add a generalization from a class to a component package.
9
+ #
10
+ #_relation_ can also be an instance of RRT_RUBY::Class, Capsule, Protocol or a string with the fully qualified name of the supplier.
11
+ #
12
+ #Returns the Relation added or nil if nothing was added
13
+ def add_relation relation,rel_type=Relation::CLASS
14
+ case relation
15
+ when Relation
16
+ relation.parent=self.qualified_name
17
+ @relations=Array.new unless @relations
18
+ @relations<<relation
19
+ return relation
20
+ else
21
+ return add_relation(Relation.generate(relation,rel_type)) if relation
22
+ end
23
+ return nil
24
+ end
25
+ #Returns the array of Relation instances.
26
+ def relations
27
+ @relations=Array.new unless @relations
28
+ return @relations
29
+ end
30
+
31
+ #Returns true if the same relation exists
32
+ def has_relation? relation
33
+ @relations=Array.new unless @relations
34
+ return @relations.include?(relation)
35
+ end
36
+ end
37
+
38
+ #Errors from the Element derived classes are reported with this class
39
+ class ElementException<RuntimeError
40
+ end
41
+
42
+ #Errors reported when handling a RoseRT model (such as source control status, writability etc)
43
+ #are of this class
44
+ class ModelException<RuntimeError
45
+ end
46
+
47
+ #This is the base class for all model elements. It corresponds to RRTEI::ModelElement
48
+ class Element
49
+ attr_reader :name,:parent,:stereotype,:documentation
50
+ attr_writer :stereotype,:documentation
51
+ #element is the OLE Object of a RRTEI::ModelElement or derived class
52
+ def initialize element=nil
53
+ @name="<unnamed>"
54
+ @stereotype=""
55
+ @documentation=""
56
+ @parent=""
57
+ begin
58
+ @name=element.Name
59
+ qualified=element.GetQualifiedName
60
+ #construct the parent name
61
+ splitted=qualified.split("::")
62
+ @parent=splitted.collect{|s|
63
+ s unless splitted.size==0 || s==splitted[splitted.size-1]
64
+ }.compact.join('::')
65
+ @parent="" unless @parent
66
+ @stereotype=element.Stereotype
67
+ @documentation=element.Documentation
68
+ rescue
69
+ raise ElementException,"Error while initialising element: #{$!}"
70
+ end if element
71
+ end
72
+ #Returns the fully qualified name for this element
73
+ def qualified_name
74
+ return @name if @parent.empty?
75
+ return "#{@parent}::#{@name}"
76
+ end
77
+ def to_s
78
+ return "<<#{@stereotype}>>#{@name}"
79
+ end
80
+ #changes the name of the element and the parent of all contained elements
81
+ def name=name
82
+ @name=name
83
+ change_parentage
84
+ end
85
+ #changes the parent of the element and the parent of all contained elements
86
+ def parent=name
87
+ @parent=name
88
+ change_parentage
89
+ end
90
+ protected
91
+ #This should be overwritten to provide the elements to be updated
92
+ def contained_elements
93
+ return []
94
+ end
95
+ private
96
+ #Sets parent for all elements of _collection_
97
+ def change_parentage
98
+ contained_elements.each{|e|
99
+ e.parent=self.qualified_name
100
+ }
101
+ end
102
+ end
103
+ #Relation represents any kind of relation between elements in the model.
104
+ #
105
+ #At the moment a Relation instance can represent a dependency (class, package or component)
106
+ #a generalization or a realization.
107
+ #
108
+ #Associations are not yet implemented
109
+ class Relation<Element
110
+ CLASS="ClassDependency"
111
+ COMPONENT="ComponentDependency"
112
+ LOGICALPACKAGE="LogicalPackageDependency"
113
+ GENERALIZATION="Generalization"
114
+ REALIZE="RealizeRelation"
115
+ attr_reader :supplier,:relation_type
116
+ attr_writer :supplier,:relation_type
117
+
118
+ def initialize element=nil,type=""
119
+ @supplier=""
120
+ @relation_type=type
121
+ super(element)
122
+ begin
123
+ @supplier=element.GetSupplier.GetQualifiedName
124
+ rescue
125
+ raise ElementException,"Error while initialising relation: #{$!}"
126
+ end if element
127
+ end
128
+
129
+ #Two Relation objects are equal when they are of the same type and have the same supplier
130
+ def eql?(other)
131
+ return true if other.instance_of?(Relation)&&self.supplier==other.supplier && self.relation_type==other.relation_type
132
+ return false
133
+ end
134
+
135
+ def ==(other)
136
+ return eql?(other)
137
+ end
138
+
139
+ def to_s
140
+ case @relation_type
141
+ when CLASS : txt="Dependency to class #{@supplier}"
142
+ when COMPONENT : txt="Dependency to component #{@supplier}"
143
+ when LOGICALPACKAGE : txt="Dependency to package #{@supplier}"
144
+ when GENERALIZATION : txt="Generalization of #{@supplier}"
145
+ when REALIZE : txt="Realization of #{@supplier}"
146
+ else
147
+ txt="Unknown relation (#{@relation_type}) to #{@supplier}"
148
+ end
149
+ return txt
150
+ end
151
+
152
+ #Creates a Relation object
153
+ #_supplier_ can be an instance of RRT_RUBY::Class, Capsule, Protocol in which case the qualified name of the instance is used as a supplier
154
+ #
155
+ #or a string containing the fully qualified name of the supplier.
156
+ #
157
+ #Returns the Relation or nil if _supplier_ was invalid
158
+ #
159
+ #By default it creates class dependencies
160
+ def self.generate supplier,rel_type=Relation::CLASS
161
+ case supplier
162
+ when String
163
+ #nothing if the string is empty
164
+ return nil if supplier.empty?
165
+ rel=Relation.new(nil,rel_type)
166
+ rel.supplier=supplier
167
+ return rel
168
+ when RRT_RUBY::Class || Capsule || Protocol
169
+ rel=Relation.new(nil,rel_type)
170
+ rel.supplier=supplier.qualified_name
171
+ return rel
172
+ end
173
+ return nil
174
+ end
175
+ end
176
+
177
+
178
+ #~ class Model#:nodoc: all
179
+ #~ attr_reader :logical_view
180
+ #~ attr_reader :component_view
181
+ #~ attr_reader :deployment_view
182
+ #~ def initialize logical_view=nil,component_view=nil,deployment_view=nil
183
+ #~ if logical_view
184
+ #~ @logical_view=logical_view if logical_view.instance_of?(LogicalPackage)
185
+ #~ else
186
+ #~ @logical_view=LogicalPackage.new
187
+ #~ end
188
+ #~ @logical_view.name="Logical View"
189
+ #~ end
190
+ #~ end
191
+
192
+ ############################# Logical view #############################
193
+
194
+ #A LogicalPackage contains Element instances that belong to the logical view of a model.
195
+ #
196
+ #Using the LogicalPackage instance returned by Finder#root_logical_package you have access to the entire
197
+ #logical view contents of a model.
198
+ #
199
+ #A LogicalPackage contains Capsule, Class, Protocol and LogicalPackage instances.
200
+ class LogicalPackage<Element
201
+ include HasRelations
202
+ attr_reader :capsules,:classes,:packages,:protocols
203
+ def initialize element=nil
204
+ @index=Hash.new
205
+ @capsules=Array.new
206
+ @classes=Array.new
207
+ @packages=Array.new
208
+ @protocols=Array.new
209
+ super(element)
210
+ begin
211
+ @capsules=Extractor.extract_capsules(element.Capsules)
212
+ @classes=Extractor.extract_classes(element.Classes)
213
+ @packages=Extractor.extract_logical_packages(element.LogicalPackages)
214
+ @protocols=Extractor.extract_protocols(element.Protocols)
215
+ @relations=Extractor.extract_relations(element.GetLogicalPackageDependencies,Relation::LOGICALPACKAGE)
216
+ @relations+=Extractor.extract_relations(element.GetGeneralizations,Relation::GENERALIZATION)
217
+ update_index
218
+ rescue
219
+ raise ElementException,"Error while initialising logical package: #{$!}"
220
+ end if element
221
+ end
222
+
223
+ def to_s
224
+ return "#{@name}, #{@packages.size} packages, #{@capsules.size} capsules, #{@classes.size} classes, #{@protocols.size} protocols"
225
+ end
226
+ #Returns an array with all the classes contained by this package and it's subpackages
227
+ def all_classes
228
+ c=@classes
229
+ @packages.each{|p|
230
+ c+=p.all_classes
231
+ }
232
+ return c
233
+ end
234
+ #Returns an array with all the capsules contained by this package and it's subpackages
235
+ def all_capsules
236
+ c=@capsules
237
+ @packages.each{|p|
238
+ c+=p.all_capsules
239
+ }
240
+ return c
241
+ end
242
+ #Returns an array with all the protocols contained by this package and it's subpackages
243
+ def all_protocols
244
+ c=@protocols
245
+ @packages.each{|p|
246
+ c+=p.all_protocols
247
+ }
248
+ return c
249
+ end
250
+ #Returns a package contained in self whose name matches
251
+ #the given name.
252
+ def package(package_name)
253
+ collection=all_packages
254
+ return find_package_element(package_name,collection)
255
+ end
256
+
257
+ #Returns a capsule contained in self whose name matches
258
+ #the given name.
259
+ def capsule(capsule_name)
260
+ collection=all_capsules
261
+ return find_package_element(capsule_name,collection)
262
+ end
263
+ #Returns a class contained in self whose name matches
264
+ #the given name.
265
+ def class(name)
266
+ collection=all_classes
267
+ return find_package_element(name,collection)
268
+ end
269
+ #Returns a protocol contained in self whose name matches
270
+ #the given name.
271
+ def protocol(name)
272
+ collection=all_protocols
273
+ return find_package_element(name,collection)
274
+ end
275
+
276
+ #Searches all elements contained in this package for a match to _qualified_name_
277
+ def element(qualified_name)
278
+ el=@index[qualified_name]
279
+ @packages.each{|pkg|
280
+ el=pkg.element(qualified_name)
281
+ return el if el
282
+ } unless el
283
+ return el
284
+ end
285
+ #If the parameter is a string a package with that name will be created in self
286
+ #
287
+ #If the parameter is a LogicalPackage instance it will be added to self and the package's parent will change
288
+ def add_package package
289
+ case package
290
+ when String
291
+ pkg=LogicalPackage.new
292
+ pkg.name=package
293
+ return add_package(pkg)
294
+ when LogicalPackage
295
+ #set the parent for this package
296
+ package.parent=self.qualified_name
297
+ #add it to the packages
298
+ @packages=Array.new unless @packages
299
+ @packages<<package
300
+ #update the index
301
+ @index[package.qualified_name]=package
302
+ return package
303
+ end
304
+ end
305
+ #If the parameter is a string a class with that name will be created in self
306
+ #
307
+ #If the parameter is a Class instance it will be added to self and the classes's parent will change
308
+ def add_class cl
309
+ case cl
310
+ when String
311
+ c=RRT_RUBY::Class.new
312
+ c.name=cl
313
+ return add_class(c)
314
+ when RRT_RUBY::Class
315
+ #set the parent for this package
316
+ cl.parent=self.qualified_name
317
+ #add it to the classes
318
+ @classes=Array.new unless @classes
319
+ @classes<<cl
320
+ #update the index
321
+ @index[cl.qualified_name]=cl
322
+ return cl
323
+ end
324
+ end
325
+ #Sets the parent name and also recursively updates and contained elements.
326
+ def parent=package_name
327
+ super(package_name)
328
+ update_index
329
+ end
330
+ #Sets the name and also recursively updates the parent name for contained elements.
331
+ def name=new_name
332
+ super(new_name)
333
+ update_index
334
+ end
335
+ #Returns an array with all packages contained in this package
336
+ #
337
+ #If you have the following structure
338
+ # A contains B,C
339
+ # B contains D,E
340
+ # D contains F
341
+ #you will get [B,C,D,F,E]
342
+ def all_packages
343
+ c=@packages
344
+ @packages.each{|p|
345
+ c+=p.all_packages
346
+ }
347
+ return c.uniq
348
+ end
349
+ protected
350
+ #all contained elements
351
+ def contained_elements
352
+ return @index.values+self.relations
353
+ end
354
+ private
355
+ def find_package_element name,collection
356
+ ret=collection.find{|p|
357
+ p.qualified_name==name
358
+ }
359
+ #check the simple name unless already matched
360
+ ret=collection.find{|p|
361
+ p.name==name
362
+ } unless ret
363
+ return ret
364
+ end
365
+ #Adds the entries to the Hash
366
+ def update_index
367
+ @classes.each{|e|
368
+ @index[e.qualified_name]=e
369
+ }
370
+ @capsules.each{|e|
371
+ @index[e.qualified_name]=e
372
+ }
373
+ @packages.each{|e|
374
+ @index[e.qualified_name]=e
375
+ }
376
+ @protocols.each{|e|
377
+ @index[e.qualified_name]=e
378
+ }
379
+ self.relations.each{|e|
380
+ @index[e.qualified_name]=e
381
+ }
382
+ end
383
+
384
+ end
385
+
386
+ #Represents a Class element in a model
387
+ class Class<Element
388
+ include HasRelations
389
+ attr_reader :attributes
390
+ def initialize element=nil
391
+ @attributes=Hash.new
392
+ super(element)
393
+ begin
394
+ @attributes=Extractor.extract_attributes(element)
395
+ @relations=Extractor.extract_relations(element.GetClassDependencies,Relation::CLASS)
396
+ @relations+=Extractor.extract_relations(element.GetGeneralizations,Relation::GENERALIZATION)
397
+ @relations+=Extractor.extract_relations(element.GetRealizeRelations ,Relation::REALIZE)
398
+ rescue
399
+ raise ElementException,"error while initialising class: #{$!}"
400
+ end if element
401
+ end
402
+ #If the parameter is a string an attribute with that name will be created in self
403
+ #
404
+ #If the parameter is an Attribute instance it will be added to self and the Attribute's parent will change
405
+ #
406
+ #Returns the added Attribute, nil if something other than String or Attribute was provided.
407
+ def add_attribute attr
408
+ case attr
409
+ when String
410
+ c=Attribute.new
411
+ c.name=attr
412
+ return add_attribute(c)
413
+ when Attribute
414
+ #set the parent for this package
415
+ attr.parent=self.qualified_name
416
+ @attributes[attr.name]=attr
417
+ return attr
418
+ end
419
+ return nil
420
+ end
421
+
422
+ def to_s
423
+ super()+", #{@attributes.size} attributes"
424
+ end
425
+ protected
426
+ #all contained elements
427
+ def contained_elements
428
+ collection=self.attributes.values
429
+ collection+=self.relations
430
+ return collection
431
+ end
432
+ end
433
+
434
+ #Represents a Capsule element in a model
435
+ class Capsule<Class
436
+ include HasRelations
437
+ attr_reader :roles, :connectors
438
+ def initialize element=nil
439
+ @roles=Array.new
440
+ @connectors=Array.new
441
+ super(element)
442
+ begin
443
+ #get the roles out of the element
444
+ @roles=Extractor.extract_roles(element.Structure.ClassifierRoles)
445
+ @connectors=Extractor.extract_connectors(element.Structure.Connectors)
446
+ rescue
447
+ raise ElementException,"Error while initialising capsule: #{$!}"
448
+ end if element
449
+ end
450
+
451
+ #Adds a Role instance to this Capsule's roles.
452
+ def add_role role
453
+ begin
454
+ role.parent=self.qualified_name
455
+ @roles<<role
456
+ end if role.instance_of?(Role)
457
+ end
458
+
459
+ def to_s
460
+ return "#{@name}, #{@roles.size} roles, #{@relations.size} relations"
461
+ end
462
+ protected
463
+ #all contained elements
464
+ def contained_elements
465
+ collection=self.roles
466
+ collection=self.connectors
467
+ collection+=self.relations
468
+ return collection
469
+ end
470
+ end
471
+
472
+ #Represents an Attribute element.
473
+ #
474
+ #Attributes are member and/or class variables in classes and capsules
475
+ class Attribute<Element
476
+ #default Attribute value
477
+ attr_reader :init_value
478
+ #Attribute type
479
+ attr_reader :type
480
+ attr_writer :init_value, :type
481
+
482
+ def initialize element=nil
483
+ @init_value=""
484
+ @type=nil
485
+ super(element)
486
+ begin
487
+ @init_value=element.InitValue
488
+ @type=element.Type
489
+ rescue
490
+ raise ElementException,"Error while initialising attribute: #{$!}"
491
+ end if element
492
+ end
493
+
494
+ def to_s
495
+ return "#{@name}=#{@init_value}/#{@type}"
496
+ end
497
+ end
498
+
499
+ #A Role is an instance of a Capsule within another Capsule (a composition relation between Capsule objects)
500
+ class Role<Element
501
+ attr_reader :class_name, :cardinality, :capsule
502
+ def initialize element=nil
503
+ @class_name=""
504
+ @cardinality=""
505
+ @capsule=nil
506
+ super(element)
507
+ begin
508
+ #name for the class and cardinality
509
+ @class_name=element.ClassifierName
510
+ @cardinality=element.multiplicity
511
+ #checking against the name of the parent ensures that we avoid endless loops
512
+ @capsule=Capsule.new(element.Classifier) if element.Classifier.IsClass("Capsule") && element.Classifier.name==@parent
513
+ rescue
514
+ raise ElementException,"Error while initialising role: #{$!}"
515
+ end
516
+ end
517
+
518
+ def to_s
519
+ return "#{@name}/#{@class_name}"
520
+ end
521
+ end
522
+
523
+ #A Connector is a connection between two wired ports.
524
+ #
525
+ #Connector is a member of Capsule indicating wired connections with contained ports.
526
+ class Connector<Element
527
+ attr_reader :connects_to,:cardinality
528
+ def initialize element
529
+ @connects_to=Array.new
530
+ @cardinality="*"
531
+ super(element)
532
+ begin
533
+ #this gets name of the capsule containing the port this connector connects to.
534
+ #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)
535
+ @connects_to<<element.PortRole1.ParentCapsuleRole.Name if element.PortRole1
536
+ @connects_to<<element.PortRole2.ParentCapsuleRole.Name if element.PortRole2
537
+ @cardinality=element.Cardinality
538
+ rescue
539
+ raise ElementException,"error while initialising connector:#{$!}"
540
+ end if element
541
+ end
542
+
543
+ def to_s
544
+ super()
545
+ end
546
+ end
547
+
548
+ #A Protocol is a class defining an asynchronous interface for Capsule use.
549
+ class Protocol<Element
550
+ include HasRelations
551
+ def initialize element=nil
552
+ super(element)
553
+ end
554
+
555
+ def to_s
556
+ super()
557
+ end
558
+ end
559
+
560
+ ############################## Component View ##########################
561
+
562
+ #A ComponentPackage contains Component and ComponentPackage instances
563
+ #
564
+ #Components come in two types: Executable and Library
565
+ class ComponentPackage<Element
566
+ include HasRelations
567
+ attr_reader :components,:packages
568
+ def initialize element=nil
569
+ @index=Hash.new
570
+ @packages=Array.new
571
+ @components=Array.new
572
+ super(element)
573
+ begin
574
+ @relations=Extractor.extract_relations(element.GetComponentDependencies,Relation::COMPONENT)
575
+ @components=Extractor.extract_components(element.Components)
576
+ @packages=Extractor.extract_component_packages(element.ComponentPackages)
577
+ update_index
578
+ rescue
579
+ raise ElementException,"Error while initialising component package: #{$!}"
580
+ end if element
581
+ end
582
+ #Returns an array with all packages contained in this package
583
+ #
584
+ #If you have the following structure
585
+ # A contains B,C
586
+ # B contains D,E
587
+ # D contains F
588
+ #you will get [B,C,D,F,E]
589
+ def all_packages
590
+ c=@packages
591
+ @packages.each{|p|
592
+ c+=p.all_packages
593
+ }
594
+ return c.uniq
595
+ end
596
+
597
+ def all_components
598
+ c=@components
599
+ @packages.each{|p|
600
+ c+=p.all_components
601
+ }
602
+ return c.uniq
603
+ end
604
+ protected
605
+ #all contained elements - to use for changing parentage
606
+ def contained_elements
607
+ return @index.values+self.relations
608
+ end
609
+ private
610
+ #Adds the entries to the Hash
611
+ def update_index
612
+ @components.each{|e|
613
+ @index[e.qualified_name]=e
614
+ }
615
+ @packages.each{|e|
616
+ @index[e.qualified_name]=e
617
+ }
618
+ self.relations.each{|e|
619
+ @index[e.qualified_name]=e
620
+ }
621
+ end
622
+ end
623
+ #Represents an RRT Component
624
+ class Component<Element
625
+ include HasRelations
626
+ attr_reader :platform,:type
627
+ def initialize element=nil
628
+ super(element)
629
+ begin
630
+ @type=element.Type
631
+ @platform=element.Platform
632
+ @relations=Extractor.extract_relations(element.GetComponentDependencies,Relation::COMPONENT)
633
+ rescue
634
+ raise ElementException,"error while initialising element: #{$!}"
635
+ end if element
636
+ end
637
+ def to_s
638
+ super()+", #{@type}/#{@platform}."
639
+ end
640
+ end
641
+ #A Library Component
642
+ class Library<Component
643
+ #attr_reader :output_directory,:unit_name
644
+
645
+ def initialize element=nil
646
+ super(element)
647
+ end
648
+ def to_s
649
+ super()
650
+ end
651
+ end
652
+
653
+ #An Executable Component
654
+ class Executable<Component
655
+ attr_reader :topcapsule
656
+ attr_writer :topcapsule
657
+
658
+ def initialize element=nil
659
+ @topcapsule=""
660
+ super(element)
661
+ begin
662
+ @topcapsule=element.FindProperty("OT::CppExec","TopCapsule").Value.sub("[event_ui\r\n\tdescription='","")
663
+ @topcapsule.sub!(/'\r\n\tcaption='Select.+\n.*/,"")
664
+ rescue
665
+ raise ElementException,"error while initialising element: #{$!}"
666
+ end if element
667
+ end
668
+ def to_s
669
+ super()+", #{@topcapsule}."
670
+ end
671
+ end
672
+
673
+
674
+ ############################## Deployment View ##########################
675
+
676
+ #A DeploymentPackage contains Processor and DeploymentPackage instances
677
+ class DeploymentPackage<Element
678
+ attr_reader :packages
679
+ def initialize element=nil
680
+ @index=Hash.new
681
+ @packages=Array.new
682
+ super(element)
683
+ begin
684
+ @packages=Extractor.extract_deployment_packages(element.DeploymentPackages)
685
+ update_index
686
+ rescue
687
+ raise ElementException,"Error while initialising deployment package: #{$!}"
688
+ end if element
689
+ end
690
+ #Returns an array with all packages contained in this package
691
+ #
692
+ #If you have the following structure
693
+ # A contains B,C
694
+ # B contains D,E
695
+ # D contains F
696
+ #you will get [B,C,D,F,E]
697
+ def all_packages
698
+ c=@packages
699
+ @packages.each{|p|
700
+ c+=p.all_packages
701
+ }
702
+ return c.uniq
703
+ end
704
+ protected
705
+ #all contained elements - to use for changing parentage
706
+ def contained_elements
707
+ return @index.values
708
+ end
709
+ private
710
+ #Adds the entries to the Hash
711
+ def update_index
712
+ @packages.each{|e|
713
+ @index[e.qualified_name]=e
714
+ }
715
+ end
716
+ end
717
+
718
+ #A Processor defines a unit of the deployment view
719
+ class Processor<Element
720
+ attr_reader :cpu,:os,:address,:server,:instances
721
+ def initialize element=nil
722
+ @cpu=""
723
+ @os=""
724
+ @address=""
725
+ @server=""
726
+ @instances=Array.new
727
+ super(element)
728
+ begin
729
+ @cpu=element.CPU
730
+ @os=element.OS
731
+ @address=element.Address
732
+ @server=element.ServerAddress
733
+ @instances=Extractor.extract_instances(element)
734
+ rescue
735
+ raise ElementException,"error while initialising element: #{$!}"
736
+ end if element
737
+ end
738
+ def to_s
739
+ return super()+", #{@os}/#{@cpu}, #{@address}, #{@processes.size} processes"
740
+ end
741
+ end
742
+ #An Instance of an Executable resides in a Processor.
743
+ class Instance<Element
744
+ def initialize element=nil
745
+ #@component=nil
746
+ begin
747
+ super(element)
748
+ #@component=element.Component
749
+ rescue
750
+ raise ElementException,"error while initialising element #{$!}"
751
+ end if element
752
+ end
753
+ def to_s
754
+ super()#+", #{@component}"
755
+ end
756
+ end
757
+ #~ class ExternalLibrary<Component
758
+ #~ def initialize element
759
+ #~ begin
760
+ #~ super(element)
761
+ #~ rescue
762
+ #~ raise ElementException,"error while initialising element"
763
+ #~ end
764
+ #~ end
765
+ #~ def to_s
766
+ #~ super()
767
+ #~ end
768
+ #~ end
769
+ private
770
+ #The methods in this module perform conversions from RRTEI element collections to arrays of RRT_RUBY class instances
771
+ module Extractor
772
+ def self.extract_classes col
773
+ ar=Array.new
774
+ count=col.Count
775
+ 1.upto(count){|i|
776
+ ar<<RRT_RUBY::Class.new(col.GetAt(i))
777
+ }
778
+ return ar
779
+ end
780
+ def self.extract_capsules col
781
+ ar=Array.new
782
+ count=col.Count
783
+ 1.upto(count){|i|
784
+ ar<<Capsule.new(col.GetAt(i))
785
+ }
786
+ return ar
787
+ end
788
+ def self.extract_protocols col
789
+ ar=Array.new
790
+ count=col.Count
791
+ 1.upto(count){|i|
792
+ ar<<Protocol.new(col.GetAt(i))
793
+ }
794
+ return ar
795
+ end
796
+ def self.extract_logical_packages col
797
+ ar=Array.new
798
+ count=col.Count
799
+ 1.upto(count){|i|
800
+ ar<<LogicalPackage.new(col.GetAt(i))
801
+ }
802
+ return ar
803
+ end
804
+ def self.extract_component_packages col
805
+ ar=Array.new
806
+ count=col.Count
807
+ 1.upto(count){|i|
808
+ ar<<ComponentPackage.new(col.GetAt(i))
809
+ }
810
+ return ar
811
+ end
812
+ def self.extract_deployment_packages col
813
+ ar=Array.new
814
+ count=col.Count
815
+ 1.upto(count){|i|
816
+ ar<<DeploymentPackage.new(col.GetAt(i))
817
+ }
818
+ return ar
819
+ end
820
+ def self.extract_components col
821
+ ar=Array.new
822
+ count=col.Count
823
+ 1.upto(count){|i|
824
+ type=col.GetAt(i).Type
825
+ ar<<RRT_RUBY::Executable.new(col.GetAt(i)) if type=~/Executable/
826
+ ar<<RRT_RUBY::Library.new(col.GetAt(i)) if type=~/Library/ && !(type=~/External/)
827
+ ar<<RRT_RUBY::Component.new(col.GetAt(i)) if type=~/External/
828
+
829
+ }
830
+ return ar
831
+ end
832
+ #extracts information out of the OLE element to construct the list of Roles contained in the capsule
833
+ def self.extract_roles col
834
+ ar=Array.new
835
+ count=col.Count
836
+ 1.upto(count){|i|
837
+ ar<<Role.new(col.GetAt(i))
838
+ }
839
+ return ar
840
+ end
841
+ #extracts information out of the OLE element to construct the list of Connectors contained in the capsule
842
+ def self.extract_connectors col
843
+ ar=Array.new
844
+ count=col.Count
845
+ 1.upto(count){|i|
846
+ ar<<Connector.new(col.GetAt(i))
847
+ }
848
+ return ar
849
+ end
850
+ #extracts the relations of a given type
851
+ def self.extract_relations col,rel_type
852
+ ar=Array.new
853
+ count=col.Count
854
+ 1.upto(count){|i|
855
+ ar<<Relation.new(col.GetAt(i),rel_type)
856
+ }
857
+ return ar
858
+ end
859
+ #extracts the attributes from a class element
860
+ def self.extract_attributes element
861
+ ar=Hash.new
862
+ col=element.Attributes
863
+ count=col.Count
864
+ 1.upto(count){|i|
865
+ a=Attribute.new(col.GetAt(i))
866
+ ar[a.name]=a
867
+ }
868
+ return ar
869
+ end
870
+ #extracts the instances from a processor element
871
+ def self.extract_instances(element)
872
+ comps=element.ComponentInstances
873
+ cnt=comps.Count
874
+ 1.upto(cnt){|i|
875
+ @processes<<Instance.new(comps.GetAt(i))
876
+ }
877
+ end
878
+ end
879
+ end