Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Papyrus » Meta-Model Constraint Validation
Meta-Model Constraint Validation [message #1708955] Tue, 22 September 2015 18:44 Go to next message
Muhammad Kashif is currently offline Muhammad KashifFriend
Messages: 52
Registered: April 2015
Member
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 #1708959 is a reply to message #1708955] Tue, 22 September 2015 20:01 Go to previous messageGo to next message
Johan Van Noten is currently offline Johan Van NotenFriend
Messages: 87
Registered: July 2009
Member
Hi Ali,

A few remarks:
* You write
self.a1=true implies self.a1<>BusyState
but I suppose you intend to write a2 after the "implies". I suppose that was just a typo in the post.
* More problematic is the comparison between self.a2 and BusyState.
The first is an instance of BusyState, the second the Stereotype itself.
Don't you intend to write self.a2.oclIsTypeOf(BusyState)?
* Depending on the precise definition of the a2 attribute (its multiplicity), you could end up with a Set.
In that case you should still select a member (e.g. self.a2->first()).

Johan
Re: Meta-Model Constraint Validation [message #1708961 is a reply to message #1708959] Tue, 22 September 2015 20:47 Go to previous messageGo to next message
Muhammad Kashif is currently offline Muhammad KashifFriend
Messages: 52
Registered: April 2015
Member
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 #1708968 is a reply to message #1708961] Tue, 22 September 2015 22:27 Go to previous messageGo to next message
Johan Van Noten is currently offline Johan Van NotenFriend
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 Go to previous messageGo to next message
Christian Damus is currently offline Christian DamusFriend
Messages: 1206
Registered: July 2009
Location: Canada
Senior Member

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 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6769
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 Go to previous messageGo to next message
Christian Damus is currently offline Christian DamusFriend
Messages: 1206
Registered: July 2009
Location: Canada
Senior Member

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 #1709072 is a reply to message #1709068] Wed, 23 September 2015 18:37 Go to previous messageGo to next message
Muhammad Kashif is currently offline Muhammad KashifFriend
Messages: 52
Registered: April 2015
Member
Hi

Thanks for responding..

@Ed Willink:
When I write
self,a1=true implies self.a2->forAll(s | s.extension_BusyState->isEmpty())
it gives me the following error..
"Unrecognized variable: (extension_BusyState)"

@Christian:
When I write
self.a1 implies self.a2->forAll(s | s.extension_BusyState->isEmpty())
it gives me the same error as above .

I have extended "BusyState" from uml metaclass "State" in my profile.. a1 and a2 are the attributes of "S1" on which the following constraint is defined.
"self.a1=true implies self.a2<>BusyState"

a2 has multiplicity [0..*].. Now when i validate the constraint in Interactive OCL, it should give me true when compared to compared to value according to constraint and false if other than constraint..
Is there any thing missing.. Please guide..

Thanks in advance

Regards
Re: Meta-Model Constraint Validation [message #1709080 is a reply to message #1709072] Wed, 23 September 2015 19:23 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6769
Registered: July 2009
Senior Member
Hi

You may find https://wiki.eclipse.org/OCL/ForumNetiquette helpful.

Regards

Ed Willink

On 23/09/2015 19:37, Ali Khan wrote:
> Hi
>
> Thanks for responding..
>
> @Ed Willink:
> When I write self,a1=true implies self.a2->forAll(s |
> s.extension_BusyState->isEmpty())
> it gives me the following error..
> "Unrecognized variable: (extension_BusyState)"
>
> @Christian:
> When I write self.a1 implies self.a2->forAll(s |
> s.extension_BusyState->isEmpty())
> it gives me the same error as above .
>
> I have extended "BusyState" from uml metaclass "State" in my profile..
> a1 and a2 are the attributes of "S1" on which the following constraint
> is defined.
> "self.a1=true implies self.a2<>BusyState"
>
> a2 has multiplicity [0..*].. Now when i validate the constraint in
> Interactive OCL, it should give me true when compared to compared to
> value according to constraint and false if other than constraint..
> Is there any thing missing.. Please guide..
>
> Thanks in advance
>
> Regards
>
Re: Meta-Model Constraint Validation [message #1709081 is a reply to message #1709080] Wed, 23 September 2015 19:34 Go to previous messageGo to next message
Johan Van Noten is currently offline Johan Van NotenFriend
Messages: 87
Registered: July 2009
Member
Hi Ali,

As Ed indicated before... it is often easier for everyone following the guidelines he pointed you at.

Just for your information:
* I reproduced my interpretation of your small example
* I tried Ed's & Christian's suggestions
* It seems to work fine

See the attached archive: profile, model + screenshot of the result.

Johan
Re: Meta-Model Constraint Validation [message #1709276 is a reply to message #1709081] Fri, 25 September 2015 14:36 Go to previous messageGo to next message
Muhammad Kashif is currently offline Muhammad KashifFriend
Messages: 52
Registered: April 2015
Member
Hi..

@Ed Willink, Christian and Johan:

I have attached MS Word file which contains sample profile model, sample sysML model and the problem. Hope it will make you clear about my problem.

Kindly suggest the solution.

Thanks in advance
Regards,
Ali
  • Attachment: Meta.docx
    (Size: 187.51KB, Downloaded 92 times)

[Updated on: Fri, 25 September 2015 14:42]

Report message to a moderator

Re: Meta-Model Constraint Validation [message #1709302 is a reply to message #1709276] Fri, 25 September 2015 18:56 Go to previous messageGo to next message
Johan Van Noten is currently offline Johan Van NotenFriend
Messages: 87
Registered: July 2009
Member
Hi Ali,

I appreciate the effort that you took editing the detailed document.
It certainly clarifies the steps you took.

It would be convenient to additionally include your real model + profile definition (similar to what I did in my previous post).
This saves the time of rebuilding the model if I would like to retry something.

For now, I did this effort and I adjusted the example from my previous post to the observations I made in your document.

Also with this model, I can't reproduce your issue.
The statement that you write seems to work for me.
You can retry my findings on the attached model.

Next steps:
* Try to reproduce it on my example
* If that works for you, verify the differences with your example
* If it remains unclear, provide us with your model + profile
* We can then retry it on your model.

Johan
Re: Meta-Model Constraint Validation [message #1709320 is a reply to message #1709302] Sat, 26 September 2015 07:06 Go to previous messageGo to next message
Muhammad Kashif is currently offline Muhammad KashifFriend
Messages: 52
Registered: April 2015
Member
HI
Thankyou very much for the response..

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..

The project u have attached is OK according to my scenario.. But the constraint is not being validated in Interactive OCL.. It gives me the error(as shown in attached screenshot) when I write it in Interactive OCL according to your screenshot,, Rest of model is same as yours..



PS: the multiplicity of a2 is [0..*], it can have maximum of one busy state but not more than one busystate...

Please Help..

Thankyou
Re: Meta-Model Constraint Validation [message #1709326 is a reply to message #1709320] Sat, 26 September 2015 12:45 Go to previous messageGo to next message
Johan Van Noten is currently offline Johan Van NotenFriend
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
Re: Meta-Model Constraint Validation [message #1709333 is a reply to message #1709326] Sat, 26 September 2015 15:50 Go to previous messageGo to next message
Muhammad Kashif is currently offline Muhammad KashifFriend
Messages: 52
Registered: April 2015
Member
Hi,

Thanks for the quick response..

I have tried "self.a2->select(s| s.extension_BusyState <>null)->size() <= 1" in interactive Xtext console and it return true, means it works there..

I was using interactive OCL only for meta-model constraint validation as when I was validating the model using Eclipse validator (right click on editor and validate), it does not voilate the constraint even when the value of stereotype's attributes are set opposite to the constraint.

I am not sure whether I can validate the constraint through interactive Xtext Console or not?

"self.a2->select(s| s.extension_BusyState <>null)->size() <= 1" works in interative OCL console..

But let me know you one thing that the "a2" can have a but its not necessary to have atleast one busystate, but if it does it can have only one busyState at one time, means there can not be two busyStates at the same time...

What you suggest me for constraint validation?
Any help will be appreciiated..

Thankyou and Regards,
Re: Meta-Model Constraint Validation [message #1709334 is a reply to message #1709333] Sat, 26 September 2015 15:58 Go to previous messageGo to next message
Muhammad Kashif is currently offline Muhammad KashifFriend
Messages: 52
Registered: April 2015
Member
PS: Kindly let me know that the meta-model constraint "self.a1=false implies self.a2<>BusyState" remains the same or that will also changed to "self.a1=false implies self.a2->select(s| s.extension_BusyState <>null)->size() <= 1"..
Thanks
Re: Meta-Model Constraint Validation [message #1709337 is a reply to message #1709334] Sat, 26 September 2015 18:54 Go to previous messageGo to next message
Johan Van Noten is currently offline Johan Van NotenFriend
Messages: 87
Registered: July 2009
Member
Hi Ali,

If you make sure that the validation of your metamodel constraints happens through Pivot OCL, you should have the same experience in both validations.
Just remember that your constraint is associated to the Stereotype, so gets evaluated in the context of the Stereotype-application.

I don't fully get the question in your 11:50 post. I already indicated that self.a2<>busyState doesn't make any sense: you would be comparing a Set(State) with a Stereotype. That always returns true.
I supposed you knew the semantics of the statements, but were just confused about the right notation. Is that correct?
It is difficult for others to help you with the exact statement, because we should then know exactly what you need.
I'm sure you can adjust the proposed solutions to express your needs correctly, no?

From the same post I get the impression that you expect the model validation to kick in automatically.
It doesn't. You have to manually select "Validation | Validate model" from the popup menu that appears when you right-click an element in the Model Explorer.
Did you try that?

Johan
Re: Meta-Model Constraint Validation [message #1709338 is a reply to message #1709334] Sat, 26 September 2015 21:10 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6769
Registered: July 2009
Senior Member
Hi

I have referred you to https://wiki.eclipse.org/OCL/ForumNetiquette

I am afraid that until you comply with the guidance I cannot help you
further.

Regards

Ed Willink


On 26/09/2015 16:58, Ali Khan wrote:
> PS: Kindly let me know that the meta-model constraint "self.a1=false
> implies self.a2<>BusyState" remains the same or that will also changed
> to "self.a1=false implies self.a2->select(s| s.extension_BusyState
> <>null)->size() <= 1"..
> Thanks
Re: Meta-Model Constraint Validation [message #1709344 is a reply to message #1709338] Sun, 27 September 2015 08:04 Go to previous messageGo to next message
Muhammad Kashif is currently offline Muhammad KashifFriend
Messages: 52
Registered: April 2015
Member
Hi,

Let me demonstrate my problem again with screenshots:

Actually I want to write the constraint (when a1=false, a2 should not contain more than 1 busystates) in my profile. the constraint is shown in image (attached) along with the complete profile model.

The model is also attached on which the profile is being applied.

After being applied on model, if in model i set values of S2 opposite to that of constraint (in profile) and then validate the constraint like right click on model editor and select "validation" and the "validate model".it should voilate the constraint. but its not..

Thats why I am trying validating the constraint in interactive OCL. But i couldn't..

Re: Meta-Model Constraint Validation [message #1709345 is a reply to message #1709344] Sun, 27 September 2015 08:08 Go to previous messageGo to next message
Muhammad Kashif is currently offline Muhammad KashifFriend
Messages: 52
Registered: April 2015
Member
PS: Images attached here

May be my meta model constraint is not correct..

Please tell how can I write that particular constraint in profile and then validate in interactive OCL.

Kindly help me solve this problem.

Thankyou
Re: Meta-Model Constraint Validation [message #1709346 is a reply to message #1709344] Sun, 27 September 2015 08:12 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6769
Registered: July 2009
Senior Member
Hi

"Screenshots are helpful for showing unexpected things on the screen.
They are NEVER useful as a way of communicating EMF models or Java; that
is what text is for!"

Regards

Ed Willink


On 27/09/2015 09:04, Ali Khan wrote:
> Hi,
> Let me demonstrate my problem again with screenshots:
>
> Actually I want to write the constraint (when a1=false, a2 should not
> contain more than 1 busystates) in my profile. the constraint is shown
> in image (attached) along with the complete profile model.
> The model is also attached on which the profile is being applied.
>
> After being applied on model, if in model i set values of S2 opposite to
> that of constraint (in profile) and then validate the constraint like
> right click on model editor and select "validation" and the "validate
> model".it should voilate the constraint. but its not..
>
> Thats why I am trying validating the constraint in interactive OCL. But
> i couldn't..
>
>
Re: Meta-Model Constraint Validation [message #1709475 is a reply to message #1709346] Mon, 28 September 2015 17:59 Go to previous messageGo to next message
Muhammad Kashif is currently offline Muhammad KashifFriend
Messages: 52
Registered: April 2015
Member
Hi,
Problem has been solved.. Thankyou very much for helping me out..

I have one more query that is:

If I type an attribute of stereotype with UML metaclass "TimeEvent". And then set its value as 5(integer). What will be its default unit (sec, min, hour etc). How can I use time suffix..e.g., if I want it to wait for 5 minutes how can i achieve that?

Anyone Please guide..

Thankyou
Re: Meta-Model Constraint Validation [message #1709586 is a reply to message #1709475] Tue, 29 September 2015 12:28 Go to previous messageGo to next message
Johan Van Noten is currently offline Johan Van NotenFriend
Messages: 87
Registered: July 2009
Member
Ali,

Glad to hear your problem is solved.
Could be good to share the final solution.

In order to get an answer to your new question, you will need to post it as a separate topic.
Don't mix subjects in one topic.

Regards,
Johan
Re: Meta-Model Constraint Validation [message #1709624 is a reply to message #1709586] Tue, 29 September 2015 16:04 Go to previous message
Muhammad Kashif is currently offline Muhammad KashifFriend
Messages: 52
Registered: April 2015
Member
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,
Previous Topic: Adding Menus when running an activity diagram
Next Topic:Help Notes and all graphical shapes are grayed out on my Papyrus
Goto Forum:
  


Current Time: Wed Jul 08 22:58:34 GMT 2020

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

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

Back to the top