|custom PrimitiveType literals [message #47912]
||Fri, 11 January 2008 13:00
Originally posted by: krzysztof_kaczmarski.o2.pl|
Another question on not so standard usage of OCL.
Lets say that I want to use a custom primitive type 'Date'. If I want
to use it in expressions effectively I need to create its instances,
using literals. How can I do that?
I could create an operation String2Date(String s):Date in type Date.
But then, what?
Will it work ?
Thanks for any ideas,
|Re: custom PrimitiveType literals [message #48004 is a reply to message #47912]
||Fri, 11 January 2008 14:01
Originally posted by: cdamus.ca.ibm.com|
This is an area into which the MDT OCL implementation has not yet ventured.
The specification of the OCL grammar defines literals only for those
primitives defined by OCL. There is no guidance about how literals of
user-defined types might be parsed.
One approach that I can think of is to parse them as string literals and let
the OCLAnalyzer attempt to convert strings to the data type expected
according to the context, probably using the appropriate
EFactory::convertToString(EDataType, String) from the data type's EPackage.
Of course, this would be another departure from the standard OCL in the
same vein as the closure() iterator and String toLower()/toUpper()
On the other hand, you can define custom string conversion operations on the
String data type in the same fashion as the regexpMatch() example in the
OCL Developer Guide (the "Advanced/Customizing the Environment" topic).
That's a solution that you can implement today, and it does work. If you
define, say, toDate() in this way, then you can do
in an OCL expression.
What wouldn't work so well is defining a static operation in the Date
EDataType, because Ecore doesn't support static features.
Krzysztof Kaczmarski wrote:
> Hi All,
> Another question on not so standard usage of OCL.
> Lets say that I want to use a custom primitive type 'Date'. If I want
> to use it in expressions effectively I need to create its instances,
> using literals. How can I do that?
> I could create an operation String2Date(String s):Date in type Date.
> But then, what?
> Will it work ?
> Thanks for any ideas,
Powered by FUDForum
. Page generated in 0.02565 seconds