Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » OCLs for abstract classes and children(How to write OCLs for abstract classes and make the children be affected by the OCL too)
OCLs for abstract classes and children [message #652744] Sun, 06 February 2011 00:20 Go to next message
Oscar Andres Fajardo F. is currently offline Oscar Andres Fajardo F.
Messages: 10
Registered: February 2011
Location: Colombia
Junior Member
Hi, I have a metamodel which has a Metaclass named "Model" this class is going to be the root of everything. Then I have another metaclass called "NamedElement" this class is going to compose the "Model". "NamedElement"that its an Abstract Class and is father of all the rest of metaclasses In the model.

import ecore_0 : 'http://www.eclipse.org/emf/2002/Ecore#/';

package MAS : MAS = 'http://MAS/1.0'
{
class MASModel
{
property Elements#MAS : MASNamedElement[*] { composes };
}
class MASNamedElement { abstract }
{
attribute name : String[?];
property MAS#Elements : MASModel[1];

-- invariant UniqueName:
-- Achieves.allInstances()or Agent.allInstances() or Capabilities.allInstances()or
-- Goal.allInstances() or Possesses.allInstances() or Requires.allInstances() or Role.allInstances()->isUnique(name) ;
}
class MASElement extends MASNamedElement { abstract };
class MASRelation extends MASNamedElement { abstract }
{
property source : MASElement[?];
property target : MASElement[?];
}
class Requires extends MASRelation
{
invariant RequiresDestinationType:
self.target->forAll(a|a.oclIsKindOf(Capabilities));
invariant RequiresSourceType:
self.source->forAll(a|a.oclIsKindOf(Role));
}
class ScoredRelation extends MASRelation { abstract }
{
attribute score : ecore_0::EFloat[?] = '0' { transient };
}
class Achieves extends ScoredRelation
{
invariant AchievesDestinationType:
self.target->forAll(a|a.oclIsKindOf(Goal));
invariant AchievesSourceType:
self.source->forAll(a|a.oclIsKindOf(Role));
}
class Possesses extends ScoredRelation
{
invariant PossessesDestinationType:
self.target->forAll(a|a.oclIsKindOf(Capabilities));
invariant PossessesSourceType:
self.source->forAll(a|a.oclIsKindOf(Agent));
}
class Role extends MASElement;
class Goal extends MASElement;
class Agent extends MASElement;
class Capabilities extends MASElement;
}

What I want is to write an OCL that checks for repeated names... normally it wold be like:
self.AllInstances->IsUnique(name); also I tried another thing where the OCL comments are...but doesn't work.
But I want to check for all the children of NamedElement(from Elements and Relations untill the end of file), and also there are no instances of NamedElement, so I'm having trouble defining this constraint for the ecore file and for the Audits in GMF.

Thanks in advance...
Re: OCLs for abstract classes and children [message #652745 is a reply to message #652744] Sun, 06 February 2011 02:00 Go to previous messageGo to next message
Eike Stepper is currently offline Eike Stepper
Messages: 5499
Registered: July 2009
Senior Member
Perhaps it's related to https://bugs.eclipse.org/bugs/show_bug.cgi?id=329389 ?

Cheers
/Eike

----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper



Am 06.02.2011 06:22, schrieb Oscar Andres Fajardo F.:
> Hi, I have a metamodel which has a Metaclass named "Model" this class is going to be the root of everything. Then I have another metaclass called "NamedElement" this class is going to compose the "Model". "NamedElement"that its an Abstract Class and is father of all the rest of metaclasses In the model.
>
> import ecore_0 : 'http://www.eclipse.org/emf/2002/Ecore#/';
>
> package MAS : MAS = 'http://MAS/1.0'
> {
> class MASModel
> {
> property Elements#MAS : MASNamedElement[*] { composes };
> }
> class MASNamedElement { abstract }
> {
> attribute name : String[?];
> property MAS#Elements : MASModel[1];
>
> -- invariant UniqueName:
> -- Achieves.allInstances()or Agent.allInstances() or Capabilities.allInstances()or
> -- Goal.allInstances() or Possesses.allInstances() or Requires.allInstances() or Role.allInstances()->isUnique(name) ;
> }
> class MASElement extends MASNamedElement { abstract };
> class MASRelation extends MASNamedElement { abstract }
> {
> property source : MASElement[?];
> property target : MASElement[?];
> }
> class Requires extends MASRelation
> {
> invariant RequiresDestinationType: self.target->forAll(a|a.oclIsKindOf(Capabilities));
> invariant RequiresSourceType: self.source->forAll(a|a.oclIsKindOf(Role));
> }
> class ScoredRelation extends MASRelation { abstract }
> {
> attribute score : ecore_0::EFloat[?] = '0' { transient };
> }
> class Achieves extends ScoredRelation
> {
> invariant AchievesDestinationType: self.target->forAll(a|a.oclIsKindOf(Goal));
> invariant AchievesSourceType: self.source->forAll(a|a.oclIsKindOf(Role));
> }
> class Possesses extends ScoredRelation
> {
> invariant PossessesDestinationType: self.target->forAll(a|a.oclIsKindOf(Capabilities));
> invariant PossessesSourceType: self.source->forAll(a|a.oclIsKindOf(Agent));
> }
> class Role extends MASElement;
> class Goal extends MASElement;
> class Agent extends MASElement;
> class Capabilities extends MASElement;
> }
>
> What I want is to write an OCL that checks for repeated names... normally it wold be like:
> self.AllInstances->IsUnique(name); also I tried another thing where the OCL comments are...but doesn't work.
> But I want to check for all the children of NamedElement(from Elements and Relations untill the end of file), and also there are no instances of NamedElement, so I'm having trouble defining this constraint for the ecore file and for the Audits in GMF.
>
> Thanks in advance...
Re: OCLs for abstract classes and children [message #652767 is a reply to message #652745] Sun, 06 February 2011 10:23 Go to previous messageGo to next message
Oscar Andres Fajardo F. is currently offline Oscar Andres Fajardo F.
Messages: 10
Registered: February 2011
Location: Colombia
Junior Member
It seems to be as you say.
Haven't you found an alternative solution?
Maybe a crazy idea might work for me (right now my thinking isn't very sharp, just a newbie).

thanks in advance
Re: OCLs for abstract classes and children [message #652789 is a reply to message #652767] Sun, 06 February 2011 13:13 Go to previous messageGo to next message
Eike Stepper is currently offline Eike Stepper
Messages: 5499
Registered: July 2009
Senior Member
Am 06.02.2011 16:23, schrieb Oscar Andres Fajardo F.:
> It seems to be as you say.
> Haven't you found an alternative solution?
> Maybe a crazy idea might work for me (right now my thinking isn't very sharp, just a newbie).
IIRC we rely on Ed to address this.

Cheers
/Eike

----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper
Re: OCLs for abstract classes and children [message #652790 is a reply to message #652744] Sun, 06 February 2011 13:49 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4030
Registered: July 2009
Senior Member
Hi Oscar

Your solution has a number of typos.

> self.AllInstances->IsUnique(name)

should be

NamedElement.allInstances()->isUnique(name)

but, as Eike points out, abstract classes don't work at present.
Hopefully fixed for Indigo, maybe even M6. Might even be fixed in
M5, but it's beyond my current testing horizon.

Regards

Ed Willink



On 06/02/2011 05:22, Oscar Andres Fajardo F. wrote:
> Hi, I have a metamodel which has a Metaclass named "Model" this class is
> going to be the root of everything. Then I have another metaclass called
> "NamedElement" this class is going to compose the "Model".
> "NamedElement"that its an Abstract Class and is father of all the rest
> of metaclasses In the model.
>
> import ecore_0 : 'http://www.eclipse.org/emf/2002/Ecore#/';
>
> package MAS : MAS = 'http://MAS/1.0'
> {
> class MASModel
> {
> property Elements#MAS : MASNamedElement[*] { composes };
> }
> class MASNamedElement { abstract }
> {
> attribute name : String[?];
> property MAS#Elements : MASModel[1];
>
> -- invariant UniqueName:
> -- Achieves.allInstances()or Agent.allInstances() or
> Capabilities.allInstances()or
> -- Goal.allInstances() or Possesses.allInstances() or
> Requires.allInstances() or Role.allInstances()->isUnique(name) ;
> }
> class MASElement extends MASNamedElement { abstract };
> class MASRelation extends MASNamedElement { abstract }
> {
> property source : MASElement[?];
> property target : MASElement[?];
> }
> class Requires extends MASRelation
> {
> invariant RequiresDestinationType:
> self.target->forAll(a|a.oclIsKindOf(Capabilities));
> invariant RequiresSourceType: self.source->forAll(a|a.oclIsKindOf(Role));
> }
> class ScoredRelation extends MASRelation { abstract }
> {
> attribute score : ecore_0::EFloat[?] = '0' { transient };
> }
> class Achieves extends ScoredRelation
> {
> invariant AchievesDestinationType:
> self.target->forAll(a|a.oclIsKindOf(Goal));
> invariant AchievesSourceType: self.source->forAll(a|a.oclIsKindOf(Role));
> }
> class Possesses extends ScoredRelation
> {
> invariant PossessesDestinationType:
> self.target->forAll(a|a.oclIsKindOf(Capabilities));
> invariant PossessesSourceType: self.source->forAll(a|a.oclIsKindOf(Agent));
> }
> class Role extends MASElement;
> class Goal extends MASElement;
> class Agent extends MASElement;
> class Capabilities extends MASElement;
> }
>
> What I want is to write an OCL that checks for repeated names...
> normally it wold be like:
> self.AllInstances->IsUnique(name); also I tried another thing where the
> OCL comments are...but doesn't work.
> But I want to check for all the children of NamedElement(from Elements
> and Relations untill the end of file), and also there are no instances
> of NamedElement, so I'm having trouble defining this constraint for the
> ecore file and for the Audits in GMF.
>
> Thanks in advance...
Re: OCLs for abstract classes and children [message #652810 is a reply to message #652790] Sun, 06 February 2011 23:19 Go to previous message
Oscar Andres Fajardo F. is currently offline Oscar Andres Fajardo F.
Messages: 10
Registered: February 2011
Location: Colombia
Junior Member
Thank you very much, both of you, you were very helpful and I hope this feature to be implemented very soon so I can do my IsUnique(name) thing...
Previous Topic:Hierarchy cast with oclAsType
Next Topic:Type of variable in "let" not agreeing with oclIsTypeOf/oclAsType
Goto Forum:
  


Current Time: Sat Aug 23 13:34:08 EDT 2014

Powered by FUDForum. Page generated in 0.02324 seconds