1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package com.finalist.mmbase.uml;
16
17 import org.omg.uml.foundation.core.AssociationEnd;
18 import org.omg.uml.foundation.core.ModelElement;
19 import org.omg.uml.foundation.datatypes.MultiplicityRange;
20 import java.util.Collection;
21 import java.util.Iterator;
22
23 /***
24 *
25 * Helper classes to get access to association specific uml model elements.
26 *
27 * @author Rudie Ekkelenkamp - Finalist IT Group
28 * @version $Revision: 1.4 $, $Date: 2004/12/08 23:27:32 $
29 *
30 */
31 public class MMBaseAssociationHelper {
32
33 private MMBaseHelper model = null;
34
35 /*** Default constructor. */
36 public MMBaseAssociationHelper(MMBaseHelper model) {
37 this.model = model;
38 }
39
40 /***
41 * Returns the name of a model element fully qualified by the
42 * name of the package that contains it.
43 *
44 * @param object model element
45 * @return fully qualifed name
46 */
47 public String getAssocationName(Object object) {
48 if ((object == null) || !(object instanceof ModelElement)) {
49 return null;
50 }
51 ModelElement modelElement = (ModelElement) object;
52 String fullName = modelElement.getName();
53 return fullName;
54 }
55
56 /***
57 * Gets the lower cardinality of an association end.
58 * If not specified, the value is set to 1.
59 * @param ae Association End
60 * @return cardinality
61 */
62 public static String getCardinalityLower(AssociationEnd ae) {
63 Collection ranges = ae.getMultiplicity().getRange();
64 for (Iterator i = ranges.iterator(); i.hasNext();) {
65 MultiplicityRange range = (MultiplicityRange) i.next();
66 return "" + range.getLower();
67 }
68 return "1";
69 }
70
71 /***
72 * get the upper cardinality of an association end.
73 * If not specified, the value is set to 1.
74 * Cardinality * will be represented by -1
75 *
76 * @param ae Association End
77 * @return cardinality
78 */
79 public static String getCardinalityUpper(AssociationEnd ae) {
80 Collection ranges = ae.getMultiplicity().getRange();
81 for (Iterator i = ranges.iterator(); i.hasNext();) {
82 MultiplicityRange range = (MultiplicityRange) i.next();
83 return "" + range.getUpper();
84 }
85 return "1";
86 }
87 }