Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » [QVTo] confused
[QVTo] confused [message #696974] Fri, 15 July 2011 04:39 Go to next message
Wilbert Alberts is currently offline Wilbert Alberts
Messages: 74
Registered: June 2010
Member
Hi,

I created a metamodel consisting of a class called Population which contains a number of Users, Items and Matches.

The model is expected to hold Users and Items at first. Matches should be generated by the following transformation.

modeltype RZH uses Ruilen('http://ruilenzonderhuilen.com');

transformation GenerateMatches(inout mdl: RZH);

main() {
	log('size:',  mdl->objectsOfType(Population)->size());
	log('size:',  mdl->objects()[Population]->size());
	log('size:',  mdl.objectsOfType(Population)->size());
	log('size:',  mdl.objects()[Population]->size());
	log('mdl', mdl);
	mdl.objectsOfType(RZH::Population).map genMatches();
}

helper createMatch(in usr1: User, in usr2: User) : Match
{
	log('Creating Match of ' + usr1.id + ' and' + usr2.id);
	return object Match {
		u1 := usr1;
		u2 := usr2;
	}
}

mapping inout Population::genMatches() : Population {
	init {
		self.matches := Set{};
	}
	population {
		log('Generating matches');
		self.matches := self.users -> collect(u1 | self.users->collect(u2 | createMatch(u1, u2)))
	}
}


I'm having troubles understanding the behavior of the objects[], objectsOfType with and without combinations of '.' and '->'.

The model I use for testing consists of one (root) instance of Population (with a number of Users). When I run the transformation, it prints:

size:, data: 1
size:, data: 0
size:, data: 0
size:, data: 0
mdl, data: RZH - http://ruilenzonderhuilen.com

Somehow, the genMatches mapping isn't invoked at all. What am I doing wrong?

Greetings,
Wilbert.

Re: [QVTo] confused [message #697031 is a reply to message #696974] Fri, 15 July 2011 06:47 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 3844
Registered: July 2009
Senior Member
Hi Wilbert

"Somehow, the genMatches mapping isn't invoked at all. What am I doing
wrong? "

You're not using the one you found worked.

One day the specification may make the following more explicit:

object . feature => object navigation
collection -> feature => collection navigation

collection . feature => collection -> collect( feature )
object -> feature => object . oclAsSet() -> feature

OclAny::oclAsSet() => Set{ self }
OclVoid::oclAsSet() => Set{}
OclInvalid::oclAsSet() => invalid

Regards

Ed Willink


On 15/07/2011 09:39, Wilbert Alberts wrote:
> Hi,
>
> I created a metamodel consisting of a class called Population which
> contains a number of Users, Items and Matches.
>
> The model is expected to hold Users and Items at first. Matches should
> be generated by the following transformation.
>
> modeltype RZH uses Ruilen('http://ruilenzonderhuilen.com');
>
> transformation GenerateMatches(inout mdl: RZH);
>
> main() {
> log('size:', mdl->objectsOfType(Population)->size());
> log('size:', mdl->objects()[Population]->size());
> log('size:', mdl.objectsOfType(Population)->size());
> log('size:', mdl.objects()[Population]->size());
> log('mdl', mdl);
> mdl.objectsOfType(RZH::Population).map genMatches();
> }
>
> helper createMatch(in usr1: User, in usr2: User) : Match
> {
> log('Creating Match of ' + usr1.id + ' and' + usr2.id);
> return object Match {
> u1 := usr1;
> u2 := usr2;
> }
> }
>
> mapping inout Population::genMatches() : Population {
> init {
> self.matches := Set{};
> }
> population {
> log('Generating matches');
> self.matches := self.users -> collect(u1 |
> self.users->collect(u2 | createMatch(u1, u2)))
> }
> }
>
> I'm having troubles understanding the behavior of the objects[],
> objectsOfType with and without combinations of '.' and '->'.
>
> The model I use for testing consists of one (root) instance of
> Population (with a number of Users). When I run the transformation, it
> prints:
>
> size:, data: 1
> size:, data: 0
> size:, data: 0
> size:, data: 0
> mdl, data: RZH - http://ruilenzonderhuilen.com
>
> Somehow, the genMatches mapping isn't invoked at all. What am I doing
> wrong?
>
> Greetings,
> Wilbert.
>
>
Re: [QVTo] confused [message #697063 is a reply to message #697031] Fri, 15 July 2011 08:55 Go to previous message
Wilbert Alberts is currently offline Wilbert Alberts
Messages: 74
Registered: June 2010
Member
Hi Edward,

Thanks for the explanation.

Actually the problem turned out to be something different. As I tried to deploy the metamodel in my development eclipse instance, I ended up having two versions of the meta model present: one as a plugin and one as a project. Removing the plugin (which I installed in the dropins directory) and keeping the one in the workspace solved the problem. My transformation was correct after all.

Greetings,
Wilbert.
Previous Topic:[ATL] Allow inter-model references programmatically
Next Topic:[QVTd] What is the status of the project?
Goto Forum:
  


Current Time: Sun Apr 20 12:19:16 EDT 2014

Powered by FUDForum. Page generated in 0.02674 seconds