Home » Modeling » Papyrus » Meta-Model Constraint Validation
Meta-Model Constraint Validation [message #1708955] |
Tue, 22 September 2015 14:44  |
Eclipse User |
|
|
|
Hi,
I was working on UML profile Diagram. In my meta-model I have made a stereotype "S1" with two attributes "a1" and "a2" and is extended by a UML metaclass "region". The attribute "a1" is of Boolean Type and "a2" is typed by UML metaclass "State". I have another Stereotype in my profile named as "BusyState" and is extended by UML metaclass "State".
Now I wrote a constraint on "S1" that is "self.a1=true implies self.a2<>BusyState" .
I applied the profile on SysML model. In SMD I applied "S1" on the Region which contains a state named as "tempState" with applied stereotype as "BusyState" It then asks me to set the values of "S1" attributes that are "a1 and "a2".
I set the value of "a1" = true and "a2" = "tempState".
Now I open my SysML model in "Sample Reflective Ecore Model Editor" for constraint validation using interactive OCL. When I open the model in "Sample Reflective Ecore Model Editor" it automatically import the applied profile there as well. it makes an instance of "S1" and "BS". I selected "S1" and wrote the constraint in interactive OCL i.e.,
"self.a1=true implies self.a1<>BusyState"
It should return me "true" as aresult but it keeps giving me error i.e
"Cannot find operation (<>(BusyState)) for the type (Set(State))"
Can anyone help me in this regard. I would be very grateful..
Thanks
|
|
| | |
Re: Meta-Model Constraint Validation [message #1708968 is a reply to message #1708961] |
Tue, 22 September 2015 18:27   |
Eclipse User |
|
|
|
In fact, I'm a bit missing what you're trying to express in your profile.
What do you want to be validated in case a1 = true?
Do you want to enforce that a2 is filled in that case?
If you're specifying the constraint in the profile definition, you were quite close.
self.a1 implies not self.a2.oclIsUndefined()
(=true is ok, but it is a bit superfluous, no?)
You don't have to express that a2 is an instance of BusyState, since the Stereotype's attribute type already enforces the fact that only null or an instance of BusyState can be assigned.
Correction triggered by Christian's reply: I mistakenly thought your profile defined a2 to be of type BusyState, while you clearly mentioned it to be of type State. Then my assumption in this paragraph is not correct and you will need to test for the presence of the BusyState extension, just like Christian and Ed mentioned.
The previous statement tests for it not to be null.
From the interactive console you will not be selecting the stereotype itself. Self will rather point to the Region to which your stereotype is applied.
Therefore, you will need to first access the stereotype through self.extension_S1.
You're constraint could sound like:
self.extension_S1.a1 implies .... etc
Disclaimer: I didn't test this on a real profile, so I could be mistaken about the correct notation...
[Updated on: Wed, 23 September 2015 11:24] by Moderator
|
|
|
Re: Meta-Model Constraint Validation [message #1709029 is a reply to message #1708961] |
Wed, 23 September 2015 08:06   |
Eclipse User |
|
|
|
Hi, Ali,
Metaclass extension in profiles is not generalization, despite the
resemblance of the extension arrow notation to a generalization. It
is, in fact, association.
So, you might try something like this:
self.a1 implies self.a2->forAll(s | s.extension_BusyState->isEmpty())
to require that when a1 is true, any and all states in a2 do not have
the BusyState stereotype applied (by reverse navigation of the
metaclass extension).
HTH,
Christian
On 2015-09-22 20:47:06 +0000, Ali Khan said:
> Hi,
>
> Thanks for the response..
>
> Yes that was a typo.....The constraint is "self.a1=true implies
> self.a2<>BusyState" .
>
> When I write "self.a1=true implies self.a2.OclIsTypeOf(BusyState), it
> gives me the following error:
>
> "Cannot find operation (implies(Bag(Boolean))) for the
> type (Boolean)"
>
> Can you please tell me the exact statement for that particular
> constraint validation?
>
> The multiplicity of "a2" is [0..*]
>
> Thanks
|
|
|
Re: Meta-Model Constraint Validation [message #1709042 is a reply to message #1709029] |
Wed, 23 September 2015 09:43   |
Eclipse User |
|
|
|
Hi
You make it very hard to provide accurate responses given the lack of a
repro:
I would be surprised if BusyState is a collection so
forAll(s | s.extension_BusyState->isEmpty())
seems wrong to me. Probably
forAll(s | s.extension_BusyState = null)
or even just
forAll(extension_BusyState = null)
Regards
Ed Willink
On 23/09/2015 13:06, Christian W. Damus wrote:
> Hi, Ali,
>
> Metaclass extension in profiles is not generalization, despite the
> resemblance of the extension arrow notation to a generalization. It
> is, in fact, association.
>
> So, you might try something like this:
>
> self.a1 implies self.a2->forAll(s | s.extension_BusyState->isEmpty())
>
> to require that when a1 is true, any and all states in a2 do not have
> the BusyState stereotype applied (by reverse navigation of the
> metaclass extension).
>
> HTH,
>
> Christian
>
>
> On 2015-09-22 20:47:06 +0000, Ali Khan said:
>
>> Hi,
>>
>> Thanks for the response..
>>
>> Yes that was a typo.....The constraint is "self.a1=true implies
>> self.a2<>BusyState" .
>>
>> When I write "self.a1=true implies self.a2.OclIsTypeOf(BusyState), it
>> gives me the following error:
>>
>> "Cannot find operation (implies(Bag(Boolean))) for the
>> type (Boolean)"
>>
>> Can you please tell me the exact statement for that particular
>> constraint validation?
>>
>> The multiplicity of "a2" is [0..*]
>>
>> Thanks
>
>
|
|
|
Re: Meta-Model Constraint Validation [message #1709068 is a reply to message #1709042] |
Wed, 23 September 2015 13:35   |
Eclipse User |
|
|
|
Hi, Ed,
I thought it might be helpful to use verbose syntax for clarity. And,
I generally use the isEmpty() collection operator because,
historically, the multiplicity of the extension end as implemented in
Eclipse OCL has been uncertain. If it happens to be a [0..1], then
this expression will coerce it to a set that is empty or not according
to whether the single value is null or not.
Cheers,
Christian
On 2015-09-23 13:43:24 +0000, Ed Willink said:
> Hi
>
> You make it very hard to provide accurate responses given the lack of a repro:
>
> I would be surprised if BusyState is a collection so
>
> forAll(s | s.extension_BusyState->isEmpty())
>
> seems wrong to me. Probably
>
> forAll(s | s.extension_BusyState = null)
>
> or even just
>
> forAll(extension_BusyState = null)
>
> Regards
>
> Ed Willink
>
> On 23/09/2015 13:06, Christian W. Damus wrote:
>> Hi, Ali,
>>
>> Metaclass extension in profiles is not generalization, despite the
>> resemblance of the extension arrow notation to a generalization. It is,
>> in fact, association.
>>
>> So, you might try something like this:
>>
>> self.a1 implies self.a2->forAll(s | s.extension_BusyState->isEmpty())
>>
>> to require that when a1 is true, any and all states in a2 do not have
>> the BusyState stereotype applied (by reverse navigation of the
>> metaclass extension).
>>
>> HTH,
>>
>> Christian
>>
>>
>> On 2015-09-22 20:47:06 +0000, Ali Khan said:
>>
>>> Hi,
>>>
>>> Thanks for the response..
>>>
>>> Yes that was a typo.....The constraint is "self.a1=true implies
>>> self.a2<>BusyState" .
>>>
>>> When I write "self.a1=true implies self.a2.OclIsTypeOf(BusyState), it
>>> gives me the following error:
>>>
>>> "Cannot find operation (implies(Bag(Boolean))) for the type (Boolean)"
>>>
>>> Can you please tell me the exact statement for that particular
>>> constraint validation?
>>>
>>> The multiplicity of "a2" is [0..*]
>>>
>>> Thanks
|
|
| | | | | | |
Re: Meta-Model Constraint Validation [message #1709326 is a reply to message #1709320] |
Sat, 26 September 2015 08:45   |
Eclipse User |
|
|
|
First a few remarks:
Quote:
I have tried the model you have attached in previous reply.. I think you are using Xtext OCL, whereas I have to check it in interactive OCL only.. The problem remains the same..
You are right, I was using Interactive Xtext OCL. Never used the other one... Why do you not desire to use the Interactive Xtext OCL console? Did you try whether it works for you?
Quote:
PS: the multiplicity of a2 is [0..*], it can have maximum of one busy state but not more than one busystate...
This is different from what you describe in your document. There the profile model's screenshot mentions [0..1].
I therefore changed now the profile definition to be [0..*] for a2.
In my previous message, the screenshot showed one of the statements that I tried for you, being "... self.a2<>BusyState". This was just as a test to reproduce literally what you tried. That does not mean that it is a useful statement, it will essentially Always return true since a Set(State) can never be equal to the Stereotype definition BusyState.
Now, to the point:
If I use the Interactive Xtext OCL console and type a statement that satisfies the behaviour that you describe this time, I get:
self.a2->select(s| s.extension_BusyState <>null)->size() <= 1
which returns true as long as "there is at most one BusyState in a2".
I propose you try this in the Interactive Xtext console on your side as well to verify whether that works. Then we have at least one common base to start from.
I also tried in the Interactive Console, but I don't know how to correctly handle stereotypes there. It works with the following statement, but I'm not sure it is the most effective one:
self.a2->select(s | s.getAppliedStereotypes()->exists(name='BusyState'))->size() <= 1
I'd rather express that as "s.isStereotypeApplied(StateProfile::BusyState)", but that seems not to work. I guess this limitation is because of the differences between the Essential OCL (which I guess is used in the Interactive OCL) and the Pivot OCL (used in Interactive Xtext console). I exclusively use the latter.
In case you want to switch the full OCL evaluation to Pivot OCL, you can go to Window | Preferences | OCL | OCLinEcore and select the Pivot variant there.
Beware: I'm not at all an expert on the differences between Essential & Pivot.
Johan
|
|
| | | | | | | | | |
Re: Meta-Model Constraint Validation [message #1709624 is a reply to message #1709586] |
Tue, 29 September 2015 12:04  |
Eclipse User |
|
|
|
Hi,
ofcourse.. I have used the following solution proposed by you, which works fine and validated through eclipse validator.. Thanks to you..
self.a2->select(s | s.getAppliedStereotypes()->exists(name='BusyState'))->size() <= 1
Let me post my question in separate topic.. See u there..
Regards,
|
|
|
Goto Forum:
Current Time: Tue Jul 08 17:58:13 EDT 2025
Powered by FUDForum. Page generated in 0.08788 seconds
|