/
Association_roles.ump
747 lines (691 loc) · 25.5 KB
/
Association_roles.ump
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
/*******************************************************************************
* Copyright (c) 2017 Ahmed M.Orabi, Mahmoud M.Orabi.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Ahmed M.Orabi
* Mahmoud M.Orabi
*
* Please refer to the code authors before making any changes.
* For any code reuse or copy, contact the authors and it is a MUST
* to refer author names.
*
* @author -Ahmed M.Orabi {@link ahmedvc@hotmail.com}
* @author Mahmoud M.Orabi {@link mahmoud_3rabi@hotmail.com}
*******************************************************************************/
class GenPackage{
singletonTemplateDefinitionT <<!
//Helper template to be extended by the classes that need to be used as singelton design pattern
template<class T> class Singleton {
Singleton(const Singleton&);
Singleton& operator=(const Singleton&);
protected:
Singleton() {}
virtual ~Singleton() {}
public:
static T& instance() {
static MutexLock lock;
synchronized(lock) {
static T theInstance;
return theInstance;
}
}
};
!>>
emit singletonTemplateDefinition()(singletonTemplateDefinitionT);
getSetElementTemplateImplementationT <<!
//A template function to get an item in a set by index
template < typename InputIterator>
void* GetAt(InputIterator& it, int index) {
std::advance(it, index);
return *it;
};
!>>
emit getSetElementTemplateImplementation()(getSetElementTemplateImplementationT);
copySetElementTemplateImplementationT <<!
//A template function to copy set
template<typename InputIterator, typename T>
void copySet(InputIterator& it, InputIterator& end ,T* setObj) {
for (; it != end; ++it) {
setObj->insert(*it);
}
};
!>>
emit copySetElementTemplateImplementation()(copySetElementTemplateImplementationT);
copyVectorElementTemplateImplementationT <<!
//A template function to copy vector
template<typename InputIterator, typename T>
void copyVector(InputIterator& it, InputIterator& end ,T* vectorObj) {
for (; it != end; ++it) {
vectorObj->push_back(*it);
}
};
!>>
emit copyVectorElementTemplateImplementation()(copyVectorElementTemplateImplementationT);
getVectorElementTemplateImplementationT <<!
//A template function to get the index of an item for a given vector. It returns -1 if the
//item was not found
template <typename InputIterator, typename EqualityComparable>
int IndexOf(const InputIterator& begin,
const InputIterator& end, const EqualityComparable& item) {
if(begin == end )
return -1;
InputIterator fnd = std::find(begin, end, item);
unsigned int index = std::distance(begin, fnd);
return fnd != end ? index : -1;
};
//Used as a function pointer to safely destroy elements or collections of elements
//Example:
// std::for_each( arr->begin(), arr->end(), delete_pointer_element());
// delete arr;
struct deleteElement{
template< typename T >
void operator()( T element ) const{
delete element;
}
};
template<typename T>
unsigned int compare(T c1, T c2, unsigned int sz ) {
if(!is_ptr<T>::value) {
return std::memcmp(&c1,&c2, sz);
}
return std::memcmp((void*)c1, (void*)c2, sz);
};
template<typename T>
void copyObject(T* object1, T* object2, unsigned int sz ) {
if(!is_ptr<T>::value) {
std::memcpy(&object2,&object1, sz);
}
std::memcpy((void*)object2, (void*)object1, sz);
};
!>>
emit getVectorElementTemplateImplementation()(getVectorElementTemplateImplementationT);
timeHelpCodeT <<!
#ifndef TIME_AND_DATE_DEFINITION
#define TIME_AND_DATE_DEFINITION
namespace {
// Ported strptime from BSD
#ifdef WINDOWS_OS
const char* Days[] = {
"Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday"
};
const char* DaySymbols[] = {"Sun", "Mon", "Tue", "Wed","Thu", "Fri", "Sat"};
const char* Monthes[] = {"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December" };
const char* MonthSymbols[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
const char* parseNumber(const char* s, int low, int high, int* value) {
const char* p = s;
for (*value = 0; *p != NULL && isdigit(*p); ++p) {
*value = (*value) * 10 + static_cast<int>(*p) - static_cast<int>('0');
}
if (p == s || *value < low || *value > high) return NULL;
return p;
}
char* strptime(const char *s, const char *format, struct tm *tm) {
while (*format != NULL && *s != NULL) {
if (*format != '%') {
if (*s != *format) return NULL;
++format;
++s;
continue;
}
++format;
int len = 0;
switch (*format) {
case 'a':
case 'A':
tm->tm_wday = -1;
for (int i = 0; i < 7; ++i) {
len = static_cast<int>(strlen(DaySymbols[i]));
if (_strnicmp(DaySymbols[i], s, len) == 0) {
tm->tm_wday = i;
break;
}
len = static_cast<int>(strlen(Days[i]));
if (_strnicmp(Days[i], s, len) == 0) {
tm->tm_wday = i;
break;
}
}
if (tm->tm_wday == -1) return NULL;
s += len;
break;
case 'b':
case 'B':
case 'h':
tm->tm_mon = -1;
for (int i = 0; i < 12; ++i) {
len = static_cast<int>(strlen(MonthSymbols[i]));
if (_strnicmp(MonthSymbols[i], s, len) == 0) {
tm->tm_mon = i;
break;
}
len = static_cast<int>(strlen(Monthes[i]));
if (_strnicmp(Monthes[i], s, len) == 0) {
tm->tm_mon = i;
break;
}
}
if (tm->tm_mon == -1) return NULL;
s += len;
break;
case 'm':
s = parseNumber(s, 1, 12, &tm->tm_mon);
if (s == NULL) return NULL;
--tm->tm_mon;
break;
case 'd':
case 'e':
s = parseNumber(s, 1, 31, &tm->tm_mday);
if (s == NULL) return NULL;
break;
case 'H':
s = parseNumber(s, 0, 23, &tm->tm_hour);
if (s == NULL) return NULL;
break;
case 'M':
s = parseNumber(s, 0, 59, &tm->tm_min);
if (s == NULL) return NULL;
break;
case 'S':
s = parseNumber(s, 0, 60, &tm->tm_sec);
if (s == NULL) return NULL;
break;
case 'Y':
s = parseNumber(s, 1900, 9999, &tm->tm_year);
if (s == NULL) return NULL;
tm->tm_year -= 1900;
break;
case 'y':
s = parseNumber(s, 0, 99, &tm->tm_year);
if (s == NULL) return NULL;
if (tm->tm_year <= 68) {
tm->tm_year += 100;
}
break;
case 't':
case 'n':
while (isspace(*s)) ++s;
break;
case '%':
if (*s != '%') return NULL;
++s;
break;
default:
return NULL;
}
++format;
}
if (*format != NULL) {return NULL;}
else {return const_cast<char*>(s);}
}
#endif
tm* ParseDate(string buf) {
time_t t(time(NULL));
tm* pDate = new tm(*localtime(&t));
char* ret = strptime(buf.c_str(), "%d-%m-%Y", pDate);
assert(ret != NULL);
return pDate;
};
time_t* ParseTime(string buf) {
tm tm;
time_t* pTime;
char* ret = strptime(buf.c_str(), "%H:%M:%S", &tm);
assert(ret != NULL);
pTime = new time_t(mktime(&tm));
return pTime;
};
}
#endif
!>>
emit timeHelpCode()(timeHelpCodeT);
}
//Constructor roles
class GenAssociation{
const String CONSTRUCT_DEFAULT_ASSIGN= "constructorDefaultAssign";
const String CONSTRUCT_VALUE_ASSIGN= "constructorValueAssign";
const String CONSTRUCT_CHECK_NULL_ASSIGN= "constructorCheckNullAssign";
const String CONSTRUCT_SET_AND_CHECK= "constructSetAndCheck";
const String CONSTRUCT_SET_VALIDATE_BOUND= "constructSetValidateBounds";
String constructDecision(){
if(getIsAttribute()){
if(isDerived() || isConstant() || getIsStatic() || isDefaulted() || getIsKey() || getIsSorted()){
return null;
}
if(getIsLazy() || getValue()!= null){
return GenAssociation.CONSTRUCT_DEFAULT_ASSIGN;
}
return isMany()?GenAssociation.CONSTRUCT_DEFAULT_ASSIGN: GenAssociation.CONSTRUCT_VALUE_ASSIGN;
}
if(source.isOptional()){
if(target.isOptional()|| target.isRangedOptional()|| target.isOne()|| target.isRangedUnbound()|| target.isRangedMandatory()|| target.isFixed()|| target.isUnbound()){
return GenAssociation.CONSTRUCT_DEFAULT_ASSIGN;
}
}else if(source.isRangedOptional()){
if(target.isOptional()|| target.isRangedOptional()|| target.isOne()|| target.isRangedUnbound()|| target.isRangedMandatory()|| target.isFixed()|| target.isUnbound()){
return GenAssociation.CONSTRUCT_DEFAULT_ASSIGN;
}
}else if(source.isOne()){
if(target.isOptional()|| target.isRangedOptional()|| target.isRangedUnbound()|| target.isRangedMandatory()|| target.isFixed()|| target.isUnbound()){
return GenAssociation.CONSTRUCT_SET_AND_CHECK;
}else if(target.isOne()){
if(source.isDirected()){
return GenAssociation.CONSTRUCT_SET_AND_CHECK;
}else{
return GenAssociation.CONSTRUCT_CHECK_NULL_ASSIGN;
}
}
}else if(source.isRangedUnbound()){
if(target.isOptional()){
return GenAssociation.CONSTRUCT_SET_VALIDATE_BOUND;
}else if(target.isRangedOptional()|| target.isOne()|| target.isRangedUnbound()|| target.isRangedMandatory()|| target.isFixed()|| target.isUnbound()){
if(source.isDirected()){
return GenAssociation.CONSTRUCT_SET_VALIDATE_BOUND;
}else{
return GenAssociation.CONSTRUCT_DEFAULT_ASSIGN;
}
}
}else if(source.isRangedMandatory()){
if(target.isOptional()|| target.isUnbound()){
return GenAssociation.CONSTRUCT_SET_VALIDATE_BOUND;
}else if(target.isRangedOptional()|| target.isOne()|| target.isRangedUnbound()|| target.isRangedMandatory()|| target.isFixed()){
if(source.isDirected()){
return GenAssociation.CONSTRUCT_SET_VALIDATE_BOUND;
}else{
return GenAssociation.CONSTRUCT_DEFAULT_ASSIGN;
}
}
}else if(source.isFixed()){
if(target.isOptional()|| target.isUnbound()){
return GenAssociation.CONSTRUCT_SET_VALIDATE_BOUND;
}else if(target.isOptional()|| target.isOne()|| target.isRangedUnbound()|| target.isRangedMandatory()|| target.isFixed()){
if(source.isDirected()){
return GenAssociation.CONSTRUCT_SET_VALIDATE_BOUND;
}else{
return GenAssociation.CONSTRUCT_DEFAULT_ASSIGN;
}
}
}else if(source.isUnbound()){
if(target.isOptional()|| target.isRangedOptional()|| target.isOne()|| source.isRangedUnbound()|| target.isRangedMandatory()|| target.isFixed()|| target.isUnbound()){
return GenAssociation.CONSTRUCT_DEFAULT_ASSIGN;
}
}
return null;
}
}
//Setter roles
class GenAssociation{
const String SETTER_ASSIGN_DIRECTLY= "attributeSetterAssignDirectly";
const String SETTER_OPTIONAL= "attributeSetterOptional";
const String SETTER_UNBOUND_CHECK= "attributeSetterUnboundCheck";
const String SETTER_UNBOUND= "attributeSetterUnbound";
const String SETTER_ONE= "attributeSetterOne";
const String SETTER_RANGED= "attributeSetterRanged";
const String SETTER_LIST_COPY= "attributeSetterListCopy";
const String SETTER_LIST= "attributeSetterList";
const String SETTER_CHECK_ASSIGN= "attributeSetterCheckAssign";
const String SETTER_USE_EXISTING_SETTER= "attributeSetterUseExistingSetter";
const String SETTER_MAXIMUM_MANY= "attributeSetterMaximumMany";
const String SETTER_USE_EXISTING_REMOVE= "attributeSetterUseExistingRemove";
const String SETTER_HASHMAP= "attributeSetterHashmap";
const String SETTER_MINIMUM_FIXED= "attributeSetterMinimumFixed";
String setterDecision(){
GenAssociationEnd source = getSource();
GenAssociationEnd target = getTarget();
if(getIsAttribute()){
if(isDerived() || isConstant() || getIsStatic()){
return null;
}
return GenAssociation.SETTER_ASSIGN_DIRECTLY;
}
if(source.isOptional()){
if(source.isDirected()){
if(target.isOptional()|| target.isRangedOptional()|| target.isOne()|| target.isRangedUnbound()|| target.isRangedMandatory()|| target.isFixed()|| target.isUnbound()){
return GenAssociation.SETTER_ASSIGN_DIRECTLY;
}
}else{
if(target.isOptional()){
return GenAssociation.SETTER_OPTIONAL;
}else if(target.isRangedOptional()){
return GenAssociation.SETTER_UNBOUND_CHECK;
}else if(target.isOne()){
return GenAssociation.SETTER_ONE;
}else if(target.isRangedUnbound()|| target.isRangedMandatory()){
return GenAssociation.SETTER_RANGED;
}else if(target.isFixed()){
/*Do Nothing */
}else if(target.isUnbound()){
return GenAssociation.SETTER_UNBOUND;
}
}
}else if(source.isRangedOptional()){
if(source.isDirected()){
if(target.isOptional()|| target.isRangedOptional()|| target.isOne()|| target.isRangedUnbound()|| target.isRangedMandatory()|| target.isFixed()|| target.isUnbound()){
return GenAssociation.SETTER_LIST_COPY;
}
}else{
if(target.isUnbound()){
return GenAssociation.SETTER_LIST;
}
}
}else if(source.isOne()){
if(source.isDirected()){
if(target.isOptional()|| target.isRangedOptional()|| target.isOne()|| target.isRangedUnbound()|| target.isRangedMandatory()|| target.isFixed()|| target.isUnbound()){
return GenAssociation.SETTER_CHECK_ASSIGN;
}
}else{
if(target.isOptional()){
return GenAssociation.SETTER_USE_EXISTING_SETTER;
}else if(target.isOne()){
/*Do Nothing */
}else if(target.isRangedUnbound()|| target.isRangedMandatory()|| target.isFixed()|| target.isRangedOptional()){
return GenAssociation.SETTER_MAXIMUM_MANY;
}else if(target.isUnbound()){
return GenAssociation.SETTER_USE_EXISTING_REMOVE;
}
}
}else if(source.isRangedUnbound()|| source.isRangedMandatory()){
if(source.isDirected()){
if(target.isOptional()|| target.isRangedOptional()|| target.isOne()|| target.isRangedUnbound()|| target.isRangedMandatory()|| target.isFixed()|| target.isUnbound()){
return GenAssociation.SETTER_LIST_COPY;
}
}else{
if(target.isOptional()){
return GenAssociation.SETTER_HASHMAP;
}else if(target.isOne()){
/*Do Nothing */
}else if(target.isRangedOptional()|| target.isRangedUnbound()|| target.isRangedMandatory()|| target.isFixed()|| target.isUnbound()){
return GenAssociation.SETTER_LIST;
}
}
}else if(source.isFixed()){
if(source.isDirected()){
if(target.isOptional()|| target.isRangedOptional()|| target.isOne()|| target.isRangedUnbound()|| target.isRangedMandatory()|| target.isFixed()|| target.isUnbound()){
return GenAssociation.SETTER_LIST_COPY;
}
}else{
if(target.isOptional()){
return GenAssociation.SETTER_MINIMUM_FIXED;
}else if(target.isRangedOptional()){
/*Do Nothing */
}else if(target.isOne()){
/*Do Nothing */
}else if(target.isRangedUnbound()|| target.isRangedMandatory()|| target.isFixed()|| target.isUnbound()){
return GenAssociation.SETTER_LIST;
}
}
}else if(source.isUnbound()){
/*Empty Block */
}
return null;
}
String getSetterBody(){
String setterType= setterDecision();
if(setterDecision()!= null){
switch (setterType) {
case SETTER_ASSIGN_DIRECTLY:
return attributeSetterAssignDirectly();
case SETTER_OPTIONAL:
return attributeSetterOptional();
case SETTER_UNBOUND_CHECK:
return attributeSetterUnbound(true);
case SETTER_UNBOUND:
return attributeSetterUnbound(false);
case SETTER_ONE:
return attributeSetterOne();
case SETTER_RANGED:
return attributeSetterRanged();
case SETTER_LIST_COPY:
return attributeSetterList(true);
case SETTER_LIST:
return attributeSetterList(false);
case SETTER_CHECK_ASSIGN:
return attributeSetterCheckAssign();
case SETTER_USE_EXISTING_SETTER:
return attributeSetterUseExistingSetter();
case SETTER_MAXIMUM_MANY:
return attributeSetterMaximumMany();
case SETTER_USE_EXISTING_REMOVE:
return attributeSetterUseExistingRemove();
case SETTER_HASHMAP:
return attributeSetterHashmap();
case SETTER_MINIMUM_FIXED:
return attributeSetterMinimumFixed();
default:
break;
}
}
return null;
}
}
//Delete roles
class GenAssociation{
const String DELETE_DIRECTLY= "deleteDirectly";
const String DELETE_CHECK_BY_SETTER= "deleteCheckBySetter(FALSE)";
const String DELETE_CHECK_NULLIFY_BY_SETTER= "deleteCheckBySetter(TRUE)";
const String DELETE_ASSIGN_REMOVE_CHECK= "deleteAssignRemoveCheck";
const String DELETE_USE_DELETE= "deleteUseDelete";
const String DELETE_REMOVE_OR_NULLIFY= "deleteRemoveOrNullify";
const String DELETE_CHECK_USE_DELETE= "deleteCheckUseDelete";
const String DELETE_NULLIFY_ALL_BY_SETTERS= "deleteNullifyAllBySetters";
const String DELETE_USE_INTERNAL_SETTER= "deleteUseInternalSetter";
const String DELETE_SAFELY_CLEAR_AND_REMOVE= "deleteSafelyClearAndRemove";
const String DELETE_NULLIFY_USE_DELETE= "deleteNullifyUseDelete";
const String DELETE_CLEAR_THEN_DELETE_OR_REMOVE= "deleteClearThenDeleteOrRemove";
const String DELETE_ASSIGN_REMOVE= "deleteAssignRemove";
String deleteDecision(){
if(getIsAttribute()){
if(isMany() && !isDerived() && !getIsKey()){
return GenAssociation.DELETE_DIRECTLY;
}
return null;
}
GenAssociationEnd source = getSource();
GenAssociationEnd target = getTarget();
if(source.isDirected()){
return GenAssociation.DELETE_DIRECTLY;
}
if(source.isOptional()){
if(target.isOptional()){
return GenAssociation.DELETE_CHECK_BY_SETTER;
}else if(target.isRangedOptional()|| target.isUnbound()){
return GenAssociation.DELETE_ASSIGN_REMOVE_CHECK;
}else if(target.isOne()){
return GenAssociation.DELETE_USE_DELETE;
}else if(target.isRangedUnbound()|| target.isRangedMandatory()){
return GenAssociation.DELETE_REMOVE_OR_NULLIFY;
}else if(target.isFixed()){
return GenAssociation.DELETE_CHECK_USE_DELETE;
}
}else if(source.isRangedOptional()){
if(target.isOptional()){
return GenAssociation.DELETE_NULLIFY_ALL_BY_SETTERS;
}else if(target.isRangedOptional()|| target.isUnbound()){
return GenAssociation.DELETE_SAFELY_CLEAR_AND_REMOVE;
}else if(target.isOne()){
return GenAssociation.DELETE_NULLIFY_USE_DELETE;
}else if(target.isRangedUnbound()|| target.isRangedMandatory()|| target.isFixed()){
return GenAssociation.DELETE_CLEAR_THEN_DELETE_OR_REMOVE;
}
}else if(source.isOne()){
if(target.isOptional()){
return GenAssociation.DELETE_CHECK_NULLIFY_BY_SETTER;
}else if(target.isRangedOptional()|| target.isRangedUnbound()|| target.isRangedMandatory()|| target.isFixed()|| target.isUnbound()){
return GenAssociation.DELETE_ASSIGN_REMOVE;
}else if(target.isOne()){
return GenAssociation.DELETE_USE_DELETE;
}
}else if(source.isRangedUnbound()|| source.isRangedMandatory()|| source.isFixed()){
if(target.isOptional()){
return GenAssociation.DELETE_USE_INTERNAL_SETTER;
}else if(target.isRangedOptional()|| target.isUnbound()){
return GenAssociation.DELETE_SAFELY_CLEAR_AND_REMOVE;
}else if(target.isOne()){
return GenAssociation.DELETE_NULLIFY_USE_DELETE;
}else if(target.isRangedUnbound()|| target.isRangedMandatory()|| target.isFixed()){
return GenAssociation.DELETE_CLEAR_THEN_DELETE_OR_REMOVE;
}
}else if(source.isUnbound()){
if(target.isOptional()){
return GenAssociation.DELETE_NULLIFY_ALL_BY_SETTERS;
}else if(target.isRangedOptional()|| target.isUnbound()){
return GenAssociation.DELETE_SAFELY_CLEAR_AND_REMOVE;
}else if(target.isOne()){
return GenAssociation.DELETE_NULLIFY_USE_DELETE;
}else if(source.isRangedUnbound()|| target.isRangedMandatory()|| target.isFixed() || target.isRangedUnbound()){
return GenAssociation.DELETE_CLEAR_THEN_DELETE_OR_REMOVE;
}
}
return null;
}
String getDeleteBody(){
String deleteType= deleteDecision();
if(deleteType!= null){
switch (deleteType) {
case SETTER_ASSIGN_DIRECTLY:
return attributeSetterAssignDirectly();
case DELETE_DIRECTLY:
return deleteDirectly();
case DELETE_CHECK_BY_SETTER:
return deleteCheckBySetter(false);
case DELETE_CHECK_NULLIFY_BY_SETTER:
return deleteCheckBySetter(true);
case DELETE_ASSIGN_REMOVE_CHECK:
return deleteAssignRemoveCheck();
case DELETE_ASSIGN_REMOVE:
return deleteAssignRemove();
case DELETE_USE_DELETE:
return deleteUseDelete();
case DELETE_REMOVE_OR_NULLIFY:
return deleteRemoveOrNullify();
case DELETE_CHECK_USE_DELETE:
return deleteCheckUseDelete();
case DELETE_NULLIFY_ALL_BY_SETTERS:
return deleteNullifyAllBySetters();
case DELETE_USE_INTERNAL_SETTER:
return deleteUseInternalSetter();
case DELETE_SAFELY_CLEAR_AND_REMOVE:
return deleteSafelyClearAndRemove();
case DELETE_NULLIFY_USE_DELETE:
return deleteNullifyUseDelete();
case DELETE_CLEAR_THEN_DELETE_OR_REMOVE:
return deleteClearThenDeleteOrRemove();
default:
break;
}
}
return null;
}
}
//Add roles
class GenAssociation{
//Only accepted if from many to one or more.
//Examples: 1 -- 2 M; 1 -- 2..4 H; 1 -- 1..3 Y; 1 -- 2..* X; 1 -- 0..* U; 1 -- 1..* W; 1 -- 5..5 F; 1 -- 2..4 H;
// 1 -- 1..3 Y; 1 -- 2..* X; 1 -- 1..* W; 1 -- 5 Q;1 -- * T;
Boolean hasAdditionalAdd= {getTarget().getLowerBound()==1 && getTarget().getUpperBound()>=1 && getSource().isMany()};
const String ADD_DIRECTLY= "attributeAddDirectly";
const String ADD_REMOVE_EXISTING_OR_THIS= "attributeAddRemoveExistingOrThis";
const String ADD_REMOVE_EXISTING= "attributeAddRemoveExisting";
const String ADD_CHECK_NEW_OTHER_EXISTING= "attributeAddCheckNewOtherExisting";
const String ADD_SET_IF_NEW= "attributeAddSetIfNew";
const String ADD_AND_AND_CHECK= "attributeAddAndCheck";
String addDecision(){
if(getIsAttribute()){
if(isMany() && !isDerived() && !getIsKey()){
return GenAssociation.ADD_DIRECTLY;
}
return null;
}
GenAssociationEnd source = getSource();
GenAssociationEnd target = getTarget();
if(source.isRangedOptional()){
if(source.isDirected()){
return GenAssociation.ADD_DIRECTLY;
}else{
if(target.isOptional()){
return GenAssociation.ADD_REMOVE_EXISTING_OR_THIS;
}else if(target.isOne()){
return GenAssociation.ADD_CHECK_NEW_OTHER_EXISTING;
}else if(target.isRangedUnbound()|| target.isRangedOptional()|| target.isRangedMandatory()|| target.isFixed()|| target.isUnbound()){
return GenAssociation.ADD_DIRECTLY;
}
}
}else if(source.isRangedUnbound()){
if(source.isDirected()){
return GenAssociation.ADD_DIRECTLY;
}else{
if(target.isOptional()){
return GenAssociation.ADD_REMOVE_EXISTING;
}else if(target.isOne()){
return GenAssociation.ADD_SET_IF_NEW;
}else if(target.isRangedUnbound()|| target.isRangedOptional()|| target.isRangedMandatory()|| target.isFixed()|| target.isUnbound()){
return GenAssociation.ADD_AND_AND_CHECK;
}
}
}else if(source.isRangedMandatory()){
if(source.isDirected()){
return GenAssociation.ADD_DIRECTLY;
}else{
if(target.isOptional()){
return GenAssociation.ADD_REMOVE_EXISTING;
}else if(target.isOne()){
return GenAssociation.ADD_SET_IF_NEW;
}else if(target.isRangedUnbound()|| target.isRangedOptional()|| target.isRangedMandatory()|| target.isFixed()|| target.isUnbound()){
return GenAssociation.ADD_AND_AND_CHECK;
}
}
}else if(source.isFixed()){
if(source.isDirected()){
//None
}else{
if(target.isOptional()){
//None
}else if(target.isOne()){
return GenAssociation.ADD_SET_IF_NEW;
}else if(target.isRangedUnbound()|| target.isRangedOptional()|| target.isRangedMandatory()|| target.isFixed()|| target.isUnbound()){
return GenAssociation.ADD_AND_AND_CHECK;
}
}
}else if(source.isUnbound()){
if(source.isDirected()){
return GenAssociation.ADD_DIRECTLY;
}else{
if(target.isOptional()){
return GenAssociation.ADD_REMOVE_EXISTING_OR_THIS;
}else if(target.isOne()){
return GenAssociation.ADD_CHECK_NEW_OTHER_EXISTING;
}else if(target.isRangedUnbound()|| target.isRangedOptional()|| target.isRangedMandatory()|| target.isFixed()|| target.isUnbound()){
return GenAssociation.ADD_AND_AND_CHECK;
}
}
}
return null;
}
String getAddBody(){
String addType= addDecision();
if(addType!= null){
switch (addType) {
case ADD_DIRECTLY:
return attributeAddDirectly();
case ADD_REMOVE_EXISTING_OR_THIS:
return attributeAddRemoveExistingOrThis();
case ADD_REMOVE_EXISTING:
return attributeAddRemoveExisting();
case ADD_CHECK_NEW_OTHER_EXISTING:
return attributeAddCheckNewOtherExisting();
case ADD_SET_IF_NEW:
return attributeAddSetIfNew();
case ADD_AND_AND_CHECK:
return attributeAddAndCheck();
default:
break;
}
}
return addType;
}
}