Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » ATL » Mapping one object to multiple
Mapping one object to multiple [message #1373915] Thu, 22 May 2014 11:31 Go to next message
Jonathon Clarke is currently offline Jonathon Clarke
Messages: 4
Registered: May 2014
Junior Member
Hi, I am new to ATL and MDD and I think I am missing something really important with this problem.

I have an object container which has a reference called group to one or more items.

I'm trying to write an in-place transformation that will insert a new item for every item already in a group so the group has twice as many elements than before the transformation is run.

Here is my current approach.

create OUT: source refining IN: source;

helper context source!item def: doSomething() : source!item = 
		 self.refSetValue('interestingValue', 1)
;

helper context source!container def: generateSequence() : Sequence(source!item) =
	 self.group->iterate(e; res: Sequence(source!item) = Sequence{} |
		res->append(e.doSomething())
	)
;
	

rule putNewThingsThere {
	from
		s: source!container
	to
		t: source!container (
			group <- s.generateSequence()
		)
	}


When I run this transformation, the items in group become the new ones, but I would like to retain the old ones as well. Can someone explain how in ATL we create fresh elements for the new model?

Thanks
Re: Mapping one object to multiple [message #1374212 is a reply to message #1373915] Thu, 22 May 2014 14:25 Go to previous messageGo to next message
Hugo Bruneliere is currently offline Hugo Bruneliere
Messages: 607
Registered: July 2009
Senior Member
Hello,

New elements can only be created from the "to" parts of rules.
Doing an in-place transformation, I would do something like:

rule duplicateItems {
     from
          i: source!item
     to
          i1: source!item(), // you don't modify the existing item
          i2: source!item ( // you create a duplicate of this existing item
              group <- i1.container, //assuming that you have a reference from an item to its container called "container"
              name <- i1.name
              //etc.
          )
}


------------------------------------------
Hugo Bruneliere - R&D Engineer
AtlanMod research team (Inria, EMN & LINA)
Ecole des Mines de Nantes
Nantes - France
------------------------------------------
Re: Mapping one object to multiple [message #1374222 is a reply to message #1374212] Thu, 22 May 2014 14:34 Go to previous messageGo to next message
Jonathon Clarke is currently offline Jonathon Clarke
Messages: 4
Registered: May 2014
Junior Member
Thanks a lot!

That's what I needed, it's working now.

And I get it now, it makes sense to do it that way.

[Updated on: Thu, 22 May 2014 14:37]

Report message to a moderator

Re: Mapping one object to multiple [message #1377755 is a reply to message #1374222] Sat, 24 May 2014 01:10 Go to previous messageGo to next message
Jonathon Clarke is currently offline Jonathon Clarke
Messages: 4
Registered: May 2014
Junior Member
Hi, I have come across another problem.

I now have the new objects being created within the same container, but I need to be able to control the order.

If I start with a model which has a container with {A, B C}

My transformation results in {A, B, C, A1, B1, C1}

I have been trying to get it to produce {A, A1, B, B1, C, C1} but I am unsuccessful.

Is there a way to specify that the new elements should be inserted straight after their counterpart?

Thank you.
Re: Mapping one object to multiple [message #1383665 is a reply to message #1377755] Mon, 26 May 2014 13:27 Go to previous messageGo to next message
Jonathon Clarke is currently offline Jonathon Clarke
Messages: 4
Registered: May 2014
Junior Member
I am actually trying to transform xml. Right now I use xslt to transform xml documents into xmi files that conform to my meta-model. Then I process them with ATL and use xslt to transform them back.

So the order in which the nodes appear in the xmi is important, because the final xml document will be affected by that.

I have been looking through the user manual and other threads, but I can't find any mention of this kind of functionality. I haven't been able to come up with a method using the stuff I know either.

Any help at all would be greatly appreciated.

Thanks.
Re: Mapping one object to multiple [message #1383878 is a reply to message #1383665] Mon, 26 May 2014 15:55 Go to previous message
Hugo Bruneliere is currently offline Hugo Bruneliere
Messages: 607
Registered: July 2009
Senior Member
Hello,

EMF is already providing some support to import XML documents as regular EMF models.
You should take a look to this (cf. the EMF documentation and forum).
If needed, you could of course use an additional ATL transformation to perform an eventually required mapping.


------------------------------------------
Hugo Bruneliere - R&D Engineer
AtlanMod research team (Inria, EMN & LINA)
Ecole des Mines de Nantes
Nantes - France
------------------------------------------
Previous Topic:[EMFTVM] What metametamodel I can use?
Next Topic:AM3 installation for ATL Version 3.x
Goto Forum:
  


Current Time: Wed Oct 22 15:42:08 GMT 2014

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

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