ontomde-uml2 1.0.4

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.
@@ -0,0 +1,638 @@
1
+ module Muml_Element
2
+ #defines wether the associated element is external to the model and should not trigger code generation.
3
+ rdf_safe_attr_reader_many :umlx_external
4
+ end
5
+
6
+ module Muml_Classifier
7
+ #defines wether this element comes from business model.
8
+ rdf_safe_attr_reader_many :umlx_businessMethod
9
+ end
10
+ module Muml_Operation
11
+ #defines wether this element comes from business model.
12
+ rdf_safe_attr_reader_many :umlx_businessMethod
13
+ end
14
+
15
+ module Mrdf_Model
16
+ def umlx_MarkAllAsbusinessMethod!
17
+ each { |k,m|
18
+ next unless m.kind_of?(Muml_Operation) || m.kind_of?(Muml_Classifier)
19
+ #do not force value if already set
20
+ next unless m.umlx_businessMethod.empty?
21
+ m.umlx_businessMethod=RDF_TRUE
22
+ }
23
+ end
24
+ end
25
+
26
+
27
+ module Muml_Property
28
+ # returns true if property is navigable
29
+ def umlx_isNavigable?
30
+ o=umlx_owner_one(true)
31
+ return false if o.nil?
32
+ return o.uml_ownedAttribute.include?(self)
33
+ end
34
+
35
+ # returns true if this property is not part of an association.
36
+ # An attribute whose type is a class is considered an association.
37
+ def umlx_isAttribute?
38
+ t=uml_type_one
39
+ ret=(uml_association.to_s.empty?) && (t.kind_of?(Muml_DataType)||t.kind_of?(Muml_Enumeration))
40
+ return ret
41
+ end
42
+
43
+ # returns true if this property is part of an association.
44
+ def umlx_isAssociation?
45
+ return (!umlx_isAttribute?) && (!uml_aggregation_one0.nil?) && (uml_aggregation_one.isNone?)
46
+ end
47
+
48
+ # returns true if this property is part of an shared association.
49
+ def umlx_isShared?
50
+ return (!umlx_isAttribute?) && (uml_aggregation_one.isShared?)
51
+ end
52
+ # returns true if this property is part of composite association
53
+ def umlx_isComposite?
54
+ return (!umlx_isAttribute?) && (!uml_aggregation_one0.nil?) && (uml_aggregation_one.isComposite?)
55
+ end
56
+
57
+ # copy elements to the attribute property in Muml_Classifier module
58
+ def umlx_copyToAttributeProperty(oa)
59
+ oa.uml_upperValue=self.uml_upperValue
60
+ oa.uml_lowerValue=self.uml_lowerValue
61
+ oa.uml_type=self.uml_type
62
+ oa.uml_isOrdered=self.uml_isOrdered
63
+ oa.uml_isUnique=self.uml_isUnique
64
+ end
65
+ end
66
+
67
+ module Muml_Parameter
68
+ # copy elements to the attribute property in Muml_Classifier module
69
+ def umlx_copyToAttributeProperty(oa)
70
+ oa.uml_upperValue=self.uml_upperValue
71
+ oa.uml_lowerValue=self.uml_lowerValue
72
+ oa.uml_type=self.uml_type
73
+ oa.uml_isOrdered=self.uml_isOrdered
74
+ oa.uml_isUnique=self.uml_isUnique
75
+ end
76
+ end
77
+
78
+
79
+ # Both Muml_Class and Muml_Interface
80
+ module Muml_Classifier
81
+ # returns true if this class directly carries
82
+ # associations, compositions or aggregations.
83
+ def umlx_hasRelation?
84
+ uml_ownedAttribute.each { |o|
85
+ return true unless o.umlx_isAttribute?
86
+ }
87
+ return false
88
+ end
89
+ end
90
+
91
+
92
+ module Muml_LiteralString
93
+ #Returns true if value is equal one
94
+ #NOTE:
95
+ #* IBM RSM uses LiteralUnlimitedNatural
96
+ #* Magicdraw uses LiteralInteger and LiteralString
97
+ def umlx_equalOne?
98
+ #log.debug { "not used ???" }
99
+ #log.debug { "LS=#{uri} #{uml_value_one}" }
100
+ return uml_value_one==1
101
+ end
102
+ def umlx_equalZero?
103
+ #log.debug { "not used ???" }
104
+ #log.debug { "LS=#{uri} #{uml_value_one}" }
105
+ return uml_value_one==0
106
+ end
107
+ end
108
+
109
+
110
+ module Muml_LiteralInteger
111
+ #Returns true if value is equal 1 (one)
112
+ #NOTE:
113
+ #* IBM RSM uses LiteralUnlimitedNatural
114
+ #* Magicdraw uses LiteralInteger and LiteralString
115
+ def umlx_equalOne?
116
+ return uml_value_one.to_i==1
117
+ end
118
+
119
+ #Returns true if value is equal 0 (zero)
120
+ #NOTE:
121
+ #* IBM RSM uses LiteralUnlimitedNatural
122
+ #* Magicdraw uses LiteralInteger and LiteralString
123
+ def umlx_equalZero?
124
+ return uml_value_one.to_i==0
125
+ end
126
+ end
127
+
128
+
129
+ module Muml_LiteralUnlimitedNatural
130
+ #Returns true if value is equal one
131
+ #NOTE:
132
+ #* IBM RSM uses LiteralUnlimitedNatural
133
+ #* Magicdraw uses LiteralInteger and LiteralString
134
+ def umlx_equalOne?
135
+ return uml_value_one.to_i==1
136
+ end
137
+
138
+ #Returns true if value is equal 0 (zero)
139
+ #NOTE:
140
+ #* IBM RSM uses LiteralUnlimitedNatural
141
+ #* Magicdraw uses LiteralInteger and LiteralString
142
+ def umlx_equalZero?
143
+ return uml_value_one.to_i==0
144
+ end
145
+ end
146
+
147
+
148
+ module Muml_TypedElement
149
+ #Returns true if upperValue is equal to one
150
+ #NOTE:
151
+ #* returns true if upperValue is undefined or empty
152
+ def umlx_upperValueIsOne?
153
+ return true if uml_upperValue.empty? # 1 is assumed to be defaut
154
+ return uml_upperValue_one.umlx_equalOne?
155
+ #return (uml_upperValue.empty? || uml_upperValue.to_s=="1")
156
+ end
157
+
158
+ #returns true if lowerValue is equal to zero
159
+ #NOTE:
160
+ #* returns true if lowerValue is undefined or empty
161
+ def umlx_lowerValueIsZero?
162
+ return true if uml_lowerValue.empty? # 0 is assumed to be defaut
163
+ return uml_lowerValue_one.umlx_equalZero?
164
+ #return (uml_lowerValue.empty? || uml_lowerValue.to_s=="0")
165
+ end
166
+ end
167
+
168
+
169
+ module Mrdf_Model
170
+ #TO BE DONE
171
+ def umlx_computeIsAnException
172
+ end
173
+ end
174
+
175
+
176
+ module Muml_Class
177
+ #TO BE DONE
178
+ #Returns true if this class is used as an exception
179
+ #
180
+ #NOTE:
181
+ #* Is a class meant to be an exception is *not* used in a throws clause, it will *not* be detected
182
+ def umlx_isAnException?
183
+ end
184
+
185
+ #TO BE DONE
186
+ def umlx_isARootException?
187
+ end
188
+ end
189
+
190
+
191
+ module Muml_Element
192
+ #returns true if element has an applied stereotype named stereotype_name
193
+ #test is not case sensitive
194
+ def umlx_hasStereotype?(stereotype_name)
195
+ uml_appliedStereotype.each { |s|
196
+ next unless s.uml_name.to_s.casecmp(stereotype_name.to_s)==0
197
+ return true
198
+ }
199
+ return false
200
+ end
201
+ end
202
+
203
+ module Muml_Element
204
+ #returns nil or element with the proper name in the current namespace
205
+ def umlx_getElementNamed(name)
206
+ return nil
207
+ end
208
+
209
+ end
210
+
211
+ module Muml_Classifier
212
+ #returns nil or element with the proper name in the current namespace
213
+ def umlx_getElementNamed(name)
214
+ uml_ownedAttribute.each { |om|
215
+ return om if om.uml_name.to_s==name
216
+ }
217
+ uml_ownedOperation.each { |om|
218
+ return om if om.uml_name.to_s==name
219
+ }
220
+ return super(name)
221
+ end
222
+ end
223
+ module Muml_Package
224
+ #returns nil or element with the proper name in the current namespace
225
+ def umlx_getElementNamed(name)
226
+ uml_ownedMember.each { |om|
227
+ return om if om.uml_name.to_s==name
228
+ }
229
+ return super(name)
230
+ end
231
+ end
232
+
233
+ module Mrdf_Model
234
+
235
+ #Model name to be ignored
236
+ #Typicaly containing metamodels
237
+ UMLX_IGNORE_MODELS=["UML2"]
238
+
239
+ #flag used to display found multiple models message only once
240
+ @@message_umlx_model_not_found_displayed=false
241
+
242
+ #return first uml model found in model
243
+ def umlx_model
244
+ ret=[]
245
+ each { |k,c|
246
+ #next unless c.kind_of?(Muml_Class)
247
+ #p=c.umlx_model
248
+ #next if p.kind_of?(Muml_Profile)
249
+ #next if c.umlx_model.uml_name=="UML2"
250
+ #return p
251
+ next unless c.kind_of?(Muml_Model)
252
+ next if c.kind_of?(Muml_Profile)
253
+ next if UMLX_IGNORE_MODELS.include?(c.uml_name.to_s)
254
+ ret<< c
255
+ }
256
+ if ret.empty?
257
+ log.error { "umlx_model:no model found in rdf_model" }
258
+ return nil
259
+ elsif ret.length > 1
260
+ ms=""; ret.each { |m| ms=ms+m.uml_name.to_s+"," }
261
+ if !@@message_umlx_model_not_found_displayed
262
+ #log.debug { "umlx_model:found multiple models: #{ms}. Returning first one found.(#{ret[0]})" }
263
+ @@message_umlx_model_not_found_displayed=true
264
+ end
265
+ end
266
+ return ret[0]
267
+ end
268
+ end
269
+ module Muml_Classifier
270
+ #Returns UML Model containing self.
271
+ def umlx_model
272
+ p=umlx_package
273
+ return p.umlx_model unless p.nil?
274
+
275
+ #(uml_nestedClassifier_inv).each { |o|
276
+ # puts "o=#{o}"
277
+ #}
278
+
279
+ log.error { "umlx_model:no model found for #{self.class.name} #{self}" }
280
+ return rdf_model.umlx_model
281
+ end
282
+ end
283
+
284
+
285
+ module Muml_Package
286
+ #Returns UML Model containing self.
287
+ def umlx_model
288
+ p=umlx_owner_one
289
+ return p.umlx_model unless p.nil?
290
+ return self
291
+ end
292
+ end
293
+
294
+
295
+ module Muml_Namespace
296
+ #returns a boolean datatype
297
+ def umlx_dataType_boolean
298
+ return umlx_getOrCreateDataType("boolean")
299
+ end
300
+ # returns a string datatype
301
+ def umlx_dataType_string
302
+ return umlx_getOrCreateDataType("string")
303
+ end
304
+ # returns an integer datatype
305
+ def umlx_dataType_integer
306
+ return umlx_getOrCreateDataType("int")
307
+ end
308
+ # returns an long integer datatype
309
+ def umlx_dataType_long
310
+ return umlx_getOrCreateDataType("long")
311
+ end
312
+
313
+ # datatypes are created and looked up in umlx_reserved_model.
314
+ def umlx_getOrCreateDataType(m_name)
315
+ mod=umlx_reserved_model
316
+ p=mod.umlx_getElementNamed(m_name)
317
+ return p unless p.nil?
318
+ return mod.umlx_createAndAddDataType(m_name,m_name)
319
+ end
320
+
321
+ # stereotype are created and looked up in umlx_reserved_model.
322
+ def umlx_getOrCreateStereotype(m_name)
323
+ mod=umlx_reserved_model
324
+ p=mod.umlx_getElementNamed(m_name)
325
+ return p unless p.nil?
326
+ return mod.umlx_createAndAddStereotype(m_name,m_name)
327
+ end
328
+
329
+
330
+ #special token used to force umlx_getOrCreateProc to search every model
331
+ UMLX_SEARCH_EVERY_MODEL=13579
332
+
333
+ # For internal use.
334
+ # Lookup element name qual_name.
335
+ # Returns element if found, yields otherwise.
336
+ def umlx_getOrCreateProc(qual_name,startpoint=nil,&create)
337
+ #TODO Patch pour la gestion des génériques : A faire mieux qd gestion complète
338
+ #Ne marche pas si plusiuers génériques encastrées
339
+ if !qual_name.nil? && qual_name.include?("<")
340
+ beforeGen = qual_name.split("<")
341
+ s=beforeGen[0].split(".")
342
+ if beforeGen.length > 1
343
+ generic = "<#{beforeGen[1]}"
344
+ s[s.length-1] += generic
345
+ end
346
+ else
347
+ s=qual_name.split(".")
348
+ end
349
+ i=s.size
350
+ c_name=s[i-1]
351
+ s.delete_at(i-1)
352
+
353
+ searchPath=[]
354
+ if startpoint==UMLX_SEARCH_EVERY_MODEL
355
+ rdf_model.each { |k,c|
356
+ if c.kind_of?(Muml_Model)
357
+ searchPath<< c
358
+ end
359
+ }
360
+ searchPath<< umlx_reserved_model
361
+ elsif startpoint.nil?
362
+ searchPath<< umlx_reserved_model
363
+ else
364
+ searchPath=[startpoint]
365
+ end
366
+
367
+ c=nil
368
+ # make cur global
369
+ cur=nil
370
+ searchPath.each { |cur|
371
+ creationOK=(cur==startpoint) || (cur==umlx_reserved_model)
372
+ s.each { |m_name|
373
+ p=cur.umlx_getElementNamed(m_name)
374
+ break if p.nil? && !creationOK
375
+ #puts "---> #{cur.rdf_uri}/#{m_name}" if (p.nil?)
376
+ cur=(!p.nil?) ? p : cur.umlx_createAndAddPackage("#{cur.rdf_uri}/#{m_name}",m_name)
377
+ }
378
+ c=cur.umlx_getElementNamed(c_name)
379
+ break unless c.nil?
380
+ }
381
+ c=yield(cur,qual_name,c_name) if c.nil?
382
+ return c
383
+ end
384
+
385
+ # Retrieves a package from its qualified name.
386
+ # Package will be created if not present in model.
387
+ # Example:
388
+ # umlx_getOrCreatePackage("com.mycompany")
389
+ def umlx_getOrCreatePackage(qual_name,startpoint=nil)
390
+ return umlx_getOrCreateProc(qual_name,startpoint) { |owner,qual_name,c_name|
391
+ owner.umlx_createAndAddPackage("#{owner.rdf_uri}/#{qual_name}",c_name)
392
+ }
393
+ end
394
+
395
+
396
+ # Retrieves an interface from its qualified name.
397
+ # Class will be created if not present in model.
398
+ # Example:
399
+ # umlx_getOrCreateInterface("java.util.Set")
400
+ def umlx_getOrCreateInterface(qual_name,startpoint=nil)
401
+ return umlx_getOrCreateProc(qual_name,startpoint) { |owner,qual_name,c_name|
402
+ ret=owner.umlx_createAndAddInterface(qual_name,c_name)
403
+ ret.umlx_external=RDF_TRUE
404
+ ret
405
+ }
406
+ end
407
+
408
+ # Retrieves an enumeration from its qualified name.
409
+ # Class will be created if not present in model.
410
+ # Example:
411
+ # umlx_getOrCreateEnumeration("com.mycompany.myEnum")
412
+ def umlx_getOrCreateEnumeration(qual_name,startpoint=nil)
413
+ return umlx_getOrCreateProc(qual_name,startpoint) { |owner,qual_name,c_name|
414
+ owner.umlx_createAndAddEnumeration(qual_name,c_name)
415
+ }
416
+ end
417
+
418
+ # Retrieves a class from its qualified name.
419
+ # Class will be created if not present in model.
420
+ # Example:
421
+ # umlx_getOrCreateClass("java.util.HashSet")
422
+ def umlx_getOrCreateClass(qual_name,startpoint=nil)
423
+ ret=umlx_getOrCreateProc(qual_name,startpoint){ |owner,qual_name,c_name|
424
+ c=owner.umlx_createAndAddClass(qual_name,c_name)
425
+ c.umlx_external=RDF_TRUE
426
+ c.db_isTransient=RDF_TRUE
427
+ c
428
+ }
429
+
430
+ if ! ret.kind_of?(Cuml_Class)
431
+ log.error { <<END
432
+ **** ERROR NAME CLASH DETECTED ****
433
+ Creating a class named #{qual_name} failed
434
+ because an element of the same name was found
435
+ **** ERROR NAME CLASH DETECTED ****
436
+ END
437
+ }
438
+ return nil
439
+ end
440
+ return ret
441
+ end
442
+
443
+ end
444
+
445
+ module Mrdf_Model
446
+ # A properly behaved model should not have inheritance from non abstract class.
447
+ # This transformation enforces that inheritance is always from an abstract class
448
+
449
+ def umlx_sanitizeAbstractsInHierarchy!
450
+ each { |k,gen|
451
+ next unless gen.kind_of?(Muml_Generalization)
452
+ g=gen.uml_general_one
453
+ sp=gen.uml_specific_one
454
+ next if g.uml_isAbstract?
455
+ next unless g.kind_of?(Muml_Class)
456
+ g.umlx_sanitizeAbstractsInHierarchy!
457
+ }
458
+ end
459
+
460
+ #Modify every composition so navigability is enabled from composante to composite.
461
+ #Composition between interface is not made navigable
462
+ def umlx_makeCompositionNavigable!
463
+ return unless context[:makeCompositionBiNavigable,true]
464
+
465
+ each { |k,p|
466
+ next unless p.kind_of?(Muml_Association)
467
+ ce=nil #composante
468
+ ci=nil #composite
469
+ p.uml_memberEnd.each {|a|
470
+ if a.uml_aggregation_one.isComposite?
471
+ ci=a
472
+ else
473
+ ce=a
474
+ end
475
+ }
476
+ next if ci.nil? || ce.nil?
477
+ next if ci.uml_type_one.kind_of?(Muml_Stereotype)
478
+ next if ce.uml_type_one.kind_of?(Muml_Stereotype)
479
+ #next if ce.uml_type_one.kind_of?(Muml_Interface)
480
+ return if ce.umlx_isNavigable?
481
+
482
+ #log.debug { "making composition bi-navigable #{p}"}
483
+ if ce.uml_name.empty?
484
+ #replace blank name with default name for composite.
485
+ ce.uml_name=context[:defaultBiNavigableCompositionName,"owner"]
486
+ end
487
+ #ce.uml_ownedAttribute_inv=ci.uml_type
488
+ #ce.uml_ownedAttribute_inv_one.uml_ownedAttribute_add(ce)
489
+ ci.uml_type_one.uml_ownedAttribute_add(ce)
490
+ }
491
+ end
492
+
493
+
494
+
495
+ end
496
+
497
+ module Muml_Class
498
+ # Suppose A derives from B and B is not abstract
499
+ # This transformater will
500
+ # 1) rename B to Babstract
501
+ # 2) mark Babstract as abstract
502
+ # 3) Create a new class B that derives from Babstract
503
+ # 4) (TBD) create facade constructors in (new) B.
504
+ def umlx_sanitizeAbstractsInHierarchy!
505
+ #log.debug { "sanitize #{uml_name} #{uml_isAbstract}==#{uml_isAbstract?}" }
506
+ self.uml_isAbstract=RDF_TRUE
507
+ c=umlx_package.umlx_createAndAddClass(rdf_uri+"_concret","_concrete")
508
+ c.uml_name="#{uml_name}"
509
+ self.uml_name="#{uml_name}Abstract"
510
+ c.umlx_createAndAddGeneralization(self)
511
+ end
512
+ end
513
+
514
+ module Muml_Operation
515
+ #uml_ownedAttribute_inv_one is sometime broken
516
+ #(RSM does not consistently populate this field)
517
+ #umlx_class_one figures out the correct value of uml_ownedAttribute_inv_one
518
+ def umlx_class_one
519
+ return uml_ownedOperation_inv_one
520
+ ##
521
+ ## ret=uml_class_one
522
+ ## #ret=uml_ownedAttribute_inv_one0
523
+ ## return ret unless ret.nil?
524
+ ##
525
+ ## #use ext_isReferencedBy
526
+ ## ext_isReferencedBy.each { |o|
527
+ ## next unless o.respond_to?(:uml_ownedOperation)
528
+ ## o.uml_ownedOperation.each { |c|
529
+ ## return o if c==self
530
+ ## }
531
+ ## }
532
+ ## log.error("umlx_class_one not found in model for #{self}:#{self.class}")
533
+ ## return nil
534
+ end
535
+ end
536
+ module Muml_Property
537
+ #uml_ownedAttribute_inv_one is sometime broken
538
+ #(RSM does not consistently populate this field)
539
+ #umlx_class_one figures out the correct value of uml_ownedAttribute_inv_one
540
+ def umlx_class_one
541
+ # return uml_ownedAttribute_inv_one
542
+
543
+ #ret=uml_ownedAttribute_inv_one0
544
+ ret=uml_class_one0
545
+ return ret unless ret.nil?
546
+
547
+ #use association other end
548
+ oe=umlx_otherEnd
549
+ ret=oe.uml_type_one if !oe.nil?
550
+ return ret unless ret.nil?
551
+
552
+ #use ext_isReferencedBy
553
+ ext_isReferencedBy.each { |o|
554
+ next unless o.respond_to?(:uml_ownedAttribute)
555
+ o.uml_ownedAttribute.each { |c|
556
+ return o if c==self
557
+ }
558
+ }
559
+ log.error("umlx_class_one not found in model for #{self}:#{self.class}")
560
+ return nil
561
+ end
562
+ end
563
+
564
+ module Muml_Operation
565
+ #Returns true if operation is a constructor
566
+ #NOTE: RSM stereotype is "Create", MagicDraw "create"
567
+ def umlx_isConstructor?
568
+ return umlx_hasStereotype?("Create")
569
+ end
570
+ end
571
+
572
+
573
+ module Muml_Classifier
574
+ #returns every type assignable to this classifier
575
+ #(this includes self and any class deriving from it)
576
+ def umlx_assignableClassifier(ret=Set.new)
577
+ return ret if ret.include?(self)
578
+ ret<< self
579
+ uml_general_inv.each { |g|
580
+ g.uml_generalization_inv.each {|c|
581
+ c.umlx_assignableClassifier(ret)
582
+ }}
583
+ return ret
584
+ end
585
+ end
586
+ module Muml_Interface
587
+ #returns every type assignable to this classifier
588
+ #(this includes self and any class deriving from it)
589
+ def umlx_assignableClassifier(ret=Set.new)
590
+ return ret if ret.include?(self)
591
+ super(ret)
592
+ uml_supplier_inv.each { |g|
593
+ g.uml_implementation_inv.each {|c|
594
+ c.umlx_assignableClassifier(ret)
595
+ }}
596
+ return ret
597
+
598
+ end
599
+ end
600
+
601
+ module Muml_Class
602
+ #return true if uml_ownedAttribute_inv is a "regular" class
603
+ def umlx_isReallyAClass?
604
+ ret=kind_of?(Cuml_Class)
605
+ #ret=!(
606
+ # kind_of?(Muml_Stereotype)||
607
+ # kind_of?(Muml_StateMachine)||
608
+ # kind_of?(Muml_Activity)||
609
+ # kind_of?(Muml_Interaction)
610
+ # kind_of?(Muml_Component)||
611
+ # kind_of?(Muml_Device)||
612
+ # kind_of?(Muml_ExecutionEnvironment)||
613
+ # kind_of?(Muml_Node)
614
+ # )
615
+ #log.debug { "umlx_isReallyAClass #{ret}::#{self.class.name}" }
616
+ return ret
617
+ end
618
+ end
619
+
620
+
621
+ module Mrdf_Resource
622
+ def umlx_reserved_model
623
+ return rdf_model.umlx_reserved_model
624
+ end
625
+ end
626
+
627
+ module Mrdf_Model
628
+ UMLX_RESERVED_MODEL_URI="http://xmda-reserved"
629
+ def umlx_reserved_model
630
+ r=self[UMLX_RESERVED_MODEL_URI]
631
+ return r unless r.nil?
632
+ r=self
633
+ r=Cuml_Model.new(self,UMLX_RESERVED_MODEL_URI)
634
+ #log.debug { "Creating reserved model (uri=#{r.uri})" }
635
+ return r
636
+ end
637
+ end
638
+