Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Traversing from child to parent in derived relation
Traversing from child to parent in derived relation [message #878946] Wed, 30 May 2012 08:54 Go to next message
ModelGeek Mising name is currently offline ModelGeek Mising nameFriend
Messages: 550
Registered: June 2011
Senior Member
Hi,

I have observed that it is not possible to traverse from child to parent in derived realtion even though opposites are mentioned on both sides.

Example :
parent.child works fine
child.parent does not work


Any reason for that?

Cheers,
Re: Traversing from child to parent in derived relation [message #878969 is a reply to message #878946] Wed, 30 May 2012 09:31 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

It should work. Since you provide no context for your code and no
indications of the tooling in use it is difficult to comment further.

There are far too many possible user errors for me to try guessing.

Regards

Ed Willink


On 30/05/2012 09:54, ModelGeek Mising name wrote:
> Hi,
>
> I have observed that it is not possible to traverse from child to
> parent in derived realtion even though opposites are mentioned on both
> sides.
>
> Example :
> parent.child works fine
> child.parent does not work
>
>
> Any reason for that?
>
> Cheers,
Re: Traversing from child to parent in derived relation [message #879030 is a reply to message #878969] Wed, 30 May 2012 11:43 Go to previous messageGo to next message
ModelGeek Mising name is currently offline ModelGeek Mising nameFriend
Messages: 550
Registered: June 2011
Senior Member
Hi,

here comes an example

there are 3 classes ClassA, ClassB, ClassC. ClassA is directly connected ith ClassB and ClassC but ClassC and ClassB are connected through derived relation.

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

package temp : EAAT = 'http://www.eclipse.org/mdt/ocl/oclinecore/tutorial'
{
class ClassA
{
attribute ID : ecore::ELongObject { ordered };
attribute name : String { ordered };
property classB#classA : ClassB[*] { composes };
property classC#classA : ClassC[*] { volatile composes };
}
class ClassB
{
attribute ID : ecore::ELongObject { ordered };
attribute name : String { ordered };
property classA#classB : ClassA[?] { ordered };
property classC#classB : ClassC[*] { ordered derived composes }
{
derivation: classA.classC->asOrderedSet();
}
}
class ClassC
{
attribute ID : ecore::ELongObject { ordered };
attribute name : String { ordered };
property classA#classC : ClassA[?] { ordered };
property classB#classC : ClassB[?] { ordered };
}
}

now if you take a dynamic instance of ClassA and add one instance of both ClassB and ClassC as child. Now you can use OCL Console and use ClassB's object as context.
Now self.classC statement will return you instance of ClassC but if you make ClassC's object as context in OCL Console and evaluate self.classB then it will not return anything. (Used Eclipse Juno). Even in UI you chould classB's object is holding ClassC's object in property classC but ClassC's object does not have ClassB's Object.

Even i have tried by removing "composes" in ClassB's derived property but same problem
property classC#classB : ClassC[*] { ordered derived}

[Updated on: Wed, 30 May 2012 11:48]

Report message to a moderator

Re: Traversing from child to parent in derived relation [message #879065 is a reply to message #879030] Wed, 30 May 2012 13:00 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Thanks for another test case for the Complete OCL tutorial I'm
struggling to get done for Juno.

I already knew that Ecore gave poor diagnosis of derivation + !transient
+ !volatile.

You've come up with a new 'nonsense' composes + derivation.

Composition is a well-defined built-in modeling relationship. Attempting
to redefine it is not going to be a good idea.

That said you get no result because the absence of transient/volatile
ensures that EMF generates a cached value that is used instead of your
OCL expression.

Regards

Ed Willink

On 30/05/2012 12:43, ModelGeek Mising name wrote:
> Hi,
>
> here comes an example
>
> there are 3 classes ClassA, ClassB, ClassC. ClassA is directly
> connected ith ClassB and ClassC but ClassC and ClassB are connected
> through derived relation.
>
> import ecore : 'http://www.eclipse.org/emf/2002/Ecore#/';
>
> package temp : EAAT =
> 'http://www.eclipse.org/mdt/ocl/oclinecore/tutorial'
> {
> class ClassA
> {
> attribute ID : ecore::ELongObject { ordered };
> attribute name : String { ordered };
> property classB#classA : ClassB[*] { composes };
> property classC#classA : ClassC[*] { volatile composes };
> }
> class ClassB
> {
> attribute ID : ecore::ELongObject { ordered };
> attribute name : String { ordered };
> property classA#classB : ClassA[?] { ordered };
> property classC#classB : ClassC[*] { ordered derived composes }
> {
> derivation: classA.classC->asOrderedSet();
> }
> }
> class ClassC
> {
> attribute ID : ecore::ELongObject { ordered };
> attribute name : String { ordered };
> property classA#classC : ClassA[?] { ordered };
> property classB#classC : ClassB[?] { ordered };
> }
> }
>
> now if you take a dynamic instance of ClassA and add one instance of
> both ClassB and ClassC as child. Now you can use OCL Console and use
> ClassB's object as context.
> Now self.classC statement will return you instance of ClassC but if
> you make ClassC's object as context in OCL Console and evaluate
> self.classB then it will not return anything. (Used Eclipse Juno).
> Even in UI you chould classB's object is holding ClassC's object in
> property classC but ClassC's object does not have ClassB's Object.
Re: Traversing from child to parent in derived relation [message #879089 is a reply to message #879065] Wed, 30 May 2012 13:50 Go to previous messageGo to next message
ModelGeek Mising name is currently offline ModelGeek Mising nameFriend
Messages: 550
Registered: June 2011
Senior Member
Hi,

Yes you are right about its not logical to use derived + composes thats why i wrote the last line of my original post.

I have tried to use transient/volatile earlier but it does not work.

Do you have any idea about this problem?

thanks for help!

Cheers,
Re: Traversing from child to parent in derived relation [message #879102 is a reply to message #879089] Wed, 30 May 2012 14:06 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

It seems that a simple initial problem has grown through incorrect
approaches. What are you actually trying to do?

Regards

Ed Willink


On 30/05/2012 14:50, ModelGeek Mising name wrote:
> Hi,
>
> Yes you are right about its not logical to use derived + composes
> thats why i wrote the last line of my original post.
>
> I have tried to use transient/volatile earlier but it does not work.
> Do you have any idea about this problem?
>
> thanks for help!
>
> Cheers,
Re: Traversing from child to parent in derived relation [message #879112 is a reply to message #879102] Wed, 30 May 2012 14:35 Go to previous messageGo to next message
ModelGeek Mising name is currently offline ModelGeek Mising nameFriend
Messages: 550
Registered: June 2011
Senior Member
Hi,

I would like to be able to traverse from child class to parent. In my situation i need to traverse using derived relation so traversing can be from parent to child or child to parent.

Is it supported?

Thanks for help!

Re: Traversing from child to parent in derived relation [message #879117 is a reply to message #879112] Wed, 30 May 2012 14:43 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Your terminology is very confusing. I';ve no idea why you need a derived
relation (whatever that might be) to do

package temp : EAAT = 'http://xxxx'
{
class Parent
{
property child#parent : Child { composes };
}
class Child
{
property parent#child : Parent[?];
}

Regards

Ed Willink


On 30/05/2012 15:35, ModelGeek Mising name wrote:
> Hi,
>
> I would like to be able to traverse from child class to parent. In my
> situation i need to traverse using derived relation so traversing can
> be from parent to child or child to parent.
>
> Is it supported?
>
> Thanks for help!
>
>
Re: Traversing from child to parent in derived relation [message #879142 is a reply to message #879117] Wed, 30 May 2012 15:41 Go to previous messageGo to next message
ModelGeek Mising name is currently offline ModelGeek Mising nameFriend
Messages: 550
Registered: June 2011
Senior Member
Actually i have a derived boolean attribute and its derived statement tries to traverse through number of relations to find a specific object and it might need to traverse using derived relation(from child to parent) and that is where it is unable to do that. In case of parent to child(derived realtion) is works fine.

The example you have written is not for derived relation.
In my earlier example, i want to traverse from ClassC(child) to ClassB(parent).

Derived Relation = Derived Property
property classC#classB : ClassC[*] { ordered derived }
{
derivation: classA.classC->asOrderedSet();
}


Hope i have explained it better this time.

thanks alot for support.

Cheers

[Updated on: Wed, 30 May 2012 15:42]

Report message to a moderator

Re: Traversing from child to parent in derived relation [message #879148 is a reply to message #879142] Wed, 30 May 2012 15:45 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

I still do not know what you mean by a "derived relation" is and I'm not
going to waste my time and create more confusion by guessing. UML has
relationships. QVT has relations. But what has this to do with Ecore;
you've yet to ask anything that is actually to do with OCL at all.

Regards

Ed Willink


On 30/05/2012 16:41, ModelGeek Mising name wrote:
>
> Actually i have a derived boolean attribute and its derived statement
> tries to traverse through number of relations to find a specific
> object and it might need to traverse using derived relation(from child
> to parent) and that is where it is unable to do that. In case of
> parent to child(derived realtion) is works fine.
>
> The example you have written is not for derived relation.
> In my earlier example, i want to traverse from ClassC(child) to
> ClassB(parent).
>
>
> Hope i have explained it better this time.
>
> thanks alot for support.
>
> Cheers
Re: Traversing from child to parent in derived relation [message #879151 is a reply to message #879148] Wed, 30 May 2012 16:03 Go to previous messageGo to next message
ModelGeek Mising name is currently offline ModelGeek Mising nameFriend
Messages: 550
Registered: June 2011
Senior Member
I guess i was not able to explain it properly.

Derived Relation means Property which is derived using derivation statement.
like

class ClassB {
property classC#classB : ClassC[*] { ordered derived }
{ derivation: classA.classC->asOrderedSet(); }
}
In this example i consider ClassB as parent and ClassC as child.

Actually i am creating and Ecore and trying to instantiate that.

Thanks alot for help and support.

Cheers,
Re: Traversing from child to parent in derived relation [message #879158 is a reply to message #879151] Wed, 30 May 2012 16:17 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Ok. I now know that "derived relation" means derived property. But I
still don't know what you're trying to derive.

I can only observe that your examples consistently refuse to use the
important transient and volatile keywords.

Regards

Ed Willink


On 30/05/2012 17:03, ModelGeek Mising name wrote:
> I guess i was not able to explain it properly.
>
> Derived Relation means Property which is derived using derivation
> statement.
> like
> class ClassB {
> property classC#classB : ClassC[*] { ordered derived }
> { derivation: classA.classC->asOrderedSet(); }
> }
> In this example i consider ClassB as parent and ClassC as child.
>
> Actually i am creating and Ecore and trying to instantiate that.
>
> Thanks alot for help and support.
>
> Cheers,
>
Re: Traversing from child to parent in derived relation [message #879181 is a reply to message #879158] Wed, 30 May 2012 17:17 Go to previous messageGo to next message
ModelGeek Mising name is currently offline ModelGeek Mising nameFriend
Messages: 550
Registered: June 2011
Senior Member
Actually i have tried trasient and volatile keyboards but it does not work.

Amy idea ?

Thanks alot!
Re: Traversing from child to parent in derived relation [message #879195 is a reply to message #879181] Wed, 30 May 2012 17:59 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

If I knew what you were trying to do, I might be able to help.

Provide an example and a clear statement of what is not working.

Regards

Ed Willink


On 30/05/2012 18:17, ModelGeek Mising name wrote:
> Actually i have tried trasient and volatile keyboards but it does not
> work.
>
> Amy idea ?
>
> Thanks alot!
Re: Traversing from child to parent in derived relation [message #879436 is a reply to message #879195] Thu, 31 May 2012 08:11 Go to previous messageGo to next message
ModelGeek Mising name is currently offline ModelGeek Mising nameFriend
Messages: 550
Registered: June 2011
Senior Member
My problem is to access parent end of derived property from child end.

In this given example i consider ClassB as parent, ClassC as child.
ClassB has a derived property classC and ClassC contains its opposite property classB. In non derived property, you can traverse from both ends (as we mentioned opposite). But in case of derived property, even though we mention opposites but to navigate from child to parent does not seem to be possible.

Here i am giving example. I have added volatite, if you want to add transient you can also try with that.

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

package temp : Test = 'http://www.eclipse.org/mdt/ocl/oclinecore/tutorial'
{
class ClassA
{
attribute ID : ecore::ELongObject { ordered };
attribute name : String { ordered };
property classB#classA : ClassB[*] { composes };
property classC#classA : ClassC[*] { volatile composes };
}
class ClassB
{
attribute ID : ecore::ELongObject { ordered };
attribute name : String { ordered };
property classA#classB : ClassA[?] { ordered };
property classC#classB : ClassC[*] { ordered derived volatile }
{
derivation: classA.classC->asOrderedSet();
}

}
class ClassC
{
attribute ID : ecore::ELongObject { ordered };
attribute name : String { ordered };
property classA#classC : ClassA[?] { ordered };
property classB#classC : ClassB[?] { ordered volatile };
}
}

Now i would try to use terminologies used by Eclipse GUI.
Create this ecore file and open it with Sample Ecore Model Editor. Right Click on ClassA and select create dynamic instance. Open xmi file. Right Click ClassA's Object and select new child -> Class B.
Again right click on ClassA's Object and select new Child->Class C

Now open OCL Console and select ClassB's Object as context and evaluate command "self.classC". It will show you classC' object. Now change the evaluation context to ClassC's Object and and evaluate command "self.classB". This command will not return any thing. This is my problem. I am expecting ClassB's Object in result.

Thanks for help!

Cheers,


Re: Traversing from child to parent in derived relation [message #879475 is a reply to message #879436] Thu, 31 May 2012 09:37 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Great. I finally grasp the problem. You've given me another stupid case
for my Complete OCL tutorial.

Opposite properties are a facility defined by the UML specification and
realised by EMOF and Ecore. The Ecore realisation uses an
EReference.eOpposite. A double opposite navigation should be an identity
navigation and the built-in realisation using non-derived behaviour does
this. When you specify a derived algorithm, you take control.

You are using an algorithmic definition of the forward property. OCL is
side effect free, so there is some scope for analyzing the forward
algorithm to deduce its inverse. However asOrderedSet() is not
monotonic, it is difficult (probably impossible) to determine how many
candidates were present when a unique one was selected for the Set. So
automated support for OCL defined opposites is going to need non-trivial
symbolic analysis/global model search, which isn't going to be available
any time soon.

So if you define a derived property, with an opposite, it is your
responsibility to provide a derived opposite property too.

Therefore in

property classC#classB : ClassC[*] { ordered derived volatile }
{
derivation: classA.classC->asOrderedSet();
}
....
property classB#classC : ClassB[?] { ordered volatile };

you have two errors:

a) already mentioned; you should use "transient" too

b) The missing opposite OCL derivation should be diagnosed.

The solution to your problem is to define two derived algorithms.

property classC#classB : ClassC[*] { ordered derived transient volatile }
{
derivation: classA.classC->asOrderedSet();
}
....
property classB#classC : ClassB[?] { ordered derived transient volatile };
{
derivation: some-inverse-algorithm;
}

and possibly an invariant for class B

invariant ConsistentOpposite: let doubleOpposites : Set(ClassC) =
classC.classB->asSet() in doubleOpposites->forAll(b | b = self);

If you open your Ecore file with the Sample Ecore Editor, and use Load
Complete OCL Resource to load the attached Complete OCL document, and
Validate, you will get diagnosis of many of the unwise things that can
be attempted with OCL derivation.

This assumes you are using a recent Juno build:
M6 for Load Complete OCL Resource
RC2 for DND of Complete OCL Document
RC3 for Load Complete OCL Resource into OCLinEcore and Papyrus editors

Regards

Ed Willink


On 31/05/2012 09:11, ModelGeek Mising name wrote:
> import ecore : 'http://www.eclipse.org/emf/2002/Ecore#/';
>
> package temp : Test =
> 'http://www.eclipse.org/mdt/ocl/oclinecore/tutorial'
> {
> class ClassA
> {
> attribute ID : ecore::ELongObject { ordered };
> attribute name : String { ordered };
> property classB#classA : ClassB[*] { composes };
> property classC#classA : ClassC[*] { volatile composes };
> }
> class ClassB
> {
> attribute ID : ecore::ELongObject { ordered };
> attribute name : String { ordered };
> property classA#classB : ClassA[?] { ordered };
> property classC#classB : ClassC[*] { ordered derived volatile }
> {
> derivation: classA.classC->asOrderedSet();
> }
> }
> class ClassC
> {
> attribute ID : ecore::ELongObject { ordered };
> attribute name : String { ordered };
> property classA#classC : ClassA[?] { ordered };
> property classB#classC : ClassB[?] { ordered volatile };
> }
> }


/**
* <copyright>
*
* Copyright (c) 2012 E.D.Willink and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* E.D.Willink - Initial API and implementation
*
* </copyright>
*
* This file provides additional validation constraints for use of OCL embedded in Ecore.
*/
import ecore : 'http://www.eclipse.org/emf/2002/Ecore#/'

package ecore

context EModelElement
/**
* Declare a helper operation to map an ok/warning verdict to ok/error.
*/
def: asError(verdict : Boolean) : Boolean = if verdict then true else null endif

/**
* Extra validation for EReference and EAttribute.
*/
context EStructuralFeature

/**
* Declare a helper property to determine whether an EStructuralFeature has an OCL derivation.
*/
def: hasDerivation : Boolean = eAnnotations->select(source.startsWith('http://www.eclipse.org/emf/2002/Ecore/OCL'))->notEmpty()

/**
* If a feature has an OCL derivation, it should be transient; otherwise it is not executed.
*/
inv DerivationIsTransient: hasDerivation implies transient

/**
* If a feature has an OCL derivation, it must be volatile; otherwise the cached value suppresses execution.
*/
inv DerivationIsVolatile: asError(hasDerivation implies volatile)

/**
* If a feature has an OCL derivation, it should not also have a default value.
*/
inv DerivationIsUninitialized: hasDerivation implies defaultValue.oclIsUndefined()

/**
* Extra validation for just EReference.
*/
context EReference

/**
* If a feature has an OCL derivation, it should not compete with built-in containment.
*/
inv DerivationIsNotComposed: asError(hasDerivation implies not containment)

/**
* If a feature has an OCL derivation, it should be not waste time resolving proxies.
*/
inv DerivationDoesNotResolveProxies: hasDerivation implies not resolveProxies

/**
* If a feature has an OCL derivation and an opposite, the opposite should also have an OCL derivation
*/
inv DerivationWithOppositeHasOppositeDerivation: hasDerivation and eOpposite <> null implies eOpposite.hasDerivation

endpackage
Re: Traversing from child to parent in derived relation [message #879487 is a reply to message #879475] Thu, 31 May 2012 09:58 Go to previous message
ModelGeek Mising name is currently offline ModelGeek Mising nameFriend
Messages: 550
Registered: June 2011
Senior Member
Thank you so much
Previous Topic:Initialize resourceSet
Next Topic:Ocl expressions
Goto Forum:
  


Current Time: Thu Mar 28 11:54:34 GMT 2024

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

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

Back to the top