You're more likely to get speedy answers using eclipse.modeling.mdt.ocl or eclipse.tools.emf forums. Of course you using TmsFactory.eINSTANCE to create instances of your model and you can use Diagnostician.INSTANCE to validate all constraints on your modeled objects.
how to call OCL constraints( generated java source code of model ) from the main code of java
-
27-11-2021 - |
Domanda
I am using OCL constraints on ecore model and generating code. So the thing is as simple as this
I have a class Task having attribute startDate
and endDate
it has an ocl constraint :- invariant which states startDate < endDate
.
I have generated java code for this project and there is a java class :
public class TmsValidator extends EObjectValidator {
//what is diagnosticChain and context in the below method
public boolean validateTask_C2(Task task, DiagnosticChain diagnostics, Map<Object, Object context) {
return validate(TmsPackage.Literals.TASK,
task,
diagnostics,
context,
"http://www.eclipse.org/emf/2002/Ecore/OCL/Pivot",
"C2",
TASK__C2__EEXPRESSION,
Diagnostic.ERROR,
DIAGNOSTIC_SOURCE,
0);
}
}
So from my main class, how do I validate my task here . I want to call the OCL
constraint to check if startDate
is less than endDate
public class {
public static void main(String []a){
Task t = new
Task ();
// How do I validate my task here . I want to call the
//OCL constraint to check if startDate is less than endDate
}
}
Soluzione
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow