Home » Modeling » Papyrus » Meta-Model Constraint Validation
| | |
Re: Meta-Model Constraint Validation [message #1708968 is a reply to message #1708961] |
Tue, 22 September 2015 22:27 |
Johan Van Noten Messages: 87 Registered: July 2009 |
Member |
|
|
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 15:24] Report message to a moderator
|
|
|
Re: Meta-Model Constraint Validation [message #1709029 is a reply to message #1708961] |
Wed, 23 September 2015 12:06 |
|
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 13:43 |
Ed Willink Messages: 7670 Registered: July 2009 |
Senior Member |
|
|
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 17:35 |
|
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 12:45 |
Johan Van Noten Messages: 87 Registered: July 2009 |
Member |
|
|
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
|
|
| | | | | | | | | | |
Goto Forum:
Current Time: Wed Sep 25 12:09:34 GMT 2024
Powered by FUDForum. Page generated in 0.08627 seconds
|