Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » constraints with Set...
constraints with Set... [message #45244] Wed, 28 November 2007 19:25 Go to next message
Eclipse UserFriend
Originally posted by: asma.charfi.com

Hi,

to verify the direction of a port, this constraint works perfectly

let port:
P::Port=self.getStereotypeApplication(self.getAppliedStereot ype('P::Port')).oclAsType(P::Port)
in port.direction=P::DirectionKind::out

now I want to verify that my component contains only out Ports (its
direction=out) I write this constraint:
self.ownedPort.getAppliedStereotypes()->forAll(s| let ports : Set( P::Port )
=self.getStereotypeApplication(s).oclAsType(Set ( P::Port )) in
ports->forAll(p|p.direction=P::DirectionKind::out)

it return illegal operation signature: (Set(OclType))

what is the problem? thank you a lot

Asma
Re: constraints with Set... [message #45344 is a reply to message #45244] Wed, 28 November 2007 13:52 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, Asma,

The oclAsType() cast operation and oclIsKindOf() conformance testing
operation only apply to instances of OclAny, which OCL's collections are
not. That is to say, you cannot cast collections.

Besides, you cannot ask the component for the stereotype applications of its
owned ports.

Does this work?

self.ownedPort->forAll(
let p : P::Port = getStereotypeApplication(
getAppliedStereotype('P::Port')).oclAsType(P::Port) in
p.direction = P::DirectionKind::out)

Again, using the UML environment this would be tidier:

self.ownedPort->forAll(
not extension_Port.oclIsUndefined() and
extension_Port.direction = P::DirectionKind::out)

HTH,

Christian


charfi asma wrote:

> Hi,
>
> to verify the direction of a port, this constraint works perfectly
>
> let port:
>
P::Port=self.getStereotypeApplication(self.getAppliedStereot ype('P::Port')).oclAsType(P::Port)
> in port.direction=P::DirectionKind::out
>
> now I want to verify that my component contains only out Ports (its
> direction=out) I write this constraint:
> self.ownedPort.getAppliedStereotypes()->forAll(s| let ports : Set( P::Port
> ) =self.getStereotypeApplication(s).oclAsType(Set ( P::Port )) in
> ports->forAll(p|p.direction=P::DirectionKind::out)
>
> it return illegal operation signature: (Set(OclType))
>
> what is the problem? thank you a lot
>
> Asma
Re: constraints with Set... [message #45393 is a reply to message #45344] Thu, 29 November 2007 02:58 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: asma.charfi.com

Hi,

Thank you Christian! it works but only in console. I think I have problem in
choosing context :-(

when I chose M2 and UML in the console's action bar this constraint works
perfectly .

self.ownedPort->forAll(let p : Gaspard::FlowPort =
getStereotypeApplication(getAppliedStereotype('Gaspard::Flow Port')).oclAsType(Gaspard::FlowPort)
in p.direction = Gaspard::DirectionKind::out) // when I click on
component whose ports are stereotypsed Port

Now, I want to validate model using my plugin:

when I put stereotype as context and add base_Component and extension_Port
to my constraint it works:

the constraint is " self.base_Component.ownedPort->forAll(let p : P::Port =
getStereotypeApplication(getAppliedStereotype('P::Port')).oc lAsType(P::Port)
in p.extension_Port.direction = P::DirectionKind::out)

-------------------------------------------------using UML
environnement:M1-------------------------------------------- ----

ocl2 = org.eclipse.ocl.uml.OCL.newInstance();



oclHelper = ocl2.createOCLHelper();

stereotype = element.getAppliedStereotypes().get(0);

oclHelper.setContext(stereotype);

oclInv = (Constraint)
oclHelper.createInvariant(stereotype.getOwnedRules().get(i). getSpecification().stringValue());

resultat=ocl2.check(element,oclInv);

My problem is, , I get errors when I put a metaclass as context (I do it to
use M2 level and this to avoid using extension_end and base_component caus
my profile is exported from magicdraw):

the constraint is: self.ownedPort->forAll(let p : Gaspard::FlowPort =
getStereotypeApplication(getAppliedStereotype('Gaspard::Flow Port')).oclAsType(Gaspard::FlowPort)
in p.direction = Gaspard::DirectionKind::out)

the error is : ERROR in (enumerationOrClassLiteralExpCS): (Unknown type ([P,
Port]))

-------------------------------------------------using UML
environnement:M2-------------------------------------------- ----

ocl2 = org.eclipse.ocl.uml.OCL.newInstance();



oclHelper = ocl2.createOCLHelper();


stereotype = element.getAppliedStereotypes().get(0);

Classifier metaclass=(Classifier)
umlMetamodel.getOwnedType(stereotype.eClass().getName());
//metaclass=Stereotype

oclHelper.setContext(metaclass);

oclInv = (Constraint)
oclHelper.createInvariant(stereotype.getOwnedRules().get(i). getSpecification().stringValue());

resultat=ocl2.check(element,oclInv);

when I use console with UML and M2 it works but when I use my plugin it did
not work? did you have any explications?

I tried to change the metaclass, I use Component (metaclass of selected
element) instead but I got the same error.

In UML M2 console's level, which context is used ?(cause the constraint was
parsed and evaluated perfectly in the console).

thank you

ASMA



"Christian W. Damus" <cdamus@ca.ibm.com> a
Re: constraints with Set... [message #45423 is a reply to message #45344] Thu, 29 November 2007 03:07 Go to previous message
Eclipse UserFriend
Originally posted by: asma.charfi.com

Hi,
In the error I used P and Port, and in the constraint I used Gspard and
FlowPort they are the same:
Rectification: P=Gaspard and Port=FlowPort
thank you ;-)
asma

"Christian W. Damus" <cdamus@ca.ibm.com> a
Previous Topic:[Announce] MDT OCL 1.2.0 I200711281424 is available
Next Topic:Re: using the Type: MyProfile::MyStereotype
Goto Forum:
  


Current Time: Fri Apr 19 07:15:50 GMT 2024

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

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

Back to the top