1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
package org.argouml.notation.providers.uml; |
40 | |
import java.text.ParseException; |
41 | |
import java.util.Collection; |
42 | |
import java.util.Iterator; |
43 | |
import java.util.StringTokenizer; |
44 | |
|
45 | |
import org.argouml.application.events.ArgoEventPump; |
46 | |
import org.argouml.application.events.ArgoEventTypes; |
47 | |
import org.argouml.application.events.ArgoHelpEvent; |
48 | |
import org.argouml.i18n.Translator; |
49 | |
import org.argouml.kernel.ProjectManager; |
50 | |
import org.argouml.model.Model; |
51 | |
import org.argouml.notation.NotationSettings; |
52 | |
import org.argouml.notation.providers.CallStateNotation; |
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
public class CallStateNotationUml extends CallStateNotation { |
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
public CallStateNotationUml(Object callState) { |
77 | 0 | super(callState); |
78 | 0 | } |
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
public void parse(Object modelElement, String text) { |
84 | |
try { |
85 | 0 | parseCallState(modelElement, text); |
86 | 0 | } catch (ParseException pe) { |
87 | 0 | String msg = "statusmsg.bar.error.parsing.callstate"; |
88 | 0 | Object[] args = {pe.getLocalizedMessage(), |
89 | |
Integer.valueOf(pe.getErrorOffset()), }; |
90 | 0 | ArgoEventPump.fireEvent(new ArgoHelpEvent( |
91 | |
ArgoEventTypes.HELP_CHANGED, this, |
92 | |
Translator.messageFormat(msg, args))); |
93 | 0 | } |
94 | 0 | } |
95 | |
|
96 | |
protected Object parseCallState(Object callState, String s1) |
97 | |
throws ParseException { |
98 | |
|
99 | 0 | String s = s1.trim(); |
100 | |
|
101 | 0 | int a = s.indexOf("("); |
102 | 0 | int b = s.indexOf(")"); |
103 | 0 | if (((a < 0) && (b >= 0)) || ((b < 0) && (a >= 0)) || (b < a)) { |
104 | 0 | throw new ParseException("No matching brackets () found.", 0); |
105 | |
} |
106 | |
|
107 | |
|
108 | 0 | String newClassName = null; |
109 | 0 | String newOperationName = null; |
110 | 0 | StringTokenizer tokenizer = new StringTokenizer(s, "("); |
111 | 0 | while (tokenizer.hasMoreTokens()) { |
112 | 0 | String nextToken = tokenizer.nextToken().trim(); |
113 | 0 | if (nextToken.endsWith(")")) { |
114 | 0 | newClassName = nextToken.substring(0, nextToken.length() - 1); |
115 | |
} else { |
116 | 0 | newOperationName = nextToken.trim(); |
117 | |
} |
118 | 0 | } |
119 | |
|
120 | |
|
121 | 0 | String oldOperationName = null; |
122 | 0 | String oldClassName = null; |
123 | 0 | Object entry = Model.getFacade().getEntry(callState); |
124 | 0 | Object operation = null; |
125 | 0 | Object clazz = null; |
126 | 0 | if (Model.getFacade().isACallAction(entry)) { |
127 | 0 | operation = Model.getFacade().getOperation(entry); |
128 | 0 | if (Model.getFacade().isAOperation(operation)) { |
129 | 0 | oldOperationName = Model.getFacade().getName(operation); |
130 | 0 | clazz = Model.getFacade().getOwner(operation); |
131 | 0 | oldClassName = Model.getFacade().getName(clazz); |
132 | |
} |
133 | |
} |
134 | |
|
135 | |
|
136 | 0 | boolean found = false; |
137 | 0 | if ((newClassName != null) |
138 | |
&& newClassName.equals(oldClassName) |
139 | |
&& (newOperationName != null) |
140 | |
&& !newOperationName.equals(oldOperationName)) { |
141 | |
|
142 | 0 | for ( Object op : Model.getFacade().getOperations(clazz)) { |
143 | 0 | if (newOperationName.equals( |
144 | |
Model.getFacade().getName(op))) { |
145 | 0 | Model.getCommonBehaviorHelper().setOperation(entry, op); |
146 | 0 | found = true; |
147 | 0 | break; |
148 | |
} |
149 | |
} |
150 | 0 | if (!found) { |
151 | 0 | throw new ParseException( |
152 | |
"Operation " + newOperationName |
153 | |
+ " not found in " + newClassName + ".", 0); |
154 | |
} |
155 | |
|
156 | 0 | } else if ((newClassName != null) |
157 | |
&& !newClassName.equals(oldClassName) |
158 | |
&& (newOperationName != null)) { |
159 | |
|
160 | 0 | Object model = |
161 | |
ProjectManager.getManager().getCurrentProject().getRoot(); |
162 | 0 | Collection c = |
163 | |
Model.getModelManagementHelper(). |
164 | |
getAllModelElementsOfKind(model, |
165 | |
Model.getMetaTypes().getClassifier()); |
166 | 0 | Iterator i = c.iterator(); |
167 | 0 | Object classifier = null; |
168 | 0 | while (i.hasNext()) { |
169 | 0 | Object cl = i.next(); |
170 | 0 | String cn = Model.getFacade().getName(cl); |
171 | 0 | if (cn.equals(newClassName)) { |
172 | 0 | classifier = cl; |
173 | 0 | break; |
174 | |
} |
175 | 0 | } |
176 | 0 | if (classifier == null) { |
177 | 0 | throw new ParseException( |
178 | |
"Classifier " + newClassName + " not found.", 0); |
179 | |
} |
180 | |
|
181 | 0 | if (classifier != null) { |
182 | 0 | Collection ops = Model.getFacade().getOperations(classifier); |
183 | 0 | Iterator io = ops.iterator(); |
184 | 0 | while (io.hasNext()) { |
185 | 0 | Object op = io.next(); |
186 | 0 | if (newOperationName.equals( |
187 | |
Model.getFacade().getName(op))) { |
188 | |
|
189 | |
|
190 | 0 | found = true; |
191 | 0 | if (!Model.getFacade().isACallAction(entry)) { |
192 | 0 | entry = Model.getCommonBehaviorFactory() |
193 | |
.buildCallAction(op, "ca"); |
194 | 0 | Model.getStateMachinesHelper().setEntry( |
195 | |
callState, entry); |
196 | |
} else { |
197 | 0 | Model.getCommonBehaviorHelper().setOperation( |
198 | |
entry, op); |
199 | |
} |
200 | 0 | break; |
201 | |
} |
202 | 0 | } |
203 | 0 | if (!found) { |
204 | 0 | throw new ParseException( |
205 | |
"Operation " + newOperationName |
206 | |
+ " not found in " + newClassName + ".", 0); |
207 | |
} |
208 | |
} |
209 | |
} |
210 | 0 | if (!found) { |
211 | 0 | throw new ParseException( |
212 | |
"Incompatible input found.", 0); |
213 | |
} |
214 | |
|
215 | 0 | return callState; |
216 | |
} |
217 | |
|
218 | |
|
219 | |
|
220 | |
|
221 | |
public String getParsingHelp() { |
222 | 0 | return "parsing.help.fig-callstate"; |
223 | |
} |
224 | |
|
225 | |
private String toString(Object modelElement) { |
226 | 0 | String ret = ""; |
227 | 0 | Object action = Model.getFacade().getEntry(modelElement); |
228 | 0 | if (Model.getFacade().isACallAction(action)) { |
229 | 0 | Object operation = Model.getFacade().getOperation(action); |
230 | 0 | if (operation != null) { |
231 | 0 | Object n = Model.getFacade().getName(operation); |
232 | 0 | if (n != null) { |
233 | 0 | ret = (String) n; |
234 | |
} |
235 | 0 | n = |
236 | |
Model.getFacade().getName( |
237 | |
Model.getFacade().getOwner(operation)); |
238 | 0 | if (n != null && !n.equals("")) { |
239 | 0 | ret += "\n(" + (String) n + ")"; |
240 | |
} |
241 | |
} |
242 | |
} |
243 | |
|
244 | 0 | if (ret == null) { |
245 | 0 | return ""; |
246 | |
} |
247 | 0 | return ret; |
248 | |
} |
249 | |
|
250 | |
@Override |
251 | |
public String toString(Object modelElement, NotationSettings settings) { |
252 | 0 | return toString(modelElement); |
253 | |
} |
254 | |
|
255 | |
} |