Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » [ATL] Catch and modify existing object in target model
[ATL] Catch and modify existing object in target model [message #673426] Mon, 23 May 2011 15:40
Patrick Schmitt is currently offline Patrick SchmittFriend
Messages: 87
Registered: July 2009
Hello guys,

I have a small ATL algorythm which is creating "Distributor" objects in a target model. The algorythm checks if no "Distributor" object with the same name already exists, just in that case a new "Distributor" object is created.

For the case the "Ditributor" object already exists I have to add children to it(if the object not exists this add is normally done in the lazy rule during its creation).

Here is my small commented algorythm, i hope u understand it and can give me a hint.

rule RootElement {
		s : A!Product
		t : B!BCModel	(
			        -- add a category and pass all references to its rule
					categories <- thisModule.addArmature(s.references.asOrderedSet())

lazy rule addArmature{
		s : OrderedSet(A!PartReference)
		t : B!Category(
			name <- 'Armature',
			-- here we add distributors with a helper 
			-- to avoid adding distributors with same name twice
			distributors <- thisModule.fetchDistributors(s)

lazy rule addDistri{
		s : A!PartReference
		t : B!Distributor( 
			name <- s.part.distributor,
			blocks <- thisModule.addBlock(s)

lazy rule addBlock{
		s : A!PartReference
		t : B!PartBlock( 
			name <-,
			price <- s.part.cost * s.amount -- calc proper price

helper def : fetchDistributors(refs : OrderedSet(A!PartReference)) : OrderedSet(B!Distributor) =
	refs->iterate(e ; retValue : OrderedSet(B!Distributor) = OrderedSet{} | 
			if e.part = OclUndefined 
				then retValue 
				if e.part.distributorExists(retValue).oclIsTypeOf(B!Distributor) = false
					then retValue.append(thisModule.addDistri(e)) 
					-- how to catch the existing distributor 
					-- and add a Partblock(how its done in addBlock rule) 
					-- with information of the iterator ???
-- this helper return OclUndefined if distributor does not exist, else the distributor instance
helper context A!Part def: distributorExists(distris : OrderedSet(B!Distributor)) : B!Distributor =
			distris->iterate(e; retValue : B!Distributor = OclUndefined |
			if = self.distributor
				then e

[Updated on: Mon, 23 May 2011 15:54]

Report message to a moderator

Previous Topic:[ATL] copy of an entire class diagram
Next Topic:[ATL]
Goto Forum:

Current Time: Sun Feb 28 14:06:44 GMT 2021

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

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

Back to the top