Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 25f1cbc53bcc38f9142a1bb16b238f6c733f40aa (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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
 [comment encoding = UTF-8 /]
 [module generate('http://www.eclipse.org/uml2/3.0.0/UML', 'http://www.eclipse.org/emf/2009/Validation', 'http://www.eclipse.org/emf/2002/Ecore')/] 

[query public getPackageForConstraint(cstr : Constraint) : String = invoke('org.eclipse.papyrus.dsml.validation.model.profilenames.Utils', 'getPackageForConstraint(org.eclipse.uml2.uml.Constraint)', Sequence{cstr}) /]
[query public getJavaConstraintBody(valueSpecificatoin : ValueSpecification) : String = invoke('org.eclipse.papyrus.dsml.validation.model.profilenames.Utils', 'getJavaConstraintBody(org.eclipse.uml2.uml.ValueSpecification)', Sequence{valueSpecificatoin}) /]
[query public hasSpecificationForJava(constraint : Constraint) : Boolean   = invoke('org.eclipse.papyrus.dsml.validation.model.profilenames.Utils', 'hasSpecificationForJava(org.eclipse.uml2.uml.Constraint)', Sequence{constraint}) /]
[query public isConstraintForStereotype(constraint : Constraint) : Boolean = invoke('org.eclipse.papyrus.dsml.validation.model.profilenames.Utils', 'isConstraintForStereotype(org.eclipse.uml2.uml.Constraint)',  Sequence{constraint}) /]
[query public getConstraintForStereotype(constraint : Constraint) : String = invoke('org.eclipse.papyrus.dsml.validation.model.profilenames.Utils', 'getConstraintForStereotype(org.eclipse.uml2.uml.Constraint)', Sequence{constraint}) /]


[template public generateConstraint(constraint : Constraint)]
[comment @main/]

[if (hasSpecificationForJava(constraint) and getPackageForConstraint(constraint) <> null)]
[file('/org/eclipse/papyrus/validation/' + getPackageForConstraint(constraint).replaceAll('\\.','/') + '/' + constraint.name + 'Constraint.java', false)]
	
package org.eclipse.papyrus.validation.[getPackageForConstraint(constraint)/];

import org.eclipse.core.runtime.IStatus;
import org.eclipse.emf.validation.AbstractModelConstraint;
import org.eclipse.emf.validation.IValidationContext;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Stereotype;

public class [constraint.name.toUpperFirst() + 'Constraint'/] extends AbstractModelConstraint{

	public IStatus validate(IValidationContext ctx) {
		if( ctx.getTarget()instanceof Element){
			Element element =(Element)ctx.getTarget();
			
			[if isConstraintForStereotype(constraint)]
			Stereotype appliedStereotype= element.getAppliedStereotype("[getConstraintForStereotype(constraint)/]");
			if( appliedStereotype!=null){
					if(evaluateConstraint(element,appliedStereotype)){
					return ctx.createSuccessStatus();
				}
				else{
					return ctx.createFailureStatus("Constraint not validated");
				}
			}
			
			[else]
				if(evaluateConstraint(element)){
					return ctx.createSuccessStatus();
				}
				else{
					return ctx.createFailureStatus("Constraint not validated");
					
				}
			[/if]	
		}

		return ctx.createSuccessStatus();

}
	private boolean evaluateConstraint (Element self, Stereotype appliedStereotype){
		[if isConstraintForStereotype(constraint)]
			[if getJavaConstraintBody(constraint.specification) <> null]
				[getJavaConstraintBody(constraint.specification)/]
			[else]
				return true;
			[/if]	

		[else]
			return true;
		[/if]	
	}
	private boolean evaluateConstraint (Element self){
	[if ( isConstraintForStereotype(constraint))<>true]
			[if getJavaConstraintBody(constraint.specification) <> null]
				[getJavaConstraintBody(constraint.specification)/]
			[else]
				return true;
			[/if]	
		[else]
			return true;
		[/if]	
	}
}
[/file]
[/if]

[/template]

[template public generateValidationContext(profile : Profile)]
[file ('/org/eclipse/papyrus/validation/ValidationDelegateClientSelector.java', false)]
[comment @main/]
package org.eclipse.papyrus.validation;

import org.eclipse.emf.validation.model.IClientSelector;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.PackageImport;

public class ValidationDelegateClientSelector implements IClientSelector {

	public boolean selects(Object object) {
		return (object instanceof Element);
	}
}

[/file]
[/template]

Back to the top