Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » constraint on abstract stereotype
constraint on abstract stereotype [message #27770] Mon, 11 June 2007 17:20 Go to next message
Eclipse UserFriend
Originally posted by: asma.charfi.com

Hi,



I specified a constraint on abstract stereotype.

I have a component which has -as a stereotype- one of the abstract
stereotype's children (relation of generalization).

I want to verify if this component respect the constraint (added to the
abstract stereotype)

In my plugin, I think that I should extract not only the
appliedStereotypes() but also the generalization.target which extract the
abstract stereotype.

And after that, extract constraints added to this abstract stereotype and
parse them and check them as usual.



My question is, in case of the use of emf validation, and when I add my
constraint in the file.ocl, could emf validation verify the component
automatically for me (i.e. I did not have to extract the abstract stereotype
and see if there is constraint defined there)



Thank you
Re: constraint on abstract stereotype [message #27818 is a reply to message #27770] Mon, 11 June 2007 13:22 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, Asma,

The EMF Validation Framework's OCL integration API is generic; it doesn't
know anything about UML or about stereotypes in particular. Perhaps the
MDT UML2 or OCL component should have extensions to the EMF Validation
Framework that do this, but those don't exist today. This improved
stereotype support would be a good idea for a contribution from a member of
the OCL community such as you! :-)

Please keep in mind, also, that the constraint provider implementation that
reads *.ocl files (in the org.eclipse.emf.validation.examples.ocl plug-in)
is only an *example*. It does not come with the same quality assurance as
the validation API. In particular, testing is only sketchy and there
aren't even JUnit tests for it.

BTW, you will find the Classifier.allParents() method useful for obtaining
all of the general Stereotypes of the stereotype applied to your component,
to more easily find the applicable Constraints. You could really simplify
access to the applicable constraints using an OCL query expression ;-)

self.allParents().ownedRule->select(
specification.oclIsKindOf(OpaqueExpression) and
specification.oclAsType(OpaqueExpression).language->includes('OCL'))

This will find all of the invariant Constraints applicable to the stereotype
(the "self" object) that are specified using OCL.

Cheers,

Christian


charfi asma wrote:

> Hi,
>
>
>
> I specified a constraint on abstract stereotype.
>
> I have a component which has -as a stereotype- one of the abstract
> stereotype's children (relation of generalization).
>
> I want to verify if this component respect the constraint (added to the
> abstract stereotype)
>
> In my plugin, I think that I should extract not only the
> appliedStereotypes() but also the generalization.target which extract the
> abstract stereotype.
>
> And after that, extract constraints added to this abstract stereotype and
> parse them and check them as usual.
>
>
>
> My question is, in case of the use of emf validation, and when I add my
> constraint in the file.ocl, could emf validation verify the component
> automatically for me (i.e. I did not have to extract the abstract
> stereotype and see if there is constraint defined there)
>
>
>
> Thank you
Re: constraint on abstract stereotype [message #27857 is a reply to message #27818] Thu, 14 June 2007 01:58 Go to previous message
Eclipse UserFriend
Originally posted by: asma.charfi.com

Hi christian,

thank you very much for all explanations!
I tried your query but it return the names of the constraints (added to my
abstract stereotype) so I change it to:
self.allParents().ownedRule.specification.stringValue()
it return all the constraints and I evaluate them using ocl.evaluate
method:-)

my question is, to post the validation result ( success or failure of all
these constraints) should I evaluate them constraint by constraint or there
is a method that can return the final result.
I put all my constraints (there are 5) in a bag and I evaluate them one by
one and each time I recover the result and I append it to my final message
it works, but I think that there is an other way to do it better, is there?

thank you!


"Christian W. Damus" <cdamus@ca.ibm.com> a
Re: constraint on abstract stereotype [message #27897 is a reply to message #27857] Wed, 13 June 2007 17:31 Go to previous message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, Asma,

See some replies in-line, below.

HTH,

Christian


charfi asma wrote:

> Hi christian,
>
> thank you very much for all explanations!
> I tried your query but it return the names of the constraints (added to my
> abstract stereotype) so I change it to:
> self.allParents().ownedRule.specification.stringValue()
> it return all the constraints and I evaluate them using ocl.evaluate
> method:-)

This will work if all of your Constraints happen to be specified in OCL by
chance. The expression I suggested selected only those Constraints
specified by OpaqueExpressions that have "OCL", but as you indicate, it
didn't go that last step to get the expression text from each. That would
look like:

self.allParents().ownedRule->iterate(
c : Constraint; s : Sequence(String) = Sequence{} |
if c.specification.oclIsKindOf(OpaqueExpression) then
let e : OpaqueExpression = c.specification.oclAsType(OpaqueExpression),
i : Integer = e.language->indexOf('OCL') in
if not i.oclIsUndefined() then s->append(e.body->at(i)) else s endif
else
s
endif)

This accounts for the possibility that:
- a Constraint is not specified by an OpaqueExpression
- an OpaqueExpression can have multiple languages
- OCL may not be one of the languages
- OCL may not be the first language

Anyway, none of this may be relevant to your situation. It was just fun to
try this in the console :-)

> my question is, to post the validation result ( success or failure of all
> these constraints) should I evaluate them constraint by constraint or
> there is a method that can return the final result.
> I put all my constraints (there are 5) in a bag and I evaluate them one by
> one and each time I recover the result and I append it to my final message
> it works, but I think that there is an other way to do it better, is
> there?

You can use the ConstraintStatus::createMultiStatus(...) method to create a
multi-status from multiple distinct constraint violations. This allows you
to validate all of the constraints in sequence, and report possibly
multiple problems from those checks as a group. You will need to evaluate
each constraint individually, which is a good idea anyway because you would
probably want to give the user a different message for each one.


>
> thank you!
>
>
> "Christian W. Damus" <cdamus@ca.ibm.com> a �rit dans le message de news:
> f4jiaj$90t$1@build.eclipse.org...
>> Hi, Asma,
>>
>> The EMF Validation Framework's OCL integration API is generic; it doesn't
>> know anything about UML or about stereotypes in particular. Perhaps the
>> MDT UML2 or OCL component should have extensions to the EMF Validation
>> Framework that do this, but those don't exist today. This improved
>> stereotype support would be a good idea for a contribution from a member
>> of
>> the OCL community such as you! :-)
>>
>> Please keep in mind, also, that the constraint provider implementation
>> that
>> reads *.ocl files (in the org.eclipse.emf.validation.examples.ocl
>> plug-in)
>> is only an *example*. It does not come with the same quality assurance
>> as
>> the validation API. In particular, testing is only sketchy and there
>> aren't even JUnit tests for it.
>>
>> BTW, you will find the Classifier.allParents() method useful for
>> obtaining all of the general Stereotypes of the stereotype applied to
>> your component,
>> to more easily find the applicable Constraints. You could really
>> simplify
>> access to the applicable constraints using an OCL query expression ;-)
>>
>> self.allParents().ownedRule->select(
>> specification.oclIsKindOf(OpaqueExpression) and
>> specification.oclAsType(OpaqueExpression).language->includes('OCL'))
>>
>> This will find all of the invariant Constraints applicable to the
>> stereotype
>> (the "self" object) that are specified using OCL.
>>
>> Cheers,
>>
>> Christian
>>
>>
>> charfi asma wrote:
>>
>>> Hi,
>>>
>>>
>>>
>>> I specified a constraint on abstract stereotype.
>>>
>>> I have a component which has -as a stereotype- one of the abstract
>>> stereotype's children (relation of generalization).
>>>
>>> I want to verify if this component respect the constraint (added to the
>>> abstract stereotype)
>>>
>>> In my plugin, I think that I should extract not only the
>>> appliedStereotypes() but also the generalization.target which extract
>>> the abstract stereotype.
>>>
>>> And after that, extract constraints added to this abstract stereotype
>>> and parse them and check them as usual.
>>>
>>>
>>>
>>> My question is, in case of the use of emf validation, and when I add my
>>> constraint in the file.ocl, could emf validation verify the component
>>> automatically for me (i.e. I did not have to extract the abstract
>>> stereotype and see if there is constraint defined there)
>>>
>>>
>>>
>>> Thank you
>>
Previous Topic:[Announce] MDT OCL 1.1.0 1.1RC3 is available
Next Topic:Tuple Type problems
Goto Forum:
  


Current Time: Thu Apr 18 06:43:51 GMT 2024

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

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

Back to the top