blob: d298aa04306b070e9b7b45ea5e63228bc1165f17 (
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
/*****************************************************************************
* 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.DerivedElement;
import org.eclipse.papyrus.qompass.designer.core.ConnectorUtils;
import org.eclipse.papyrus.uml.tools.utils.StereotypeUtil;
import org.eclipse.uml2.uml.Class;
import org.eclipse.uml2.uml.Connector;
import org.eclipse.uml2.uml.Port;
import org.eclipse.uml2.uml.Property;
/**
* Check whether the multiplicity of the ports (of a part) are consistent with the defined connectors, in particular whether a
* port with a required interface is not connected with more connectors than its own multiplicity
* @author ansgar
*
* TODO: does not find violation on composite side (partWithPort = null), simplify? (loop over connectors)
*/
public class ConnectorCallMultiplicity extends AbstractModelConstraint
{
@Override
public IStatus validate (IValidationContext ctx)
{
String portsStr = ""; //$NON-NLS-1$
Property part = (Property) ctx.getTarget();
if (!StereotypeUtil.isApplicable(part, DerivedElement.class)) {
// make rule Qompass specific: only perform check, if the FCM profile is applied (checked via applicability
// the DerviedElement stereotype)
return ctx.createSuccessStatus();
}
Class owner = part.getClass_ ();
if (owner != null) {
if (part.getType () instanceof Class) {
Class class_ = (Class) part.getType ();
for (Port port : class_.getOwnedPorts ()) {
if (port.getRequireds ().size () > 0) {
int connections = 0;
for (Connector connector : owner.getOwnedConnectors ()) {
if (ConnectorUtils.connectsPort (connector, port)) {
connections ++;
break;
}
}
if (connections > port.getUpper ()) {
if (portsStr.length () != 0) {
portsStr += ", "; //$NON-NLS-1$
}
portsStr += port.getName ();
}
}
}
}
}
if (portsStr.length () > 0) {
return ctx.createFailureStatus ("The port(s) '" + portsStr + "' with a required interface of part '" + part.getName () +
"' have more connections than their multiplicty within composite '" + owner.getQualifiedName () + "'");
}
else {
return ctx.createSuccessStatus();
}
}
}
|