How to validate java.util.Date attribute in ocl?

346 views Asked by At

I'm trying to add validation for date type in emf.ecore 2.23 as following examples

invariant validation1:
        self.startDate.before(self.terminationDate);

or

invariant validation2:
            self.startDate < self.terminationDate;

Using this link https://wiki.eclipse.org/EMF/Recipes#Recipe:_Generating_data_types_that_support_date.2Ftime_format, I included the date java.util.Date, but ocl still doesn't recognize methods. I also failed to add an EAnnotation type http:///org/eclipse/emf/ecore/util/DateConversionDelegate.

1

There are 1 answers

1
Ed Willink On

Unfortunately Ecore models EDate as an EDataType for which EMF does not support user-defined methods. OCL support 'finds' only =/<>. Once Eclipse OCL support expands to support use of underlying language APIs this is a good use case for improvement. Comment added to https://bugs.eclipse.org/bugs/show_bug.cgi?id=370087

Today it is an EMF 'bug'. EDate should have been declared as an EClass, but that would have created other difficulties.

Again today, the workaround is to declare and manually implement a stateless EDateHelper class with methods such as before(date1 : EDate, date2 : EDate) : Boolean.