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.model.mdr; |
40 | |
|
41 | |
import java.util.Collection; |
42 | |
import java.util.Iterator; |
43 | |
|
44 | |
import org.argouml.model.CoreHelper; |
45 | |
import org.argouml.model.ExtensionMechanismsFactory; |
46 | |
import org.argouml.model.ExtensionMechanismsHelper; |
47 | |
import org.omg.uml.foundation.core.ModelElement; |
48 | |
import org.omg.uml.foundation.core.Namespace; |
49 | |
import org.omg.uml.foundation.core.Stereotype; |
50 | |
import org.omg.uml.foundation.core.TagDefinition; |
51 | |
import org.omg.uml.foundation.core.TaggedValue; |
52 | |
import org.omg.uml.foundation.datatypes.Multiplicity; |
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | 14 | class ExtensionMechanismsFactoryMDRImpl extends |
66 | |
AbstractUmlModelFactoryMDR implements ExtensionMechanismsFactory { |
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
private MDRModelImplementation modelImpl; |
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
private ExtensionMechanismsHelper extensionHelper; |
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | 900 | ExtensionMechanismsFactoryMDRImpl(MDRModelImplementation implementation) { |
85 | 900 | modelImpl = implementation; |
86 | 900 | extensionHelper = implementation.getExtensionMechanismsHelper(); |
87 | 900 | } |
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
public TaggedValue createTaggedValue() { |
93 | 0 | TaggedValue tv = modelImpl.getUmlPackage().getCore().getTaggedValue(). |
94 | |
createTaggedValue(); |
95 | 0 | super.initialize(tv); |
96 | 0 | return tv; |
97 | |
} |
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
TagDefinition getTagDefinition(String tagName) { |
106 | 0 | if (tagName == null) { |
107 | 0 | throw new IllegalArgumentException("Argument may not be null"); |
108 | |
} |
109 | |
|
110 | |
|
111 | 0 | for (Iterator i = modelImpl.getUmlPackage().getCore().getTagDefinition() |
112 | 0 | .refAllOfClass().iterator(); i.hasNext();) { |
113 | 0 | TagDefinition td = (TagDefinition) i.next(); |
114 | 0 | if (tagName.equals(td.getName())) { |
115 | 0 | return td; |
116 | |
} |
117 | 0 | } |
118 | |
|
119 | |
|
120 | 0 | Object rootModel = modelImpl.getModelManagementFactory().getRootModel(); |
121 | 0 | TagDefinition td = buildTagDefinition(tagName, null, rootModel); |
122 | |
|
123 | 0 | super.initialize(td); |
124 | 0 | return td; |
125 | |
} |
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
|
131 | |
|
132 | |
|
133 | |
|
134 | |
|
135 | |
|
136 | |
public Stereotype buildStereotype( |
137 | |
Object theModelElementObject, |
138 | |
Object theName, |
139 | |
Object theNamespaceObject) { |
140 | |
|
141 | 0 | if (theModelElementObject == null || theName == null |
142 | |
|| theNamespaceObject == null) { |
143 | 0 | throw new IllegalArgumentException( |
144 | |
"one of the arguments is null: modelElement=" |
145 | |
+ theModelElementObject |
146 | |
+ " name=" + theName |
147 | |
+ " namespace=" + theNamespaceObject); |
148 | |
} |
149 | |
|
150 | 0 | ModelElement me = (ModelElement) theModelElementObject; |
151 | |
|
152 | 0 | String text = (String) theName; |
153 | 0 | Namespace ns = (Namespace) theNamespaceObject; |
154 | 0 | Stereotype stereo = buildStereotype(text); |
155 | 0 | stereo.getBaseClass().add(modelImpl.getMetaTypes().getName(me)); |
156 | |
|
157 | 0 | Stereotype stereo2 = (Stereotype) extensionHelper.getStereotype(ns, |
158 | |
stereo); |
159 | 0 | if (stereo2 != null) { |
160 | 0 | me.getStereotype().add(stereo2); |
161 | 0 | modelImpl.getUmlFactory().delete(stereo); |
162 | 0 | return stereo2; |
163 | |
} |
164 | 0 | stereo.setNamespace(ns); |
165 | 0 | me.getStereotype().add(stereo); |
166 | 0 | return stereo; |
167 | |
} |
168 | |
|
169 | |
|
170 | |
public Stereotype buildStereotype( |
171 | |
Object theModelElementObject, |
172 | |
String theName, |
173 | |
Object model, |
174 | |
Collection models) { |
175 | |
|
176 | 0 | ModelElement me = (ModelElement) theModelElementObject; |
177 | |
|
178 | 0 | Stereotype stereo = buildStereotype(theName); |
179 | 0 | stereo.getBaseClass().add(modelImpl.getMetaTypes().getName(me)); |
180 | 0 | Stereotype stereo2 = (Stereotype) extensionHelper.getStereotype(models, |
181 | |
stereo); |
182 | 0 | if (stereo2 != null) { |
183 | 0 | me.getStereotype().add(stereo2); |
184 | 0 | modelImpl.getUmlFactory().delete(stereo); |
185 | 0 | return stereo2; |
186 | |
} |
187 | 0 | stereo.setNamespace((org.omg.uml.modelmanagement.Model) model); |
188 | 0 | if (me != null) { |
189 | 0 | me.getStereotype().add(stereo); |
190 | |
} |
191 | 0 | return stereo; |
192 | |
} |
193 | |
|
194 | |
|
195 | |
|
196 | |
|
197 | |
|
198 | |
|
199 | |
|
200 | |
|
201 | |
|
202 | |
|
203 | |
private Stereotype buildStereotype(String text) { |
204 | 0 | Stereotype stereotype = modelImpl.getUmlPackage().getCore(). |
205 | |
getStereotype().createStereotype(); |
206 | 0 | super.initialize(stereotype); |
207 | 0 | stereotype.setName(text); |
208 | 0 | return stereotype; |
209 | |
} |
210 | |
|
211 | |
|
212 | |
public Stereotype buildStereotype(String text, Object namespace) { |
213 | 14 | if (!(namespace instanceof Namespace)) { |
214 | 0 | throw new IllegalArgumentException( |
215 | |
"Namespace is wrong type - text:" + text + ",ns:" |
216 | |
+ namespace); |
217 | |
} |
218 | 14 | Namespace ns = (Namespace) namespace; |
219 | 14 | org.omg.uml.UmlPackage umlPkg = ((org.omg.uml.UmlPackage) ns |
220 | |
.refOutermostPackage()); |
221 | 14 | Stereotype stereotype = umlPkg.getCore().getStereotype() |
222 | |
.createStereotype(); |
223 | 14 | super.initialize(stereotype); |
224 | 14 | stereotype.setName(text); |
225 | 14 | stereotype.setNamespace(ns); |
226 | 14 | return stereotype; |
227 | |
} |
228 | |
|
229 | |
|
230 | |
@Deprecated |
231 | |
public TaggedValue buildTaggedValue(String tag, String value) { |
232 | 0 | TaggedValue tv = buildTaggedValue(getTagDefinition(tag)); |
233 | 0 | tv.getDataValue().add(value); |
234 | 0 | return tv; |
235 | |
} |
236 | |
|
237 | |
private TaggedValue buildTaggedValue(TagDefinition type) { |
238 | 0 | TaggedValue tv = createTaggedValue(); |
239 | 0 | tv.setType(type); |
240 | 0 | return tv; |
241 | |
} |
242 | |
|
243 | |
public TaggedValue buildTaggedValue(Object type, String[] values) { |
244 | 0 | if (!(type instanceof TagDefinition)) { |
245 | 0 | throw new IllegalArgumentException( |
246 | |
"TagDefinition required, received - " + type); |
247 | |
} |
248 | 0 | TaggedValue tv = buildTaggedValue((TagDefinition) type); |
249 | 0 | for (String value : values) { |
250 | 0 | tv.getDataValue().add(value); |
251 | |
} |
252 | 0 | return tv; |
253 | |
} |
254 | |
|
255 | |
|
256 | |
public void copyTaggedValues(Object source, Object target) { |
257 | 0 | if (!(source instanceof ModelElement) |
258 | |
|| !(target instanceof ModelElement)) { |
259 | 0 | throw new IllegalArgumentException(); |
260 | |
} |
261 | |
|
262 | 0 | Iterator it = ((ModelElement) source).getTaggedValue().iterator(); |
263 | 0 | Collection taggedValues = ((ModelElement) target).getTaggedValue(); |
264 | |
|
265 | |
|
266 | 0 | taggedValues.clear(); |
267 | 0 | while (it.hasNext()) { |
268 | 0 | taggedValues.add(copyTaggedValue((TaggedValue) it.next())); |
269 | |
} |
270 | 0 | } |
271 | |
|
272 | |
|
273 | |
|
274 | |
|
275 | |
|
276 | |
|
277 | |
|
278 | |
private Object copyTaggedValue(TaggedValue source) { |
279 | 0 | TaggedValue tv = createTaggedValue(); |
280 | 0 | tv.setType(source.getType()); |
281 | 0 | tv.getDataValue().addAll(source.getDataValue()); |
282 | 0 | tv.getReferenceValue().addAll(source.getReferenceValue()); |
283 | 0 | return tv; |
284 | |
} |
285 | |
|
286 | |
|
287 | |
|
288 | |
|
289 | |
|
290 | |
void deleteStereotype(Object elem) { |
291 | 0 | if (!(elem instanceof Stereotype)) { |
292 | 0 | throw new IllegalArgumentException(); |
293 | |
} |
294 | 0 | modelImpl.getUmlHelper().deleteCollection( |
295 | |
((Stereotype) elem).getDefinedTag()); |
296 | 0 | modelImpl.getUmlHelper().deleteCollection( |
297 | |
((Stereotype) elem).getStereotypeConstraint()); |
298 | 0 | } |
299 | |
|
300 | |
|
301 | |
|
302 | |
|
303 | |
|
304 | |
void deleteTaggedValue(Object elem) { |
305 | 0 | if (!(elem instanceof TaggedValue)) { |
306 | 0 | throw new IllegalArgumentException(); |
307 | |
} |
308 | 0 | } |
309 | |
|
310 | |
|
311 | |
|
312 | |
|
313 | |
|
314 | |
|
315 | |
void deleteTagDefinition(Object elem) { |
316 | 0 | if (!(elem instanceof TagDefinition)) { |
317 | 0 | throw new IllegalArgumentException(); |
318 | |
} |
319 | |
|
320 | 0 | TagDefinition td = (TagDefinition) elem; |
321 | 0 | modelImpl.getUmlHelper().deleteCollection( |
322 | |
((org.omg.uml.UmlPackage) td.refOutermostPackage()).getCore() |
323 | |
.getATypeTypedValue().getTypedValue(td)); |
324 | 0 | } |
325 | |
|
326 | |
|
327 | |
public Object copyStereotype(Object source, Object ns) { |
328 | 0 | if (!(source instanceof Stereotype)) { |
329 | 0 | throw new IllegalArgumentException("source"); |
330 | |
} |
331 | 0 | if (!(ns instanceof Namespace)) { |
332 | 0 | throw new IllegalArgumentException("namespace"); |
333 | |
} |
334 | |
|
335 | 0 | Stereotype st = buildStereotype(null, ns); |
336 | 0 | doCopyStereotype((Stereotype) source, st); |
337 | 0 | return st; |
338 | |
} |
339 | |
|
340 | |
|
341 | |
|
342 | |
|
343 | |
|
344 | |
|
345 | |
|
346 | |
|
347 | |
|
348 | |
private void doCopyStereotype(Stereotype source, Stereotype target) { |
349 | 0 | ((CoreFactoryMDRImpl) modelImpl.getCoreFactory()) |
350 | |
.doCopyGeneralizableElement(source, target); |
351 | 0 | target.getBaseClass().clear(); |
352 | 0 | target.getBaseClass().addAll(source.getBaseClass()); |
353 | 0 | target.setIcon(source.getIcon()); |
354 | |
|
355 | |
|
356 | 0 | } |
357 | |
|
358 | |
public TagDefinition buildTagDefinition(String name, Object owner, |
359 | |
Object namespace) { |
360 | 0 | return buildTagDefinition(name, owner, namespace, null); |
361 | |
} |
362 | |
|
363 | |
public TagDefinition buildTagDefinition(String name, Object owner, |
364 | |
Object ns, String tagType) { |
365 | 0 | if (owner != null) { |
366 | 0 | if (!(owner instanceof Stereotype)) { |
367 | 0 | throw new IllegalArgumentException("owner: " + owner); |
368 | |
} |
369 | 0 | if (ns != null) { |
370 | 0 | throw new IllegalArgumentException( |
371 | |
"only one of owner & namespace may be specified"); |
372 | |
} |
373 | 0 | } else if (!(ns instanceof Namespace)) { |
374 | 0 | throw new IllegalArgumentException("namespace: " + ns); |
375 | |
} |
376 | 0 | TagDefinition td = (TagDefinition) createTagDefinition(); |
377 | 0 | CoreHelper coreHelper = org.argouml.model.Model.getCoreHelper(); |
378 | 0 | if (owner != null) { |
379 | 0 | coreHelper.setOwner(td, owner); |
380 | |
} else { |
381 | 0 | coreHelper.setNamespace(td, ns); |
382 | |
} |
383 | 0 | coreHelper.setName(td, name); |
384 | 0 | coreHelper.setMultiplicity(td, 0, 1); |
385 | 0 | td.setTagType(tagType); |
386 | 0 | return td; |
387 | |
} |
388 | |
|
389 | |
|
390 | |
public Object createTagDefinition() { |
391 | 0 | TagDefinition td = modelImpl.getUmlPackage().getCore() |
392 | |
.getTagDefinition().createTagDefinition(); |
393 | 0 | super.initialize(td); |
394 | 0 | return td; |
395 | |
} |
396 | |
|
397 | |
|
398 | |
public Object createStereotype() { |
399 | 0 | Stereotype st = modelImpl.getUmlPackage().getCore().getStereotype() |
400 | |
.createStereotype(); |
401 | 0 | super.initialize(st); |
402 | 0 | return st; |
403 | |
} |
404 | |
|
405 | |
|
406 | |
public Object copyTagDefinition(Object anElement, Object aNs) { |
407 | 0 | if (!(anElement instanceof TagDefinition)) { |
408 | 0 | throw new IllegalArgumentException("source: " + anElement); |
409 | |
} |
410 | 0 | if (!(aNs instanceof Namespace || aNs instanceof Stereotype)) { |
411 | 0 | throw new IllegalArgumentException("namespace: " + aNs); |
412 | |
} |
413 | 0 | TagDefinition source = (TagDefinition) anElement; |
414 | 0 | TagDefinition td = (TagDefinition) createTagDefinition(); |
415 | 0 | if (aNs instanceof Namespace) { |
416 | 0 | td.setNamespace((Namespace) aNs); |
417 | |
} else { |
418 | 0 | td.setOwner((Stereotype) aNs); |
419 | |
} |
420 | 0 | doCopyTagDefinition(source, td); |
421 | 0 | return td; |
422 | |
} |
423 | |
|
424 | |
|
425 | |
|
426 | |
|
427 | |
|
428 | |
|
429 | |
|
430 | |
|
431 | |
|
432 | |
private void doCopyTagDefinition(TagDefinition source, |
433 | |
TagDefinition target) { |
434 | 0 | ((CoreFactoryMDRImpl) modelImpl.getCoreFactory()) |
435 | |
.doCopyModelElement(source, target); |
436 | 0 | target.setTagType(source.getTagType()); |
437 | 0 | String srcMult = org.argouml.model.Model.getFacade().toString( |
438 | |
source.getMultiplicity()); |
439 | 0 | target.setMultiplicity(modelImpl.getDataTypesFactoryInternal() |
440 | |
.createMultiplicityInternal(srcMult)); |
441 | 0 | } |
442 | |
} |