-
Notifications
You must be signed in to change notification settings - Fork 9
/
Association.java
10573 lines (9477 loc) · 396 KB
/
Association.java
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
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import java.util.Vector;
import java.io.*;
import java.util.List;
/******************************
* Copyright (c) 2003--2024 Kevin Lano
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
* *****************************/
/* package: Class Diagram */
/* Major change: May 2016 - addr(obj,val) for 0..1 association
end now enforces val : obj.r even if it displaces an
existing element of obj.r */
public class Association extends ModelElement
{ private Entity entity1;
private Entity entity2;
private Entity linkedClass = null; // for association classes only
private int card1 = MANY; // MANY, ONE, ZEROONE or >= 2
private int card2 = MANY;
private String role1; // one of these is usually null
private String role2;
private boolean ordered = false; // role2 is a sequence
private boolean sortedAsc = false; // a sorted set
private boolean sortedDesc = false; // not implemented yet
// also ADDONLY, FROZEN options
private boolean addOnly = false; // also represented as stereotypes
private boolean frozen = false;
private boolean aggregation = false;
private Vector constraints = new Vector(); // those that involve this association
private Attribute qualifier = null; // non-null for qualified associations
private boolean instanceScope = true;
private Expression initialExpression = null;
public Association(Entity e1, Entity e2, int c1,
int c2, String r1, String r2)
{ super(e1 + "_" + e2);
entity1 = e1;
entity2 = e2;
card1 = c1;
card2 = c2;
role1 = r1;
role2 = r2;
if (e1 == null)
{ System.err.println("!!! FATAL ERROR: null class at association end 1");
return;
}
if (e2 == null)
{ System.err.println("!!! FATAL ERROR: null class at association end 2");
return;
}
}
public Association(Entity e1, Entity e2, String r2)
{ super(e1 + "_" + e2);
entity1 = e1;
entity2 = e2;
card1 = MANY;
card2 = MANY;
// role1 = r1;
role2 = r2;
/* if (e1 == null)
{ System.err.println("!!! FATAL ERROR: null class at association end 1");
return;
}
if (e2 == null)
{ System.err.println("!!! FATAL ERROR: null class at association end 2");
return;
} */
}
public Association(Entity e1, Attribute att)
{ super(e1.getName() + "_" + att.getName());
entity1 = e1;
Type tt = att.getType();
if (tt != null && tt.isEntity())
{ entity2 = tt.getEntity();
card1 = MANY;
card2 = ONE;
}
else if (tt != null && Type.isEntityCollection(tt))
{ Type et = tt.getElementType();
entity2 = et.getEntity();
card1 = MANY;
card2 = MANY;
if (tt.isSequenceType())
{ setOrdered(true); }
}
role1 = "";
role2 = att.getName();
}
public Object clone()
{ Association res = new Association(entity1, entity2, card1, card2, role1, role2);
res.setAddOnly(addOnly);
res.setFrozen(frozen);
res.setOrdered(ordered);
res.sortedAsc = sortedAsc;
res.aggregation = aggregation;
res.setQualifier(qualifier);
res.setInstanceScope(instanceScope);
return res;
}
public Association(Entity e1, Entity e2, String c1,
String c2, String r1, String r2)
{ super(e1.getName() + "_" + e2.getName());
entity1 = e1;
entity2 = e2;
card2 = ONE; // default in Ecore
// c1 is lower bound on role2, c2 is upper bound
if ("-1".equals(c2))
{ card2 = MANY; }
else if ("1".equals(c2))
{ if ("1".equals(c1))
{ card2 = ONE; }
else
{ card2 = ZEROONE; }
}
else
{ card2 = MANY; } // a..b with b > 1
card1 = MANY; // default - depends on the opposite
role1 = r1;
role2 = r2;
}
public void setInitialExpression(Expression init)
{ initialExpression = init; }
public void setType(Type t) { }
public void addParameter(Attribute att)
{ }
public Vector getParameters() { return new Vector(); }
public Type getType()
{ return getRole2Type(); }
public Association generateSubAssociation(Entity e1, Entity e2)
{ // assume e1 is ancestor of entity1, e2 of entity2
int c1 = card1;
int c2 = card2;
if (card1 == ONE)
{ c1 = ZEROONE; }
if (card2 == ONE)
{ c2 = ZEROONE; }
Association res = new Association(e1,e2,c1,c2,role1,role2);
return res;
} // copy ordered, sorted
public Association generateInverseAssociation()
{ Association inv = new Association(entity2,entity1,card2,card1,role2,role1);
if (isSource())
{ inv.setSource(true); }
else if (isTarget())
{ inv.setTarget(true); }
if (isPersistent())
{ inv.setPersistent(true); }
else
{ inv.setPersistent(false); }
return inv;
} // and other stereotypes?
public boolean isInverseAssociation(Association ast)
{ if (entity1 == ast.entity2 && entity2 == ast.entity1 &&
(role1 + "").equals(ast.role2) && role2.equals(ast.role1 + ""))
{ return true; }
return false;
}
public void updateAssociation(int c1, int c2, String r1, String r2,
Vector stereos)
{ card1 = c1;
card2 = c2;
role1 = r1;
role2 = r2;
setStereotypes(stereos);
if (stereos.contains("ordered"))
{ setOrdered(true); }
else
{ setOrdered(false); }
}
public void setName(String nme)
{ name = nme; }
public void setEntity1(Entity e1)
{ entity1 = e1; }
public void setEntity2(Entity e2)
{ entity2 = e2; }
public void setCard1(String lower, String upper)
{ if ("-1".equals(upper))
{ card1 = MANY; }
else if ("1".equals(upper))
{ if ("1".equals(lower))
{ card1 = ONE; }
else
{ card1 = ZEROONE; }
}
}
public boolean getAggregation()
{ return aggregation; }
public void setAggregation(boolean a)
{ aggregation = a;
if (a)
{ if (hasStereotype("aggregation")) { }
else
{ addStereotype("aggregation"); }
}
else
{ removeStereotype("aggregation"); }
}
public void setSource(boolean a)
{ if (a)
{ if (hasStereotype("source")) { }
else
{ addStereotype("source"); }
}
else
{ removeStereotype("source"); }
}
public void setTarget(boolean a)
{ if (a)
{ if (hasStereotype("target")) { }
else
{ addStereotype("target"); }
}
else
{ removeStereotype("target"); }
}
public void setQualifier(Attribute q)
{ qualifier = q;
if (q != null)
{ addStereotype("qualifier");
addStereotype(q.getName() + "");
}
}
public void unsetQualifier()
{ if (qualifier != null)
{ String qnme = qualifier.getName();
qualifier = null;
removeStereotype("qualifier");
removeStereotype(qnme);
}
}
public void setLinkedClass(Entity e)
{ linkedClass = e;
addStereotype("associationClass");
addStereotype(e.getName() + "");
}
public void unsetLinkedClass()
{ if (linkedClass != null)
{ String lc = linkedClass.getName();
linkedClass = null;
removeStereotype("associationClass");
removeStereotype(lc);
}
}
public void setSorted(boolean srt)
{ sortedAsc = srt; }
public void makeE1Optional()
{ if (card1 == ZEROONE) { }
else if (card1 == ONE)
{ card1 = ZEROONE; }
else
{ card1 = MANY; }
}
public void makeE2Optional()
{ if (card2 == ZEROONE) { }
else if (card2 == ONE)
{ card2 = ZEROONE; }
else
{ card2 = MANY; }
}
public Entity getEntity1()
{ return entity1; }
public Entity getEntity2()
{ return entity2; }
public static Vector allRole2Classes(Vector assocs)
{ Vector res = new Vector();
for (int i = 0; i < assocs.size(); i++)
{ Association ast = (Association) assocs.get(i);
Entity ent2 = ast.getEntity2();
res.add(ent2);
}
return res;
}
public static Vector allRole1Classes(Vector assocs)
{ Vector res = new Vector();
for (int i = 0; i < assocs.size(); i++)
{ Association ast = (Association) assocs.get(i);
if (ast.role1 != null && ast.role1.length() > 0)
{ Entity ent1 = ast.getEntity1();
res.add(ent1);
}
}
return res;
}
public String getRole1()
{ return role1; }
public String getRole2()
{ return role2; }
public int getCard1()
{ return card1; }
public int getCard2()
{ return card2; }
public boolean isAggregation()
{ return aggregation; }
public boolean isClassScope()
{ return !instanceScope; }
public boolean isSingleValued()
{ return card2 == ONE; }
public void addConstraint(Constraint con)
{ constraints.add(con); }
public void setInstanceScope(boolean iscope)
{ instanceScope = iscope; }
public boolean getInstanceScope()
{ return instanceScope; }
public boolean isOrdered()
{ return ordered; }
public boolean isSorted()
{ return sortedAsc; }
public boolean isInjective()
{ return card1 == ZEROONE && card2 == ONE; }
public boolean isManyMany()
{ return card1 == MANY && card2 == MANY; }
public boolean isManyOne() // either way round
{ return card1 == MANY && card2 == ONE ||
card1 == ONE && card2 == MANY;
}
public boolean isOneMany()
{ return card1 == ONE && card2 == MANY; }
public boolean isZeroOneMany()
{ return card1 == ZEROONE && card2 == MANY; }
public boolean isZeroOne()
{ return card2 == ZEROONE; }
public boolean isMany()
{ return card2 == MANY; }
public boolean isOptional()
{ return card2 == ZEROONE || card2 == MANY; }
public boolean isMandatory()
{ return card2 == ONE || card2 > 1; }
public boolean isPersistent()
{ return hasStereotype("persistent"); }
public void setPersistent(boolean b)
{ if (b)
{ addStereotype("persistent"); }
else
{ removeStereotype("persistent"); }
}
public boolean isExplicit()
{ return hasStereotype("explicit"); } // default
public boolean isImplicit()
{ return hasStereotype("implicit"); }
public boolean isSource()
{ return hasStereotype("source"); }
public boolean isTarget()
{ return hasStereotype("target"); }
public boolean isDerived()
{ return hasStereotype("derived"); }
public boolean isQualified()
{ return qualifier != null; }
public Attribute getQualifier()
{ return qualifier; }
public Vector getConstraints()
{ return constraints; }
public void setRole1(String r1)
{ role1 = r1; }
public void setRole2(String r2)
{ role2 = r2; }
public void setCard1(int c1)
{ card1 = c1; }
public void setCard2(int c2)
{ card2 = c2; }
public Type getType2()
{ Type e2type = new Type(entity2);
if (card2 == ONE)
{ return e2type; }
Type res;
if (ordered)
{ res = new Type("Sequence", null); }
else
{ res = new Type("Set",null); }
res.setElementType(e2type);
return res;
}
public Type getRole2Type()
{ Type e2type = new Type(entity2);
if (isQualified())
{ if (card2 == ONE)
{ Type mapres = new Type("Map",null);
mapres.setKeyType(new Type("String",null));
mapres.setElementType(e2type);
}
Type res;
if (ordered)
{ res = new Type("Sequence", null); }
else
{ res = new Type("Set",null); }
Type mres = new Type("Map", null);
mres.setKeyType(new Type("String",null));
mres.setElementType(res);
return mres;
}
else
{ return getType2(); }
}
public void setOrdered(boolean ord)
{ ordered = ord;
if (ordered == true)
{ addStereotype("ordered"); }
else
{ removeStereotype("ordered"); }
}
public void setSorted(String direction)
{ if (direction.equals("<"))
{ sortedAsc = true;
addStereotype("sorted<");
}
else if (direction.equals(">"))
{ sortedDesc = true;
addStereotype("sorted>");
}
}
public void setAddOnly(boolean ao)
{ addOnly = ao;
if (addOnly == true)
{ addStereotype("addOnly"); }
else
{ removeStereotype("addOnly"); }
}
public void setFrozen(boolean froz)
{ frozen = froz;
if (frozen == true)
{ addStereotype("readOnly"); }
else
{ removeStereotype("readOnly"); }
}
public boolean isFrozen()
{ return frozen; }
public boolean isAddOnly()
{ return addOnly; }
public String subsets()
{ String res = "";
// System.out.println(stereotypes);
if (stereotypes.size() > 0)
{ String stereo = (String) stereotypes.get(0);
if (stereo.length() > 6 && "subsets".equals(stereo.substring(0,7)))
{ return stereo.substring(7,stereo.length()); }
}
return res;
}
public Association getOpposite()
{ return entity2.getDefinedRole(role1); }
// for write frames:
public static String getOppositeEnd(String rle, Entity e, Vector assocs)
{ for (int i = 0; i < assocs.size(); i++)
{ Association a = (Association) assocs.get(i);
if (rle.equals(a.getRole1()) && e == a.getEntity2())
{ String rle2 = a.getRole2();
if (rle2 != null && rle2.length() > 0)
{ return a.getEntity1() + "::" + rle2; }
}
if (rle.equals(a.getRole2()) && e == a.getEntity1())
{ String rle1 = a.getRole1();
if (rle1 != null && rle1.length() > 0)
{ return a.getEntity2() + "::" + rle1; }
}
}
return null;
}
public static Vector getManyOneAssociations(Vector asts)
{ Vector res = new Vector();
for (int i = 0; i < asts.size(); i++)
{ Association ast = (Association) asts.get(i);
// if (ast.isManyOne())
if (ast.getCard1() == ONE && ast.getCard2() == MANY)
{ res.add(ast); }
else if (ast.getCard2() == ONE && ast.getCard1() == MANY)
{ res.add(ast); }
}
return res;
}
public static Vector getManyManyAssociations(Vector asts)
{ Vector res = new Vector();
for (int i = 0; i < asts.size(); i++)
{ Association ast = (Association) asts.get(i);
// if (ast.isManyMany())
if (ast.getCard1() == MANY && ast.getCard2() == MANY)
{ res.add(ast); }
// else if (ast.getCard2() == ONE && ast.getCard1() == MANY)
// { res.add(ast); } // also consider ZEROONE?
}
return res;
}
public boolean hasEnd(Entity e)
{ return ((e == entity1) || (e == entity2)); }
public Vector hasNamedEnds(Entity e)
{ Vector res = new Vector();
if (e == entity1 && role1 != null && role1.length() > 0)
{ res.add(role1); }
if (e == entity2)
{ if (res.contains(role2)) { }
else
{ res.add(role2); }
}
return res;
}
// public boolean isLinkedTo(Association ast)
// { return (hasEnd(ast.getEntity1()) || hasEnd(ast.getEntity2())); }
public boolean isLinkedTo(Association ast)
{ return entity1.equals(ast.getEntity1()) ||
entity1.equals(ast.getEntity2()) ||
entity2.equals(ast.getEntity1()) ||
entity2.equals(ast.getEntity2());
}
public boolean linkedToAny(List rels)
{ for (int i = 0; i < rels.size(); i++)
{ Association ast = (Association) rels.get(i);
if (isLinkedTo(ast))
{ return true; }
}
return false;
}
public static Vector getEndpoints(Vector rels)
{ Vector res = new Vector();
for (int i = 0; i < rels.size(); i++)
{ Association ast = (Association) rels.get(i);
res.add(ast.getEntity1());
res.add(ast.getEntity2());
}
return res;
}
public static List reorderFromSource(String src,
List assocs)
{ // places those r : assocs that have entity1 or 2
// with name src first in the list, then those
// r linked to these, etc. Puts groups of linked
// rels together even if not connected to src
List oldrels = (List) ((Vector) assocs).clone();
List res = new Vector();
for (int i = 0; i < assocs.size(); i++)
{ Association ast = (Association) assocs.get(i);
Entity e1 = ast.getEntity1();
Entity e2 = ast.getEntity2();
if (e1.getName().equals(src) ||
e2.getName().equals(src))
{ res.add(ast); }
}
// res is now all rels linked direct to src
oldrels.removeAll(res);
List newrels;
do
{ newrels = new Vector();
for (int j = 0; j < oldrels.size(); j++)
{ Association ast = (Association) oldrels.get(j);
if (ast.linkedToAny(res))
{ newrels.add(ast); }
}
oldrels.removeAll(newrels);
res.addAll(newrels);
} while (newrels.size() > 0);
// res is all rels connected to src
while (oldrels.size() > 0)
{ Object r = oldrels.get(0);
oldrels.remove(0);
Vector v = new Vector();
v.add(r);
res.addAll(findConnected(v,oldrels));
}
return res;
}
private static List findConnected(List rels, List oldrels)
{ // finds group of all r:oldrels connected to any x:rels
List res = (List) ((Vector) rels).clone();
List newrels;
do
{ newrels = new Vector();
for (int j = 0; j < oldrels.size(); j++)
{ Association ast = (Association) oldrels.get(j);
if (ast.linkedToAny(res))
{ newrels.add(ast); }
}
oldrels.removeAll(newrels);
res.addAll(newrels);
} while (newrels.size() > 0);
// res is all rels connected to src
return res;
}
public static void main(String[] args)
{ Entity e1 = new Entity("e1");
Entity e2 = new Entity("e2");
Entity e3 = new Entity("e3");
Entity e4 = new Entity("e4");
Entity e5 = new Entity("e5");
Entity e6 = new Entity("e6");
Entity e7 = new Entity("e7");
String r = "";
Association a1 = new Association(e1,e2,0,0,r,r);
Association a2 = new Association(e3,e4,0,0,r,r);
Association a3 = new Association(e4,e5,0,0,r,r);
Association a4 = new Association(e4,e6,0,0,r,r);
Association a5 = new Association(e1,e1,0,0,r,r);
Association a6 = new Association(e7,e7,0,0,r,r);
Vector rels = new Vector();
rels.add(a1);
rels.add(a2);
rels.add(a3);
rels.add(a4);
rels.add(a5);
rels.add(a6);
System.out.println(reorderFromSource("e3",rels));
String stereo = "subsetsrr";
if (stereo.length() > 6 && "subsets".equals(stereo.substring(0,7)))
{ System.out.println(stereo.substring(7,stereo.length())); }
}
public void generateJava(PrintWriter out)
{ String qual = "";
String initialiser = " = new Vector()";
if (frozen)
{ qual = "final ";
initialiser = "";
}
if (role2 != null) // attribute of entity1
{ if (entity1.isAbstract())
{ out.print(" protected " + qual); }
else
{ out.print(" private " + qual); }
if (qualifier != null)
{ out.println("java.util.HashMap " + role2 + " = new java.util.HashMap();"); }
else if (card2 == ONE && entity2 != null &&
initialExpression != null)
{ java.util.HashMap env = new java.util.HashMap();
out.println(entity2.getName() + " " + role2 + " = " +
initialExpression + ";");
}
else if (card2 == ONE && entity2 != null)
{ out.println(entity2.getName() + " " + role2 + ";"); }
else if (entity2 != null)
{ out.println("List " +
role2 + initialiser + "; // of " +
entity2.getName());
}
else
{ out.println("Object " + role2 + "; // Undefined class type"); }
}
} // not valid for a..b a > 0. Should be array then?
public void generateJava6(PrintWriter out)
{ String qual = "";
String initialiser = "";
if (ordered)
{ initialiser = " = new ArrayList()"; }
else
{ initialiser = " = new HashSet()"; }
if (frozen)
{ qual = "final ";
initialiser = "";
}
if (role2 != null) // attribute of entity1
{ if (entity1.isAbstract())
{ out.print(" protected " + qual); }
else
{ out.print(" private " + qual); }
if (qualifier != null)
{ out.println("java.util.HashMap " + role2 + " = new java.util.HashMap();"); }
else if (card2 == ONE && initialExpression != null)
{ java.util.HashMap env = new java.util.HashMap();
out.println(entity2.getName() + " " + role2 + " = " +
initialExpression + ";");
}
else if (card2 == ONE)
{ out.println(entity2.getName() + " " + role2 + ";"); }
else if (ordered)
{ out.println("ArrayList " +
role2 + initialiser + "; // of " +
entity2.getName());
}
else
{ out.println("HashSet " +
role2 + initialiser + "; // of " +
entity2.getName());
}
}
} // not valid for a..b a > 0. Should be array then?
public void generateJava7(PrintWriter out)
{ String qual = "";
String e2name = entity2.getName();
String initialiser = "";
String reltype = e2name;
if (card2 == ONE)
{ initialiser = " = null";
reltype = e2name;
}
else if (ordered)
{ initialiser = " = new ArrayList<" + e2name + ">()";
reltype = "ArrayList<" + e2name + ">";
}
else if (sortedAsc)
{ initialiser = " = new TreeSet<" + e2name + ">()";
reltype = "TreeSet<" + e2name + ">";
}
else
{ initialiser = " = new HashSet<" + e2name + ">()";
reltype = "HashSet<" + e2name + ">";
}
if (frozen)
{ qual = "final ";
initialiser = "";
}
if (role2 != null) // attribute of entity1
{ if (entity1.isAbstract())
{ out.print(" protected " + qual); }
else
{ out.print(" private " + qual); }
// Type t2 = getType2();
// String j2type = t2.getJava7(t2.getElementType());
if (qualifier != null)
{ out.println("java.util.HashMap<String, " + reltype + "> " + role2 +
" = new java.util.HashMap<String, " + reltype + ">();");
}
else if (card2 == ONE && initialExpression != null)
{ java.util.HashMap env = new java.util.HashMap();
out.println(entity2.getName() + " " + role2 + " = " +
initialExpression + ";");
}
else if (card2 == ONE)
{ out.println(entity2.getName() + " " + role2 + ";"); }
else
{ out.println(reltype + " " +
role2 + initialiser + "; // of " +
entity2.getName());
}
}
} // not valid for a..b a > 0. Should be array then?
public void generateCSharp(PrintWriter out)
{ String qual = "";
String initialiser = " = new ArrayList()";
if (frozen)
{ qual = "const ";
initialiser = "";
}
if (role2 != null) // attribute of entity1
{ if (entity1.isAbstract())
{ out.print(" protected " + qual); }
else
{ out.print(" private " + qual); }
if (qualifier != null)
{ out.println("Hashtable " + role2 + " = new Hashtable();"); }
else if (card2 == ONE)
{ out.println(entity2.getName() + " " + role2 + ";"); }
else
{ out.println("ArrayList " +
role2 + initialiser + "; // of " +
entity2.getName());
}
}
} // not valid for a..b a > 0. Should be array then?
public void generateCPP(PrintWriter out)
{ String qual = "";
// String initialiser = " = new Vector()";
if (frozen)
{ qual = "const ";
// initialiser = "";
}
String e2name = entity2.getName() + "*";
out.print(" " + qual);
if (role2 != null) // attribute of entity1
{ if (qualifier != null)
{ if (card2 == ONE)
{ out.println("map<string," + e2name + ">* " + role2 + ";"); }
else if (ordered)
{ out.println("map<string, vector<" + e2name + ">*>* " + role2 + ";"); }
else
{ out.println("map<string, std::set<" + e2name + ">*>* " + role2 + ";"); }
}
else if (card2 == ONE)
{ out.println(e2name + " " + role2 + ";"); }
else if (ordered)
{ out.println("vector<" + e2name + ">* " + role2 + ";"); }
else
{ out.println("std::set<" + e2name + ">* " + role2 + ";"); }
}
} // not valid for a..b a > 0. Should be array then?
public void generateInterfaceJava(PrintWriter out)
{ out.print(" // ");
String qual = "";
String initialiser = " = new ArrayList()";
if (frozen)
{ qual = "final ";
initialiser = "";
}
if (role2 != null) // attribute of entity1
{ out.print(" protected " + qual);
if (qualifier != null)
{ out.println("java.util.Map " + role2 + " = new java.util.HashMap();"); }
else if (card2 == ONE)
{ out.println(entity2.getName() + " " +
role2 + ";");
}
else
{ out.println("List " +
role2 + initialiser + "; // of " +
entity2.getName());
}
}
} // not valid for a..b a > 0. Should be array then?
public void generateInterfaceJava6(PrintWriter out)
{ out.print(" // ");
String qual = "";
String initialiser = "";
if (ordered)
{ initialiser = " = new ArrayList()"; }
else
{ initialiser = " = new HashSet()"; }
if (frozen)
{ qual = "final ";
initialiser = "";
}
if (role2 != null) // attribute of entity1
{ out.print(" protected " + qual);
if (qualifier != null)
{ out.println("java.util.Map " + role2 + " = new java.util.HashMap();"); }
else if (card2 == ONE)
{ out.println(entity2.getName() + " " +
role2 + ";");
}
else if (ordered)
{ out.println("ArrayList " +
role2 + initialiser + "; // of " +
entity2.getName());
}
else
{ out.println("HashSet " +
role2 + initialiser + "; // of " +
entity2.getName());
}
}
} // not valid for a..b a > 0. Should be array then?
public void generateInterfaceJava7(PrintWriter out)
{ out.print(" // ");
String qual = "";
String e2name = entity2.getName();
String initialiser = "";
String reltype = e2name;
if (ordered)
{ initialiser = " = new ArrayList<" + e2name + ">()";
reltype = "ArrayList<" + e2name + ">";
}
else if (sortedAsc)
{ initialiser = " = new TreeSet<" + e2name + ">()";
reltype = "TreeSet<" + e2name + ">";
}
else
{ initialiser = " = new HashSet<" + e2name + ">()";
reltype = "HashSet<" + e2name + ">";
}
if (frozen)
{ qual = "final ";
initialiser = "";
}
if (role2 != null) // attribute of entity1
{ out.print(" protected " + qual);
// Type t2 = getType2();
// String j2type = t2.getJava7(t2.getElementType());
if (qualifier != null)
{ out.println("java.util.Map<String, " + reltype + "> " + role2 +
" = new java.util.HashMap<String, " + reltype + ">();");