Home » Modeling » OCL » how to call OCL constraints( generated java source code of model ) from the main code of java(want to validate OCL constraints generated in source code from java code)
how to call OCL constraints( generated java source code of model ) from the main code of java [message #976833] |
Thu, 08 November 2012 22:07 |
Ekansh Missing name Messages: 3 Registered: November 2012 |
Junior Member |
|
|
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(Start Date) is less than endDate(End Date)
public static void main(String[] args) {
// How do I validate my task here . I want to call the
//OCL constraint to check if startDate is less than endDate
// this is what I am doing
Map<Object, Object> context = new HashMap<Object, Object>();
BasicDiagnostic diag = new BasicDiagnostic();
Task t= TmsFactory.eINSTANCE.createTask();
boolean flag =TmsValidator.INSTANCE.validateTask_C2(t, diag, context);
System.out.println(flag);
}
|
|
|
Re: how to call OCL constraints( generated java source code of model ) from the main code of java [message #977315 is a reply to message #976833] |
Fri, 09 November 2012 07:15 |
Ed Willink Messages: 7669 Registered: July 2009 |
Senior Member |
|
|
Hi
From the EMF Java
/**
* Validates the object in the given context, optionally producing
diagnostics.
* @param diagnostics a place to accumulate diagnostics; if it's
<code>null</code>, no diagnostics should be produced.
* @param context a place to cache information, if it's
<code>null</code>, no cache is supported.
* @return whether the object is valid.
*/
boolean validate(EObject eObject, DiagnosticChain diagnostics,
Map<Object, Object> context);
In practice the 'context' is pre-initialized by the normal EMF
invocation with usefuil helpers such as a SubstitutionLabelProvider.
Regards
Ed Willink
On 08/11/2012 22:13, Ekansh Mising name wrote:
> 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(Start Date) is less than
> endDate(End Date)
>
> public static void main(String[] args) {
> // How do I validate my task here . I want to call the //OCL
> constraint to check if startDate is less than endDate // this is what
> I am doing
> Map<Object, Object> context = new HashMap<Object, Object>();
> BasicDiagnostic diag = new BasicDiagnostic();
> Task t= TmsFactory.eINSTANCE.createTask();
> boolean flag =TmsValidator.INSTANCE.validateTask_C2(t, diag,
> context);
> System.out.println(flag);
> }
>
|
|
|
Goto Forum:
Current Time: Mon Sep 09 14:33:45 GMT 2024
Powered by FUDForum. Page generated in 0.04264 seconds
|