Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
CrWrongDepEnds |
|
| 5.8;5.8 |
1 | /* $Id: CrWrongDepEnds.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 | * tfmorris | |
11 | ***************************************************************************** | |
12 | * | |
13 | * Some portions of this file was previously release using the BSD License: | |
14 | */ | |
15 | ||
16 | // Copyright (c) 1996-2006 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 | ||
43 | import org.argouml.cognitive.Designer; | |
44 | import org.argouml.cognitive.ListSet; | |
45 | import org.argouml.cognitive.ToDoItem; | |
46 | import org.argouml.model.Model; | |
47 | import org.argouml.uml.cognitive.UMLDecision; | |
48 | import org.argouml.uml.cognitive.UMLToDoItem; | |
49 | import org.argouml.uml.diagram.deployment.ui.UMLDeploymentDiagram; | |
50 | import org.argouml.uml.diagram.ui.FigDependency; | |
51 | ||
52 | /** | |
53 | * A critic to detect when in a deployment-diagram the supplier or the | |
54 | * client of a dependency is a mobject and inside a figComponent and | |
55 | * the other end is a mobject and inside a figComponentInstance. | |
56 | * | |
57 | * @author 5eichler | |
58 | */ | |
59 | public class CrWrongDepEnds extends CrUML { | |
60 | ||
61 | /** | |
62 | * The constructor. | |
63 | */ | |
64 | 0 | public CrWrongDepEnds() { |
65 | 0 | setupHeadAndDesc(); |
66 | 0 | addSupportedDecision(UMLDecision.PATTERNS); |
67 | 0 | } |
68 | ||
69 | /* | |
70 | * @see org.argouml.uml.cognitive.critics.CrUML#predicate2( | |
71 | * java.lang.Object, org.argouml.cognitive.Designer) | |
72 | */ | |
73 | @Override | |
74 | public boolean predicate2(Object dm, Designer dsgr) { | |
75 | 0 | if (!(dm instanceof UMLDeploymentDiagram)) { |
76 | 0 | return NO_PROBLEM; |
77 | } | |
78 | 0 | UMLDeploymentDiagram dd = (UMLDeploymentDiagram) dm; |
79 | 0 | ListSet offs = computeOffenders(dd); |
80 | 0 | if (offs == null) { |
81 | 0 | return NO_PROBLEM; |
82 | } | |
83 | 0 | return PROBLEM_FOUND; |
84 | } | |
85 | ||
86 | /* | |
87 | * @see org.argouml.cognitive.critics.Critic#toDoItem( java.lang.Object, | |
88 | * org.argouml.cognitive.Designer) | |
89 | */ | |
90 | @Override | |
91 | public ToDoItem toDoItem(Object dm, Designer dsgr) { | |
92 | 0 | UMLDeploymentDiagram dd = (UMLDeploymentDiagram) dm; |
93 | 0 | ListSet offs = computeOffenders(dd); |
94 | 0 | return new UMLToDoItem(this, offs, dsgr); |
95 | } | |
96 | ||
97 | /* | |
98 | * @see org.argouml.cognitive.Poster#stillValid( | |
99 | * org.argouml.cognitive.ToDoItem, org.argouml.cognitive.Designer) | |
100 | */ | |
101 | @Override | |
102 | public boolean stillValid(ToDoItem i, Designer dsgr) { | |
103 | 0 | if (!isActive()) { |
104 | 0 | return false; |
105 | } | |
106 | 0 | ListSet offs = i.getOffenders(); |
107 | 0 | UMLDeploymentDiagram dd = (UMLDeploymentDiagram) offs.get(0); |
108 | //if (!predicate(dm, dsgr)) return false; | |
109 | 0 | ListSet newOffs = computeOffenders(dd); |
110 | 0 | boolean res = offs.equals(newOffs); |
111 | 0 | return res; |
112 | } | |
113 | ||
114 | /** | |
115 | * If there are deps that are going from inside a FigComponent to | |
116 | * inside a FigComponentInstance the returned vector-set is not | |
117 | * null. Then in the vector-set are the UMLDeploymentDiagram and | |
118 | * all FigDependencies with this characteristic and their | |
119 | * FigObjects described over the supplier and client. | |
120 | * | |
121 | * @param dd the diagram to check | |
122 | * @return the set of offenders | |
123 | */ | |
124 | public ListSet computeOffenders(UMLDeploymentDiagram dd) { | |
125 | 0 | Collection figs = dd.getLayer().getContents(); |
126 | 0 | ListSet offs = null; |
127 | 0 | for (Object obj : figs) { |
128 | 0 | if (!(obj instanceof FigDependency)) { |
129 | 0 | continue; |
130 | } | |
131 | 0 | FigDependency figDependency = (FigDependency) obj; |
132 | 0 | if (!(Model.getFacade().isADependency(figDependency.getOwner()))) { |
133 | 0 | continue; |
134 | } | |
135 | 0 | Object dependency = figDependency.getOwner(); |
136 | 0 | Collection suppliers = Model.getFacade().getSuppliers(dependency); |
137 | 0 | int count = 0; |
138 | 0 | if (suppliers != null) { |
139 | 0 | for (Object moe : suppliers) { |
140 | 0 | if (Model.getFacade().isAObject(moe)) { |
141 | 0 | Object objSup = moe; |
142 | 0 | if (Model.getFacade().getElementResidences(objSup) |
143 | != null | |
144 | && (Model.getFacade().getElementResidences(objSup) | |
145 | .size() > 0)) { | |
146 | 0 | count += 2; |
147 | } | |
148 | 0 | if (Model.getFacade().getComponentInstance(objSup) |
149 | != null) { | |
150 | 0 | count++; |
151 | } | |
152 | 0 | } |
153 | } | |
154 | } | |
155 | 0 | Collection clients = Model.getFacade().getClients(dependency); |
156 | 0 | if (clients != null && (clients.size() > 0)) { |
157 | 0 | for (Object moe : clients) { |
158 | 0 | if (Model.getFacade().isAObject(moe)) { |
159 | 0 | Object objCli = moe; |
160 | 0 | if (Model.getFacade().getElementResidences(objCli) |
161 | != null | |
162 | && (Model.getFacade().getElementResidences(objCli) | |
163 | .size() > 0)) { | |
164 | 0 | count += 2; |
165 | } | |
166 | 0 | if (Model.getFacade().getComponentInstance(objCli) |
167 | != null) { | |
168 | 0 | count++; |
169 | } | |
170 | 0 | } |
171 | } | |
172 | } | |
173 | 0 | if (count == 3) { |
174 | 0 | if (offs == null) { |
175 | 0 | offs = new ListSet(); |
176 | 0 | offs.add(dd); |
177 | } | |
178 | 0 | offs.add(figDependency); |
179 | 0 | offs.add(figDependency.getSourcePortFig()); |
180 | 0 | offs.add(figDependency.getDestPortFig()); |
181 | } | |
182 | 0 | } |
183 | 0 | return offs; |
184 | } | |
185 | ||
186 | /** | |
187 | * The UID. | |
188 | */ | |
189 | private static final long serialVersionUID = -6587198606342935144L; | |
190 | } |