Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
CrMultipleAgg |
|
| 4.0;4 |
1 | /* $Id: CrMultipleAgg.java 17849 2010-01-12 19:50:34Z linus $ | |
2 | ***************************************************************************** | |
3 | * Copyright (c) 2009 Contributors - see below | |
4 | * All rights reserved. This program and the accompanying materials | |
5 | * are made available under the terms of the Eclipse Public License v1.0 | |
6 | * which accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
8 | * | |
9 | * Contributors: | |
10 | * maurelio1234 | |
11 | ***************************************************************************** | |
12 | * | |
13 | * Some portions of this file was previously release using the BSD License: | |
14 | */ | |
15 | ||
16 | // Copyright (c) 1996-2007 The Regents of the University of California. All | |
17 | // Rights Reserved. Permission to use, copy, modify, and distribute this | |
18 | // software and its documentation without fee, and without a written | |
19 | // agreement is hereby granted, provided that the above copyright notice | |
20 | // and this paragraph appear in all copies. This software program and | |
21 | // documentation are copyrighted by The Regents of the University of | |
22 | // California. The software program and documentation are supplied "AS | |
23 | // IS", without any accompanying services from The Regents. The Regents | |
24 | // does not warrant that the operation of the program will be | |
25 | // uninterrupted or error-free. The end-user understands that the program | |
26 | // was developed for research purposes and is advised not to rely | |
27 | // exclusively on the program for any reason. IN NO EVENT SHALL THE | |
28 | // UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, | |
29 | // SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, | |
30 | // ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF | |
31 | // THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF | |
32 | // SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY | |
33 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
34 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE | |
35 | // PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF | |
36 | // CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, | |
37 | // UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | |
38 | ||
39 | package org.argouml.uml.cognitive.critics; | |
40 | ||
41 | import java.util.Collection; | |
42 | import java.util.HashSet; | |
43 | import java.util.Iterator; | |
44 | import java.util.Set; | |
45 | ||
46 | import org.argouml.cognitive.Critic; | |
47 | import org.argouml.cognitive.Designer; | |
48 | import org.argouml.cognitive.ToDoItem; | |
49 | import org.argouml.model.Model; | |
50 | import org.argouml.uml.cognitive.UMLDecision; | |
51 | ||
52 | /** | |
53 | * A critic to check that only one end of a binary association is an | |
54 | * aggregation.<p> | |
55 | * | |
56 | * This is the second well-formedness rule for associations in the UML 1.3 | |
57 | * standard (see section 2.5.3 of the standard).<p> | |
58 | * | |
59 | * Well-formedness rule [2] for Association. See page 52 of UML 1.4 | |
60 | * Semantics. OMG document UML 1.4.2 formal/04-07-02. | |
61 | * | |
62 | * <em>Note</em>. This only applies to binary associations. There is a | |
63 | * separate critic (see {@link org.argouml.uml.cognitive.critics.CrNWayAgg}) | |
64 | * which deals with 3- or more-way assocations.<p> | |
65 | * | |
66 | * See ArgoUML User Manual: Two Aggregate ends (roles) in binary Association | |
67 | * | |
68 | * @author jrobbins | |
69 | */ | |
70 | public class CrMultipleAgg extends CrUML { | |
71 | ||
72 | /** | |
73 | * Constructor for the critic.<p> | |
74 | * | |
75 | * Sets up the resource name, which will allow headline and description | |
76 | * to found for the current locale. Provides a design issue category | |
77 | * (CONTAINMENT), a knowledge type (SEMANTICS) and add triggers for | |
78 | * "end_aggregation".<p> | |
79 | */ | |
80 | 900 | public CrMultipleAgg() { |
81 | 900 | setupHeadAndDesc(); |
82 | 900 | addSupportedDecision(UMLDecision.CONTAINMENT); |
83 | 900 | setKnowledgeTypes(Critic.KT_SEMANTICS); |
84 | ||
85 | // These may not actually make any difference at present (the code | |
86 | // behind addTrigger needs more work). | |
87 | ||
88 | 900 | addTrigger("end_aggregation"); |
89 | 900 | } |
90 | ||
91 | /** | |
92 | * The trigger for the critic.<p> | |
93 | * | |
94 | * Check that the number of ends is two, otherwise this should be | |
95 | * handled by the critic for N-way assocations (see {@link | |
96 | * org.argouml.uml.cognitive.critics.CrNWayAgg}).<p> | |
97 | * | |
98 | * We do not handle association roles, which are a subclass of | |
99 | * association. An association role should be fine, if its parent is OK, | |
100 | * since it must be more tightly constrained than its parent.<p> | |
101 | * | |
102 | * <em>Note</em>. ArgoUML does not currently have a constructor to check | |
103 | * that an association role is more tightly constrained than its | |
104 | * parent.<p> | |
105 | * | |
106 | * Then loop through the ends, counting the number of aggregate | |
107 | * ends. Note that we look for aggregation explicitly, rather than just | |
108 | * absence of "no aggregation", so we don't trigger if the aggregation is | |
109 | * just undefined.<p> | |
110 | * | |
111 | * @param dm the {@link java.lang.Object Object} to be checked against | |
112 | * the critic. | |
113 | * | |
114 | * @param dsgr the {@link org.argouml.cognitive.Designer Designer} | |
115 | * creating the model. Not used, this is for future | |
116 | * development of ArgoUML. | |
117 | * | |
118 | * @return {@link #PROBLEM_FOUND PROBLEM_FOUND} if the critic is | |
119 | * triggered, otherwise {@link #NO_PROBLEM NO_PROBLEM}. | |
120 | */ | |
121 | public boolean predicate2(Object dm, Designer dsgr) { | |
122 | ||
123 | // Only for associations | |
124 | ||
125 | 0 | if (!(Model.getFacade().isAAssociation(dm))) { |
126 | 0 | return NO_PROBLEM; |
127 | } | |
128 | ||
129 | // Get the assocations and connections. No problem (there is a separate | |
130 | // critic) if this is not a binary association or is an association | |
131 | // role. | |
132 | ||
133 | 0 | Object asc = /*(MAssociation)*/ dm; |
134 | ||
135 | 0 | if (Model.getFacade().isAAssociationRole(asc)) { |
136 | 0 | return NO_PROBLEM; |
137 | } | |
138 | ||
139 | 0 | Collection conns = Model.getFacade().getConnections(asc); |
140 | ||
141 | 0 | if ((conns == null) || (conns.size() != 2)) { |
142 | 0 | return NO_PROBLEM; |
143 | } | |
144 | ||
145 | // Loop through the associations, counting the ends with aggregations | |
146 | ||
147 | 0 | int aggCount = 0; |
148 | 0 | Iterator assocEnds = conns.iterator(); |
149 | 0 | while (assocEnds.hasNext()) { |
150 | 0 | Object ae = /*(MAssociationEnd)*/ assocEnds.next(); |
151 | 0 | if (Model.getFacade().isAggregate(ae) |
152 | || Model.getFacade().isComposite(ae)) { | |
153 | 0 | aggCount++; |
154 | } | |
155 | 0 | } |
156 | ||
157 | // A problem if we found more than 1 aggregation | |
158 | ||
159 | 0 | if (aggCount > 1) { |
160 | 0 | return PROBLEM_FOUND; |
161 | } else { | |
162 | 0 | return NO_PROBLEM; |
163 | } | |
164 | } | |
165 | ||
166 | /** | |
167 | * Find the class which will handle the wizard behaviour.<p> | |
168 | * | |
169 | * @param item the {@link ToDoItem} that triggered the critic. | |
170 | * | |
171 | * @return {@link Class} of the wizard. | |
172 | */ | |
173 | ||
174 | public Class getWizardClass(ToDoItem item) { | |
175 | 0 | return WizAssocComposite.class; |
176 | } | |
177 | ||
178 | /* | |
179 | * @see org.argouml.uml.cognitive.critics.CrUML#getCriticizedDesignMaterials() | |
180 | */ | |
181 | public Set<Object> getCriticizedDesignMaterials() { | |
182 | 900 | Set<Object> ret = new HashSet<Object>(); |
183 | 900 | ret.add(Model.getMetaTypes().getAssociationClass()); |
184 | 900 | return ret; |
185 | } | |
186 | ||
187 | } /* end class CrMultipleAgg */ |