Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
CommentEdge |
|
| 2.769230769230769;2.769 |
1 | /* $Id: CommentEdge.java 17846 2010-01-12 19:37:12Z 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 | * mvw | |
11 | ***************************************************************************** | |
12 | * | |
13 | * Some portions of this file was previously release using the BSD License: | |
14 | */ | |
15 | ||
16 | // Copyright (c) 1996-2009 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; | |
40 | ||
41 | import javax.management.Notification; | |
42 | import javax.management.NotificationBroadcasterSupport; | |
43 | ||
44 | import org.argouml.i18n.Translator; | |
45 | import org.argouml.model.Model; | |
46 | import org.argouml.model.UUIDManager; | |
47 | ||
48 | ||
49 | /** | |
50 | * An object tagged as being the owner of a FigEdgeNote. Has knowledge | |
51 | * about the source and destination of the FigEdgeNote. <p> | |
52 | * | |
53 | * The source and destination are ModelElements. | |
54 | * At least one of them is a Comment - but they may be both Comments. | |
55 | * | |
56 | * TODO: There's tons of special case code scattered around ArgoUML for this | |
57 | * one class since it is the only "owner" of a FigEdgeModelElement which is not | |
58 | * a UML element. We should find a way to generalize this.<p> | |
59 | * | |
60 | * TODO: Issue 3031 requires this class to be replaced by | |
61 | * a similar mechanism as the n-ary association class: | |
62 | * the node and the edges shall all have the same owner, | |
63 | * i.e. the UML Comment object. | |
64 | * | |
65 | * @since Jul 17, 2004 | |
66 | * @author jaap.branderhorst@xs4all.nl | |
67 | */ | |
68 | public class CommentEdge extends NotificationBroadcasterSupport { | |
69 | private Object source; | |
70 | private Object dest; | |
71 | private Object uuid; | |
72 | private Object comment; | |
73 | private Object annotatedElement; | |
74 | ||
75 | 0 | public CommentEdge() { |
76 | 0 | uuid = UUIDManager.getInstance().getNewUUID(); |
77 | 0 | } |
78 | ||
79 | /** | |
80 | * Constructor. | |
81 | * | |
82 | * @param theSource the source | |
83 | * @param theDest the destination | |
84 | */ | |
85 | 0 | public CommentEdge(Object theSource, Object theDest) { |
86 | 0 | if (!(Model.getFacade().isAModelElement(theSource))) { |
87 | 0 | throw new IllegalArgumentException( |
88 | "The source of the CommentEdge must be a model element"); | |
89 | } | |
90 | 0 | if (!(Model.getFacade().isAModelElement(theDest))) { |
91 | 0 | throw new IllegalArgumentException( |
92 | "The destination of the CommentEdge " | |
93 | + "must be a model element"); | |
94 | } | |
95 | 0 | if (Model.getFacade().isAComment(theSource)) { |
96 | 0 | comment = theSource; |
97 | 0 | annotatedElement = theDest; |
98 | } else { | |
99 | 0 | comment = theDest; |
100 | 0 | annotatedElement = theSource; |
101 | } | |
102 | 0 | this.source = theSource; |
103 | 0 | this.dest = theDest; |
104 | 0 | uuid = UUIDManager.getInstance().getNewUUID(); |
105 | 0 | } |
106 | ||
107 | /** | |
108 | * The source of this CommentEdge. | |
109 | * | |
110 | * @return the source | |
111 | */ | |
112 | public Object getSource() { | |
113 | 0 | return source; |
114 | } | |
115 | ||
116 | /** | |
117 | * The destination of this CommentEdge. | |
118 | * | |
119 | * @return the destination | |
120 | */ | |
121 | public Object getDestination() { | |
122 | 0 | return dest; |
123 | } | |
124 | ||
125 | /** | |
126 | * @return the uuid | |
127 | */ | |
128 | public Object getUUID() { | |
129 | 0 | return uuid; |
130 | } | |
131 | ||
132 | ||
133 | /** | |
134 | * @param destination The destination to set. | |
135 | */ | |
136 | public void setDestination(Object destination) { | |
137 | 0 | if (destination == null) { |
138 | 0 | throw new IllegalArgumentException( |
139 | "The destination of a comment edge cannot be null"); | |
140 | } | |
141 | 0 | if (!(Model.getFacade().isAModelElement(destination))) { |
142 | 0 | throw new IllegalArgumentException( |
143 | "The destination of the CommentEdge cannot be a " | |
144 | + destination.getClass().getName()); | |
145 | } | |
146 | 0 | dest = destination; |
147 | 0 | } |
148 | ||
149 | /** | |
150 | * @param theSource The source to set. | |
151 | */ | |
152 | public void setSource(Object theSource) { | |
153 | 0 | if (theSource == null) { |
154 | 0 | throw new IllegalArgumentException( |
155 | "The source of a comment edge cannot be null"); | |
156 | } | |
157 | 0 | if (!(Model.getFacade().isAModelElement(theSource))) { |
158 | 0 | throw new IllegalArgumentException( |
159 | "The source of the CommentEdge cannot be a " | |
160 | + theSource.getClass().getName()); | |
161 | } | |
162 | 0 | this.source = theSource; |
163 | 0 | } |
164 | ||
165 | /** | |
166 | * Commit suicide. Adapt the UML model. | |
167 | */ | |
168 | public void delete() { | |
169 | 0 | if (Model.getFacade().isAComment(source)) { |
170 | 0 | Model.getCoreHelper().removeAnnotatedElement(source, dest); |
171 | } else { | |
172 | // not safe to presume the destination is the comment | |
173 | 0 | if (Model.getFacade().isAComment(dest)) { |
174 | 0 | Model.getCoreHelper().removeAnnotatedElement(dest, source); |
175 | } | |
176 | } | |
177 | 0 | this.sendNotification(new Notification("remove", this, 0)); |
178 | 0 | } |
179 | ||
180 | /* | |
181 | * @see java.lang.Object#toString() | |
182 | */ | |
183 | public String toString() { | |
184 | // This is the tooltip of a comment link | |
185 | 0 | return Translator.localize("misc.tooltip.commentlink"); |
186 | } | |
187 | ||
188 | public Object getAnnotatedElement() { | |
189 | 0 | return annotatedElement; |
190 | } | |
191 | ||
192 | public void setAnnotatedElement(Object theAnnotatedElement) { | |
193 | 0 | if (theAnnotatedElement == null) { |
194 | 0 | throw new IllegalArgumentException( |
195 | "An annotated element must be supplied"); | |
196 | } | |
197 | 0 | if (Model.getFacade().isAComment(theAnnotatedElement)) { |
198 | 0 | throw new IllegalArgumentException( |
199 | "An annotated element cannot be a comment"); | |
200 | } | |
201 | 0 | this.annotatedElement = theAnnotatedElement; |
202 | 0 | } |
203 | ||
204 | public Object getComment() { | |
205 | 0 | return comment; |
206 | } | |
207 | ||
208 | public void setComment(Object theComment) { | |
209 | 0 | if (theComment == null) { |
210 | 0 | throw new IllegalArgumentException("A comment must be supplied"); |
211 | } | |
212 | 0 | if (!Model.getFacade().isAComment(theComment)) { |
213 | 0 | throw new IllegalArgumentException("A comment cannot be a " |
214 | + theComment.getClass().getName()); | |
215 | } | |
216 | 0 | this.comment = theComment; |
217 | 0 | } |
218 | } |