Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Custom primitive types in OCL(Can I use the operator minus for properties of a custom type)
Custom primitive types in OCL [message #1206083] Sat, 23 November 2013 23:46 Go to next message
Damjan Temelkovski is currently offline Damjan TemelkovskiFriend
Messages: 16
Registered: November 2013
Junior Member
Hi,

I realize that I can do "self.Attribute1 - self.Attribute2 < 5" if the attributes are Real. But if an attribute is of a different type, e.g. a custom primitive type, then the operator minus is not overloaded and doesn't work. I was wondering if someone has had some experience with OCL constraints and custom primitive types? Is this possible in OCL?

In my example I am using a MARTE <<NfpType>> stereotyped primitive type and I want to know if the constraint can be "the difference between two such types < 5".

Thank you,
Damjan
Re: Custom primitive types in OCL [message #1206816 is a reply to message #1206083] Sun, 24 November 2013 08:23 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 4186
Registered: July 2009
Senior Member
Hi

The intended functionality is that user data types are mapped to an
appropriate OCL behavioural type, so it appears that your types have not
been recognized.

Perhaps you should use an EDataType stereotype so that you can define a
known instance class.

Can you please post a small example for me to look at.

Regards

Ed Willink

On 23/11/2013 23:46, Damjan Temelkovski wrote:
> Hi,
>
> I realize that I can do "self.Attribute1 - self.Attribute2 < 5" if the
> attributes are Real. But if an attribute is of a different type, e.g.
> a custom primitive type, then the operator minus is not overloaded and
> doesn't work. I was wondering if someone has had some experience with
> OCL constraints and custom primitive types? Is this possible in OCL?
>
> In my example I am using a MARTE <<NfpType>> stereotyped primitive
> type and I want to know if the constraint can be "the difference
> between two such types < 5".
>
> Thank you,
> Damjan
Re: Custom primitive types in OCL [message #1207261 is a reply to message #1206816] Sun, 24 November 2013 13:31 Go to previous messageGo to next message
Damjan Temelkovski is currently offline Damjan TemelkovskiFriend
Messages: 16
Registered: November 2013
Junior Member
Thank you Ed,

You are incredibly helpful. I am only starting to learn OCL, so perhaps I don't know the right way to access the needed property. But, so far I couldn't find some information about using custom types in OCL.

This is what I am trying to achieve:
index.php/fa/16807/0/

I am sure I saw a constraint for the Nfp somewhere that was in the form "self.Nfp1 < (5, CustomUnit)". I have tried this as well, and maybe it is not possible in OCL. I thought if I can overload the operator in OCL to work for CustomTypes, or if I can access the 'value' of the custom type, that it would work.

Thank you,

Damjan
  • Attachment: ocl_nfp.png
    (Size: 83.68KB, Downloaded 139 times)
Re: Custom primitive types in OCL [message #1207269 is a reply to message #1207261] Sun, 24 November 2013 13:39 Go to previous messageGo to next message
Damjan Temelkovski is currently offline Damjan TemelkovskiFriend
Messages: 16
Registered: November 2013
Junior Member
Oh wow,

I just saw the oclAsType()
and I suppose
self.Nfp1.extension_NfpType.valueAttrib.oclAsType(Real)-self.Nfp2.extension_NfpType.valueAttrib.oclAsType(Real)< 5.0


will do the job.

Sorry for asking prematurely, but it's how I learn I guess :/

Damjan
Re: Custom primitive types in OCL [message #1207448 is a reply to message #1207269] Sun, 24 November 2013 15:42 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 4186
Registered: July 2009
Senior Member
Hi

oclAsType(Real) might make the compiler error go away, but I doubt that
it will execute.

You still need to associate your CustomType with a sensible behaviour.

How would you expect a tool to use your type?

For an arbitrary Java class the only guaranteed method is toString().
Eclipse OCL could use it, but it's such a stupid approach that I've only
just thought of it. You really need to use something that implements the
java.lang.Number API.

Regards

Ed Willink


On 24/11/2013 13:39, Damjan Temelkovski wrote:
> Oh wow,
>
> I just saw the oclAsType()
> and I suppose
> self.Nfp1.extension_NfpType.valueAttrib.oclAsType(Real)-self.Nfp2.extension_NfpType.valueAttrib.oclAsType(Real)<
> 5.0
>
> will do the job.
>
> Sorry for asking prematurely, but it's how I learn I guess :/
>
> Damjan
Re: Custom primitive types in OCL [message #1207529 is a reply to message #1207448] Sun, 24 November 2013 16:40 Go to previous messageGo to next message
Damjan Temelkovski is currently offline Damjan TemelkovskiFriend
Messages: 16
Registered: November 2013
Junior Member
Oh ok, so I haven't answered my own question after all:/

Is it possible for you to explain a bit further how I can use the java.lang.Number API?

Can I make an operation of the primitive type, define the body in Java somehow, and then call it from OCL?
Where can I define a function such as toString() or overload the operator '-'?
Can you please point me to somewhere I can read more about this or to an example where something similar has been implemented?

Thank you very much, I really appreciate it,

Damjan

Re: Custom primitive types in OCL [message #1208794 is a reply to message #1207529] Mon, 25 November 2013 07:18 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 4186
Registered: July 2009
Senior Member
Hi

There is no tutorial so you are on the edge of what is intended to be
extye nsible but is not yet demonstrably so; expect to do some work.

You use an API by reading the javadoc and implementing the interfaces.

You might finmd just defining the "-" method works.

But I suggested an EDataType stereotype since I would try that first.

Regards

Ed Willink


On 24/11/2013 16:40, Damjan Temelkovski wrote:
> Oh ok, so I haven't answered my own question after all:/
>
> Is it possible for you to explain a bit further how I can use the
> java.lang.Number API?
>
> Can I make an operation of the primitive type, define the body in Java
> somehow, and then call it from OCL?
> Where can I define a function such as toString() or overload the
> operator '-'? Can you please point me to somewhere I can read more
> about this or to an example where something similar has been implemented?
>
> Thank you very much, I really appreciate it,
>
> Damjan
>
Re: Custom primitive types in OCL [message #1212177 is a reply to message #1208794] Tue, 26 November 2013 20:01 Go to previous message
Damjan Temelkovski is currently offline Damjan TemelkovskiFriend
Messages: 16
Registered: November 2013
Junior Member
Thank you very much Ed,
I will try to figure it out.
I really appreciate your answers especially during a weekend.

Damjan
Previous Topic:"misplaced contructs" using second import statement
Next Topic:Multiple Contexts and allInstances Override
Goto Forum:
  


Current Time: Fri Dec 19 06:31:28 GMT 2014

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

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