View Javadoc

1   /*
2    * UML2MMBase module.
3    *
4    * The contents of this file are subject to the Mozilla Public License
5    * Version 1.0 (the "License"); you may not use this file except in
6    * compliance with the License. You may obtain a copy of the License at
7    * http://www.mozilla.org/MPL/
8    *
9    * Software distributed under the License is distributed on an "AS IS"
10   * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
11   * License for the specific language governing rights and limitations
12   * under the License.
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  }