Home » Modeling » OCL » Checking whether "self" is a reference of it's "container"
Checking whether "self" is a reference of it's "container" [message #42386] 
Wed, 31 October 2007 20:48 

Originally posted by: marco.pantel.unibw.de
Good morning!
I've been trying to find a solution to my problem for a while now but I
just can't find it...
Imagine the following situation in my ecore:
an EClass, e.g. "Calculation", contains two EReferences, let's say
"function" and "argument".
Another EClass, "Variable", which can be each of these references has
got an oclconstraint.
Though the constraint should not be active when Variable acts as
"function", I wanted to check, if the "argument" of the container
(=Calculation) of Variable is the Variable itself.
My first approach was something like "self.container.argument=self" but
that is neither beautiful nor did it work... ;)
Can anybody help me?
Regards, Marco



Re: Checking whether "self" is a reference of it's "container" [message #42541 is a reply to message #42386] 
Thu, 01 November 2007 10:28 

Originally posted by: cdamus.ca.ibm.com
Hi, Marco,
If you have a container reference defined from Variable to Calculation
(i.e., an EReference whose eOpposite is the containment EReference from
Calculation to Variable), then you will be able to do what you need.
So, if you have
EClass Calculation
EReference variable : Variable [0..*]
{isContainment}
{eOpposite = Variable::calculation}
EClass Variable
EReference calculation : Calculation [0..1]
{eOpposite = Calculation::variable}
then you can do
self.calculation.argument = self
in the context of the Variable EClass.
Of course, if and when https://bugs.eclipse.org/bugs/show_bug.cgi?id=152003
is implemented (which is more feasible now that we have the newinM3
support for OCL parser warnings and problem options), you would be able to
do
self.eContainer().oclIsKindOf(Calculation) and
self.eContainer().oclAsType(Calculation).argument = self
which is more ugly anyway. :)
HTH,
Christian
Marco Pantel wrote:
> Good morning!
>
> I've been trying to find a solution to my problem for a while now but I
> just can't find it...
>
> Imagine the following situation in my ecore:
>
> an EClass, e.g. "Calculation", contains two EReferences, let's say
> "function" and "argument".
> Another EClass, "Variable", which can be each of these references has
> got an oclconstraint.
> Though the constraint should not be active when Variable acts as
> "function", I wanted to check, if the "argument" of the container
> (=Calculation) of Variable is the Variable itself.
> My first approach was something like "self.container.argument=self" but
> that is neither beautiful nor did it work... ;)
>
> Can anybody help me?
>
>
> Regards, Marco



Goto Forum:
Current Time: Tue Jul 29 15:08:55 EDT 2014
Powered by FUDForum. Page generated in 0.01465 seconds
