|
3 | 3 | import java.util.List; |
4 | 4 |
|
5 | 5 | /****************************** |
6 | | -* Copyright (c) 2003,2019 Kevin Lano |
| 6 | +* Copyright (c) 2003,2020 Kevin Lano |
7 | 7 | * This program and the accompanying materials are made available under the |
8 | 8 | * terms of the Eclipse Public License 2.0 which is available at |
9 | 9 | * http://www.eclipse.org/legal/epl-2.0 |
@@ -36,13 +36,41 @@ public class Association extends ModelElement |
36 | 36 |
|
37 | 37 | public Association(Entity e1, Entity e2, int c1, |
38 | 38 | int c2, String r1, String r2) |
39 | | - { super(e1.getName() + "_" + e2.getName()); |
| 39 | + { super(e1 + "_" + e2); |
| 40 | + |
40 | 41 | entity1 = e1; |
41 | 42 | entity2 = e2; |
42 | 43 | card1 = c1; |
43 | 44 | card2 = c2; |
44 | 45 | role1 = r1; |
45 | 46 | role2 = r2; |
| 47 | + if (e1 == null) |
| 48 | + { System.err.println("!!! FATAL ERROR: null class at association end 1"); |
| 49 | + return; |
| 50 | + } |
| 51 | + if (e2 == null) |
| 52 | + { System.err.println("!!! FATAL ERROR: null class at association end 2"); |
| 53 | + return; |
| 54 | + } |
| 55 | + } |
| 56 | + |
| 57 | + public Association(Entity e1, Entity e2, String r2) |
| 58 | + { super(e1 + "_" + e2); |
| 59 | + |
| 60 | + entity1 = e1; |
| 61 | + entity2 = e2; |
| 62 | + card1 = MANY; |
| 63 | + card2 = MANY; |
| 64 | + // role1 = r1; |
| 65 | + role2 = r2; |
| 66 | + /* if (e1 == null) |
| 67 | + { System.err.println("!!! FATAL ERROR: null class at association end 1"); |
| 68 | + return; |
| 69 | + } |
| 70 | + if (e2 == null) |
| 71 | + { System.err.println("!!! FATAL ERROR: null class at association end 2"); |
| 72 | + return; |
| 73 | + } */ |
46 | 74 | } |
47 | 75 |
|
48 | 76 | public Association(Entity e1, Attribute att) |
@@ -294,6 +322,15 @@ public boolean isManyOne() // either way round |
294 | 322 | card1 == ONE && card2 == MANY; |
295 | 323 | } |
296 | 324 |
|
| 325 | + public boolean isZeroOne() |
| 326 | + { return card2 == ZEROONE; } |
| 327 | + |
| 328 | + public boolean isOptional() |
| 329 | + { return card2 == ZEROONE || card2 == MANY; } |
| 330 | + |
| 331 | + public boolean isMandatory() |
| 332 | + { return card2 == ONE || card2 > 1; } |
| 333 | + |
297 | 334 | public boolean isPersistent() |
298 | 335 | { return hasStereotype("persistent"); } |
299 | 336 |
|
@@ -596,13 +633,15 @@ public void generateJava(PrintWriter out) |
596 | 633 |
|
597 | 634 | if (qualifier != null) |
598 | 635 | { out.println("java.util.Map " + role2 + " = new java.util.HashMap();"); } |
599 | | - else if (card2 == ONE) |
| 636 | + else if (card2 == ONE && entity2 != null) |
600 | 637 | { out.println(entity2.getName() + " " + role2 + ";"); } |
601 | | - else |
| 638 | + else if (entity2 != null) |
602 | 639 | { out.println("List " + |
603 | 640 | role2 + initialiser + "; // of " + |
604 | 641 | entity2.getName()); |
605 | 642 | } |
| 643 | + else |
| 644 | + { out.println("Object " + role2 + "; // Undefined class type"); } |
606 | 645 | } |
607 | 646 | } // not valid for a..b a > 0. Should be array then? |
608 | 647 |
|
|
0 commit comments