Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » [QVTO] Avoiding multiple object creation
[QVTO] Avoiding multiple object creation [message #91769] Wed, 08 October 2008 15:37 Go to next message
Eclipse UserFriend
Originally posted by: mahdider.students.uni-mainz.de

Hello,

I have the following code for creating a mutator for each attribute:

/*
Generates a mutator or setter method for a given attribute.
*/
mapping SIMPLE_UML::UmlAttribute::attribute2Setter() :
SIMPLE_UML::UmlMethod {
name := 'set' + self.name.firstToUpper();
visibility := UmlVisibility::PUBLIC;

-- TODO add parameters.

-- Create a new object, since void is unknown in the incoming model.
classifier := object UmlClassifier {
name := 'void';
};
}

The issue is of course, that this method is being called multiple times
and this will result in multiple "void" classifier instances in the
target model. I played around with var, basically trying to keep a
reference to the created object but it did not really work (syntax wise)
as I expected.

What is a good way to create such instances only once? Or should I
basically check somehow if there is already such an instance in self.
with some resolve() call) and then create the instance only?

Thanks for your help!

Best Regards,
Mahdi D-Manesh
Re: [QVTO] Avoiding multiple object creation [message #91783 is a reply to message #91769] Wed, 08 October 2008 16:16 Go to previous messageGo to next message
Radomil Dvorak is currently offline Radomil DvorakFriend
Messages: 249
Registered: July 2009
Senior Member
Hi Mahdi,

The easiest way to define a singleton is using mapping with no input =

parameters.
If such a mapping is executed, a trace for the mapping call with empty s=
et =

of source
objects is recorded.
Any subsequent call represents a call on the same source objects (empty =
=

set) and
the result is fetched from traces instead of executing the mapping again=
..

See the example bellow:

main() {
var x :=3D map singleVoid();
var y :=3D map singleVoid();
assert fatal (x =3D y);
}

mapping singleVoid() : UML::Classifier {
name :=3D 'void';
}


Another technique could be to check for existing instances in the init {=
} =

section and
eventually assign one of them to the 'result' variable explicitly, thus =
=

limiting a repeated creation.
This might be useful, if you have specific constraints on the number of =
=

instances
to be created. The former way is the simplest for your usecase.

Regards,
/Radek



On Wed, 08 Oct 2008 17:37:26 +0200, Mahdi D-Manesh =

<mahdider@students.uni-mainz.de> wrote:

> Hello,
>
> I have the following code for creating a mutator for each attribute:
>
> /*
> Generates a mutator or setter method for a given attribute.
> */
> mapping SIMPLE_UML::UmlAttribute::attribute2Setter() : =

> SIMPLE_UML::UmlMethod {
> name :=3D 'set' + self.name.firstToUpper();
> visibility :=3D UmlVisibility::PUBLIC;
> =

> -- TODO add parameters.
>
> -- Create a new object, since void is unknown in the incoming model.
> classifier :=3D object UmlClassifier {
> name :=3D 'void';
> };
> }
>
> The issue is of course, that this method is being called multiple time=
s =

> and this will result in multiple "void" classifier instances in the =

> target model. I played around with var, basically trying to keep a =

> reference to the created object but it did not really work (syntax wis=
e) =

> as I expected.
>
> What is a good way to create such instances only once? Or should I =

> basically check somehow if there is already such an instance in self. =
=

> with some resolve() call) and then create the instance only?
>
> Thanks for your help!
>
> Best Regards,
> Mahdi D-Manesh



-- =

Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Re: [QVTO] Avoiding multiple object creation [message #91867 is a reply to message #91783] Thu, 09 October 2008 09:25 Go to previous message
Eclipse UserFriend
Originally posted by: mahdider.students.uni-mainz.de

Radek,

I tried your approach and it works like expected. So I am using the
"singleton" way now. :)

Best Regards,
Mahdi


Radek Dvorak schrieb:
> Hi Mahdi,
>
> The easiest way to define a singleton is using mapping with no input
> parameters.
> If such a mapping is executed, a trace for the mapping call with empty
> set of source
> objects is recorded.
> Any subsequent call represents a call on the same source objects (empty
> set) and
> the result is fetched from traces instead of executing the mapping again.
>
> See the example bellow:
>
> main() {
> var x := map singleVoid();
> var y := map singleVoid();
> assert fatal (x = y);
> }
>
> mapping singleVoid() : UML::Classifier {
> name := 'void';
> }
>
>
> Another technique could be to check for existing instances in the init
> {} section and
> eventually assign one of them to the 'result' variable explicitly, thus
> limiting a repeated creation.
> This might be useful, if you have specific constraints on the number of
> instances
> to be created. The former way is the simplest for your usecase.
>
> Regards,
> /Radek
>
>
>
> On Wed, 08 Oct 2008 17:37:26 +0200, Mahdi D-Manesh
> <mahdider@students.uni-mainz.de> wrote:
>
>> Hello,
>>
>> I have the following code for creating a mutator for each attribute:
>>
>> /*
>> Generates a mutator or setter method for a given attribute.
>> */
>> mapping SIMPLE_UML::UmlAttribute::attribute2Setter() :
>> SIMPLE_UML::UmlMethod {
>> name := 'set' + self.name.firstToUpper();
>> visibility := UmlVisibility::PUBLIC;
>>
>> -- TODO add parameters.
>>
>> -- Create a new object, since void is unknown in the incoming model.
>> classifier := object UmlClassifier {
>> name := 'void';
>> };
>> }
>>
>> The issue is of course, that this method is being called multiple
>> times and this will result in multiple "void" classifier instances in
>> the target model. I played around with var, basically trying to keep a
>> reference to the created object but it did not really work (syntax
>> wise) as I expected.
>>
>> What is a good way to create such instances only once? Or should I
>> basically check somehow if there is already such an instance in self.
>> with some resolve() call) and then create the instance only?
>>
>> Thanks for your help!
>>
>> Best Regards,
>> Mahdi D-Manesh
>
>
>
Previous Topic:[QVTO] Text2Model
Next Topic:[QVTO][ATL] expert in models transformation Job
Goto Forum:
  


Current Time: Thu Dec 26 15:47:33 GMT 2024

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

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

Back to the top