Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » custom PrimitiveType literals
custom PrimitiveType literals [message #47912] Fri, 11 January 2008 13:00 Go to next message
Eclipse UserFriend
Originally posted by: krzysztof_kaczmarski.o2.pl

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?

Date.String2Date("2007-01-11")

Will it work ?

Thanks for any ideas,
Krzysztof
Re: custom PrimitiveType literals [message #48004 is a reply to message #47912] Fri, 11 January 2008 14:01 Go to previous message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, Krzysztof,

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()
operations.

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

'2007-01-11'.toDate()

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.

HTH,

Christian

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?
>
> Date.String2Date("2007-01-11")
>
> Will it work ?
>
> Thanks for any ideas,
> Krzysztof
Previous Topic:Namespace URIs and Serialization issue
Next Topic:collection(T2)
Goto Forum:
  


Current Time: Fri Apr 26 15:13:48 GMT 2024

Powered by FUDForum. Page generated in 0.03245 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top