Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » ATL : Reference to a target class using a different rule
ATL : Reference to a target class using a different rule [message #722943] Wed, 07 September 2011 05:23 Go to next message
fafanellu  is currently offline fafanellu
Messages: 37
Registered: July 2011
Member
Hello,
I've got a problem with ATL while trying to re-use created classes.

For instance (MMA is the source metamodel, MMB is the target metamodel):

I have one source class, and two target classes. I want to put a reference to the second target class in the first one.

rule R1 {
	from
		cA : MMA!ClassA
	to
		c1 : MMB!Class1 (
			attribute_c1<- c2
                               ....
		),
		c2 : MMB!Class2 ()
}


Here, it is possible to use the created target Class2 reference in the Class1 : attribute_c1 will receive the reference to Class 2.

What if I wanted to do so, using two distinct rules ? Let's imagine, I have two sources classes ClassA and ClassB. Rule R2 is used to instanciate Class2, and rule R1 is used to give to the attribute_c1 a reference to the Class2 instanciated in the R2 rule. How can I express that ?

rule R1 {
	from
		cA : MMA!ClassA
	to
		c1 : MMB!Class1 (
			attribute_c1<- ? (link to Class2 here)
                                   ....
		)
}

rule R2 {
	from
		cB : MMA!ClassB
	to
		c2 : MMB!Class2 ()
}



This time, "c2" will not recognized because it doesn't belong to the same rule. What must I write instead of "?" lol

First solution works, but if there exist n instances of classA in the model, Class2 will be instanciated n times too, while in the second solution, if there is only one instance of ClassB, Class2 will be instanciated only once, then reused with all the attribute_c1 of the instances of ClassA...

Thank you for your help

[Updated on: Wed, 07 September 2011 05:35]

Report message to a moderator

Re: ATL : Reference to a target class using a different rule [message #722961 is a reply to message #722943] Wed, 07 September 2011 06:07 Go to previous messageGo to next message
Sylvain EVEILLARD is currently offline Sylvain EVEILLARD
Messages: 511
Registered: July 2009
Senior Member
How do you access ClassB from ClassA ?

Imagine cA.classB = cB then you'd directly code :
attribute_cl <- cA.classB
Re: ATL : Reference to a target class using a different rule [message #722975 is a reply to message #722961] Wed, 07 September 2011 06:55 Go to previous messageGo to next message
fafanellu  is currently offline fafanellu
Messages: 37
Registered: July 2011
Member
In the source metamodel, there is no link between cA and cB. In the destination metamodel, there is one : Class1 has a reference to Class2 because
attribute_c1<- c2
Actually, I only use cB to instanciate Class2 once.
And with attribute_cl <- cA.classB, the problem is that since cA is not defined in the same rule, it is not recognized !
Thanks

[Updated on: Wed, 07 September 2011 08:02]

Report message to a moderator

Re: ATL : Reference to a target class using a different rule [message #723048 is a reply to message #722975] Wed, 07 September 2011 10:05 Go to previous messageGo to next message
fafanellu  is currently offline fafanellu
Messages: 37
Registered: July 2011
Member
I think I must use thisModule.resolveTemp(...)...but, so far, I didn't manage to get what I want
Re: ATL : Reference to a target class using a different rule [message #723058 is a reply to message #723048] Wed, 07 September 2011 10:26 Go to previous messageGo to next message
Sylvain EVEILLARD is currently offline Sylvain EVEILLARD
Messages: 511
Registered: July 2009
Senior Member
No, what you need is an unique lazy rule since your class B instance doesn't come directly from the input model.
Re: ATL : Reference to a target class using a different rule [message #723064 is a reply to message #723058] Wed, 07 September 2011 10:38 Go to previous messageGo to next message
fafanellu  is currently offline fafanellu
Messages: 37
Registered: July 2011
Member
Thank you for your reply =)
Do you mean that rule R2 must be declared as a lazy rule and called like that : attribute_c1<-thisModule.R2(cB) ?
If I do so, cB can't be recognized

[Updated on: Wed, 07 September 2011 10:38]

Report message to a moderator

Re: ATL : Reference to a target class using a different rule [message #723072 is a reply to message #723064] Wed, 07 September 2011 10:54 Go to previous messageGo to next message
fafanellu  is currently offline fafanellu
Messages: 37
Registered: July 2011
Member
It seems to work when I give MMA!ClassB as a parameter : attribute_c1<-thisModule.R2(MMA!CLassB), but it doesn't if there is a parameter in the Class2 instance :

rule R2 {
	from
		cB : MMA!ClassB
	to
		c2 : MMB!Class2 (
                 parameter<-classB.something)
}
doesn't work.

[Updated on: Wed, 07 September 2011 10:59]

Report message to a moderator

Re: ATL : Reference to a target class using a different rule [message #723102 is a reply to message #723072] Wed, 07 September 2011 12:09 Go to previous messageGo to next message
Sylvain EVEILLARD is currently offline Sylvain EVEILLARD
Messages: 511
Registered: July 2009
Senior Member
You create an instance of Class2 from nothing, what would be the value ?
Re: ATL : Reference to a target class using a different rule [message #723111 is a reply to message #723102] Wed, 07 September 2011 12:39 Go to previous messageGo to next message
fafanellu  is currently offline fafanellu
Messages: 37
Registered: July 2011
Member
In my example, for instance, the parameter was a string. The value could be a litteral string expression like 'test'. Or a string which could come from the source model. It's possible to create a target class "from nothing", using a called rule, a lazu rule or even a match rule. I tried to make a full example, the lazy rule I wrote above doesn't work any more, but I'll try to post it with all the files I'm using, it will be easier =)

[Updated on: Wed, 07 September 2011 12:40]

Report message to a moderator

Re: ATL : Reference to a target class using a different rule [message #723112 is a reply to message #723072] Wed, 07 September 2011 12:41 Go to previous messageGo to next message
fafanellu  is currently offline fafanellu
Messages: 37
Registered: July 2011
Member
I'll try to illustrate my problem providing the files I'm using :

I've two .ecore files, meta1.ecore and meta2.ecore. All the attributes with a A refer to meta1, while those with B refer to meta2.

Here, ModelA can be seen as a container which contains several ClassA.

module _'meta1.ecore'
package Meta1 : Meta1 = 'Meta1'
{
	class ModelA
	{
		property contains : ClassA[*] { ordered composes };
		attribute modelA_name : String[1] { ordered };
	}
	class ClassA
	{
		attribute nameA : String[?] { ordered };
	}
}


The following metamodel is more or less the same as the first one, I've just added to it the ability to handle Types (and I have an abstract Type class, which children are T1 and T2).

module _'meta2.ecore'
package Meta2 : Meta2 = 'Meta2'
{
	abstract class AbstractClass
	{
		property uses_type : Type[1] { ordered };
	}
	class ClassB extends AbstractClass
	{
		attribute nameB : String[?] { ordered };
	}
	class ModelB
	{
		property handles_types : Type[+] { ordered };
		property contains : ClassB[+] { ordered };
		attribute modelB_name : String[1] { ordered };
	}
	abstract class Type;
	class TypeOne extends Type;
	class TypeTwo extends Type;
}


I'm working with this model : ModelA.xmi

<?xml version="1.0" encoding="ASCII"?>
<Meta1:ModelA xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:Meta1="Meta1" xsi:schemaLocation="Meta1 meta1.ecore" modelA_name="this_is_a_model">
  <contains nameA="toto"/>
  <contains nameA="tata"/>
  <contains nameA="titi"/>
</Meta1:ModelA>


My purpose is to create one instance of ModelB, which contains as many classes as there are in the ModelA.xmi (here, 3 instances of ClassA). Each one of those classes must have a name (the same as the source classes) and a type, T1 or T2. Both of those types must instanciated juste once. A suitable target model would look like this :

<?xml version="1.0" encoding="ASCII"?>
<Meta2:ModelB xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:Meta2="Meta2" xsi:schemaLocation="Meta2 meta2.ecore" modelB_name="this_is_a_model">
  <handles_types xsi:type="Meta2:TypeOne"/>
  <handles_types xsi:type="Meta2:TypeTwo"/>
  <contains uses_type="//@handles_types.0" nameB="toto"/>
  <contains uses_type="//@handles_types.0" nameB="tata"/>
  <contains uses_type="//@handles_types.1" nameB="titi"/>
</Meta2:ModelB>


In the following post, I'll show where my problems are.

Re: ATL : Reference to a target class using a different rule [message #723114 is a reply to message #723112] Wed, 07 September 2011 12:54 Go to previous messageGo to next message
Sylvain EVEILLARD is currently offline Sylvain EVEILLARD
Messages: 511
Registered: July 2009
Senior Member
There's no way to know which type each class will get...
Re: ATL : Reference to a target class using a different rule [message #723127 is a reply to message #723114] Wed, 07 September 2011 13:45 Go to previous messageGo to next message
fafanellu  is currently offline fafanellu
Messages: 37
Registered: July 2011
Member
In my example, there is not. In the metamodels I'm working on, there is =)
Re: ATL : Reference to a target class using a different rule [message #723129 is a reply to message #723112] Wed, 07 September 2011 13:50 Go to previous messageGo to next message
fafanellu  is currently offline fafanellu
Messages: 37
Registered: July 2011
Member
-- @path Meta1=/ATL_Test/Meta1.ecore
-- @path Meta2=/ATL_Test/Meta2.ecore
module testATL;
create OUT: meta2 from IN: meta1;


rule M1toM2 {
	from
		mA:meta1!ModelA
	to
		mB:meta2!ModelB(
			modelB_name<-mA.modelA_name
		)
		typesB1:meta2!TypeOne,
		typesB2:meta2!TypeTwo		
}

rule Class2Class {
	from 
		mcA:meta1!ClassA
	to
		mcB:meta2!ClassB(
		nameB<-mcA.nameA
		
		)	
}


gives

<?xml version="1.0" encoding="ISO-8859-1"?>
<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:Meta2="Meta2">
  <Meta2:ModelB modelB_name="this_is_a_model"/>
  <Meta2:TypeOne/>
  <Meta2:TypeTwo/>
  <Meta2:ClassB nameB="toto"/>
  <Meta2:ClassB nameB="tata"/>
  <Meta2:ClassB nameB="titi"/>
</xmi:XMI>


which is far away from what we want. Now, when trying this :

 rule M1toM2 {
	from
		mA:meta1!ModelA
	to
		mB:meta2!ModelB(
			modelB_name<-mA.modelA_name,
			handles_types<-typesB1,
			handles_types<-typesB2,
			contains<-thisModule.ClassA2ClassB(meta1!ModelA)
		),
		typesB1:meta2!TypeOne,
		typesB2:meta2!TypeTwo		
}

 lazy rule ClassA2ClassB {
	from 
		mcA:meta1!ClassA
	to
		mcB:meta2!ClassB(
			nameB<-'test')		
			
}


I get :

<?xml version="1.0" encoding="ISO-8859-1"?>
<Meta2:ModelB xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:Meta2="Meta2" modelB_name="this_is_a_model">
  <handles_types xsi:type="Meta2:TypeOne"/>
  <handles_types xsi:type="Meta2:TypeTwo"/>
  <contains nameB="test"/>
</Meta2:ModelB>


Here, the problems are :
1) My source is ModelA, modelA is unique, so it creates only one matching target classB...but I want to have as many classB as classA
2)If I only write in the lazy rule mcB:meta2!ClassB(), "contains" relation exists, but has no reference to any class.
3)If I don't use a litteral final value for the class B name but a reference to an attribute, i.e. I use : nameB<-mcA.nameA, I get this error :
org.eclipse.m2m.atl.engine.vm.VMException: Feature nameA does not exist on MOF!EClass
at A.ClassA2ClassB(1 : Mmeta1!ClassA;) : ??#26(testATL.atl[26:11-26:20])
local variables = {mcB=OUT!<unnamed>, mcA=meta1!ModelA, self=testATL : ASMModule}
local stack = [OUT!<unnamed>, OUT!<unnamed>, testATL : ASMModule]

[Updated on: Wed, 07 September 2011 17:50]

Report message to a moderator

Re: ATL : Reference to a target class using a different rule [message #723343 is a reply to message #723129] Thu, 08 September 2011 07:35 Go to previous message
fafanellu  is currently offline fafanellu
Messages: 37
Registered: July 2011
Member
Partially solved...


-- @path Meta1=/ATL_Test/Meta1.ecore
-- @path Meta2=/ATL_Test/Meta2.ecore
module testATL;
create OUT: meta2 from IN: meta1;


rule M1toM2 {
	from
		mA:meta1!ModelA
	to
		mB:meta2!ModelB(
			modelB_name<-mA.modelA_name,
			handles_types<-typesB1,
			handles_types<-typesB2,
			--contains<-thisModule.ClassA2ClassB(meta1!ClassA)
			contains <- mA.contains-> collect(e | thisModule.ClassA2ClassB(e))
		),
		typesB1:meta2!TypeOne,
		typesB2:meta2!TypeTwo		
}

 lazy rule ClassA2ClassB {
	from 
		mcA:meta1!ClassA
	to
		mcB:meta2!ClassB(
			nameB<-mcA.nameA,
			uses_type<-meta2!TypeOne --orTypeTwo
			)		
			
}


gives

<?xml version="1.0" encoding="ISO-8859-1"?>
<Meta2:ModelB xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:Meta2="Meta2" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" modelB_name="this_is_a_model">
  <handles_types xsi:type="Meta2:TypeOne"/>
  <handles_types xsi:type="Meta2:TypeTwo"/>
  <contains nameB="toto">
    <uses_type xsi:type="ecore:EClass" href="meta2.ecore#//TypeOne"/>
  </contains>
  <contains nameB="tata">
    <uses_type xsi:type="ecore:EClass" href="meta2.ecore#//TypeOne"/>
  </contains>
  <contains nameB="titi">
    <uses_type xsi:type="ecore:EClass" href="meta2.ecore#//TypeOne"/>
  </contains>
</Meta2:ModelB>


which is quite similar to the result I was expecting :

<?xml version="1.0" encoding="ASCII"?>
<Meta2:ModelB xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:Meta2="Meta2" xsi:schemaLocation="Meta2 meta2.ecore" modelB_name="this_is_a_model">
  <handles_types xsi:type="Meta2:TypeOne"/>
  <handles_types xsi:type="Meta2:TypeTwo"/>
  <contains uses_type="//@handles_types.0" nameB="toto"/>
  <contains uses_type="//@handles_types.0" nameB="tata"/>
  <contains uses_type="//@handles_types.1" nameB="titi"/>
</Meta2:ModelB>


even if in the former the "uses_type" reference doesn't open new XMI tags, while in the latter it does...
Previous Topic:[QVT] Replacing entities in a transformation
Next Topic:[QVTo] UML Stereotypes application not set when launching transformation from Java
Goto Forum:
  


Current Time: Wed Apr 16 06:47:50 EDT 2014

Powered by FUDForum. Page generated in 0.07784 seconds