blob: 965bb595889971c58950eb10194a4badb1722f61 (
plain) (
blame)
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
/*****************************************************************************
* Copyright (c) 2013 CEA LIST.
*
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Ansgar Radermacher ansgar.radermacher@cea.fr
*
*****************************************************************************/
package org.eclipse.papyrus.qompass.designer.validation.constraints;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.emf.validation.AbstractModelConstraint;
import org.eclipse.emf.validation.IValidationContext;
import org.eclipse.papyrus.FCM.ConfigurationProperty;
import org.eclipse.papyrus.uml.tools.utils.StereotypeUtil;
import org.eclipse.uml2.uml.Class;
import org.eclipse.uml2.uml.Classifier;
import org.eclipse.uml2.uml.InstanceSpecification;
import org.eclipse.uml2.uml.Property;
import org.eclipse.uml2.uml.Slot;
/**
* check whether an instance specification for a classifier defines slots for
* each configuration attribute. This rule is specific to Qompass, since only
* attributes with the ConfigurationProperty stereotypes are checked.
*/
public class InstanceSpecificationSlotForAllProperties extends AbstractModelConstraint {
@Override
public IStatus validate(IValidationContext ctx)
{
InstanceSpecification is = (InstanceSpecification) ctx.getTarget();
if (is.getClassifiers().size() > 0) {
Classifier cl = is.getClassifiers().get(0);
if (cl instanceof Class) {
Class class_ = (Class) cl;
for (Property attribute : class_.getOwnedAttributes ()) {
boolean foundAttribute = false;
if (StereotypeUtil.isApplied(attribute, ConfigurationProperty.class)) {
for (Slot slot : is.getSlots ()) {
if (slot.getDefiningFeature () == attribute) {
foundAttribute = true;
break;
}
}
if (foundAttribute == false) {
return ctx.createFailureStatus ("The instance specification '" + is.getName () + "' has no slot for property '" + attribute.getName () + "'");
}
}
}
}
}
return ctx.createSuccessStatus();
}
}
|