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 | |
|
40 | |
|
41 | |
package org.argouml.model.mdr; |
42 | |
|
43 | |
import java.util.ArrayList; |
44 | |
import java.util.Collection; |
45 | |
import java.util.Collections; |
46 | |
import java.util.HashSet; |
47 | |
import java.util.Iterator; |
48 | |
import java.util.LinkedList; |
49 | |
import java.util.List; |
50 | |
import java.util.Set; |
51 | |
|
52 | |
import javax.jmi.reflect.InvalidObjectException; |
53 | |
|
54 | |
import org.apache.log4j.Logger; |
55 | |
import org.argouml.model.CoreFactory; |
56 | |
import org.argouml.model.CoreHelper; |
57 | |
import org.argouml.model.InvalidElementException; |
58 | |
import org.argouml.model.Model; |
59 | |
import org.argouml.model.ModelCommand; |
60 | |
import org.argouml.model.ModelManagementHelper; |
61 | |
import org.argouml.model.NotImplementedException; |
62 | |
import org.argouml.model.mdr.UndoCoreHelperDecorator.StringSetter; |
63 | |
import org.omg.uml.behavioralelements.activitygraphs.ActivityGraph; |
64 | |
import org.omg.uml.behavioralelements.activitygraphs.ClassifierInState; |
65 | |
import org.omg.uml.behavioralelements.activitygraphs.ObjectFlowState; |
66 | |
import org.omg.uml.behavioralelements.activitygraphs.Partition; |
67 | |
import org.omg.uml.behavioralelements.collaborations.AssociationEndRole; |
68 | |
import org.omg.uml.behavioralelements.collaborations.AssociationRole; |
69 | |
import org.omg.uml.behavioralelements.collaborations.ClassifierRole; |
70 | |
import org.omg.uml.behavioralelements.collaborations.Collaboration; |
71 | |
import org.omg.uml.behavioralelements.collaborations.CollaborationInstanceSet; |
72 | |
import org.omg.uml.behavioralelements.collaborations.Interaction; |
73 | |
import org.omg.uml.behavioralelements.collaborations.Message; |
74 | |
import org.omg.uml.behavioralelements.commonbehavior.Action; |
75 | |
import org.omg.uml.behavioralelements.commonbehavior.AttributeLink; |
76 | |
import org.omg.uml.behavioralelements.commonbehavior.ComponentInstance; |
77 | |
import org.omg.uml.behavioralelements.commonbehavior.DataValue; |
78 | |
import org.omg.uml.behavioralelements.commonbehavior.Instance; |
79 | |
import org.omg.uml.behavioralelements.commonbehavior.Link; |
80 | |
import org.omg.uml.behavioralelements.commonbehavior.LinkEnd; |
81 | |
import org.omg.uml.behavioralelements.commonbehavior.NodeInstance; |
82 | |
import org.omg.uml.behavioralelements.commonbehavior.Reception; |
83 | |
import org.omg.uml.behavioralelements.commonbehavior.Signal; |
84 | |
import org.omg.uml.behavioralelements.commonbehavior.Stimulus; |
85 | |
import org.omg.uml.behavioralelements.commonbehavior.SubsystemInstance; |
86 | |
import org.omg.uml.behavioralelements.statemachines.CompositeState; |
87 | |
import org.omg.uml.behavioralelements.statemachines.Event; |
88 | |
import org.omg.uml.behavioralelements.statemachines.Guard; |
89 | |
import org.omg.uml.behavioralelements.statemachines.Pseudostate; |
90 | |
import org.omg.uml.behavioralelements.statemachines.State; |
91 | |
import org.omg.uml.behavioralelements.statemachines.StateMachine; |
92 | |
import org.omg.uml.behavioralelements.statemachines.StateVertex; |
93 | |
import org.omg.uml.behavioralelements.statemachines.Transition; |
94 | |
import org.omg.uml.behavioralelements.usecases.Actor; |
95 | |
import org.omg.uml.behavioralelements.usecases.Extend; |
96 | |
import org.omg.uml.behavioralelements.usecases.Include; |
97 | |
import org.omg.uml.behavioralelements.usecases.UseCase; |
98 | |
import org.omg.uml.behavioralelements.usecases.UseCaseInstance; |
99 | |
import org.omg.uml.foundation.core.Abstraction; |
100 | |
import org.omg.uml.foundation.core.AssociationEnd; |
101 | |
import org.omg.uml.foundation.core.Attribute; |
102 | |
import org.omg.uml.foundation.core.BehavioralFeature; |
103 | |
import org.omg.uml.foundation.core.Binding; |
104 | |
import org.omg.uml.foundation.core.Classifier; |
105 | |
import org.omg.uml.foundation.core.Comment; |
106 | |
import org.omg.uml.foundation.core.Component; |
107 | |
import org.omg.uml.foundation.core.Constraint; |
108 | |
import org.omg.uml.foundation.core.DataType; |
109 | |
import org.omg.uml.foundation.core.Dependency; |
110 | |
import org.omg.uml.foundation.core.ElementResidence; |
111 | |
import org.omg.uml.foundation.core.Enumeration; |
112 | |
import org.omg.uml.foundation.core.EnumerationLiteral; |
113 | |
import org.omg.uml.foundation.core.Feature; |
114 | |
import org.omg.uml.foundation.core.Flow; |
115 | |
import org.omg.uml.foundation.core.GeneralizableElement; |
116 | |
import org.omg.uml.foundation.core.Generalization; |
117 | |
import org.omg.uml.foundation.core.Interface; |
118 | |
import org.omg.uml.foundation.core.Method; |
119 | |
import org.omg.uml.foundation.core.ModelElement; |
120 | |
import org.omg.uml.foundation.core.Namespace; |
121 | |
import org.omg.uml.foundation.core.Node; |
122 | |
import org.omg.uml.foundation.core.Operation; |
123 | |
import org.omg.uml.foundation.core.Parameter; |
124 | |
import org.omg.uml.foundation.core.Permission; |
125 | |
import org.omg.uml.foundation.core.Relationship; |
126 | |
import org.omg.uml.foundation.core.Stereotype; |
127 | |
import org.omg.uml.foundation.core.StructuralFeature; |
128 | |
import org.omg.uml.foundation.core.TagDefinition; |
129 | |
import org.omg.uml.foundation.core.TaggedValue; |
130 | |
import org.omg.uml.foundation.core.TemplateArgument; |
131 | |
import org.omg.uml.foundation.core.TemplateParameter; |
132 | |
import org.omg.uml.foundation.core.UmlAssociation; |
133 | |
import org.omg.uml.foundation.core.UmlClass; |
134 | |
import org.omg.uml.foundation.datatypes.AggregationKind; |
135 | |
import org.omg.uml.foundation.datatypes.AggregationKindEnum; |
136 | |
import org.omg.uml.foundation.datatypes.BooleanExpression; |
137 | |
import org.omg.uml.foundation.datatypes.CallConcurrencyKind; |
138 | |
import org.omg.uml.foundation.datatypes.ChangeableKind; |
139 | |
import org.omg.uml.foundation.datatypes.ChangeableKindEnum; |
140 | |
import org.omg.uml.foundation.datatypes.Expression; |
141 | |
import org.omg.uml.foundation.datatypes.Multiplicity; |
142 | |
import org.omg.uml.foundation.datatypes.OrderingKind; |
143 | |
import org.omg.uml.foundation.datatypes.ParameterDirectionKind; |
144 | |
import org.omg.uml.foundation.datatypes.ParameterDirectionKindEnum; |
145 | |
import org.omg.uml.foundation.datatypes.ProcedureExpression; |
146 | |
import org.omg.uml.foundation.datatypes.PseudostateKind; |
147 | |
import org.omg.uml.foundation.datatypes.ScopeKind; |
148 | |
import org.omg.uml.foundation.datatypes.ScopeKindEnum; |
149 | |
import org.omg.uml.foundation.datatypes.VisibilityKind; |
150 | |
import org.omg.uml.foundation.datatypes.VisibilityKindEnum; |
151 | |
import org.omg.uml.modelmanagement.ElementImport; |
152 | |
import org.omg.uml.modelmanagement.Subsystem; |
153 | |
import org.omg.uml.modelmanagement.UmlPackage; |
154 | |
|
155 | |
|
156 | |
|
157 | |
|
158 | |
|
159 | |
|
160 | |
|
161 | |
|
162 | |
|
163 | |
|
164 | |
|
165 | 900 | class CoreHelperMDRImpl implements CoreHelper { |
166 | |
|
167 | |
|
168 | |
|
169 | |
|
170 | 900 | private static final Logger LOG = Logger.getLogger(CoreHelperMDRImpl.class); |
171 | |
|
172 | |
|
173 | |
|
174 | |
|
175 | |
private MDRModelImplementation modelImpl; |
176 | |
|
177 | |
|
178 | |
|
179 | |
|
180 | |
|
181 | |
|
182 | |
|
183 | |
public CoreHelperMDRImpl(MDRModelImplementation theModelImpl) { |
184 | 900 | super(); |
185 | 900 | modelImpl = theModelImpl; |
186 | 900 | } |
187 | |
|
188 | |
|
189 | |
|
190 | |
|
191 | |
|
192 | |
|
193 | |
|
194 | |
|
195 | |
|
196 | |
private static Object getFirstItemOrNull(Collection c) { |
197 | 0 | if (c.size() == 0) { |
198 | 0 | return null; |
199 | |
} |
200 | 0 | if (c instanceof List) { |
201 | 0 | return ((List) c).get(0); |
202 | |
} |
203 | 0 | return c.iterator().next(); |
204 | |
} |
205 | |
|
206 | |
public boolean isSubType(Object type, Object subType) { |
207 | 0 | if (!(type instanceof Class) || !(subType instanceof Class)) { |
208 | 0 | throw new IllegalArgumentException("Metatypes are expected"); |
209 | |
} |
210 | 0 | return ((Class) type).isAssignableFrom((Class) subType); |
211 | |
} |
212 | |
|
213 | |
public Collection<GeneralizableElement> getAllSupertypes(Object cls1) { |
214 | |
|
215 | 0 | if (!(cls1 instanceof Classifier)) { |
216 | 0 | throw new IllegalArgumentException(); |
217 | |
} |
218 | |
|
219 | 0 | GeneralizableElement ge = (GeneralizableElement) cls1; |
220 | |
|
221 | 0 | Collection<GeneralizableElement> result = |
222 | |
new HashSet<GeneralizableElement>(); |
223 | |
try { |
224 | 0 | Collection<GeneralizableElement> toBeAdded = getSupertypes(ge); |
225 | |
do { |
226 | 0 | Collection<GeneralizableElement> newlyAdded = |
227 | |
new HashSet<GeneralizableElement>(); |
228 | 0 | for (GeneralizableElement element : toBeAdded) { |
229 | 0 | newlyAdded.addAll(getSupertypes(element)); |
230 | |
} |
231 | 0 | result.addAll(toBeAdded); |
232 | 0 | toBeAdded = newlyAdded; |
233 | 0 | toBeAdded.removeAll(result); |
234 | 0 | } while (!toBeAdded.isEmpty()); |
235 | 0 | } catch (InvalidObjectException e) { |
236 | 0 | throw new InvalidElementException(e); |
237 | 0 | } |
238 | 0 | return result; |
239 | |
} |
240 | |
|
241 | |
public Collection<GeneralizableElement> getSupertypes(Object genElement) { |
242 | 0 | Collection<GeneralizableElement> result = |
243 | |
new HashSet<GeneralizableElement>(); |
244 | |
try { |
245 | 0 | if (genElement instanceof GeneralizableElement) { |
246 | 0 | for (Generalization gen : ((GeneralizableElement) genElement) |
247 | |
.getGeneralization()) { |
248 | 0 | result.add(gen.getParent()); |
249 | |
} |
250 | |
} |
251 | 0 | } catch (InvalidObjectException e) { |
252 | 0 | throw new InvalidElementException(e); |
253 | 0 | } |
254 | 0 | return result; |
255 | |
} |
256 | |
|
257 | |
public Collection<Object> getUtilizedElements(Object artifact) { |
258 | 0 | throw new NotImplementedException("UML 1.4 artifacts have no manifestations with utilized elements"); |
259 | |
} |
260 | |
|
261 | |
public Collection<AssociationEnd> getAssociateEndsInh(Object classifier1) { |
262 | 0 | if (!(classifier1 instanceof Classifier)) { |
263 | 0 | throw new IllegalArgumentException(); |
264 | |
} |
265 | |
|
266 | 0 | Classifier classifier = (Classifier) classifier1; |
267 | 0 | Collection<AssociationEnd> result = new ArrayList<AssociationEnd>(); |
268 | |
try { |
269 | 0 | result.addAll(modelImpl.getFacade().getAssociationEnds(classifier)); |
270 | 0 | for (Generalization gen : classifier.getGeneralization()) { |
271 | 0 | Object parent = gen.getParent(); |
272 | 0 | result.addAll(getAssociateEndsInh(parent)); |
273 | 0 | } |
274 | 0 | } catch (InvalidObjectException e) { |
275 | 0 | throw new InvalidElementException(e); |
276 | 0 | } |
277 | 0 | return result; |
278 | |
} |
279 | |
|
280 | |
|
281 | |
public void removeFeature(Object cls, Object feature) { |
282 | |
try { |
283 | 0 | if (cls instanceof Classifier && feature instanceof Feature) { |
284 | 0 | ((Classifier) cls).getFeature().remove(feature); |
285 | 0 | return; |
286 | |
} |
287 | 0 | } catch (InvalidObjectException e) { |
288 | 0 | throw new InvalidElementException(e); |
289 | 0 | } |
290 | 0 | throw new IllegalArgumentException("classifier: " + cls |
291 | |
+ " or feature: " + feature); |
292 | |
} |
293 | |
|
294 | |
|
295 | |
public void removeLiteral(Object enu, Object literal) { |
296 | |
try { |
297 | 0 | if (enu instanceof Enumeration |
298 | |
&& literal instanceof EnumerationLiteral) { |
299 | 0 | ((Enumeration) enu).getLiteral().remove(literal); |
300 | 0 | return; |
301 | |
} |
302 | 0 | } catch (InvalidObjectException e) { |
303 | 0 | throw new InvalidElementException(e); |
304 | 0 | } |
305 | 0 | throw new IllegalArgumentException("enumeration: " + enu |
306 | |
+ " or literal: " + literal); |
307 | |
} |
308 | |
|
309 | |
|
310 | |
public void setOperations(Object classifier, List operations) { |
311 | 0 | if (classifier instanceof Classifier) { |
312 | 0 | Classifier mclassifier = (Classifier) classifier; |
313 | 0 | List<Feature> result = |
314 | |
new ArrayList<Feature>(mclassifier.getFeature()); |
315 | 0 | for (Feature feature : mclassifier.getFeature()) { |
316 | 0 | if (feature instanceof Operation) { |
317 | 0 | result.remove(feature); |
318 | |
} |
319 | |
} |
320 | 0 | result.addAll(operations); |
321 | |
|
322 | |
|
323 | |
|
324 | |
|
325 | |
|
326 | 0 | mclassifier.getFeature().clear(); |
327 | 0 | mclassifier.getFeature().addAll(result); |
328 | |
} |
329 | 0 | } |
330 | |
|
331 | |
|
332 | |
public void setAttributes(Object classifier, List attributes) { |
333 | 0 | if (classifier instanceof Classifier) { |
334 | 0 | Classifier mclassifier = (Classifier) classifier; |
335 | 0 | List<Feature> result = |
336 | |
new ArrayList<Feature>(mclassifier.getFeature()); |
337 | 0 | for (Feature feature : mclassifier.getFeature()) { |
338 | 0 | if (feature instanceof Attribute) { |
339 | 0 | result.remove(feature); |
340 | |
} |
341 | |
} |
342 | 0 | result.addAll(attributes); |
343 | |
|
344 | |
|
345 | 0 | mclassifier.getFeature().clear(); |
346 | 0 | mclassifier.getFeature().addAll(result); |
347 | |
} |
348 | 0 | } |
349 | |
|
350 | |
|
351 | |
public Collection<Attribute> getAttributesInh(Object classifier) { |
352 | |
|
353 | 0 | if (!(classifier instanceof Classifier)) { |
354 | 0 | throw new IllegalArgumentException(); |
355 | |
} |
356 | |
|
357 | 0 | Collection result = new ArrayList(); |
358 | |
try { |
359 | 0 | result.addAll(modelImpl.getFacade().getStructuralFeatures( |
360 | |
classifier)); |
361 | 0 | for (Generalization gen : ((Classifier) classifier) |
362 | |
.getGeneralization()) { |
363 | 0 | result.addAll(getAttributesInh(gen.getParent())); |
364 | |
} |
365 | 0 | } catch (InvalidObjectException e) { |
366 | 0 | throw new InvalidElementException(e); |
367 | 0 | } |
368 | 0 | return result; |
369 | |
} |
370 | |
|
371 | |
|
372 | |
public Collection<Operation> getOperationsInh(Object classifier) { |
373 | 0 | if (!(classifier instanceof Classifier)) { |
374 | 0 | throw new IllegalArgumentException(); |
375 | |
} |
376 | |
|
377 | 0 | Collection<Operation> result = new ArrayList<Operation>(); |
378 | |
try { |
379 | 0 | result.addAll(modelImpl.getFacade().getOperations(classifier)); |
380 | 0 | for (Generalization gen : ((Classifier) classifier) |
381 | |
.getGeneralization()) { |
382 | 0 | result.addAll(getOperationsInh(gen.getParent())); |
383 | |
} |
384 | 0 | } catch (InvalidObjectException e) { |
385 | 0 | throw new InvalidElementException(e); |
386 | 0 | } |
387 | 0 | return result; |
388 | |
} |
389 | |
|
390 | |
|
391 | |
|
392 | |
public Collection<GeneralizableElement> getParents( |
393 | |
Object generalizableElement) { |
394 | 0 | if (!(generalizableElement instanceof GeneralizableElement)) { |
395 | 0 | throw new IllegalArgumentException(); |
396 | |
} |
397 | |
try { |
398 | 0 | return getParents((GeneralizableElement) generalizableElement); |
399 | 0 | } catch (InvalidObjectException e) { |
400 | 0 | throw new InvalidElementException(e); |
401 | |
} |
402 | |
} |
403 | |
|
404 | |
|
405 | |
|
406 | |
|
407 | |
|
408 | |
|
409 | |
static Collection<GeneralizableElement> getParents( |
410 | |
GeneralizableElement ge) { |
411 | 0 | Set<GeneralizableElement> result = new HashSet<GeneralizableElement>(); |
412 | 0 | for (Generalization g : ge.getGeneralization()) { |
413 | 0 | result.add(g.getParent()); |
414 | |
} |
415 | 0 | return result; |
416 | |
} |
417 | |
|
418 | |
|
419 | |
|
420 | |
|
421 | |
|
422 | |
|
423 | |
|
424 | |
|
425 | |
static Collection<GeneralizableElement> getAllParents( |
426 | |
GeneralizableElement ge) { |
427 | 0 | Collection<GeneralizableElement> result = |
428 | |
new HashSet<GeneralizableElement>(2000); |
429 | 0 | getAllParents(result, ge); |
430 | 0 | return result; |
431 | |
} |
432 | |
|
433 | |
private static void getAllParents( |
434 | |
final Collection<GeneralizableElement> result, |
435 | |
final GeneralizableElement ge) { |
436 | 0 | for (Generalization g : ge.getGeneralization()) { |
437 | 0 | GeneralizableElement parent = g.getParent(); |
438 | 0 | result.add(parent); |
439 | 0 | getAllParents(result, parent); |
440 | 0 | } |
441 | 0 | } |
442 | |
|
443 | |
|
444 | |
|
445 | |
|
446 | |
|
447 | |
|
448 | |
|
449 | |
|
450 | |
|
451 | |
|
452 | |
|
453 | |
|
454 | |
|
455 | |
private boolean isVisiblyOwned( |
456 | |
final ModelElement element, |
457 | |
final GeneralizableElement ge, |
458 | |
final Set<ModelElement> dupCheck) { |
459 | |
|
460 | 0 | assert dupCheck != null; |
461 | 0 | assert ge != null; |
462 | 0 | assert element != null; |
463 | |
|
464 | 0 | final boolean alreadyChecked = !dupCheck.add(ge); |
465 | 0 | if (alreadyChecked) { |
466 | 0 | LOG.warn("Cyclic generalization found " + getFullName(ge)); |
467 | 0 | return false; |
468 | |
} |
469 | |
|
470 | 0 | for (final Generalization g : ge.getGeneralization()) { |
471 | 0 | final GeneralizableElement parent = g.getParent(); |
472 | 0 | if (parent instanceof Namespace |
473 | |
&& isVisiblyOwned(element, (Namespace) parent)) { |
474 | 0 | return true; |
475 | |
} |
476 | 0 | } |
477 | |
|
478 | 0 | for (final Generalization g : ge.getGeneralization()) { |
479 | |
|
480 | 0 | if (isVisiblyOwned(element, g.getParent(), dupCheck)) { |
481 | 0 | return true; |
482 | |
} |
483 | |
} |
484 | 0 | return false; |
485 | |
} |
486 | |
|
487 | |
private String getFullName(ModelElement elem) { |
488 | 0 | String name = elem.getName(); |
489 | 0 | while (elem.getNamespace() != null) { |
490 | 0 | elem = elem.getNamespace(); |
491 | 0 | name = elem.getName() + "." + name; |
492 | |
} |
493 | 0 | return name; |
494 | |
} |
495 | |
|
496 | |
public List<Parameter> getReturnParameters(Object bf) { |
497 | 0 | List<Parameter> returnParams = new ArrayList<Parameter>(); |
498 | |
try { |
499 | 0 | for (Parameter parameter : ((BehavioralFeature) bf).getParameter()) { |
500 | 0 | if (ParameterDirectionKindEnum.PDK_RETURN.equals(parameter |
501 | |
.getKind())) { |
502 | 0 | returnParams.add(parameter); |
503 | |
} |
504 | |
} |
505 | 0 | } catch (InvalidObjectException e) { |
506 | 0 | throw new InvalidElementException(e); |
507 | 0 | } |
508 | 0 | return returnParams; |
509 | |
} |
510 | |
|
511 | |
public Object getSpecification(Object object) { |
512 | 0 | if (!(object instanceof Method)) { |
513 | 0 | throw new IllegalArgumentException("Not a method : " + object); |
514 | |
} |
515 | |
try { |
516 | 0 | return ((Method) object).getSpecification(); |
517 | 0 | } catch (InvalidObjectException e) { |
518 | 0 | throw new InvalidElementException(e); |
519 | |
} |
520 | |
} |
521 | |
|
522 | |
|
523 | |
public Collection<GeneralizableElement> getSubtypes(Object cls) { |
524 | 0 | if (!(cls instanceof Classifier)) { |
525 | 0 | throw new IllegalArgumentException(); |
526 | |
} |
527 | |
|
528 | 0 | Collection<GeneralizableElement> result = |
529 | |
new ArrayList<GeneralizableElement>(); |
530 | |
try { |
531 | 0 | Collection<Generalization> gens = Model.getFacade() |
532 | |
.getSpecializations(cls); |
533 | 0 | for (Generalization gen : gens) { |
534 | 0 | result.add(gen.getChild()); |
535 | |
} |
536 | 0 | } catch (InvalidObjectException e) { |
537 | 0 | throw new InvalidElementException(e); |
538 | 0 | } |
539 | 0 | return result; |
540 | |
} |
541 | |
|
542 | |
|
543 | |
public Collection<BehavioralFeature> getAllBehavioralFeatures(Object element) { |
544 | 0 | if (!(element instanceof ModelElement)) { |
545 | 0 | throw new IllegalArgumentException(); |
546 | |
} |
547 | 0 | List contents = new ArrayList(); |
548 | 0 | List<BehavioralFeature> result = new ArrayList<BehavioralFeature>(); |
549 | |
try { |
550 | 0 | contents.addAll(Model.getFacade() |
551 | |
.getTaggedValuesCollection(element)); |
552 | 0 | contents.addAll(((ModelElement) element).getTemplateParameter()); |
553 | 0 | Iterator it = contents.iterator(); |
554 | 0 | while (it.hasNext()) { |
555 | 0 | Object o = it.next(); |
556 | 0 | if (o instanceof Classifier) { |
557 | 0 | Classifier clazz = (Classifier) o; |
558 | 0 | if (!(clazz instanceof DataType)) { |
559 | 0 | for (Object o1 : clazz.getFeature()) { |
560 | 0 | if (o1 instanceof BehavioralFeature) { |
561 | 0 | result.add((BehavioralFeature) o1); |
562 | |
} |
563 | |
} |
564 | |
} |
565 | 0 | } else { |
566 | |
|
567 | 0 | result.addAll(getAllBehavioralFeatures(it.next())); |
568 | |
} |
569 | 0 | } |
570 | 0 | } catch (InvalidObjectException e) { |
571 | 0 | throw new InvalidElementException(e); |
572 | 0 | } |
573 | 0 | return result; |
574 | |
} |
575 | |
|
576 | |
|
577 | |
public List<BehavioralFeature> getBehavioralFeatures(Object clazz) { |
578 | 0 | if (clazz instanceof Classifier) { |
579 | 0 | List<BehavioralFeature> ret = new ArrayList<BehavioralFeature>(); |
580 | |
try { |
581 | 0 | for (Object o : modelImpl.getFacade().getFeatures(clazz)) { |
582 | 0 | if (o instanceof BehavioralFeature) { |
583 | 0 | ret.add((BehavioralFeature) o); |
584 | |
} |
585 | |
} |
586 | 0 | } catch (InvalidObjectException e) { |
587 | 0 | throw new InvalidElementException(e); |
588 | 0 | } |
589 | 0 | return ret; |
590 | |
} else { |
591 | 0 | throw new IllegalArgumentException("Argument is not a classifier"); |
592 | |
} |
593 | |
} |
594 | |
|
595 | |
|
596 | |
public Collection<Interface> getAllInterfaces(Object ns) { |
597 | 0 | if (ns == null) { |
598 | 0 | return Collections.EMPTY_SET; |
599 | |
} |
600 | 0 | if (!(ns instanceof Namespace)) { |
601 | 0 | throw new IllegalArgumentException(); |
602 | |
} |
603 | 0 | List<Interface> result = new ArrayList<Interface>(); |
604 | 0 | for (Object o : ((Namespace) ns).getOwnedElement()) { |
605 | 0 | if (o instanceof Namespace) { |
606 | 0 | result.addAll(getAllInterfaces(o)); |
607 | |
} |
608 | 0 | if (o instanceof Interface) { |
609 | 0 | result.add((Interface) o); |
610 | |
} |
611 | |
} |
612 | 0 | return result; |
613 | |
} |
614 | |
|
615 | |
|
616 | |
public Collection<UmlClass> getAllClasses(Object ns) { |
617 | 0 | if (ns == null) { |
618 | 0 | return Collections.EMPTY_SET; |
619 | |
} |
620 | 0 | if (!(ns instanceof Namespace)) { |
621 | 0 | throw new IllegalArgumentException(); |
622 | |
} |
623 | |
|
624 | 0 | List<UmlClass> result = new ArrayList<UmlClass>(); |
625 | |
try { |
626 | 0 | for (Object o : ((Namespace) ns).getOwnedElement()) { |
627 | 0 | if (o instanceof Namespace) { |
628 | 0 | result.addAll(getAllClasses(o)); |
629 | |
} |
630 | 0 | if (o instanceof UmlClass) { |
631 | 0 | result.add((UmlClass) o); |
632 | |
} |
633 | |
} |
634 | 0 | } catch (InvalidObjectException e) { |
635 | 0 | throw new InvalidElementException(e); |
636 | 0 | } |
637 | 0 | return result; |
638 | |
} |
639 | |
|
640 | |
|
641 | |
public Collection<Interface> getRealizedInterfaces(Object cls) { |
642 | 0 | Classifier classifier = (Classifier) cls; |
643 | 0 | if (classifier == null) { |
644 | 0 | return Collections.emptyList(); |
645 | |
} |
646 | 0 | List<Interface> result = new ArrayList<Interface>(); |
647 | |
|
648 | |
try { |
649 | |
for (Dependency clientDependency |
650 | 0 | : classifier.getClientDependency()) { |
651 | 0 | if (clientDependency instanceof Abstraction) { |
652 | 0 | Abstraction abstraction = (Abstraction) clientDependency; |
653 | 0 | for (Stereotype stereo : abstraction.getStereotype()) { |
654 | 0 | if (stereo != null |
655 | |
&& CoreFactory.REALIZE_STEREOTYPE.equals(stereo |
656 | |
.getName()) |
657 | |
|
658 | |
&& stereo.getBaseClass() |
659 | |
.contains("Abstraction")) { |
660 | 0 | for (Object supplier : abstraction.getSupplier()) { |
661 | 0 | if (supplier instanceof Interface) { |
662 | 0 | result.add((Interface) supplier); |
663 | |
} |
664 | |
} |
665 | |
} |
666 | |
} |
667 | 0 | } |
668 | |
} |
669 | 0 | } catch (InvalidObjectException e) { |
670 | 0 | throw new InvalidElementException(e); |
671 | 0 | } |
672 | 0 | return result; |
673 | |
} |
674 | |
|
675 | |
|
676 | |
public Collection<Classifier> getExtendedClassifiers(Object clazz) { |
677 | 0 | if (clazz == null) { |
678 | 0 | return Collections.EMPTY_SET; |
679 | |
} |
680 | 0 | List<Classifier> result = new ArrayList<Classifier>(); |
681 | |
try { |
682 | 0 | for (Object gen : modelImpl.getFacade().getGeneralizations(clazz)) { |
683 | 0 | GeneralizableElement parent = ((Generalization) gen).getParent(); |
684 | 0 | if (parent != null) { |
685 | |
|
686 | |
|
687 | 0 | result.add((Classifier) parent); |
688 | |
} |
689 | 0 | } |
690 | 0 | } catch (InvalidObjectException e) { |
691 | 0 | throw new InvalidElementException(e); |
692 | 0 | } |
693 | 0 | return result; |
694 | |
} |
695 | |
|
696 | |
|
697 | |
public Object getGeneralization(Object achild, Object aparent) { |
698 | 0 | if (!(achild instanceof GeneralizableElement) |
699 | |
|| !(aparent instanceof GeneralizableElement)) { |
700 | 0 | throw new IllegalArgumentException(); |
701 | |
} |
702 | 0 | GeneralizableElement child = (GeneralizableElement) achild; |
703 | 0 | GeneralizableElement parent = (GeneralizableElement) aparent; |
704 | |
try { |
705 | 0 | Iterator it = |
706 | |
modelImpl.getFacade().getGeneralizations(child).iterator(); |
707 | 0 | while (it.hasNext()) { |
708 | 0 | Generalization gen = (Generalization) it.next(); |
709 | 0 | if (gen.getParent() == parent) { |
710 | 0 | return gen; |
711 | |
} |
712 | 0 | } |
713 | 0 | } catch (InvalidObjectException e) { |
714 | 0 | throw new InvalidElementException(e); |
715 | 0 | } |
716 | 0 | return null; |
717 | |
} |
718 | |
|
719 | |
|
720 | |
public String getBody(Object comment) { |
721 | 0 | if (comment instanceof Comment) { |
722 | |
|
723 | |
|
724 | |
|
725 | |
|
726 | |
|
727 | |
try { |
728 | 0 | return ((Comment) comment).getBody(); |
729 | 0 | } catch (InvalidObjectException e) { |
730 | 0 | throw new InvalidElementException(e); |
731 | |
} |
732 | |
} |
733 | 0 | throw new IllegalArgumentException(); |
734 | |
} |
735 | |
|
736 | |
|
737 | |
public Collection<Flow> getFlows(Object source, Object target) { |
738 | 0 | if (!(source instanceof ModelElement)) { |
739 | 0 | throw new IllegalArgumentException("source"); |
740 | |
} |
741 | 0 | if (!(target instanceof ModelElement)) { |
742 | 0 | throw new IllegalArgumentException("target"); |
743 | |
} |
744 | |
|
745 | 0 | List<Flow> ret = new ArrayList<Flow>(); |
746 | |
try { |
747 | 0 | Collection<Flow> targetFlows = ((ModelElement) target).getTargetFlow(); |
748 | 0 | for (Flow flow : ((ModelElement) source).getSourceFlow()) { |
749 | 0 | if (targetFlows.contains(flow)) { |
750 | 0 | ret.add(flow); |
751 | |
} |
752 | |
} |
753 | 0 | } catch (InvalidObjectException e) { |
754 | 0 | throw new InvalidElementException(e); |
755 | 0 | } |
756 | 0 | return ret; |
757 | |
} |
758 | |
|
759 | |
|
760 | |
public Collection<GeneralizableElement> getExtendingElements(Object clazz) { |
761 | 0 | if (clazz == null) { |
762 | 0 | return Collections.EMPTY_SET; |
763 | |
} |
764 | 0 | List<GeneralizableElement> list = |
765 | |
new ArrayList<GeneralizableElement>(); |
766 | |
try { |
767 | 0 | for (Generalization gen : (Collection<Generalization>) modelImpl |
768 | |
.getFacade().getSpecializations(clazz)) { |
769 | 0 | GeneralizableElement client = gen.getChild(); |
770 | 0 | if (client != null) { |
771 | 0 | list.add(client); |
772 | |
} |
773 | 0 | } |
774 | 0 | } catch (InvalidObjectException e) { |
775 | 0 | throw new InvalidElementException(e); |
776 | 0 | } |
777 | 0 | return list; |
778 | |
} |
779 | |
|
780 | |
|
781 | |
public Collection<Classifier> getExtendingClassifiers(Object clazz) { |
782 | 0 | if (clazz == null) { |
783 | 0 | return Collections.EMPTY_SET; |
784 | |
} |
785 | 0 | if (!(clazz instanceof Classifier)) { |
786 | 0 | throw new IllegalArgumentException(); |
787 | |
} |
788 | 0 | List<Classifier> result = new ArrayList<Classifier>(); |
789 | |
try { |
790 | 0 | for (Object gen : Model.getFacade().getSpecializations(clazz)) { |
791 | 0 | GeneralizableElement client = ((Generalization) gen).getChild(); |
792 | 0 | if (client instanceof Classifier) { |
793 | 0 | result.add((Classifier) client); |
794 | |
} |
795 | 0 | } |
796 | 0 | } catch (InvalidObjectException e) { |
797 | 0 | throw new InvalidElementException(e); |
798 | 0 | } |
799 | 0 | return result; |
800 | |
} |
801 | |
|
802 | |
|
803 | |
public Collection<Component> getAllComponents(Object ns) { |
804 | 0 | if (ns == null) { |
805 | 0 | return Collections.EMPTY_SET; |
806 | |
} |
807 | 0 | if (!(ns instanceof Namespace)) { |
808 | 0 | throw new IllegalArgumentException(); |
809 | |
} |
810 | |
|
811 | 0 | List<Component> result = new ArrayList<Component>(); |
812 | |
try { |
813 | 0 | for (Object o : ((Namespace) ns).getOwnedElement()) { |
814 | 0 | if (o instanceof Namespace) { |
815 | 0 | result.addAll(getAllComponents(o)); |
816 | |
} |
817 | 0 | if (o instanceof Component) { |
818 | 0 | result.add((Component) o); |
819 | |
} |
820 | |
} |
821 | 0 | } catch (InvalidObjectException e) { |
822 | 0 | throw new InvalidElementException(e); |
823 | 0 | } |
824 | 0 | return result; |
825 | |
} |
826 | |
|
827 | |
|
828 | |
public Collection<DataType> getAllDataTypes(Object ns) { |
829 | 0 | if (ns == null) { |
830 | 0 | return Collections.EMPTY_SET; |
831 | |
} |
832 | 0 | if (!(ns instanceof Namespace)) { |
833 | 0 | throw new IllegalArgumentException(); |
834 | |
} |
835 | |
|
836 | 0 | List<DataType> result = new ArrayList<DataType>(); |
837 | |
try { |
838 | 0 | for (Object o : ((Namespace) ns).getOwnedElement()) { |
839 | 0 | if (o instanceof Namespace) { |
840 | 0 | result.addAll(getAllDataTypes(o)); |
841 | |
} |
842 | 0 | if (o instanceof DataType) { |
843 | 0 | result.add((DataType) o); |
844 | |
} |
845 | |
} |
846 | 0 | } catch (InvalidObjectException e) { |
847 | 0 | throw new InvalidElementException(e); |
848 | 0 | } |
849 | 0 | return result; |
850 | |
} |
851 | |
|
852 | |
|
853 | |
public Collection<Node> getAllNodes(Object ns) { |
854 | 0 | if (ns == null) { |
855 | 0 | return Collections.EMPTY_SET; |
856 | |
} |
857 | 0 | if (!(ns instanceof Namespace)) { |
858 | 0 | throw new IllegalArgumentException(); |
859 | |
} |
860 | |
|
861 | 0 | List<Node> result = new ArrayList<Node>(); |
862 | |
try { |
863 | 0 | for (Object o : ((Namespace) ns).getOwnedElement()) { |
864 | 0 | if (o instanceof Namespace) { |
865 | 0 | result.addAll(getAllNodes(o)); |
866 | |
} |
867 | 0 | if (o instanceof Node) { |
868 | 0 | result.add((Node) o); |
869 | |
} |
870 | |
} |
871 | 0 | } catch (InvalidObjectException e) { |
872 | 0 | throw new InvalidElementException(e); |
873 | 0 | } |
874 | 0 | return result; |
875 | |
} |
876 | |
|
877 | |
|
878 | |
public Collection<Classifier> getAssociatedClassifiers(Object aclassifier) { |
879 | 0 | Classifier classifier = (Classifier) aclassifier; |
880 | 0 | if (classifier == null) { |
881 | 0 | return Collections.EMPTY_SET; |
882 | |
} |
883 | 0 | List<Classifier> list = new ArrayList<Classifier>(); |
884 | |
try { |
885 | 0 | for (AssociationEnd end : (Collection<AssociationEnd>) Model |
886 | |
.getFacade().getAssociationEnds(classifier)) { |
887 | 0 | UmlAssociation assoc = end.getAssociation(); |
888 | 0 | for (AssociationEnd end2 : assoc.getConnection()) { |
889 | 0 | if (end2 != end) { |
890 | 0 | list.add(end2.getParticipant()); |
891 | |
} |
892 | |
} |
893 | 0 | } |
894 | 0 | } catch (InvalidObjectException e) { |
895 | 0 | throw new InvalidElementException(e); |
896 | 0 | } |
897 | 0 | return list; |
898 | |
} |
899 | |
|
900 | |
|
901 | |
public Collection<UmlAssociation> getAssociations(Object from, Object to) { |
902 | 0 | if (!(from instanceof Classifier) || !(to instanceof Classifier)) { |
903 | 0 | throw new IllegalArgumentException(); |
904 | |
} |
905 | 0 | Set<UmlAssociation> ret = new HashSet<UmlAssociation>(); |
906 | |
try { |
907 | 0 | for (AssociationEnd end : (Collection<AssociationEnd>) Model |
908 | |
.getFacade().getAssociationEnds(from)) { |
909 | 0 | UmlAssociation assoc = end.getAssociation(); |
910 | 0 | for (AssociationEnd end2 : assoc.getConnection()) { |
911 | 0 | if (end2.getParticipant() == to) { |
912 | 0 | ret.add(assoc); |
913 | |
} |
914 | |
} |
915 | 0 | } |
916 | 0 | } catch (InvalidObjectException e) { |
917 | 0 | throw new InvalidElementException(e); |
918 | 0 | } |
919 | 0 | return ret; |
920 | |
} |
921 | |
|
922 | |
|
923 | |
public Collection<Classifier> getAllClassifiers(Object namespace) { |
924 | 0 | if (namespace == null) { |
925 | 0 | throw new IllegalArgumentException(); |
926 | |
} |
927 | 0 | List<Classifier> result = new ArrayList<Classifier>(); |
928 | |
try { |
929 | 0 | for (Object o : ((Namespace) namespace).getOwnedElement()) { |
930 | 0 | if (o instanceof Namespace) { |
931 | 0 | result.addAll(getAllClassifiers(o)); |
932 | |
} |
933 | 0 | if (o instanceof Classifier) { |
934 | 0 | result.add((Classifier) o); |
935 | |
} |
936 | |
} |
937 | 0 | } catch (InvalidObjectException e) { |
938 | 0 | throw new InvalidElementException(e); |
939 | 0 | } |
940 | 0 | return result; |
941 | |
} |
942 | |
|
943 | |
|
944 | |
public Collection<UmlAssociation> getAssociations(Object oclassifier) { |
945 | 0 | Collection<UmlAssociation> result = new ArrayList<UmlAssociation>(); |
946 | |
try { |
947 | 0 | if (oclassifier instanceof Classifier) { |
948 | 0 | for (Object end : Model.getFacade().getAssociationEnds( |
949 | |
oclassifier)) { |
950 | 0 | result.add(((AssociationEnd) end).getAssociation()); |
951 | |
} |
952 | |
} |
953 | 0 | } catch (InvalidObjectException e) { |
954 | 0 | throw new InvalidElementException(e); |
955 | 0 | } |
956 | 0 | return result; |
957 | |
} |
958 | |
|
959 | |
|
960 | |
public AssociationEnd getAssociationEnd(Object type, Object assoc) { |
961 | 0 | if (!(type instanceof Classifier)) { |
962 | 0 | throw new IllegalArgumentException(); |
963 | |
} |
964 | 0 | if (!(assoc instanceof UmlAssociation)) { |
965 | 0 | throw new IllegalArgumentException(); |
966 | |
} |
967 | |
try { |
968 | 0 | for (AssociationEnd end : (Collection<AssociationEnd>) Model |
969 | |
.getFacade().getAssociationEnds(type)) { |
970 | 0 | if (((UmlAssociation) assoc).getConnection().contains(end)) { |
971 | 0 | return end; |
972 | |
} |
973 | |
} |
974 | 0 | } catch (InvalidObjectException e) { |
975 | 0 | throw new InvalidElementException(e); |
976 | 0 | } |
977 | 0 | return null; |
978 | |
} |
979 | |
|
980 | |
|
981 | |
public Collection<Attribute> getAllAttributes(Object clazz) { |
982 | 0 | if (clazz == null) { |
983 | 0 | return Collections.emptySet(); |
984 | |
} |
985 | 0 | if (!(clazz instanceof Classifier)) { |
986 | 0 | throw new IllegalArgumentException(); |
987 | |
} |
988 | |
|
989 | 0 | List<Attribute> list = new ArrayList<Attribute>(); |
990 | |
try { |
991 | 0 | for (Feature feature : ((Classifier) clazz).getFeature()) { |
992 | 0 | if (feature instanceof Attribute) { |
993 | 0 | list.add((Attribute) feature); |
994 | |
} |
995 | |
} |
996 | 0 | for (Object gen : modelImpl.getFacade().getGeneralizations(clazz)) { |
997 | 0 | list.addAll(getAllAttributes(gen)); |
998 | |
} |
999 | 0 | } catch (InvalidObjectException e) { |
1000 | 0 | throw new InvalidElementException(e); |
1001 | 0 | } |
1002 | 0 | return list; |
1003 | |
} |
1004 | |
|
1005 | |
|
1006 | |
public Collection<ModelElement> getAllVisibleElements(Object ns) { |
1007 | 0 | if (!(ns instanceof Namespace)) { |
1008 | 0 | throw new IllegalArgumentException(); |
1009 | |
} |
1010 | |
try { |
1011 | 0 | return getAllVisibleElements((Namespace) ns); |
1012 | 0 | } catch (InvalidObjectException e) { |
1013 | 0 | throw new InvalidElementException(e); |
1014 | |
} |
1015 | |
} |
1016 | |
|
1017 | |
|
1018 | |
|
1019 | |
|
1020 | |
|
1021 | |
|
1022 | |
static Collection<ModelElement> getAllVisibleElements(Namespace ns) { |
1023 | 0 | Collection<ModelElement> result = new ArrayList<ModelElement>(); |
1024 | 0 | for (ModelElement element : ns.getOwnedElement()) { |
1025 | 0 | if (VisibilityKindEnum.VK_PUBLIC.equals(element.getVisibility())) { |
1026 | 0 | result.add(element); |
1027 | |
} |
1028 | |
} |
1029 | 0 | return result; |
1030 | |
} |
1031 | |
|
1032 | |
|
1033 | |
public Object getSource(Object relationship) { |
1034 | 0 | if (!(relationship instanceof Relationship) |
1035 | |
&& !(relationship instanceof Link) |
1036 | |
&& !(relationship instanceof Message) |
1037 | |
&& !(relationship instanceof AssociationEnd)) { |
1038 | |
|
1039 | 0 | throw new IllegalArgumentException("Argument " |
1040 | |
+ relationship.toString() + " is not " + "a relationship"); |
1041 | |
|
1042 | |
} |
1043 | |
try { |
1044 | 0 | if (relationship instanceof Link) { |
1045 | 0 | Iterator it = |
1046 | |
modelImpl.getFacade() |
1047 | |
.getConnections(relationship).iterator(); |
1048 | 0 | if (it.hasNext()) { |
1049 | 0 | return modelImpl.getFacade().getInstance(it.next()); |
1050 | |
} else { |
1051 | 0 | return null; |
1052 | |
} |
1053 | |
} |
1054 | 0 | if (relationship instanceof UmlAssociation) { |
1055 | 0 | UmlAssociation assoc = (UmlAssociation) relationship; |
1056 | 0 | List<AssociationEnd> conns = assoc.getConnection(); |
1057 | 0 | if (conns == null || conns.isEmpty()) { |
1058 | 0 | return null; |
1059 | |
} |
1060 | 0 | return conns.get(0).getParticipant(); |
1061 | |
} |
1062 | 0 | if (relationship instanceof Generalization) { |
1063 | 0 | Generalization gen = (Generalization) relationship; |
1064 | 0 | return gen.getChild(); |
1065 | |
} |
1066 | 0 | if (relationship instanceof Dependency) { |
1067 | 0 | Dependency dep = (Dependency) relationship; |
1068 | 0 | Collection<ModelElement> col = dep.getClient(); |
1069 | 0 | if (col.isEmpty()) { |
1070 | 0 | return null; |
1071 | |
} |
1072 | 0 | return col.iterator().next(); |
1073 | |
} |
1074 | 0 | if (relationship instanceof Flow) { |
1075 | 0 | Flow flow = (Flow) relationship; |
1076 | 0 | Collection<ModelElement> col = flow.getSource(); |
1077 | 0 | if (col.isEmpty()) { |
1078 | 0 | return null; |
1079 | |
} |
1080 | 0 | return col.iterator().next(); |
1081 | |
} |
1082 | 0 | if (relationship instanceof Extend) { |
1083 | 0 | Extend extend = (Extend) relationship; |
1084 | 0 | return extend.getExtension(); |
1085 | |
|
1086 | |
} |
1087 | 0 | if (relationship instanceof Include) { |
1088 | 0 | Include include = (Include) relationship; |
1089 | 0 | return modelImpl.getFacade().getBase(include); |
1090 | |
} |
1091 | 0 | if (relationship instanceof AssociationEnd) { |
1092 | 0 | return ((AssociationEnd) relationship).getAssociation(); |
1093 | |
} |
1094 | 0 | if (relationship instanceof Message) { |
1095 | 0 | return ((Message) relationship).getSender(); |
1096 | |
} |
1097 | 0 | } catch (InvalidObjectException e) { |
1098 | 0 | throw new InvalidElementException(e); |
1099 | 0 | } |
1100 | 0 | return null; |
1101 | |
} |
1102 | |
|
1103 | |
|
1104 | |
public Object getDestination(Object relationship) { |
1105 | 0 | if (!(relationship instanceof Relationship) |
1106 | |
&& !(relationship instanceof Link) |
1107 | |
&& !(relationship instanceof Message) |
1108 | |
&& !(relationship instanceof AssociationEnd)) { |
1109 | |
|
1110 | 0 | throw new IllegalArgumentException("Argument is not " |
1111 | |
+ "a relationship"); |
1112 | |
} |
1113 | |
|
1114 | |
try { |
1115 | 0 | if (relationship instanceof Link) { |
1116 | 0 | Iterator it = modelImpl.getFacade() |
1117 | |
.getConnections(relationship).iterator(); |
1118 | 0 | if (it.hasNext()) { |
1119 | 0 | it.next(); |
1120 | 0 | if (it.hasNext()) { |
1121 | 0 | return modelImpl.getFacade().getInstance(it.next()); |
1122 | |
} else { |
1123 | 0 | return null; |
1124 | |
} |
1125 | |
} else { |
1126 | 0 | return null; |
1127 | |
} |
1128 | |
} |
1129 | |
|
1130 | 0 | if (relationship instanceof UmlAssociation) { |
1131 | 0 | UmlAssociation assoc = (UmlAssociation) relationship; |
1132 | 0 | List<AssociationEnd> conns = assoc.getConnection(); |
1133 | 0 | if (conns.size() <= 1) { |
1134 | 0 | return null; |
1135 | |
} |
1136 | 0 | return conns.get(1).getParticipant(); |
1137 | |
} |
1138 | 0 | if (relationship instanceof Generalization) { |
1139 | 0 | Generalization gen = (Generalization) relationship; |
1140 | 0 | return gen.getParent(); |
1141 | |
} |
1142 | 0 | if (relationship instanceof Dependency) { |
1143 | 0 | Dependency dep = (Dependency) relationship; |
1144 | 0 | Collection<ModelElement> col = dep.getSupplier(); |
1145 | 0 | if (col.isEmpty()) { |
1146 | 0 | return null; |
1147 | |
} |
1148 | 0 | return getFirstItemOrNull(col); |
1149 | |
} |
1150 | 0 | if (relationship instanceof Flow) { |
1151 | 0 | Flow flow = (Flow) relationship; |
1152 | 0 | Collection<ModelElement> col = flow.getTarget(); |
1153 | 0 | if (col.isEmpty()) { |
1154 | 0 | return null; |
1155 | |
} |
1156 | 0 | return getFirstItemOrNull(col); |
1157 | |
} |
1158 | 0 | if (relationship instanceof Extend) { |
1159 | 0 | Extend extend = (Extend) relationship; |
1160 | 0 | return extend.getBase(); |
1161 | |
} |
1162 | 0 | if (relationship instanceof Include) { |
1163 | 0 | Include include = (Include) relationship; |
1164 | 0 | return modelImpl.getFacade().getAddition(include); |
1165 | |
} |
1166 | 0 | if (relationship instanceof AssociationEnd) { |
1167 | 0 | return ((AssociationEnd) relationship).getParticipant(); |
1168 | |
} |
1169 | 0 | if (relationship instanceof Message) { |
1170 | 0 | return ((Message) relationship).getReceiver(); |
1171 | |
} |
1172 | 0 | } catch (InvalidObjectException e) { |
1173 | 0 | throw new InvalidElementException(e); |
1174 | 0 | } |
1175 | 0 | return null; |
1176 | |
} |
1177 | |
|
1178 | |
|
1179 | |
public Collection<Dependency> getDependencies(Object supplierObj, |
1180 | |
Object clientObj) { |
1181 | |
|
1182 | 0 | if (!(supplierObj instanceof ModelElement) |
1183 | |
|| !(clientObj instanceof ModelElement)) { |
1184 | 0 | throw new IllegalArgumentException("invalid argument(s)"); |
1185 | |
} |
1186 | |
|
1187 | 0 | ModelElement supplier = (ModelElement) supplierObj; |
1188 | 0 | ModelElement client = (ModelElement) clientObj; |
1189 | |
|
1190 | 0 | List<Dependency> ret = new ArrayList<Dependency>(); |
1191 | |
try { |
1192 | 0 | Collection<Dependency> clientDependencies = client |
1193 | |
.getClientDependency(); |
1194 | 0 | Iterator it = |
1195 | |
Model.getFacade().getSupplierDependencies(supplier).iterator(); |
1196 | 0 | while (it.hasNext()) { |
1197 | 0 | Dependency dep = (Dependency) it.next(); |
1198 | 0 | if (clientDependencies.contains(dep)) { |
1199 | 0 | ret.add(dep); |
1200 | |
} |
1201 | 0 | } |
1202 | 0 | } catch (InvalidObjectException e) { |
1203 | 0 | throw new InvalidElementException(e); |
1204 | 0 | } |
1205 | 0 | return ret; |
1206 | |
} |
1207 | |
|
1208 | |
public Collection<Permission> getPackageImports(Object client) { |
1209 | 0 | if (!(client instanceof Namespace)) { |
1210 | 0 | throw new IllegalArgumentException("invalid argument"); |
1211 | |
} |
1212 | 0 | List<Permission> result = new ArrayList<Permission>(); |
1213 | |
try { |
1214 | 0 | for (Dependency dependency : ((ModelElement) client) |
1215 | |
.getClientDependency()) { |
1216 | 0 | if (dependency instanceof Permission |
1217 | |
&& hasImportStereotype((Permission) dependency)) { |
1218 | 0 | result.add((Permission) dependency); |
1219 | |
} |
1220 | |
} |
1221 | 0 | } catch (InvalidObjectException e) { |
1222 | 0 | throw new InvalidElementException(e); |
1223 | 0 | } |
1224 | 0 | return result; |
1225 | |
} |
1226 | |
|
1227 | |
|
1228 | |
|
1229 | |
|
1230 | |
|
1231 | |
|
1232 | |
|
1233 | |
|
1234 | |
|
1235 | |
|
1236 | |
private boolean hasImportStereotype(Permission permission) { |
1237 | 0 | return (Model.getExtensionMechanismsHelper().hasStereotype(permission, |
1238 | |
ModelManagementHelper.IMPORT_STEREOTYPE) |
1239 | |
|| Model.getExtensionMechanismsHelper().hasStereotype( |
1240 | |
permission, ModelManagementHelper.ACCESS_STEREOTYPE) |
1241 | |
|
1242 | |
|
1243 | |
|
1244 | |
); |
1245 | |
} |
1246 | |
|
1247 | |
public Permission getPackageImport(Object supplier, Object client) { |
1248 | 0 | for (Dependency dependency : getDependencies(supplier, client)) { |
1249 | 0 | if (dependency instanceof Permission |
1250 | |
&& Model.getExtensionMechanismsHelper() |
1251 | |
.hasStereotype(dependency, |
1252 | |
ModelManagementHelper.IMPORT_STEREOTYPE)) { |
1253 | 0 | return (Permission) dependency; |
1254 | |
} |
1255 | |
} |
1256 | 0 | return null; |
1257 | |
} |
1258 | |
|
1259 | |
|
1260 | |
public Collection getRelationships(Object source, Object dest) { |
1261 | 0 | Set ret = new HashSet(); |
1262 | 0 | if (!(source instanceof ModelElement)) { |
1263 | 0 | throw new IllegalArgumentException("source"); |
1264 | |
} |
1265 | 0 | if (!(dest instanceof ModelElement)) { |
1266 | 0 | throw new IllegalArgumentException("dest"); |
1267 | |
} |
1268 | |
|
1269 | |
try { |
1270 | 0 | ret.addAll(getFlows(source, dest)); |
1271 | 0 | ret.addAll(getFlows(dest, source)); |
1272 | 0 | ret.addAll(getDependencies(source, dest)); |
1273 | 0 | ret.addAll(getDependencies(dest, source)); |
1274 | 0 | if (source instanceof GeneralizableElement |
1275 | |
&& dest instanceof GeneralizableElement) { |
1276 | 0 | ret.add(getGeneralization(source, dest)); |
1277 | 0 | ret.add(getGeneralization(dest, source)); |
1278 | 0 | if (source instanceof Classifier |
1279 | |
&& dest instanceof Classifier) { |
1280 | 0 | ret.addAll(getAssociations(source, dest)); |
1281 | |
} |
1282 | |
} |
1283 | 0 | } catch (InvalidObjectException e) { |
1284 | 0 | throw new InvalidElementException(e); |
1285 | 0 | } |
1286 | 0 | return ret; |
1287 | |
} |
1288 | |
|
1289 | |
|
1290 | |
public boolean isValidNamespace(Object mObj, Object nsObj) { |
1291 | |
|
1292 | 0 | if (!(mObj instanceof ModelElement) || !(nsObj instanceof Namespace)) { |
1293 | 0 | return false; |
1294 | |
} |
1295 | |
|
1296 | 0 | ModelElement modelElement = (ModelElement) mObj; |
1297 | 0 | Namespace ns = (Namespace) nsObj; |
1298 | |
|
1299 | |
try { |
1300 | |
|
1301 | 0 | if (modelElement == ns) { |
1302 | 0 | return false; |
1303 | |
} |
1304 | |
|
1305 | 0 | if (ns instanceof Interface |
1306 | |
|| ns instanceof Actor |
1307 | |
|| ns instanceof DataType |
1308 | |
|| ns instanceof DataValue |
1309 | |
|| ns instanceof NodeInstance |
1310 | |
|| ns instanceof Signal |
1311 | |
|
1312 | |
|| ns instanceof UseCaseInstance |
1313 | |
|| ns instanceof ClassifierInState) { |
1314 | 0 | return false; |
1315 | 0 | } else if (ns instanceof UseCase |
1316 | |
&& modelElement instanceof Classifier) { |
1317 | |
|
1318 | |
|
1319 | |
|
1320 | |
|
1321 | |
|
1322 | |
|
1323 | |
|
1324 | 0 | return false; |
1325 | 0 | } else if (ns instanceof Component) { |
1326 | 0 | return (modelElement instanceof Component |
1327 | |
&& modelElement != ns); |
1328 | 0 | } else if (ns instanceof ComponentInstance) { |
1329 | 0 | return (modelElement instanceof ComponentInstance |
1330 | |
&& modelElement != ns); |
1331 | 0 | } else if (ns |
1332 | |
instanceof |
1333 | |
org.omg.uml.behavioralelements.commonbehavior.Object) { |
1334 | |
|
1335 | |
|
1336 | |
|
1337 | 0 | if (!(modelElement |
1338 | |
instanceof |
1339 | |
org.omg.uml.behavioralelements.commonbehavior.Object |
1340 | |
|| modelElement instanceof DataValue |
1341 | |
|| modelElement instanceof Link |
1342 | |
|| modelElement instanceof UseCaseInstance |
1343 | |
|| modelElement instanceof CollaborationInstanceSet |
1344 | |
|| modelElement instanceof Stimulus)) { |
1345 | 0 | return false; |
1346 | |
} |
1347 | 0 | } else if (ns instanceof SubsystemInstance) { |
1348 | |
|
1349 | |
|
1350 | 0 | if (!(modelElement |
1351 | |
instanceof |
1352 | |
org.omg.uml.behavioralelements.commonbehavior.Object |
1353 | |
|| modelElement instanceof DataValue |
1354 | |
|| modelElement instanceof Link |
1355 | |
|| modelElement instanceof UseCaseInstance |
1356 | |
|| modelElement instanceof CollaborationInstanceSet |
1357 | |
|| modelElement instanceof SubsystemInstance |
1358 | |
|| modelElement instanceof Stimulus)) { |
1359 | 0 | return false; |
1360 | |
} |
1361 | 0 | } else if (ns instanceof Subsystem) { |
1362 | 0 | if (!(modelElement instanceof UmlPackage |
1363 | |
|| modelElement instanceof UmlClass |
1364 | |
|| modelElement instanceof DataType |
1365 | |
|| modelElement instanceof Interface |
1366 | |
|| modelElement instanceof UseCase |
1367 | |
|| modelElement instanceof Actor |
1368 | |
|| modelElement instanceof Subsystem |
1369 | |
|| modelElement instanceof Signal |
1370 | |
|| modelElement instanceof UmlAssociation |
1371 | |
|| modelElement instanceof Generalization |
1372 | |
|| modelElement instanceof Dependency |
1373 | |
|| modelElement instanceof Constraint |
1374 | |
|| modelElement instanceof Collaboration |
1375 | |
|| modelElement instanceof StateMachine |
1376 | |
|| modelElement instanceof Stereotype)) { |
1377 | 0 | return false; |
1378 | |
} |
1379 | 0 | } else if (modelElement instanceof ClassifierRole) { |
1380 | 0 | return ns instanceof Collaboration; |
1381 | 0 | } else if (ns instanceof Collaboration) { |
1382 | |
|
1383 | |
|
1384 | |
|
1385 | |
|
1386 | |
|
1387 | |
|
1388 | |
|
1389 | |
|
1390 | 0 | if (!(modelElement instanceof ClassifierRole |
1391 | |
|| modelElement instanceof AssociationRole |
1392 | |
|| modelElement instanceof Generalization |
1393 | |
|| modelElement instanceof Action |
1394 | |
|| modelElement instanceof Constraint)) { |
1395 | 0 | return false; |
1396 | |
} |
1397 | 0 | } else if (ns instanceof UmlPackage) { |
1398 | |
|
1399 | |
|
1400 | 0 | if (isProfilePackage(ns)) { |
1401 | 0 | if (!(modelElement instanceof Stereotype |
1402 | |
|| modelElement instanceof Constraint |
1403 | |
|| modelElement instanceof TagDefinition |
1404 | |
|| modelElement instanceof DataType)) { |
1405 | 0 | return false; |
1406 | |
} |
1407 | |
} else { |
1408 | 0 | if (!(modelElement instanceof UmlPackage |
1409 | |
|| modelElement instanceof Classifier |
1410 | |
|| modelElement instanceof UmlAssociation |
1411 | |
|| modelElement instanceof Generalization |
1412 | |
|| modelElement instanceof Dependency |
1413 | |
|
1414 | |
|| modelElement instanceof Extend |
1415 | |
|| modelElement instanceof Include |
1416 | |
|| modelElement instanceof Constraint |
1417 | |
|| modelElement instanceof Collaboration |
1418 | |
|| modelElement instanceof StateMachine |
1419 | |
|| modelElement instanceof Stereotype)) { |
1420 | 0 | return false; |
1421 | |
} |
1422 | |
} |
1423 | 0 | } else if (ns instanceof UmlClass) { |
1424 | 0 | if (!(modelElement instanceof UmlClass |
1425 | |
|| modelElement instanceof UmlAssociation |
1426 | |
|| modelElement instanceof Generalization |
1427 | |
|| modelElement instanceof UseCase |
1428 | |
|| modelElement instanceof Constraint |
1429 | |
|| modelElement instanceof Dependency |
1430 | |
|| modelElement instanceof Collaboration |
1431 | |
|
1432 | |
|
1433 | |
|
1434 | |
|| modelElement instanceof DataType |
1435 | |
|| modelElement instanceof Interface)) { |
1436 | 0 | return false; |
1437 | |
} |
1438 | 0 | } else if (ns instanceof ClassifierRole) { |
1439 | 0 | ClassifierRole cr = (ClassifierRole) ns; |
1440 | 0 | if (!(cr.getAvailableContents().contains(modelElement) || cr. |
1441 | |
getAvailableFeature().contains(modelElement))) { |
1442 | 0 | return false; |
1443 | |
} |
1444 | |
} |
1445 | 0 | if (modelElement instanceof StructuralFeature) { |
1446 | 0 | if (!isValidNamespace((StructuralFeature) modelElement, ns)) { |
1447 | 0 | return false; |
1448 | |
} |
1449 | |
|
1450 | |
|
1451 | |
|
1452 | |
|
1453 | |
|
1454 | |
|
1455 | |
|
1456 | 0 | } else if (modelElement instanceof Generalization) { |
1457 | 0 | if (!isValidNamespace((Generalization) modelElement, ns)) { |
1458 | 0 | return false; |
1459 | |
} |
1460 | |
} |
1461 | 0 | if (modelElement instanceof UmlAssociation) { |
1462 | 0 | if (!isValidNamespace((UmlAssociation) modelElement, ns)) { |
1463 | 0 | return false; |
1464 | |
} |
1465 | 0 | } else if (modelElement instanceof Collaboration) { |
1466 | 0 | if (!isValidNamespace((Collaboration) modelElement, ns)) { |
1467 | 0 | return false; |
1468 | |
} |
1469 | |
} |
1470 | 0 | return true; |
1471 | 0 | } catch (InvalidObjectException e) { |
1472 | 0 | throw new InvalidElementException(e); |
1473 | |
} |
1474 | |
} |
1475 | |
|
1476 | |
private boolean isProfilePackage(Namespace ns) { |
1477 | |
|
1478 | 0 | return Model.getFacade().isStereotype(ns, "profile"); |
1479 | |
} |
1480 | |
|
1481 | |
|
1482 | |
|
1483 | |
|
1484 | |
|
1485 | |
|
1486 | |
|
1487 | |
|
1488 | |
|
1489 | |
private boolean isValidNamespace(Collaboration collab, Namespace ns) { |
1490 | 0 | for (ModelElement m : collab.getOwnedElement()) { |
1491 | 0 | if (m instanceof ClassifierRole) { |
1492 | 0 | ClassifierRole role = (ClassifierRole) m; |
1493 | 0 | for (Classifier base : role.getBase()) { |
1494 | 0 | if (!ns.getOwnedElement().contains(base)) { |
1495 | 0 | return false; |
1496 | |
} |
1497 | |
} |
1498 | 0 | } else if (m instanceof AssociationRole) { |
1499 | 0 | AssociationRole ar = (AssociationRole) m; |
1500 | 0 | UmlAssociation a = ar.getBase(); |
1501 | 0 | if (a != null && !ns.getOwnedElement().contains(a)) { |
1502 | 0 | return false; |
1503 | |
} |
1504 | 0 | } |
1505 | |
} |
1506 | 0 | return true; |
1507 | |
} |
1508 | |
|
1509 | |
private boolean isValidNamespace(Generalization gen, Namespace ns) { |
1510 | |
|
1511 | |
|
1512 | |
|
1513 | |
|
1514 | |
|
1515 | |
|
1516 | |
|
1517 | |
|
1518 | |
|
1519 | |
|
1520 | |
|
1521 | 0 | return true; |
1522 | |
|
1523 | |
|
1524 | |
|
1525 | |
|
1526 | |
|
1527 | |
|
1528 | |
|
1529 | |
|
1530 | |
|
1531 | |
|
1532 | |
|
1533 | |
|
1534 | |
} |
1535 | |
|
1536 | |
private boolean isValidNamespace(StructuralFeature struc, Namespace ns) { |
1537 | |
|
1538 | |
|
1539 | 0 | if (struc.getType() == null || struc.getOwner() == null) { |
1540 | 0 | return true; |
1541 | |
} |
1542 | |
|
1543 | |
|
1544 | |
|
1545 | |
|
1546 | |
|
1547 | |
|
1548 | |
|
1549 | |
|
1550 | 0 | return false; |
1551 | |
} |
1552 | |
|
1553 | |
private boolean isValidNamespace( |
1554 | |
final UmlAssociation assoc, |
1555 | |
final Namespace ns) { |
1556 | 0 | for (AssociationEnd end : assoc.getConnection()) { |
1557 | 0 | if (!isVisible(end.getParticipant(), ns)) { |
1558 | 0 | return false; |
1559 | |
} |
1560 | |
} |
1561 | 0 | return true; |
1562 | |
} |
1563 | |
|
1564 | |
|
1565 | |
|
1566 | |
|
1567 | |
|
1568 | |
|
1569 | |
|
1570 | |
|
1571 | |
|
1572 | |
|
1573 | |
|
1574 | |
|
1575 | |
|
1576 | |
|
1577 | |
|
1578 | |
|
1579 | |
|
1580 | |
|
1581 | |
|
1582 | |
|
1583 | |
|
1584 | |
|
1585 | |
|
1586 | |
|
1587 | |
|
1588 | |
|
1589 | |
|
1590 | |
|
1591 | |
|
1592 | |
|
1593 | |
|
1594 | |
|
1595 | |
|
1596 | |
|
1597 | |
|
1598 | |
private boolean isVisible(ModelElement element, Namespace ns) { |
1599 | 0 | if (ns == null || element == null) { |
1600 | 0 | return false; |
1601 | |
} |
1602 | |
|
1603 | |
|
1604 | |
|
1605 | 0 | Collection nsAllContents = |
1606 | |
modelImpl.getModelManagementHelper().getAllContents(ns); |
1607 | 0 | if (nsAllContents.contains(element)) { |
1608 | 0 | return true; |
1609 | |
} |
1610 | |
|
1611 | |
|
1612 | |
|
1613 | |
|
1614 | |
|
1615 | |
|
1616 | |
|
1617 | |
|
1618 | |
|
1619 | |
|
1620 | |
|
1621 | |
|
1622 | 0 | final Collection<Permission> permissions = getPackageImports(ns); |
1623 | 0 | for (Permission imp : permissions) { |
1624 | 0 | final Collection<ModelElement> suppliers = imp.getSupplier(); |
1625 | 0 | for (ModelElement me : suppliers) { |
1626 | |
|
1627 | |
|
1628 | |
|
1629 | 0 | if (me instanceof Namespace |
1630 | |
&& isVisiblyOwned(element, (Namespace) me)) { |
1631 | 0 | return true; |
1632 | |
} |
1633 | |
|
1634 | |
|
1635 | |
|
1636 | |
|
1637 | 0 | if (me instanceof GeneralizableElement) { |
1638 | |
|
1639 | |
|
1640 | |
|
1641 | |
|
1642 | 0 | final Set<ModelElement> dupCheck = |
1643 | |
new HashSet<ModelElement>(10); |
1644 | |
|
1645 | 0 | if (isVisiblyOwned( |
1646 | |
element, |
1647 | |
(GeneralizableElement) me, |
1648 | |
dupCheck)) { |
1649 | 0 | return true; |
1650 | |
} |
1651 | |
} |
1652 | |
|
1653 | |
|
1654 | |
|
1655 | 0 | if (me instanceof UmlPackage) { |
1656 | 0 | final Collection<ElementImport> imports = |
1657 | |
((UmlPackage) me).getElementImport(); |
1658 | 0 | for (ElementImport ei : imports) { |
1659 | 0 | if (element.equals(ei.getImportedElement()) |
1660 | |
&& VisibilityKindEnum.VK_PUBLIC.equals(ei |
1661 | |
.getVisibility())) { |
1662 | 0 | return true; |
1663 | |
} |
1664 | |
} |
1665 | 0 | } |
1666 | |
} |
1667 | 0 | } |
1668 | 0 | return false; |
1669 | |
} |
1670 | |
|
1671 | |
|
1672 | |
|
1673 | |
|
1674 | |
|
1675 | |
|
1676 | |
|
1677 | |
|
1678 | |
|
1679 | |
|
1680 | |
private boolean isVisiblyOwned(ModelElement me, Namespace ns) { |
1681 | 0 | return ns.getOwnedElement().contains(me) |
1682 | |
&& VisibilityKindEnum.VK_PUBLIC.equals(me.getVisibility()); |
1683 | |
} |
1684 | |
|
1685 | |
|
1686 | |
|
1687 | |
|
1688 | |
|
1689 | |
|
1690 | |
|
1691 | |
|
1692 | |
|
1693 | |
|
1694 | |
|
1695 | |
|
1696 | |
|
1697 | |
|
1698 | |
|
1699 | |
|
1700 | |
|
1701 | |
|
1702 | |
|
1703 | |
|
1704 | |
|
1705 | |
|
1706 | |
|
1707 | |
|
1708 | |
|
1709 | |
|
1710 | |
|
1711 | |
|
1712 | |
|
1713 | |
|
1714 | |
|
1715 | |
|
1716 | |
|
1717 | |
|
1718 | |
|
1719 | |
|
1720 | |
public Namespace getFirstSharedNamespace(Object ns1, Object ns2) { |
1721 | 0 | if (ns1 == null || ns2 == null) { |
1722 | 0 | throw new IllegalArgumentException("null argument"); |
1723 | |
} |
1724 | 0 | if (!(ns1 instanceof Namespace)) { |
1725 | 0 | throw new IllegalArgumentException( |
1726 | |
"Expecting a Namespace argument. Got a " |
1727 | |
+ ns1.getClass().getName()); |
1728 | |
} |
1729 | 0 | if (!(ns2 instanceof Namespace)) { |
1730 | 0 | throw new IllegalArgumentException( |
1731 | |
"Expecting a Namespace argument. Got a " |
1732 | |
+ ns2.getClass().getName()); |
1733 | |
} |
1734 | 0 | if (ns1 == ns2) { |
1735 | 0 | return (Namespace) ns1; |
1736 | |
} |
1737 | |
|
1738 | |
try { |
1739 | |
|
1740 | 0 | Iterator<Namespace> path1 = getPath((Namespace) ns1).iterator(); |
1741 | 0 | Iterator<Namespace> path2 = getPath((Namespace) ns2).iterator(); |
1742 | |
|
1743 | |
|
1744 | 0 | Namespace lastMatch = null; |
1745 | 0 | while (path1.hasNext() && path2.hasNext()) { |
1746 | 0 | Namespace element = path1.next(); |
1747 | 0 | if (element != path2.next()) { |
1748 | 0 | return lastMatch; |
1749 | |
} |
1750 | 0 | lastMatch = element; |
1751 | 0 | } |
1752 | 0 | return lastMatch; |
1753 | 0 | } catch (InvalidObjectException e) { |
1754 | 0 | throw new InvalidElementException(e); |
1755 | |
} |
1756 | |
} |
1757 | |
|
1758 | |
|
1759 | |
|
1760 | |
|
1761 | |
|
1762 | |
|
1763 | |
private List<Namespace> getPath(Namespace element) { |
1764 | 0 | LinkedList<Namespace> path = new LinkedList<Namespace>(); |
1765 | 0 | path.add(element); |
1766 | 0 | Namespace ns = element.getNamespace(); |
1767 | 0 | while (ns != null) { |
1768 | 0 | path.addFirst(ns); |
1769 | 0 | ns = ns.getNamespace(); |
1770 | |
} |
1771 | 0 | return path; |
1772 | |
} |
1773 | |
|
1774 | |
|
1775 | |
public Collection<Namespace> getAllPossibleNamespaces(Object modelElement, |
1776 | |
Object model) { |
1777 | 0 | LOG.debug("getAllPossibleNamespaces start"); |
1778 | 0 | ModelElement m = (ModelElement) modelElement; |
1779 | 0 | Collection<Namespace> ret = new HashSet<Namespace> (); |
1780 | 0 | if (m == null) { |
1781 | 0 | LOG.debug("getAllPossibleNamespaces end"); |
1782 | 0 | return ret; |
1783 | |
} |
1784 | |
|
1785 | |
try { |
1786 | 0 | if (isValidNamespace(m, model)) { |
1787 | 0 | ret.add((Namespace) model); |
1788 | |
} |
1789 | 0 | Collection<Namespace> namespaces = modelImpl |
1790 | |
.getModelManagementHelper().getAllModelElementsOfKind( |
1791 | |
model, Namespace.class); |
1792 | 0 | for (Namespace ns : namespaces) { |
1793 | 0 | if (isValidNamespace(m, ns)) { |
1794 | 0 | ret.add(ns); |
1795 | |
} |
1796 | |
} |
1797 | 0 | } catch (InvalidObjectException e) { |
1798 | 0 | throw new InvalidElementException(e); |
1799 | 0 | } |
1800 | |
|
1801 | 0 | if (LOG.isDebugEnabled()) { |
1802 | |
|
1803 | |
|
1804 | 0 | LOG.debug( |
1805 | |
"getAllPossibleNamespaces returns " |
1806 | |
+ ret.size() + " items"); |
1807 | |
} |
1808 | 0 | return ret; |
1809 | |
} |
1810 | |
|
1811 | |
|
1812 | |
public Collection<GeneralizableElement> getChildren(Object o) { |
1813 | 35628 | if (o instanceof GeneralizableElement) { |
1814 | 35628 | Collection<GeneralizableElement> col = |
1815 | |
new ArrayList<GeneralizableElement>(); |
1816 | 35628 | Collection<Generalization> generalizations = new ArrayList<Generalization>(); |
1817 | |
try { |
1818 | 35628 | if (o instanceof GeneralizableElement) { |
1819 | 35628 | Collection<Generalization> specializations = |
1820 | |
Model.getFacade().getSpecializations(o); |
1821 | 35628 | for (Generalization specialization : specializations) { |
1822 | 0 | getChildren(col, specialization, generalizations); |
1823 | |
} |
1824 | |
} |
1825 | 0 | } catch (InvalidObjectException e) { |
1826 | 0 | throw new InvalidElementException(e); |
1827 | 35628 | } |
1828 | 35628 | return col; |
1829 | |
} |
1830 | 0 | throw new IllegalArgumentException("Illegal arguments: " + o); |
1831 | |
} |
1832 | |
|
1833 | |
|
1834 | |
|
1835 | |
|
1836 | |
|
1837 | |
|
1838 | |
|
1839 | |
|
1840 | |
|
1841 | |
|
1842 | |
|
1843 | |
|
1844 | |
|
1845 | |
|
1846 | |
|
1847 | |
private void getChildren(Collection<GeneralizableElement> currentChildren, |
1848 | |
Generalization gen, Collection<Generalization> generalizations) { |
1849 | 0 | GeneralizableElement child = gen.getChild(); |
1850 | 0 | if (currentChildren.contains(child) && generalizations.contains(gen)) { |
1851 | 0 | throw new IllegalStateException("Circular inheritance occured."); |
1852 | |
} else { |
1853 | 0 | currentChildren.add(child); |
1854 | 0 | generalizations.add(gen); |
1855 | |
} |
1856 | 0 | Collection<Generalization> specializations = |
1857 | |
Model.getFacade().getSpecializations(child); |
1858 | 0 | for (Generalization specialization : specializations) { |
1859 | 0 | getChildren(currentChildren, specialization, generalizations); |
1860 | |
} |
1861 | 0 | } |
1862 | |
|
1863 | |
|
1864 | |
public Collection getAllRealizedInterfaces(Object o) { |
1865 | |
try { |
1866 | 0 | return internalGetAllRealizedInterfaces(o, new ArrayList(), |
1867 | |
new HashSet()); |
1868 | 0 | } catch (InvalidObjectException e) { |
1869 | 0 | throw new InvalidElementException(e); |
1870 | |
} |
1871 | |
} |
1872 | |
|
1873 | |
|
1874 | |
|
1875 | |
|
1876 | |
|
1877 | |
|
1878 | |
|
1879 | |
|
1880 | |
|
1881 | |
private Collection internalGetAllRealizedInterfaces(Object o, |
1882 | |
Collection col, Set visited) { |
1883 | 0 | visited.add(o); |
1884 | 0 | if (o != null) { |
1885 | 0 | if (o instanceof Classifier) { |
1886 | 0 | Classifier clazz = (Classifier) o; |
1887 | 0 | for (Dependency dependency : clazz.getClientDependency()) { |
1888 | 0 | Stereotype stereo = |
1889 | |
(Stereotype) getFirstItemOrNull( |
1890 | |
dependency.getStereotype()); |
1891 | 0 | if (dependency instanceof Abstraction && stereo != null |
1892 | |
&& CoreFactory.REALIZE_STEREOTYPE.equals(stereo |
1893 | |
.getName()) |
1894 | |
&& "Abstraction".equals(stereo.getBaseClass())) { |
1895 | |
|
1896 | 0 | col.addAll(dependency.getSupplier()); |
1897 | |
} |
1898 | 0 | } |
1899 | 0 | for (Object supertype : getSupertypes(o)) { |
1900 | 0 | if (!visited.contains(supertype)) { |
1901 | 0 | internalGetAllRealizedInterfaces(supertype, col, |
1902 | |
visited); |
1903 | |
} |
1904 | |
} |
1905 | |
} |
1906 | |
} |
1907 | 0 | return col; |
1908 | |
} |
1909 | |
|
1910 | |
|
1911 | |
public final boolean hasCompositeEnd(Object association) { |
1912 | 0 | if (!(association instanceof UmlAssociation)) { |
1913 | 0 | throw new IllegalArgumentException(); |
1914 | |
} |
1915 | |
|
1916 | 0 | UmlAssociation association1 = (UmlAssociation) association; |
1917 | |
try { |
1918 | 0 | for (AssociationEnd end : association1.getConnection()) { |
1919 | 0 | if (end.getAggregation() == AggregationKindEnum.AK_COMPOSITE) { |
1920 | 0 | return true; |
1921 | |
} |
1922 | |
} |
1923 | 0 | } catch (InvalidObjectException e) { |
1924 | 0 | throw new InvalidElementException(e); |
1925 | 0 | } |
1926 | 0 | return false; |
1927 | |
} |
1928 | |
|
1929 | |
|
1930 | |
public final boolean equalsAggregationKind(Object associationEnd, |
1931 | |
String kindType) { |
1932 | 0 | if (!(associationEnd instanceof AssociationEnd)) { |
1933 | 0 | throw new IllegalArgumentException(); |
1934 | |
} |
1935 | |
|
1936 | 0 | AssociationEnd associationEnd1 = (AssociationEnd) associationEnd; |
1937 | |
|
1938 | |
|
1939 | |
|
1940 | 0 | if (kindType.equals("composite")) { |
1941 | 0 | return AggregationKindEnum.AK_COMPOSITE.equals(associationEnd1. |
1942 | |
getAggregation()); |
1943 | |
} else { |
1944 | 0 | throw new IllegalArgumentException("kindType: " + kindType |
1945 | |
+ " not supported"); |
1946 | |
} |
1947 | |
} |
1948 | |
|
1949 | |
|
1950 | |
public void removeAnnotatedElement(Object handle, Object me) { |
1951 | 0 | if (handle instanceof Comment && me instanceof ModelElement) { |
1952 | |
try { |
1953 | 0 | if (((Comment) handle).getAnnotatedElement().contains(me)) { |
1954 | 0 | ((Comment) handle).getAnnotatedElement().remove(me); |
1955 | |
} |
1956 | 0 | } catch (InvalidObjectException e) { |
1957 | 0 | throw new InvalidElementException(e); |
1958 | 0 | } |
1959 | 0 | return; |
1960 | |
} |
1961 | 0 | throw new IllegalArgumentException("handle: " + handle |
1962 | |
+ " or model element: " + me); |
1963 | |
} |
1964 | |
|
1965 | |
|
1966 | |
public void removeClientDependency(Object handle, Object dep) { |
1967 | |
try { |
1968 | 0 | if (handle instanceof ModelElement && dep instanceof Dependency) { |
1969 | 0 | ModelElement me = (ModelElement) handle; |
1970 | 0 | Collection deps = me.getClientDependency(); |
1971 | 0 | if (deps != null && deps.contains(dep)) { |
1972 | 0 | deps.remove(dep); |
1973 | |
} |
1974 | 0 | return; |
1975 | |
} |
1976 | 0 | } catch (InvalidObjectException e) { |
1977 | 0 | throw new InvalidElementException(e); |
1978 | 0 | } |
1979 | 0 | throw new IllegalArgumentException(); |
1980 | |
} |
1981 | |
|
1982 | |
|
1983 | |
public void removeConnection(Object handle, Object connection) { |
1984 | |
try { |
1985 | 0 | if (handle instanceof UmlAssociation |
1986 | |
&& connection instanceof AssociationEnd) { |
1987 | 0 | ((UmlAssociation) handle).getConnection().remove(connection); |
1988 | 0 | return; |
1989 | |
} |
1990 | 0 | if (handle instanceof Link && connection instanceof LinkEnd) { |
1991 | 0 | ((Link) handle).getConnection().remove(connection); |
1992 | 0 | return; |
1993 | |
} |
1994 | 0 | } catch (InvalidObjectException e) { |
1995 | 0 | throw new InvalidElementException(e); |
1996 | 0 | } |
1997 | 0 | throw new IllegalArgumentException("handle: " + handle |
1998 | |
+ " or connection: " + connection); |
1999 | |
|
2000 | |
} |
2001 | |
|
2002 | |
|
2003 | |
public void removeConstraint(Object handle, Object cons) { |
2004 | |
try { |
2005 | 0 | if (handle instanceof ModelElement && cons instanceof Constraint) { |
2006 | 0 | ((ModelElement) handle).getConstraint().remove(cons); |
2007 | 0 | return; |
2008 | |
} |
2009 | 0 | } catch (InvalidObjectException e) { |
2010 | 0 | throw new InvalidElementException(e); |
2011 | 0 | } |
2012 | 0 | throw new IllegalArgumentException("handle: " + handle + " or cons: " |
2013 | |
+ cons); |
2014 | |
} |
2015 | |
|
2016 | |
|
2017 | |
public void removeOwnedElement(Object handle, Object value) { |
2018 | |
try { |
2019 | 0 | if (handle instanceof Namespace && value instanceof ModelElement) { |
2020 | 0 | ModelElement elem = (ModelElement) value; |
2021 | 0 | if (!(elem.getNamespace().equals(handle))) { |
2022 | 0 | throw new IllegalStateException( |
2023 | |
"ModelElement isn't in Namespace"); |
2024 | |
} |
2025 | 0 | elem.setNamespace(null); |
2026 | 0 | return; |
2027 | |
} |
2028 | 0 | } catch (InvalidObjectException e) { |
2029 | 0 | throw new InvalidElementException(e); |
2030 | 0 | } |
2031 | 0 | throw new IllegalArgumentException("handle: " + handle + " or value: " |
2032 | |
+ value); |
2033 | |
} |
2034 | |
|
2035 | |
|
2036 | |
public void removeParameter(Object handle, Object parameter) { |
2037 | |
try { |
2038 | 0 | if (parameter instanceof Parameter) { |
2039 | 0 | if (handle instanceof ObjectFlowState) { |
2040 | 0 | ((ObjectFlowState) handle).getParameter().remove( |
2041 | |
parameter); |
2042 | 0 | return; |
2043 | |
} |
2044 | 0 | if (handle instanceof Event) { |
2045 | 0 | ((Event) handle).getParameter().remove(parameter); |
2046 | 0 | return; |
2047 | |
} |
2048 | 0 | if (handle instanceof BehavioralFeature) { |
2049 | 0 | ((BehavioralFeature) handle).getParameter().remove( |
2050 | |
parameter); |
2051 | 0 | return; |
2052 | |
} |
2053 | 0 | if (handle instanceof Classifier) { |
2054 | 0 | ((Parameter) parameter).setType(null); |
2055 | 0 | return; |
2056 | |
} |
2057 | |
} |
2058 | 0 | } catch (InvalidObjectException e) { |
2059 | 0 | throw new InvalidElementException(e); |
2060 | 0 | } |
2061 | 0 | throw new IllegalArgumentException("handle: " + handle |
2062 | |
+ " or parameter: " + parameter); |
2063 | |
} |
2064 | |
|
2065 | |
|
2066 | |
public void removeQualifier(Object handle, Object qualifier) { |
2067 | |
try { |
2068 | 0 | if (qualifier instanceof Attribute) { |
2069 | 0 | if (handle instanceof AssociationEnd) { |
2070 | 0 | ((AssociationEnd) handle).getQualifier().remove( |
2071 | |
qualifier); |
2072 | 0 | return; |
2073 | |
} |
2074 | |
} |
2075 | 0 | } catch (InvalidObjectException e) { |
2076 | 0 | throw new InvalidElementException(e); |
2077 | 0 | } |
2078 | 0 | throw new IllegalArgumentException("handle: " + handle |
2079 | |
+ " or qualifier: " + qualifier); |
2080 | |
} |
2081 | |
|
2082 | |
|
2083 | |
public void removeSourceFlow(Object handle, Object flow) { |
2084 | |
try { |
2085 | 0 | if (handle instanceof ModelElement && flow instanceof Flow) { |
2086 | 0 | ((ModelElement) handle).getSourceFlow().remove(flow); |
2087 | 0 | return; |
2088 | |
} |
2089 | 0 | } catch (InvalidObjectException e) { |
2090 | 0 | throw new InvalidElementException(e); |
2091 | 0 | } |
2092 | 0 | throw new IllegalArgumentException("handle: " + handle + " or flow: " |
2093 | |
+ flow); |
2094 | |
} |
2095 | |
|
2096 | |
|
2097 | |
public void removeSupplierDependency(Object supplier, Object dependency) { |
2098 | |
try { |
2099 | 0 | if (supplier instanceof ModelElement |
2100 | |
&& dependency instanceof Dependency) { |
2101 | 0 | ((Dependency) dependency).getSupplier().remove(supplier); |
2102 | 0 | return; |
2103 | |
} |
2104 | 0 | } catch (InvalidObjectException e) { |
2105 | 0 | throw new InvalidElementException(e); |
2106 | 0 | } |
2107 | 0 | throw new IllegalArgumentException("supplier: " + supplier |
2108 | |
+ " or dependency: " + dependency); |
2109 | |
} |
2110 | |
|
2111 | |
|
2112 | |
public void removeTargetFlow(Object handle, Object flow) { |
2113 | |
try { |
2114 | 0 | if (handle instanceof ModelElement && flow instanceof Flow) { |
2115 | 0 | ((ModelElement) handle).getTargetFlow().remove(flow); |
2116 | 0 | return; |
2117 | |
} |
2118 | 0 | } catch (InvalidObjectException e) { |
2119 | 0 | throw new InvalidElementException(e); |
2120 | 0 | } |
2121 | 0 | throw new IllegalArgumentException("handle: " + handle + " or flow: " |
2122 | |
+ flow); |
2123 | |
} |
2124 | |
|
2125 | |
|
2126 | |
public void removeTemplateArgument(Object handle, Object argument) { |
2127 | |
try { |
2128 | 0 | if (argument instanceof TemplateArgument) { |
2129 | 0 | if (handle instanceof Binding) { |
2130 | 0 | ((Binding) handle).getArgument().remove(argument); |
2131 | 0 | return; |
2132 | |
} |
2133 | |
} |
2134 | 0 | } catch (InvalidObjectException e) { |
2135 | 0 | throw new InvalidElementException(e); |
2136 | 0 | } |
2137 | 0 | throw new IllegalArgumentException("handle: " + handle |
2138 | |
+ " or parameter: " + argument); |
2139 | |
} |
2140 | |
|
2141 | |
|
2142 | |
public void removeTemplateParameter(Object handle, Object parameter) { |
2143 | |
try { |
2144 | 0 | if (parameter instanceof TemplateParameter) { |
2145 | 0 | if (handle instanceof ModelElement) { |
2146 | 0 | ((ModelElement) handle).getTemplateParameter().remove( |
2147 | |
parameter); |
2148 | 0 | return; |
2149 | |
} |
2150 | |
} |
2151 | 0 | } catch (InvalidObjectException e) { |
2152 | 0 | throw new InvalidElementException(e); |
2153 | 0 | } |
2154 | 0 | throw new IllegalArgumentException("handle: " + handle |
2155 | |
+ " or parameter: " + parameter); |
2156 | |
} |
2157 | |
|
2158 | |
public void addAnnotatedElement(Object comment, Object annotatedElement) { |
2159 | 0 | if (comment instanceof Comment |
2160 | |
&& annotatedElement instanceof ModelElement) { |
2161 | 0 | ((Comment) comment).getAnnotatedElement().add((ModelElement) annotatedElement); |
2162 | 0 | return; |
2163 | |
} |
2164 | 0 | throw new IllegalArgumentException("comment: " + comment |
2165 | |
+ " or annotatedElement: " + annotatedElement); |
2166 | |
} |
2167 | |
|
2168 | |
|
2169 | |
public void addClient(Object handle, Object element) { |
2170 | 0 | if (handle instanceof Dependency && element instanceof ModelElement) { |
2171 | 0 | ((Dependency) handle).getClient().add((ModelElement) element); |
2172 | 0 | return; |
2173 | |
} |
2174 | 0 | throw new IllegalArgumentException("handle: " + handle |
2175 | |
+ " or element: " + element); |
2176 | |
} |
2177 | |
|
2178 | |
|
2179 | |
public void addClientDependency(Object handle, Object dependency) { |
2180 | 0 | if (handle instanceof ModelElement |
2181 | |
&& dependency instanceof Dependency) { |
2182 | 0 | ((ModelElement) handle).getClientDependency().add( |
2183 | |
(Dependency) dependency); |
2184 | 0 | return; |
2185 | |
} |
2186 | 0 | throw new IllegalArgumentException("handle: " + handle |
2187 | |
+ " or dependency: " + dependency); |
2188 | |
} |
2189 | |
|
2190 | |
|
2191 | |
public void addComment(Object element, Object comment) { |
2192 | 0 | if (element instanceof ModelElement && comment instanceof Comment) { |
2193 | 0 | ((ModelElement) element).getComment().add((Comment) comment); |
2194 | 0 | return; |
2195 | |
} |
2196 | 0 | throw new IllegalArgumentException("element: " + element); |
2197 | |
} |
2198 | |
|
2199 | |
|
2200 | |
public void addConnection(Object handle, Object connection) { |
2201 | 0 | if (handle instanceof UmlAssociation |
2202 | |
&& connection instanceof AssociationEnd) { |
2203 | 0 | List<AssociationEnd> ends = |
2204 | |
((UmlAssociation) handle).getConnection(); |
2205 | 0 | ends.add((AssociationEnd) connection); |
2206 | |
|
2207 | 0 | if (ends.size() >= 3) { |
2208 | 0 | for (AssociationEnd end : ends) { |
2209 | 0 | end.setAggregation(AggregationKindEnum.AK_NONE); |
2210 | |
} |
2211 | |
} |
2212 | 0 | return; |
2213 | |
} |
2214 | 0 | if (handle instanceof Link && connection instanceof LinkEnd) { |
2215 | 0 | ((Link) handle).getConnection().add((LinkEnd) connection); |
2216 | 0 | return; |
2217 | |
} |
2218 | 0 | throw new IllegalArgumentException("handle: " + handle |
2219 | |
+ " or connection: " + connection); |
2220 | |
} |
2221 | |
|
2222 | |
|
2223 | |
public void addConnection(Object handle, int position, Object connection) { |
2224 | 0 | if (handle instanceof UmlAssociation |
2225 | |
&& connection instanceof AssociationEnd) { |
2226 | 0 | ((UmlAssociation) handle).getConnection().add(position, |
2227 | |
(AssociationEnd) connection); |
2228 | 0 | List<AssociationEnd> ends = |
2229 | |
((UmlAssociation) handle).getConnection(); |
2230 | |
|
2231 | 0 | if (ends.size() >= 3) { |
2232 | 0 | for (AssociationEnd end : ends) { |
2233 | 0 | end.setAggregation(AggregationKindEnum.AK_NONE); |
2234 | |
} |
2235 | |
} |
2236 | 0 | return; |
2237 | |
} |
2238 | |
|
2239 | |
|
2240 | |
|
2241 | |
|
2242 | 0 | if (handle instanceof Link && connection instanceof LinkEnd) { |
2243 | 0 | ((Link) handle).getConnection().add((LinkEnd) connection); |
2244 | 0 | return; |
2245 | |
} |
2246 | 0 | throw new IllegalArgumentException("handle: " + handle |
2247 | |
+ " or connection: " + connection); |
2248 | |
} |
2249 | |
|
2250 | |
|
2251 | |
public void addConstraint(Object handle, Object mc) { |
2252 | 0 | if (handle instanceof ModelElement && mc instanceof Constraint) { |
2253 | 0 | ((ModelElement) handle).getConstraint().add((Constraint) mc); |
2254 | 0 | return; |
2255 | |
} |
2256 | 0 | throw new IllegalArgumentException("handle: " + handle + " or mc: " |
2257 | |
+ mc); |
2258 | |
} |
2259 | |
|
2260 | |
|
2261 | |
public void addDeploymentLocation(Object handle, Object node) { |
2262 | 0 | if (handle instanceof Component && node instanceof Node) { |
2263 | 0 | ((Component) handle).getDeploymentLocation().add((Node) node); |
2264 | 0 | return; |
2265 | |
} |
2266 | 0 | throw new IllegalArgumentException("handle: " + handle + " or node: " |
2267 | |
+ node); |
2268 | |
} |
2269 | |
|
2270 | |
|
2271 | |
public void addElementResidence(Object handle, Object node) { |
2272 | |
|
2273 | |
|
2274 | 0 | if (handle instanceof ModelElement |
2275 | |
&& node instanceof ElementResidence) { |
2276 | 0 | ((ElementResidence) node).setResident((ModelElement) handle); |
2277 | 0 | return; |
2278 | |
} |
2279 | 0 | throw new IllegalArgumentException("handle: " + handle + " or node: " |
2280 | |
+ node); |
2281 | |
} |
2282 | |
|
2283 | |
|
2284 | |
public void removeElementResidence(Object handle, Object node) { |
2285 | |
try { |
2286 | 0 | if (handle instanceof ModelElement |
2287 | |
&& node instanceof ElementResidence) { |
2288 | 0 | ((ElementResidence) node).setResident(null); |
2289 | 0 | return; |
2290 | |
} |
2291 | 0 | } catch (InvalidObjectException e) { |
2292 | 0 | throw new InvalidElementException(e); |
2293 | 0 | } |
2294 | 0 | throw new IllegalArgumentException("handle: " + handle + " or node: " |
2295 | |
+ node); |
2296 | |
} |
2297 | |
|
2298 | |
|
2299 | |
|
2300 | |
|
2301 | |
|
2302 | |
|
2303 | |
|
2304 | |
|
2305 | |
|
2306 | |
public Collection<ElementResidence> getElementResidence(Object handle) { |
2307 | |
try { |
2308 | 0 | if (handle instanceof ModelElement) { |
2309 | 0 | return ((org.omg.uml.UmlPackage) ((ModelElement) handle) |
2310 | |
.refOutermostPackage()).getCore() |
2311 | |
.getAResidentElementResidence().getElementResidence( |
2312 | |
(ModelElement) handle); |
2313 | |
} |
2314 | 0 | } catch (InvalidObjectException e) { |
2315 | 0 | throw new InvalidElementException(e); |
2316 | 0 | } |
2317 | 0 | throw new IllegalArgumentException("handle: " + handle); |
2318 | |
} |
2319 | |
|
2320 | |
|
2321 | |
public void addFeature(Object handle, int index, Object f) { |
2322 | 0 | if (handle instanceof Classifier && f instanceof Feature) { |
2323 | 0 | ((Classifier) handle).getFeature().add(index, (Feature) f); |
2324 | 0 | return; |
2325 | |
} |
2326 | 0 | throw new IllegalArgumentException("handle: " + handle + " or f: " + f); |
2327 | |
} |
2328 | |
|
2329 | |
|
2330 | |
public void addLiteral(Object handle, int index, Object literal) { |
2331 | 0 | if (handle instanceof Enumeration |
2332 | |
&& literal instanceof EnumerationLiteral) { |
2333 | 0 | ((Enumeration) handle).getLiteral().add(index, |
2334 | |
(EnumerationLiteral) literal); |
2335 | 0 | return; |
2336 | |
} |
2337 | 0 | throw new IllegalArgumentException("enumeration: " + handle |
2338 | |
+ " or literal: " + literal); |
2339 | |
} |
2340 | |
|
2341 | |
|
2342 | |
public void addFeature(Object handle, Object f) { |
2343 | 0 | if (handle instanceof Classifier && f instanceof Feature) { |
2344 | 0 | ((Classifier) handle).getFeature().add((Feature) f); |
2345 | 0 | return; |
2346 | |
} |
2347 | 0 | throw new IllegalArgumentException("handle: " + handle); |
2348 | |
} |
2349 | |
|
2350 | |
|
2351 | |
public void addLink(Object handle, Object link) { |
2352 | 0 | if (handle instanceof UmlAssociation && link instanceof Link) { |
2353 | 0 | ((Link) link).setAssociation((UmlAssociation) handle); |
2354 | 0 | return; |
2355 | |
} |
2356 | 0 | throw new IllegalArgumentException("handle: " + handle + " or link: " |
2357 | |
+ link); |
2358 | |
} |
2359 | |
|
2360 | |
public void addManifestation(Object handle, Object manifestation) { |
2361 | 0 | throw new NotImplementedException( "UML 1.4 has no manifestations"); |
2362 | |
} |
2363 | |
|
2364 | |
public void addMethod(Object handle, Object m) { |
2365 | 0 | if (handle instanceof Operation && m instanceof Method) { |
2366 | 0 | ((Method) m).setVisibility(((Operation) handle).getVisibility()); |
2367 | 0 | ((Method) m).setOwnerScope(((Operation) handle).getOwnerScope()); |
2368 | 0 | ((Method) m).setSpecification((Operation) handle); |
2369 | 0 | return; |
2370 | |
} |
2371 | 0 | throw new IllegalArgumentException("handle: " + handle + " or m: " + m); |
2372 | |
} |
2373 | |
|
2374 | |
|
2375 | |
public void addOwnedElement(Object handle, Object me) { |
2376 | 0 | if (handle instanceof Namespace && me instanceof ModelElement) { |
2377 | 0 | Namespace ns = (Namespace) handle; |
2378 | 0 | ModelElement elem = (ModelElement) me; |
2379 | 0 | elem.setNamespace(ns); |
2380 | 0 | ns.getOwnedElement().add(elem); |
2381 | 0 | return; |
2382 | |
} |
2383 | 0 | throw new IllegalArgumentException("handle: " + handle + " or me: " |
2384 | |
+ me); |
2385 | |
} |
2386 | |
|
2387 | |
|
2388 | |
public void addParameter(Object handle, int index, Object parameter) { |
2389 | 0 | if (parameter instanceof Parameter) { |
2390 | 0 | if (handle instanceof Event) { |
2391 | 0 | ((Event) handle).getParameter().add(index, |
2392 | |
(Parameter) parameter); |
2393 | 0 | return; |
2394 | |
} |
2395 | 0 | if (handle instanceof BehavioralFeature) { |
2396 | 0 | ((BehavioralFeature) handle).getParameter().add(index, |
2397 | |
(Parameter) parameter); |
2398 | 0 | return; |
2399 | |
} |
2400 | |
} |
2401 | 0 | throw new IllegalArgumentException("handle: " + handle |
2402 | |
+ " or parameter: " + parameter); |
2403 | |
} |
2404 | |
|
2405 | |
|
2406 | |
public void addParameter(Object handle, Object parameter) { |
2407 | 0 | if (parameter instanceof Parameter) { |
2408 | 0 | if (handle instanceof ObjectFlowState) { |
2409 | 0 | ((ObjectFlowState) handle).getParameter().add( |
2410 | |
(Parameter) parameter); |
2411 | 0 | return; |
2412 | |
} |
2413 | 0 | if (handle instanceof Event) { |
2414 | 0 | ((Event) handle).getParameter().add((Parameter) parameter); |
2415 | 0 | return; |
2416 | |
} |
2417 | 0 | if (handle instanceof BehavioralFeature) { |
2418 | 0 | ((BehavioralFeature) handle).getParameter().add( |
2419 | |
(Parameter) parameter); |
2420 | 0 | return; |
2421 | |
} |
2422 | 0 | if (handle instanceof Classifier) { |
2423 | 0 | ((Parameter) parameter).setType((Classifier) handle); |
2424 | 0 | return; |
2425 | |
} |
2426 | |
} |
2427 | 0 | throw new IllegalArgumentException("handle: " + handle |
2428 | |
+ " or parameter: " + parameter); |
2429 | |
} |
2430 | |
|
2431 | |
|
2432 | |
public void addQualifier(Object handle, int index, Object qualifier) { |
2433 | 0 | if (qualifier instanceof Attribute) { |
2434 | 0 | if (handle instanceof AssociationEnd) { |
2435 | 0 | ((AssociationEnd) handle).getQualifier().add(index, |
2436 | |
(Attribute) qualifier); |
2437 | 0 | return; |
2438 | |
} |
2439 | |
} |
2440 | 0 | throw new IllegalArgumentException("handle: " + handle |
2441 | |
+ " or qualifier: " + qualifier); |
2442 | |
} |
2443 | |
|
2444 | |
|
2445 | |
public void addRaisedSignal(Object handle, Object sig) { |
2446 | 0 | if (sig instanceof Signal) { |
2447 | 0 | if (handle instanceof Message) { |
2448 | 0 | ((org.omg.uml.UmlPackage) ((Signal) sig) |
2449 | |
.refOutermostPackage()).getCommonBehavior() |
2450 | |
.getAContextRaisedSignal().add( |
2451 | |
(BehavioralFeature) handle, (Signal) sig); |
2452 | 0 | return; |
2453 | |
} |
2454 | 0 | if (handle instanceof Operation) { |
2455 | 0 | ((org.omg.uml.UmlPackage) ((Signal) sig).refOutermostPackage()) |
2456 | |
.getCommonBehavior().getAContextRaisedSignal().add( |
2457 | |
(BehavioralFeature) handle, (Signal) sig); |
2458 | 0 | return; |
2459 | |
} |
2460 | |
} |
2461 | 0 | throw new IllegalArgumentException("handle: " + handle + " or sig: " |
2462 | |
+ sig); |
2463 | |
} |
2464 | |
|
2465 | |
|
2466 | |
|
2467 | |
|
2468 | |
|
2469 | |
|
2470 | |
|
2471 | |
|
2472 | |
public void addRaisedException(Object handle, Object Exception) { |
2473 | 0 | throw new NotImplementedException( "UML 1.4 has no exceptions for operations"); |
2474 | |
} |
2475 | |
|
2476 | |
public void addSourceFlow(Object handle, Object flow) { |
2477 | 0 | if (handle instanceof ModelElement && flow instanceof Flow) { |
2478 | 0 | ((ModelElement) handle).getSourceFlow().add((Flow) flow); |
2479 | 0 | return; |
2480 | |
} |
2481 | |
|
2482 | 0 | throw new IllegalArgumentException("handle: " + handle + " or flow: " |
2483 | |
+ flow); |
2484 | |
} |
2485 | |
|
2486 | |
|
2487 | |
public void addSupplier(Object handle, Object element) { |
2488 | 0 | if (handle instanceof Dependency && element instanceof ModelElement) { |
2489 | 0 | ((Dependency) handle).getSupplier().add((ModelElement) element); |
2490 | 0 | return; |
2491 | |
} |
2492 | 0 | throw new IllegalArgumentException("handle: " + handle |
2493 | |
+ " or element: " + element); |
2494 | |
} |
2495 | |
|
2496 | |
|
2497 | |
public void addSupplierDependency(Object supplier, Object dependency) { |
2498 | 0 | if (supplier instanceof ModelElement |
2499 | |
&& dependency instanceof Dependency) { |
2500 | 0 | ((Dependency) dependency).getSupplier() |
2501 | |
.add((ModelElement) supplier); |
2502 | 0 | return; |
2503 | |
} |
2504 | 0 | throw new IllegalArgumentException("supplier: " + supplier |
2505 | |
+ " or dependency: " + dependency); |
2506 | |
} |
2507 | |
|
2508 | |
|
2509 | |
public void addTargetFlow(Object handle, Object flow) { |
2510 | 0 | if (handle instanceof ModelElement && flow instanceof Flow) { |
2511 | 0 | ((ModelElement) handle).getTargetFlow().add((Flow) flow); |
2512 | 0 | return; |
2513 | |
} |
2514 | |
|
2515 | 0 | throw new IllegalArgumentException("handle: " + handle + " or flow: " |
2516 | |
+ flow); |
2517 | |
} |
2518 | |
|
2519 | |
public void addTemplateArgument(Object handle, int index, Object argument) { |
2520 | 0 | if (argument instanceof TemplateArgument) { |
2521 | 0 | if (handle instanceof Binding) { |
2522 | 0 | ((Binding) handle).getArgument().add(index, |
2523 | |
(TemplateArgument) argument); |
2524 | 0 | return; |
2525 | |
} |
2526 | |
} |
2527 | 0 | throw new IllegalArgumentException("handle: " + handle |
2528 | |
+ " or parameter: " + argument); |
2529 | |
} |
2530 | |
|
2531 | |
|
2532 | |
public void addTemplateArgument(Object handle, Object argument) { |
2533 | 0 | if (argument instanceof TemplateArgument |
2534 | |
&& handle instanceof Binding) { |
2535 | 0 | ((Binding) handle).getArgument().add((TemplateArgument) argument); |
2536 | 0 | return; |
2537 | |
} |
2538 | 0 | throw new IllegalArgumentException("handle: " + handle |
2539 | |
+ " or argument: " + argument); |
2540 | |
} |
2541 | |
|
2542 | |
|
2543 | |
public void addTemplateParameter(Object handle, int index, |
2544 | |
Object parameter) { |
2545 | 0 | if (parameter instanceof TemplateParameter) { |
2546 | 0 | if (handle instanceof ModelElement) { |
2547 | 0 | ((ModelElement) handle).getTemplateParameter().add( |
2548 | |
index, (TemplateParameter) parameter); |
2549 | 0 | return; |
2550 | |
} |
2551 | |
} |
2552 | 0 | throw new IllegalArgumentException("handle: " + handle |
2553 | |
+ " or parameter: " + parameter); |
2554 | |
} |
2555 | |
|
2556 | |
|
2557 | |
public void addTemplateParameter(Object handle, Object parameter) { |
2558 | 0 | if (parameter instanceof TemplateParameter) { |
2559 | 0 | if (handle instanceof ModelElement) { |
2560 | 0 | ((ModelElement) handle).getTemplateParameter().add( |
2561 | |
(TemplateParameter) parameter); |
2562 | 0 | return; |
2563 | |
} |
2564 | |
} |
2565 | 0 | throw new IllegalArgumentException("handle: " + handle |
2566 | |
+ " or parameter: " + parameter); |
2567 | |
} |
2568 | |
|
2569 | |
|
2570 | |
public void setAbstract(Object handle, boolean flag) { |
2571 | 0 | if (handle instanceof GeneralizableElement) { |
2572 | 0 | ((GeneralizableElement) handle).setAbstract(flag); |
2573 | 0 | return; |
2574 | |
} |
2575 | 0 | if (handle instanceof Operation) { |
2576 | 0 | ((Operation) handle).setAbstract(flag); |
2577 | 0 | return; |
2578 | |
} |
2579 | 0 | if (handle instanceof Reception) { |
2580 | 0 | ((Reception) handle).setAbstract(flag); |
2581 | 0 | return; |
2582 | |
} |
2583 | 0 | throw new IllegalArgumentException("handle: " + handle); |
2584 | |
} |
2585 | |
|
2586 | |
|
2587 | |
public void setActive(Object handle, boolean active) { |
2588 | 0 | if (handle instanceof UmlClass) { |
2589 | 0 | ((UmlClass) handle).setActive(active); |
2590 | 0 | return; |
2591 | |
} |
2592 | 0 | throw new IllegalArgumentException("handle: " + handle); |
2593 | |
} |
2594 | |
|
2595 | |
|
2596 | |
public void setAggregation(Object handle, Object aggregationKind) { |
2597 | 0 | if (handle instanceof AssociationEnd |
2598 | |
&& aggregationKind instanceof AggregationKind) { |
2599 | 0 | AggregationKind ak = (AggregationKind) aggregationKind; |
2600 | 0 | AssociationEnd ae = (AssociationEnd) handle; |
2601 | |
|
2602 | |
|
2603 | 0 | if (ak == AggregationKindEnum.AK_NONE |
2604 | |
|| ae.getAssociation().getConnection().size() < 3) { |
2605 | 0 | ae.setAggregation(ak); |
2606 | |
} else { |
2607 | 0 | ae.setAggregation(AggregationKindEnum.AK_NONE); |
2608 | |
} |
2609 | |
|
2610 | |
|
2611 | 0 | if (ak == AggregationKindEnum.AK_AGGREGATE |
2612 | |
|| ak == AggregationKindEnum.AK_COMPOSITE) { |
2613 | 0 | for (AssociationEnd end : ae.getAssociation().getConnection()) { |
2614 | 0 | if (!end.equals(ae) |
2615 | |
&& end.getAggregation() != AggregationKindEnum.AK_NONE) { |
2616 | 0 | end.setAggregation(AggregationKindEnum.AK_NONE); |
2617 | |
} |
2618 | |
} |
2619 | |
} |
2620 | 0 | return; |
2621 | |
} |
2622 | 0 | throw new IllegalArgumentException("handle: " + handle |
2623 | |
+ " or aggregationKind: " + aggregationKind); |
2624 | |
} |
2625 | |
|
2626 | |
|
2627 | |
public void setAnnotatedElements(Object handle, Collection elems) { |
2628 | 0 | if (handle instanceof Comment && elems instanceof List) { |
2629 | 0 | CollectionHelper.update( |
2630 | |
((Comment) handle).getAnnotatedElement(), elems); |
2631 | 0 | return; |
2632 | |
} |
2633 | 0 | throw new IllegalArgumentException("handle: " + handle); |
2634 | |
} |
2635 | |
|
2636 | |
|
2637 | |
public void setAssociation(Object handle, Object association) { |
2638 | 0 | if (association instanceof UmlAssociation) { |
2639 | 0 | if (handle instanceof AssociationEnd) { |
2640 | 0 | ((AssociationEnd) handle). |
2641 | |
setAssociation((UmlAssociation) association); |
2642 | 0 | return; |
2643 | |
} |
2644 | 0 | if (handle instanceof Link) { |
2645 | 0 | ((Link) handle).setAssociation((UmlAssociation) association); |
2646 | 0 | return; |
2647 | |
} |
2648 | 0 | } else if (association instanceof AssociationRole) { |
2649 | 0 | if (handle instanceof AssociationEndRole) { |
2650 | 0 | ((AssociationEndRole) handle). |
2651 | |
setAssociation((AssociationRole) association); |
2652 | 0 | return; |
2653 | |
} |
2654 | |
} |
2655 | 0 | throw new IllegalArgumentException("handle: " + handle |
2656 | |
+ " or association: " + association); |
2657 | |
} |
2658 | |
|
2659 | |
|
2660 | |
public void setLeaf(Object handle, boolean flag) { |
2661 | 0 | if (handle instanceof Reception) { |
2662 | 0 | ((Reception) handle).setLeaf(flag); |
2663 | 0 | return; |
2664 | |
} |
2665 | 0 | if (handle instanceof Operation) { |
2666 | 0 | ((Operation) handle).setLeaf(flag); |
2667 | 0 | return; |
2668 | |
} |
2669 | 0 | if (handle instanceof GeneralizableElement) { |
2670 | 0 | ((GeneralizableElement) handle).setLeaf(flag); |
2671 | 0 | return; |
2672 | |
} |
2673 | 0 | throw new IllegalArgumentException("handle: " + handle); |
2674 | |
} |
2675 | |
|
2676 | |
|
2677 | |
public void setRaisedSignals(Object handle, Collection raisedSignals) { |
2678 | 0 | throw new NotImplementedException(); |
2679 | |
} |
2680 | |
|
2681 | |
|
2682 | |
public void setBody(Object handle, Object expr) { |
2683 | 0 | if (handle instanceof Method |
2684 | |
&& (expr == null || expr instanceof ProcedureExpression)) { |
2685 | 0 | ProcedureExpression oldPe = ((Method)handle).getBody(); |
2686 | 0 | if (!equal(oldPe, (ProcedureExpression) expr)) { |
2687 | 0 | ((Method) handle).setBody(null); |
2688 | 0 | if (oldPe != null) { |
2689 | 0 | Model.getUmlFactory().delete(oldPe); |
2690 | |
} |
2691 | 0 | ((Method) handle).setBody((ProcedureExpression) expr); |
2692 | |
} |
2693 | 0 | return; |
2694 | |
} |
2695 | |
|
2696 | 0 | if (handle instanceof Constraint |
2697 | |
&& (expr == null || expr instanceof BooleanExpression)) { |
2698 | 0 | BooleanExpression oldBe = ((Constraint)handle).getBody(); |
2699 | 0 | if (!equal(oldBe, (BooleanExpression) expr)) { |
2700 | 0 | ((Constraint) handle).setBody((BooleanExpression) expr); |
2701 | 0 | if (oldBe != null) { |
2702 | 0 | Model.getUmlFactory().delete(oldBe); |
2703 | |
} |
2704 | |
} |
2705 | 0 | return; |
2706 | |
} |
2707 | |
|
2708 | 0 | throw new IllegalArgumentException("handle: " + handle + " or expr: " |
2709 | |
+ expr); |
2710 | |
} |
2711 | |
|
2712 | |
|
2713 | |
private boolean equal(Expression expr1, Expression expr2) { |
2714 | 0 | if (expr1 == null) { |
2715 | 0 | if (expr2 == null) { |
2716 | 0 | return true; |
2717 | |
} else { |
2718 | 0 | return false; |
2719 | |
} |
2720 | |
} else { |
2721 | 0 | return expr1.equals(expr2); |
2722 | |
} |
2723 | |
} |
2724 | |
|
2725 | |
@Deprecated |
2726 | |
public void setChangeability(Object handle, Object ck) { |
2727 | 0 | if (ck == null || ck instanceof ChangeableKind) { |
2728 | 0 | ChangeableKind changeableKind = (ChangeableKind) ck; |
2729 | |
|
2730 | 0 | if (handle instanceof StructuralFeature) { |
2731 | 0 | ((StructuralFeature) handle).setChangeability(changeableKind); |
2732 | 0 | return; |
2733 | |
} |
2734 | 0 | if (handle instanceof AssociationEnd) { |
2735 | 0 | ((AssociationEnd) handle).setChangeability(changeableKind); |
2736 | 0 | return; |
2737 | |
} |
2738 | |
} |
2739 | 0 | throw new IllegalArgumentException("handle: " + handle + " or ck: " |
2740 | |
+ ck); |
2741 | |
} |
2742 | |
|
2743 | |
|
2744 | |
public void setReadOnly(Object handle, boolean isReadOnly) { |
2745 | 0 | setChangeability(handle, isReadOnly ? ChangeableKindEnum.CK_FROZEN |
2746 | |
: ChangeableKindEnum.CK_CHANGEABLE); |
2747 | 0 | } |
2748 | |
|
2749 | |
public void setChild(Object handle, Object child) { |
2750 | 0 | if (handle instanceof Generalization) { |
2751 | 0 | ((Generalization) handle).setChild((GeneralizableElement) child); |
2752 | 0 | return; |
2753 | |
} |
2754 | 0 | throw new IllegalArgumentException("handle: " + handle + " or child: " |
2755 | |
+ child); |
2756 | |
} |
2757 | |
|
2758 | |
|
2759 | |
public void setConcurrency(Object handle, Object concurrencyKind) { |
2760 | 0 | if (handle instanceof Operation |
2761 | |
&& concurrencyKind instanceof CallConcurrencyKind) { |
2762 | 0 | ((Operation) handle). |
2763 | |
setConcurrency((CallConcurrencyKind) concurrencyKind); |
2764 | 0 | return; |
2765 | |
} |
2766 | 0 | throw new IllegalArgumentException("handle: " + handle |
2767 | |
+ " or concurrencyKind: " + concurrencyKind); |
2768 | |
} |
2769 | |
|
2770 | |
|
2771 | |
public void setConnections(Object handle, Collection elems) { |
2772 | 0 | if (handle instanceof UmlAssociation && elems instanceof List) { |
2773 | 0 | List<AssociationEnd> ends = |
2774 | |
((UmlAssociation) handle).getConnection(); |
2775 | 0 | CollectionHelper.update(ends, elems); |
2776 | |
|
2777 | 0 | if (ends.size() >= 3) { |
2778 | 0 | for (AssociationEnd end : ends) { |
2779 | 0 | end.setAggregation(AggregationKindEnum.AK_NONE); |
2780 | |
} |
2781 | |
} |
2782 | 0 | return; |
2783 | |
} |
2784 | 0 | if (handle instanceof Link && elems instanceof List) { |
2785 | 0 | CollectionHelper.update( |
2786 | |
((Link) handle).getConnection(), elems); |
2787 | 0 | return; |
2788 | |
} |
2789 | 0 | throw new IllegalArgumentException("handle: " + handle); |
2790 | |
} |
2791 | |
|
2792 | |
public void setDefaultElement(Object handle, Object element) { |
2793 | 0 | if (handle instanceof TemplateParameter |
2794 | |
&& element instanceof ModelElement) { |
2795 | 0 | ((TemplateParameter) handle) |
2796 | |
.setDefaultElement((ModelElement) element); |
2797 | 0 | return; |
2798 | |
} |
2799 | 0 | throw new IllegalArgumentException("handle: " + handle |
2800 | |
+ " or model element: " + element); |
2801 | |
} |
2802 | |
|
2803 | |
|
2804 | |
public void setDefaultValue(Object handle, Object expr) { |
2805 | 0 | if (handle instanceof Parameter |
2806 | |
&& (expr == null || expr instanceof Expression)) { |
2807 | 0 | Expression oldExp = ((Parameter) handle).getDefaultValue(); |
2808 | 0 | if (!equal(oldExp, (Expression) expr)) { |
2809 | 0 | ((Parameter) handle).setDefaultValue((Expression) expr); |
2810 | 0 | if (oldExp != null) { |
2811 | 0 | Model.getUmlFactory().delete(oldExp); |
2812 | |
} |
2813 | |
} |
2814 | 0 | return; |
2815 | |
} |
2816 | 0 | throw new IllegalArgumentException("handle: " + handle + " or expr: " |
2817 | |
+ expr); |
2818 | |
} |
2819 | |
|
2820 | |
|
2821 | |
public void setDiscriminator(Object handle, String discriminator) { |
2822 | 0 | if (handle instanceof Generalization) { |
2823 | 0 | ((Generalization) handle).setDiscriminator(discriminator); |
2824 | 0 | return; |
2825 | |
} |
2826 | 0 | throw new IllegalArgumentException("handle: " + handle); |
2827 | |
} |
2828 | |
|
2829 | |
|
2830 | |
public void setFeature(Object elem, int i, Object impl) { |
2831 | 0 | if (elem instanceof Classifier && impl instanceof Feature) { |
2832 | 0 | ((Classifier) elem).getFeature().add(i, (Feature) impl); |
2833 | 0 | return; |
2834 | |
} |
2835 | |
|
2836 | 0 | throw new IllegalArgumentException("elem: " + elem + " or impl: " |
2837 | |
+ impl); |
2838 | |
} |
2839 | |
|
2840 | |
|
2841 | |
public void setFeatures(Object handle, Collection features) { |
2842 | 0 | if (handle instanceof Classifier) { |
2843 | 0 | List featuresList = null; |
2844 | 0 | if (features instanceof List) { |
2845 | 0 | featuresList = (List) features; |
2846 | |
} else { |
2847 | 0 | featuresList = new ArrayList(features); |
2848 | |
} |
2849 | |
|
2850 | |
|
2851 | |
|
2852 | |
|
2853 | |
|
2854 | 0 | ((Classifier) handle).getFeature().clear(); |
2855 | 0 | ((Classifier) handle).getFeature().addAll(featuresList); |
2856 | 0 | return; |
2857 | |
} |
2858 | 0 | throw new IllegalArgumentException("handle: " + handle); |
2859 | |
} |
2860 | |
|
2861 | |
|
2862 | |
public void setContainer(Object handle, Object container) { |
2863 | 0 | if (handle instanceof ElementResidence |
2864 | |
&& (container instanceof Component || container == null)) { |
2865 | 0 | ElementResidence er = (ElementResidence) handle; |
2866 | 0 | er.setContainer((Component) container); |
2867 | 0 | } else { |
2868 | 0 | throw new IllegalArgumentException("handle: " + handle |
2869 | |
+ " or container: " + container); |
2870 | |
} |
2871 | 0 | } |
2872 | |
|
2873 | |
|
2874 | |
public void setInitialValue(Object at, Object expr) { |
2875 | 0 | if (at instanceof Attribute |
2876 | |
&& (expr == null || expr instanceof Expression)) { |
2877 | 0 | Expression oldExp = ((Attribute) at).getInitialValue(); |
2878 | 0 | if (!equal(oldExp, (Expression) expr)) { |
2879 | 0 | ((Attribute) at).setInitialValue((Expression) expr); |
2880 | 0 | if (oldExp != null) { |
2881 | 0 | Model.getUmlFactory().delete(oldExp); |
2882 | |
} |
2883 | |
} |
2884 | 0 | return; |
2885 | |
} |
2886 | 0 | throw new IllegalArgumentException("at: " + at + " or expr: " + expr); |
2887 | |
} |
2888 | |
|
2889 | |
|
2890 | |
public void setKind(Object handle, Object kind) { |
2891 | 0 | if (handle instanceof Parameter |
2892 | |
&& kind instanceof ParameterDirectionKind) { |
2893 | 0 | ((Parameter) handle).setKind((ParameterDirectionKind) kind); |
2894 | 0 | return; |
2895 | |
} |
2896 | 0 | if (handle instanceof Pseudostate && kind instanceof PseudostateKind) { |
2897 | 0 | ((Pseudostate) handle).setKind((PseudostateKind) kind); |
2898 | 0 | return; |
2899 | |
} |
2900 | 0 | throw new IllegalArgumentException("handle: " + handle + " or kind: " |
2901 | |
+ kind); |
2902 | |
} |
2903 | |
|
2904 | |
|
2905 | |
public void setModelElementContainer(Object handle, Object container) { |
2906 | |
|
2907 | |
|
2908 | |
|
2909 | |
|
2910 | |
|
2911 | |
|
2912 | 0 | if (handle instanceof Partition && container instanceof ActivityGraph) { |
2913 | 0 | ((Partition) handle).setActivityGraph((ActivityGraph) container); |
2914 | 0 | } else if (handle instanceof ModelElement |
2915 | |
&& container instanceof Partition) { |
2916 | 0 | ((Partition) container).getContents().add((ModelElement) handle); |
2917 | 0 | } else if (handle instanceof Constraint |
2918 | |
&& container instanceof Stereotype) { |
2919 | 0 | ((Stereotype) container).getStereotypeConstraint().add( |
2920 | |
(Constraint) handle); |
2921 | 0 | } else if (handle instanceof Interaction |
2922 | |
&& container instanceof Collaboration) { |
2923 | 0 | ((Interaction) handle).setContext((Collaboration) container); |
2924 | 0 | } else if (handle instanceof ElementResidence |
2925 | |
&& (container instanceof Component || container == null)) { |
2926 | 0 | ElementResidence er = (ElementResidence) handle; |
2927 | 0 | er.setContainer((Component) container); |
2928 | 0 | } else if (handle instanceof AttributeLink |
2929 | |
&& container instanceof Instance) { |
2930 | 0 | ((AttributeLink) handle).setInstance((Instance) container); |
2931 | 0 | } else if (handle instanceof Message |
2932 | |
&& container instanceof Interaction) { |
2933 | 0 | ((Message) handle).setInteraction((Interaction) container); |
2934 | 0 | } else if (handle instanceof LinkEnd && container instanceof Link) { |
2935 | 0 | ((LinkEnd) handle).setLink((Link) container); |
2936 | 0 | } else if (handle instanceof AttributeLink |
2937 | |
&& container instanceof LinkEnd) { |
2938 | 0 | ((AttributeLink) handle).setLinkEnd((LinkEnd) container); |
2939 | 0 | } else if (handle instanceof TaggedValue |
2940 | |
&& container instanceof Stereotype) { |
2941 | 0 | ((TaggedValue) handle).getStereotype().clear(); |
2942 | 0 | ((TaggedValue) handle).getStereotype().add((Stereotype) container); |
2943 | 0 | } else if (handle instanceof TaggedValue |
2944 | |
&& container instanceof ModelElement) { |
2945 | 0 | ((TaggedValue) handle).setModelElement((ModelElement) container); |
2946 | 0 | } else if (handle instanceof StateVertex |
2947 | |
&& container instanceof CompositeState) { |
2948 | 0 | ((StateVertex) handle).setContainer((CompositeState) container); |
2949 | 0 | } else if (handle instanceof ElementImport |
2950 | |
&& container instanceof UmlPackage) { |
2951 | 0 | ((ElementImport) handle).setUmlPackage((UmlPackage) container); |
2952 | 0 | } else if (handle instanceof Transition && container instanceof State) { |
2953 | 0 | ((State) container).getInternalTransition() |
2954 | |
.add((Transition) handle); |
2955 | 0 | } else if (handle instanceof State |
2956 | |
&& container instanceof StateMachine) { |
2957 | 0 | ((State) handle).setStateMachine((StateMachine) container); |
2958 | 0 | } else if (handle instanceof Transition |
2959 | |
&& container instanceof StateMachine) { |
2960 | 0 | ((Transition) handle).setStateMachine((StateMachine) container); |
2961 | 0 | } else if (handle instanceof Action |
2962 | |
&& container instanceof Transition) { |
2963 | 0 | ((Transition) container).setEffect((Action) handle); |
2964 | 0 | } else if (handle instanceof Guard && container instanceof Transition) { |
2965 | 0 | ((Guard) handle).setTransition((Transition) container); |
2966 | 0 | } else if (handle instanceof ModelElement |
2967 | |
&& container instanceof Namespace) { |
2968 | 0 | ((ModelElement) handle).setNamespace((Namespace) container); |
2969 | |
} else { |
2970 | 0 | throw new IllegalArgumentException("handle: " + handle |
2971 | |
+ " or container: " + container); |
2972 | |
} |
2973 | 0 | } |
2974 | |
|
2975 | |
public void setMultiplicity(Object handle, String arg) { |
2976 | 0 | setMultiplicity(handle,createMultiplicity(arg)); |
2977 | 0 | } |
2978 | |
|
2979 | |
private void setMultiplicity(Object handle, Multiplicity arg) { |
2980 | 0 | Multiplicity previousMult = |
2981 | |
(Multiplicity) Model.getFacade().getMultiplicity(handle); |
2982 | 0 | if (handle instanceof AssociationRole) { |
2983 | 0 | ((AssociationRole) handle).setMultiplicity(arg); |
2984 | 0 | } else if (handle instanceof ClassifierRole) { |
2985 | 0 | ((ClassifierRole) handle).setMultiplicity(arg); |
2986 | 0 | } else if (handle instanceof StructuralFeature) { |
2987 | 0 | ((StructuralFeature) handle).setMultiplicity(arg); |
2988 | 0 | } else if (handle instanceof AssociationEnd) { |
2989 | 0 | ((AssociationEnd) handle).setMultiplicity(arg); |
2990 | 0 | } else if (handle instanceof TagDefinition) { |
2991 | 0 | ((TagDefinition) handle).setMultiplicity(arg); |
2992 | |
} |
2993 | 0 | if (previousMult != null && |
2994 | |
Model.getFacade().getModelElementContainer(previousMult) |
2995 | |
== null) { |
2996 | 0 | if (LOG.isDebugEnabled()) { |
2997 | 0 | LOG.debug("Previous multiplicity of " + handle + " will be deleted." + arg); |
2998 | |
} |
2999 | 0 | Model.getUmlFactory().delete(previousMult); |
3000 | |
} |
3001 | 0 | } |
3002 | |
|
3003 | |
@Deprecated |
3004 | |
public void setMultiplicity(Object handle, Object arg) { |
3005 | 0 | if (arg instanceof String) { |
3006 | 0 | setMultiplicity(handle, (String) arg); |
3007 | 0 | return; |
3008 | |
} |
3009 | 0 | if (arg == null || arg instanceof Multiplicity) { |
3010 | 0 | setMultiplicity(handle, (Multiplicity) arg); |
3011 | |
} else { |
3012 | 0 | throw new IllegalArgumentException("handle: " + handle + " or arg: " |
3013 | |
+ arg); |
3014 | |
} |
3015 | 0 | } |
3016 | |
|
3017 | |
private Multiplicity createMultiplicity(String sarg) { |
3018 | 0 | boolean allDigits = true; |
3019 | 0 | for (int i=0; i < sarg.length(); ++i) { |
3020 | 0 | if (!Character.isDigit(sarg.charAt(i))) { |
3021 | 0 | allDigits = false; |
3022 | |
} |
3023 | |
} |
3024 | 0 | if (allDigits || sarg.indexOf('.') > -1 || sarg.indexOf(',') > -1) { |
3025 | 0 | return modelImpl.getDataTypesFactoryInternal() |
3026 | |
.createMultiplicityInternal(sarg); |
3027 | |
} else { |
3028 | |
|
3029 | |
|
3030 | |
|
3031 | 0 | if ("1_N".equals(sarg)) { |
3032 | 0 | return modelImpl.getDataTypesFactoryInternal() |
3033 | |
.createMultiplicityInternal(1, -1); |
3034 | |
} else { |
3035 | 0 | return modelImpl.getDataTypesFactoryInternal() |
3036 | |
.createMultiplicityInternal(1, 1); |
3037 | |
} |
3038 | |
} |
3039 | |
} |
3040 | |
|
3041 | |
public void setMultiplicity(Object handle, int lower, int upper) { |
3042 | |
|
3043 | 0 | Multiplicity arg = modelImpl.getDataTypesFactoryInternal() |
3044 | |
.createMultiplicityInternal(lower, upper); |
3045 | |
|
3046 | 0 | setMultiplicity(handle, arg); |
3047 | 0 | } |
3048 | |
|
3049 | |
public void setName(final Object handle, final String name) { |
3050 | 1006 | if (handle instanceof ModelElement) { |
3051 | 1006 | createCommand( |
3052 | 1006 | new StringSetter() { |
3053 | |
public void set(String value) { |
3054 | 1006 | ((ModelElement) handle).setName(value); |
3055 | 1006 | } |
3056 | |
}, |
3057 | |
name, |
3058 | |
Model.getFacade().getName(handle), |
3059 | |
"name = " + name); |
3060 | |
|
3061 | 1006 | return; |
3062 | |
} |
3063 | 0 | throw new IllegalArgumentException("handle: " + handle + " or name: " |
3064 | |
+ name); |
3065 | |
} |
3066 | |
|
3067 | |
|
3068 | |
public void setBody(Object handle, String body) { |
3069 | 0 | if ((handle instanceof Comment) && (body != null)) { |
3070 | |
|
3071 | 0 | ((Comment) handle).setBody(body); |
3072 | |
} |
3073 | 0 | } |
3074 | |
|
3075 | |
|
3076 | |
public void setNamespace(Object handle, Object ns) { |
3077 | 77 | if (handle instanceof ModelElement |
3078 | |
&& (ns == null || ns instanceof Namespace)) { |
3079 | 77 | Namespace oldNs = ((ModelElement) handle).getNamespace(); |
3080 | 77 | if (((ns == null) && (oldNs == null)) |
3081 | |
|| ((oldNs != null) && oldNs.equals(ns))) { |
3082 | 0 | return; |
3083 | |
} |
3084 | 77 | ((ModelElement) handle).setNamespace((Namespace) ns); |
3085 | 77 | return; |
3086 | |
} |
3087 | 0 | throw new IllegalArgumentException("handle: " + handle + " or ns: " |
3088 | |
+ ns); |
3089 | |
} |
3090 | |
|
3091 | |
|
3092 | |
public void setNavigable(Object handle, boolean flag) { |
3093 | 0 | if (handle instanceof AssociationEnd) { |
3094 | 0 | ((AssociationEnd) handle).setNavigable(flag); |
3095 | 0 | return; |
3096 | |
} |
3097 | 0 | throw new IllegalArgumentException("handle: " + handle); |
3098 | |
} |
3099 | |
|
3100 | |
|
3101 | |
public void setOrdering(Object handle, Object ok) { |
3102 | 0 | if (handle instanceof AssociationEnd && ok instanceof OrderingKind) { |
3103 | 0 | ((AssociationEnd) handle).setOrdering((OrderingKind) ok); |
3104 | 0 | return; |
3105 | |
} |
3106 | 0 | throw new IllegalArgumentException("handle: " + handle + " or ok: " |
3107 | |
+ ok); |
3108 | |
} |
3109 | |
|
3110 | |
|
3111 | |
public void setOwner(Object handle, Object owner) { |
3112 | 0 | if (handle instanceof Feature |
3113 | |
&& (owner == null || owner instanceof Classifier)) { |
3114 | 0 | setNamespace(handle, null); |
3115 | 0 | ((Feature) handle).setOwner((Classifier) owner); |
3116 | 0 | return; |
3117 | |
} |
3118 | 0 | if (handle instanceof TagDefinition |
3119 | |
&& (owner == null || owner instanceof Stereotype)) { |
3120 | 0 | setNamespace(handle, null); |
3121 | 0 | ((TagDefinition) handle).setOwner((Stereotype) owner); |
3122 | 0 | if (owner != null) { |
3123 | 0 | ((Stereotype) owner).getDefinedTag() |
3124 | |
.add((TagDefinition) handle); |
3125 | |
} |
3126 | 0 | return; |
3127 | |
} |
3128 | 0 | throw new IllegalArgumentException("handle: " + handle + " or owner: " |
3129 | |
+ owner); |
3130 | |
} |
3131 | |
|
3132 | |
|
3133 | |
public void setStatic(Object handle, boolean isStatic) { |
3134 | 0 | if (handle instanceof Feature) { |
3135 | 0 | ((Feature) handle) |
3136 | |
.setOwnerScope(isStatic ? ScopeKindEnum.SK_CLASSIFIER |
3137 | |
: ScopeKindEnum.SK_INSTANCE); |
3138 | 0 | return; |
3139 | |
} |
3140 | 0 | if (handle instanceof AssociationEnd) { |
3141 | 0 | ((AssociationEnd) handle) |
3142 | |
.setTargetScope(isStatic ? ScopeKindEnum.SK_CLASSIFIER |
3143 | |
: ScopeKindEnum.SK_INSTANCE); |
3144 | 0 | return; |
3145 | |
} |
3146 | 0 | throw new IllegalArgumentException("handle: " + handle); |
3147 | |
} |
3148 | |
|
3149 | |
public void setParameter(Object handle, Object parameter) { |
3150 | 0 | if (handle instanceof TemplateParameter |
3151 | |
&& parameter instanceof ModelElement) { |
3152 | 0 | ((TemplateParameter) handle).setParameter((ModelElement) parameter); |
3153 | 0 | return; |
3154 | |
} |
3155 | 0 | throw new IllegalArgumentException("handle: " + handle |
3156 | |
+ " or parameters: " + parameter); |
3157 | |
} |
3158 | |
|
3159 | |
public void setParameters(Object handle, Collection parameters) { |
3160 | 0 | if (handle instanceof ObjectFlowState || handle instanceof Classifier |
3161 | |
|| handle instanceof Event |
3162 | |
|| handle instanceof BehavioralFeature) { |
3163 | 0 | Collection params = Model.getFacade().getParameters(handle); |
3164 | 0 | if (!params.isEmpty()) { |
3165 | 0 | Collection actualParams = new ArrayList(params); |
3166 | 0 | for (Object param : actualParams) { |
3167 | 0 | removeParameter(handle, param); |
3168 | |
} |
3169 | |
} |
3170 | 0 | for (Object param : parameters) { |
3171 | 0 | addParameter(handle, param); |
3172 | |
} |
3173 | 0 | return; |
3174 | |
} |
3175 | 0 | throw new IllegalArgumentException("handle: " + handle |
3176 | |
+ " or parameters: " + parameters); |
3177 | |
} |
3178 | |
|
3179 | |
|
3180 | |
public void setParent(Object handle, Object parent) { |
3181 | 0 | if (handle instanceof Generalization |
3182 | |
&& parent instanceof GeneralizableElement) { |
3183 | 0 | ((Generalization) handle).setParent((GeneralizableElement) parent); |
3184 | 0 | return; |
3185 | |
} |
3186 | 0 | throw new IllegalArgumentException("handle: " + handle + " or parent: " |
3187 | |
+ parent); |
3188 | |
} |
3189 | |
|
3190 | |
|
3191 | |
public void setPowertype(Object handle, Object pt) { |
3192 | 0 | if (handle instanceof Generalization |
3193 | |
&& (pt == null || pt instanceof Classifier)) { |
3194 | 0 | ((Generalization) handle).setPowertype((Classifier) pt); |
3195 | 0 | return; |
3196 | |
} |
3197 | 0 | throw new IllegalArgumentException("handle: " + handle + " or pt: " |
3198 | |
+ pt); |
3199 | |
} |
3200 | |
|
3201 | |
|
3202 | |
public void setQualifiers(Object handle, List elems) { |
3203 | 0 | if (handle instanceof AssociationEnd) { |
3204 | 0 | ((AssociationEnd) handle).getQualifier().clear(); |
3205 | 0 | ((AssociationEnd) handle).getQualifier().addAll(elems); |
3206 | 0 | return; |
3207 | |
} |
3208 | 0 | throw new IllegalArgumentException("handle: " + handle); |
3209 | |
} |
3210 | |
|
3211 | |
|
3212 | |
public void setQuery(Object handle, boolean flag) { |
3213 | 0 | if (handle instanceof BehavioralFeature) { |
3214 | 0 | ((BehavioralFeature) handle).setQuery(flag); |
3215 | 0 | return; |
3216 | |
} |
3217 | 0 | throw new IllegalArgumentException("handle: " + handle); |
3218 | |
} |
3219 | |
|
3220 | |
|
3221 | |
public void setResident(Object handle, Object resident) { |
3222 | 0 | if (handle instanceof ElementResidence |
3223 | |
&& (resident == null || resident instanceof ModelElement)) { |
3224 | 0 | ((ElementResidence) handle).setResident((ModelElement) resident); |
3225 | 0 | return; |
3226 | |
} |
3227 | 0 | throw new IllegalArgumentException("handle: " + handle |
3228 | |
+ " or resident: " + resident); |
3229 | |
} |
3230 | |
|
3231 | |
|
3232 | |
public void setResidents(Object handle, Collection residents) { |
3233 | 0 | if (handle instanceof NodeInstance) { |
3234 | 0 | CollectionHelper.update( |
3235 | |
((NodeInstance) handle).getResident(), residents); |
3236 | 0 | return; |
3237 | |
} |
3238 | 0 | if (handle instanceof ComponentInstance) { |
3239 | 0 | CollectionHelper.update( |
3240 | |
((ComponentInstance) handle).getResident(), residents); |
3241 | 0 | return; |
3242 | |
} |
3243 | 0 | throw new IllegalArgumentException("handle: " + handle); |
3244 | |
} |
3245 | |
|
3246 | |
|
3247 | |
public void setRoot(Object handle, boolean flag) { |
3248 | 0 | if (handle instanceof Reception) { |
3249 | 0 | ((Reception) handle).setRoot(flag); |
3250 | 0 | return; |
3251 | |
} |
3252 | 0 | if (handle instanceof Operation) { |
3253 | 0 | ((Operation) handle).setRoot(flag); |
3254 | 0 | return; |
3255 | |
} |
3256 | 0 | if (handle instanceof GeneralizableElement) { |
3257 | 0 | ((GeneralizableElement) handle).setRoot(flag); |
3258 | 0 | return; |
3259 | |
} |
3260 | 0 | throw new IllegalArgumentException("handle: " + handle); |
3261 | |
} |
3262 | |
|
3263 | |
|
3264 | |
public void setSources(Object handle, Collection specifications) { |
3265 | 0 | if (handle instanceof Flow) { |
3266 | 0 | CollectionHelper.update( |
3267 | |
((Flow) handle).getSource(), specifications); |
3268 | 0 | return; |
3269 | |
} |
3270 | 0 | throw new IllegalArgumentException("handle: " + handle); |
3271 | |
} |
3272 | |
|
3273 | |
|
3274 | |
public void setSpecification(Object handle, boolean specification) { |
3275 | 0 | if (handle instanceof ModelElement) { |
3276 | 0 | ((ModelElement) handle).setSpecification(specification); |
3277 | 0 | return; |
3278 | |
} |
3279 | 0 | throw new IllegalArgumentException("handle: " + handle); |
3280 | |
} |
3281 | |
|
3282 | |
|
3283 | |
public void setSpecification(Object operation, String specification) { |
3284 | 0 | if (operation instanceof Operation) { |
3285 | 0 | ((Operation) operation).setSpecification(specification); |
3286 | 0 | return; |
3287 | |
} |
3288 | 0 | if (operation instanceof Reception) { |
3289 | 0 | ((Reception) operation).setSpecification(specification); |
3290 | 0 | return; |
3291 | |
} |
3292 | 0 | throw new IllegalArgumentException("operation: " + operation); |
3293 | |
} |
3294 | |
|
3295 | |
|
3296 | |
public void setSpecification(Object method, Object specification) { |
3297 | 0 | if (method instanceof Method && specification instanceof Operation) { |
3298 | 0 | ((Method) method).setSpecification((Operation) specification); |
3299 | 0 | return; |
3300 | |
} |
3301 | 0 | throw new IllegalArgumentException("method: " + method |
3302 | |
+ " or operation: " + specification); |
3303 | |
} |
3304 | |
|
3305 | |
|
3306 | |
public void setSpecifications(Object handle, Collection specifications) { |
3307 | 0 | if (handle instanceof AssociationEnd) { |
3308 | 0 | ((AssociationEnd) handle).getSpecification().addAll(specifications); |
3309 | 0 | return; |
3310 | |
} |
3311 | 0 | throw new IllegalArgumentException("handle: " + handle); |
3312 | |
} |
3313 | |
|
3314 | |
|
3315 | |
@Deprecated |
3316 | |
public void setTaggedValue(Object handle, String tag, String value) { |
3317 | 0 | if (handle instanceof ModelElement) { |
3318 | 0 | TaggedValue tv = |
3319 | |
(TaggedValue) modelImpl.getFacade().getTaggedValue(handle, |
3320 | |
tag); |
3321 | 0 | if (tv == null) { |
3322 | 0 | tv = |
3323 | |
(TaggedValue) modelImpl.getExtensionMechanismsFactory(). |
3324 | |
buildTaggedValue(tag, value); |
3325 | 0 | ((ModelElement) handle).getTaggedValue().add(tv); |
3326 | |
} else { |
3327 | 0 | modelImpl.getExtensionMechanismsHelper().setDataValues(tv, |
3328 | |
new String[] {value}); |
3329 | |
} |
3330 | 0 | return; |
3331 | |
} |
3332 | 0 | throw new IllegalArgumentException("handle: " + handle); |
3333 | |
} |
3334 | |
|
3335 | |
|
3336 | |
@Deprecated |
3337 | |
public void setTargetScope(Object handle, Object scopeKind) { |
3338 | 0 | if (scopeKind instanceof ScopeKind) { |
3339 | 0 | if (handle instanceof StructuralFeature) { |
3340 | 0 | ((StructuralFeature) handle). |
3341 | |
setTargetScope((ScopeKind) scopeKind); |
3342 | 0 | return; |
3343 | |
} |
3344 | 0 | if (handle instanceof AssociationEnd) { |
3345 | 0 | ((AssociationEnd) handle).setTargetScope((ScopeKind) scopeKind); |
3346 | 0 | return; |
3347 | |
} |
3348 | |
} |
3349 | 0 | throw new IllegalArgumentException("handle: " + handle |
3350 | |
+ " or scopeKind: " + scopeKind); |
3351 | |
} |
3352 | |
|
3353 | |
|
3354 | |
public void setType(Object handle, Object type) { |
3355 | 0 | if (type == null || type instanceof Classifier) { |
3356 | 0 | if (handle instanceof ObjectFlowState) { |
3357 | 0 | ((ObjectFlowState) handle).setType((Classifier) type); |
3358 | 0 | return; |
3359 | |
} |
3360 | 0 | if (handle instanceof ClassifierInState) { |
3361 | 0 | ((ClassifierInState) handle).setType((Classifier) type); |
3362 | 0 | return; |
3363 | |
} |
3364 | 0 | if (handle instanceof Parameter) { |
3365 | 0 | ((Parameter) handle).setType((Classifier) type); |
3366 | 0 | return; |
3367 | |
} |
3368 | 0 | if (handle instanceof AssociationEnd) { |
3369 | 0 | ((AssociationEnd) handle).setParticipant((Classifier) type); |
3370 | 0 | return; |
3371 | |
} |
3372 | 0 | if (handle instanceof StructuralFeature) { |
3373 | 0 | ((StructuralFeature) handle).setType((Classifier) type); |
3374 | 0 | return; |
3375 | |
} |
3376 | |
} |
3377 | 0 | throw new IllegalArgumentException("handle: " + handle + " or type: " |
3378 | |
+ type); |
3379 | |
} |
3380 | |
|
3381 | |
|
3382 | |
public void setVisibility(Object handle, Object visibility) { |
3383 | 0 | if (visibility instanceof VisibilityKind) { |
3384 | 0 | if (handle instanceof ModelElement) { |
3385 | 0 | ((ModelElement) handle). |
3386 | |
setVisibility((VisibilityKind) visibility); |
3387 | 0 | return; |
3388 | |
} |
3389 | 0 | if (handle instanceof ElementResidence) { |
3390 | 0 | ((ElementResidence) handle). |
3391 | |
setVisibility((VisibilityKind) visibility); |
3392 | 0 | return; |
3393 | |
} |
3394 | 0 | if (handle instanceof ElementImport) { |
3395 | 0 | ((ElementImport) handle). |
3396 | |
setVisibility((VisibilityKind) visibility); |
3397 | 0 | return; |
3398 | |
} |
3399 | |
} |
3400 | 0 | throw new IllegalArgumentException("handle: " + handle |
3401 | |
+ " or visibility: " + visibility); |
3402 | |
} |
3403 | |
|
3404 | |
|
3405 | |
public void removeDeploymentLocation(Object handle, Object node) { |
3406 | |
try { |
3407 | 0 | if (handle instanceof Component && node instanceof Node) { |
3408 | 0 | ((Component) handle).getDeploymentLocation().remove(node); |
3409 | 0 | return; |
3410 | |
} |
3411 | 0 | } catch (InvalidObjectException e) { |
3412 | 0 | throw new InvalidElementException(e); |
3413 | 0 | } |
3414 | 0 | throw new IllegalArgumentException("handle: " + handle + " or node: " |
3415 | |
+ node); |
3416 | |
} |
3417 | |
|
3418 | |
|
3419 | |
public void addStereotype(Object modelElement, Object stereo) { |
3420 | 0 | if (modelElement instanceof ModelElement |
3421 | |
&& stereo instanceof Stereotype) { |
3422 | 0 | ModelElement me = (ModelElement) modelElement; |
3423 | 0 | Stereotype stereotype = (Stereotype) stereo; |
3424 | 0 | if (!(me.getStereotype().contains(stereo))) { |
3425 | 0 | me.getStereotype().add(stereotype); |
3426 | |
} |
3427 | 0 | return; |
3428 | |
} |
3429 | 0 | throw new IllegalArgumentException("handle: " + modelElement |
3430 | |
+ " or stereo: " + stereo); |
3431 | |
} |
3432 | |
|
3433 | |
|
3434 | |
|
3435 | |
public void addAllStereotypes(Object modelElement, Collection stereos) { |
3436 | 0 | if (modelElement instanceof ModelElement) { |
3437 | 0 | ModelElement me = (ModelElement) modelElement; |
3438 | 0 | me.getStereotype().addAll(stereos); |
3439 | 0 | return; |
3440 | |
} |
3441 | 0 | throw new IllegalArgumentException("handle: " + modelElement |
3442 | |
+ " or stereos: " + stereos); |
3443 | |
} |
3444 | |
|
3445 | |
|
3446 | |
public void removeStereotype(Object modelElement, Object stereo) { |
3447 | |
try { |
3448 | 0 | if (modelElement instanceof ModelElement |
3449 | |
&& stereo instanceof Stereotype) { |
3450 | |
|
3451 | 0 | ModelElement me = (ModelElement) modelElement; |
3452 | 0 | Stereotype stereotype = (Stereotype) stereo; |
3453 | |
|
3454 | 0 | if (me.getStereotype().contains(stereo)) { |
3455 | 0 | me.getStereotype().remove(stereotype); |
3456 | |
} |
3457 | 0 | return; |
3458 | |
} |
3459 | 0 | } catch (InvalidObjectException e) { |
3460 | 0 | throw new InvalidElementException(e); |
3461 | 0 | } |
3462 | 0 | throw new IllegalArgumentException("handle: " + modelElement |
3463 | |
+ " or stereo: " + stereo); |
3464 | |
} |
3465 | |
|
3466 | |
|
3467 | |
|
3468 | |
|
3469 | |
|
3470 | |
public void clearStereotypes(Object modelElement) { |
3471 | 0 | if (modelElement instanceof ModelElement) { |
3472 | 0 | ((ModelElement) modelElement).getStereotype().clear(); |
3473 | 0 | return; |
3474 | |
} |
3475 | 0 | throw new IllegalArgumentException("handle: " + modelElement); |
3476 | |
} |
3477 | |
|
3478 | |
|
3479 | |
public void setEnumerationLiterals(Object enumeration, List literals) { |
3480 | 0 | if (enumeration instanceof Enumeration) { |
3481 | 0 | ((Enumeration) enumeration).getLiteral().clear(); |
3482 | 0 | ((Enumeration) enumeration).getLiteral().addAll(literals); |
3483 | |
} |
3484 | 0 | } |
3485 | |
|
3486 | |
|
3487 | |
public Collection<String> getAllMetatypeNames() { |
3488 | 0 | Set<String> names = new HashSet<String>(); |
3489 | 0 | for (Object element : modelImpl.getModelPackage().getMofClass() |
3490 | |
.refAllOfClass()) { |
3491 | 0 | String name = ((javax.jmi.model.ModelElement) element).getName(); |
3492 | 0 | if (names.add(name)) { |
3493 | 0 | LOG.debug(" Class " + name); |
3494 | |
} else { |
3495 | 0 | LOG.error("Found duplicate class " + name + " in metamodel"); |
3496 | |
} |
3497 | 0 | } |
3498 | 0 | return names; |
3499 | |
} |
3500 | |
|
3501 | |
public Collection<String> getAllMetaDatatypeNames() { |
3502 | 0 | Set<String> names = new HashSet<String>(); |
3503 | |
|
3504 | 0 | for (Object element : modelImpl.getModelPackage().getDataType() |
3505 | |
.refAllOfClass()) { |
3506 | 0 | String name = ((javax.jmi.model.DataType) element).getName(); |
3507 | 0 | if (names.add(name)) { |
3508 | 0 | LOG.debug(" DataType " + name); |
3509 | |
} else { |
3510 | 0 | LOG.error("Found duplicate datatype " + name + " in metamodel"); |
3511 | |
} |
3512 | 0 | } |
3513 | |
|
3514 | |
|
3515 | 0 | for (Object element : modelImpl.getModelPackage().getEnumerationType() |
3516 | |
.refAllOfClass()) { |
3517 | 0 | String name = ((javax.jmi.model.EnumerationType) element).getName(); |
3518 | 0 | if (names.add(name)) { |
3519 | 0 | LOG.debug(" EnumerationType " + name); |
3520 | |
} else { |
3521 | 0 | LOG.error("Found duplicate EnumerationType " + name |
3522 | |
+ " in metamodel"); |
3523 | |
} |
3524 | 0 | } |
3525 | |
|
3526 | |
|
3527 | 0 | for (Object element : modelImpl.getModelPackage().getPrimitiveType() |
3528 | |
.refAllOfClass()) { |
3529 | 0 | String name = ((javax.jmi.model.PrimitiveType) element).getName(); |
3530 | 0 | if (names.add(name)) { |
3531 | 0 | LOG.debug(" PrimitiveType " + name); |
3532 | |
} else { |
3533 | 0 | LOG.error("Found duplicate primitive type " + name |
3534 | |
+ " in metamodel"); |
3535 | |
} |
3536 | 0 | } |
3537 | |
|
3538 | 0 | return names; |
3539 | |
} |
3540 | |
|
3541 | |
|
3542 | |
|
3543 | |
|
3544 | |
|
3545 | |
|
3546 | |
|
3547 | |
|
3548 | |
|
3549 | |
private void createCommand( |
3550 | |
final StringSetter accesser, |
3551 | |
final String newValue, |
3552 | |
final String oldValue, |
3553 | |
final String descr) { |
3554 | 1006 | if (newValue == oldValue) { |
3555 | 0 | return; |
3556 | |
} |
3557 | 1006 | if (newValue != null |
3558 | |
&& newValue.equals(oldValue)) { |
3559 | 0 | return; |
3560 | |
} |
3561 | 1006 | ModelCommand command = new ModelCommand() { |
3562 | |
public void undo() { |
3563 | 0 | accesser.set(oldValue); |
3564 | 0 | } |
3565 | |
public Object execute() { |
3566 | 1006 | accesser.set(newValue); |
3567 | 1006 | return null; |
3568 | |
} |
3569 | |
public boolean isUndoable() { |
3570 | 0 | return true; |
3571 | |
} |
3572 | |
public boolean isRedoable() { |
3573 | 0 | return true; |
3574 | |
} |
3575 | |
public String toString() { |
3576 | 0 | return descr; |
3577 | |
} |
3578 | |
}; |
3579 | 1006 | Model.execute(command); |
3580 | 1006 | } |
3581 | |
} |