Book a Demo

Author Topic: OCL constraint to traverse from class to port  (Read 2596 times)

Lars J.

  • EA User
  • **
  • Posts: 30
  • Karma: +0/-0
    • View Profile
OCL constraint to traverse from class to port
« on: March 10, 2012, 01:41:01 am »
Hi all,

I am creating a tiny modeling language based on UML. For this I defined a UML Profile and added it to an mdg technology.

The profile contains 2 extensions of the metaclass Class and two extensions of the metaclass Port:

MyClassStereo_1 --> Class
MyClassStereo_2 --> Class
MyPortStereo_1 --> Port
MyPortStereo_2 --> Port

I only want to put instances of MyPortStereo_1 on instances of MyClassStereo_1. But the tool does not prevent me from putting instances of MyPortStereo_2 on instances of MyClassStereo_1. That's why I want to place an OCL constraint on the stereotype MyClassStereo_1 which checks that all contained ports are MyPortStereo_1 ports.

The question is: What would I have to write in OCL to check this?

My suggestion is something like: self.<relation>->forAll(p | p.isKindOf(MyPortStereo_2)) or so.

But what is the relation to get from a class to its contained ports and is the check for being MyPortStereo_2 done using oclIsKindOf?

thanks in Advance.

Lars

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: OCL constraint to traverse from class to port
« Reply #1 on: March 10, 2012, 03:44:28 am »
Quote
The question is: What would I have to write in OCL to check this?
EA can not execute OCL. It just can check the syntax of OCL (and I don't know how well it does that).

q.

[edit:] Just give it a try. In a class enter a OCL constraint with the value "this is not valid" (which is most likely an invalid OCL statement). Now run the model validation agains this class...
« Last Edit: March 12, 2012, 11:42:43 pm by qwerty »

Lars J.

  • EA User
  • **
  • Posts: 30
  • Karma: +0/-0
    • View Profile
Re: OCL constraint to traverse from class to port
« Reply #2 on: March 12, 2012, 07:52:06 pm »
Oh, if this is really the case, then the only sense I see in the possibility to write OCL constraints is to feed it to an addin that does the job. But this is really not much.

I was thinking that EA is at least capable of executing OCL during a model validation step. But if this isn't the case then I will refrain from trying to accomplish the above and try to achieve it by other means.

So, is this an official statement from Sparxsystem that OCL is not executed?

thanks.
« Last Edit: March 13, 2012, 11:01:57 pm by califax2k »