Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
CrNWayAgg |
|
| 4.666666666666667;4.667 |
1 | /* $Id: CrNWayAgg.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.model.Model; | |
49 | import org.argouml.uml.cognitive.UMLDecision; | |
50 | ||
51 | /** | |
52 | * A critic to check that no end of a 3-way (or more) association is an | |
53 | * aggregation.<p> | |
54 | * | |
55 | * This is the third well-formedness rule for associations in the UML 1.3 | |
56 | * standard (see section 2.5.3 of the standard).<p> | |
57 | * | |
58 | * Well-formedness rule [3] for Association. See page 52 of UML 1.4 | |
59 | * Semantics. OMG document UML 1.4.2 formal/04-07-02. | |
60 | * | |
61 | * <em>Note</em>. This only applies to 3-way or more | |
62 | * associations. There is a separate critic (see {@link | |
63 | * org.argouml.uml.cognitive.critics.CrMultipleAgg}) which deals with | |
64 | * 2-way assocations. <p> | |
65 | * | |
66 | * See ArgoUML User Manual: Two Aggregate ends (roles) in binary Association | |
67 | * | |
68 | * @author jrobbins | |
69 | */ | |
70 | public class CrNWayAgg 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 | * "connection" and "end_aggregation". | |
79 | */ | |
80 | 900 | public CrNWayAgg() { |
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("connection"); |
89 | 900 | addTrigger("end_aggregation"); |
90 | 900 | } |
91 | ||
92 | ||
93 | /** | |
94 | * The trigger for the critic.<p> | |
95 | * | |
96 | * Check that the number of ends more than two, otherwise this should be | |
97 | * handled by the critic for 2-way assocations (see {@link | |
98 | * org.argouml.uml.cognitive.critics.CrMultipleAgg}).<p> | |
99 | * | |
100 | * We do not handle association roles, which are a subclass of | |
101 | * association. An association role should be fine, if its parent is OK, | |
102 | * since it must be more tightly constrained than its parent.<p> | |
103 | * | |
104 | * <em>Note</em>. ArgoUML does not currently have a constructor to check | |
105 | * that an association role is more tightly constrained than its | |
106 | * parent.<p> | |
107 | * | |
108 | * Then loop through the ends, looking for aggregate ends. Note that we | |
109 | * look for aggregation explicitly, rather than just absence of "no | |
110 | * aggregation", so we don't trigger if the aggregation is just | |
111 | * undefined. | |
112 | * | |
113 | * @param dm the {@link java.lang.Object Object} to be checked against | |
114 | * the critic. | |
115 | * | |
116 | * @param dsgr the {@link org.argouml.cognitive.Designer Designer} | |
117 | * creating the model. Not used, this is for future | |
118 | * development of ArgoUML. | |
119 | * | |
120 | * @return {@link #PROBLEM_FOUND PROBLEM_FOUND} if the critic is | |
121 | * triggered, otherwise {@link #NO_PROBLEM NO_PROBLEM}. | |
122 | */ | |
123 | ||
124 | public boolean predicate2(Object dm, Designer dsgr) { | |
125 | ||
126 | // Only work for associatins | |
127 | ||
128 | 0 | if (!(Model.getFacade().isAAssociation(dm))) { |
129 | 0 | return NO_PROBLEM; |
130 | } | |
131 | ||
132 | // Get the assocations and connections. No problem (there is a separate | |
133 | // critic) if this is a binary association or is an association role. | |
134 | ||
135 | 0 | Object asc = /*(MAssociation)*/ dm; |
136 | ||
137 | 0 | if (Model.getFacade().isAAssociationRole(asc)) { |
138 | 0 | return NO_PROBLEM; |
139 | } | |
140 | ||
141 | 0 | Collection conns = Model.getFacade().getConnections(asc); |
142 | ||
143 | 0 | if ((conns == null) || (conns.size() <= 2)) { |
144 | 0 | return NO_PROBLEM; |
145 | } | |
146 | ||
147 | // Loop through the associations, looking for one with aggregation | |
148 | ||
149 | 0 | Iterator assocEnds = conns.iterator(); |
150 | 0 | while (assocEnds.hasNext()) { |
151 | 0 | Object ae = /*(MAssociationEnd)*/ assocEnds.next(); |
152 | 0 | if (Model.getFacade().isAggregate(ae) |
153 | || Model.getFacade().isComposite(ae)) { | |
154 | 0 | return PROBLEM_FOUND; |
155 | } | |
156 | 0 | } |
157 | ||
158 | // If drop out, we're OK | |
159 | ||
160 | 0 | return NO_PROBLEM; |
161 | } | |
162 | ||
163 | ||
164 | /* | |
165 | * @see org.argouml.uml.cognitive.critics.CrUML#getCriticizedDesignMaterials() | |
166 | */ | |
167 | public Set<Object> getCriticizedDesignMaterials() { | |
168 | 900 | Set<Object> ret = new HashSet<Object>(); |
169 | 900 | ret.add(Model.getMetaTypes().getAssociationClass()); |
170 | 900 | return ret; |
171 | } | |
172 | ||
173 | /** | |
174 | * The UID. | |
175 | */ | |
176 | private static final long serialVersionUID = 5318978944855930303L; | |
177 | } /* end class CrNWayAgg.java */ |