Skip to main content



      Home
Home » Archived » M2M (model-to-model transformation) » [QVTO] Input model parameter '...' is read-only!
[QVTO] Input model parameter '...' is read-only! [message #90911] Wed, 01 October 2008 10:46 Go to next message
Eclipse UserFriend
Originally posted by: mahdider.students.uni-mainz.de

Hello everyone,

this is my first shot on QVTO and I am just trying to get a very basic
transformation working. The code is as follows and takes in an ecore
file with a single package, containing a single class and should write a
second ecore file, basically a copy of it but with changed names.

First here is the code:

------------------------------------------------------------ ----------

-- The metametamodel is ecore.
modeltype ECORE uses "http://www.eclipse.org/emf/2002/Ecore";

-- Transform nice animals to wild animals.
transformation NewTransformation(in nice : ECORE, out ECORE);

main() {
nice.rootObjects()[ECORE::EPackage]->map package2Package();
}

/*
Setup the package so that the postfix is wild.
Also add the nsPrefix and nsURI accordingly.
*/
mapping ECORE::EPackage::package2Package() : ECORE::EPackage {
name := self.name.substringBefore('nice') + 'wild';
nsPrefix := self.name.substringBefore('nice') + 'wild';
nsURI := self.nsURI;

-- Is it legal to perform the next two lines like this?
eSubpackages := self.eSubpackages;
eClassifiers := self.eClassifiers;
}

------------------------------------------------------------ ----------

The main issue arrises in the following line:

eClassifiers := self.eClassifiers;

Eclipse compains:

org.eclipse.m2m.internal.qvt.oml.evaluator.QvtRuntimeExcepti on: Input
model parameter 'nice : NewTransformation::ECORE' is read-only!
at EPackage.package2Package(NewTransformation.qvto:21)
at NewTransformation.main(NewTransformation.qvto:8)
at NewTransformation.<init>(NewTransformation.qvto:7)

Is my assignment of a collection / OrderedSet like this not a valid
transformation?

Kind Regards,
Mahdi
Re: [QVTO] Input model parameter '...' is read-only! [message #90928 is a reply to message #90911] Wed, 01 October 2008 10:56 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: mahdider.students.uni-mainz.de

PS:

I changed some of the code and the EClass gets copied now using an
explicit mapping rule.

My code looks like follows:

------------------------------------------------------------ ----------

mapping ECORE::EPackage::package2Package() : ECORE::EPackage {
name := self.name.substringBefore('nice') + 'wild';
nsPrefix := self.name.substringBefore('nice') + 'wild';
nsURI := self.nsURI;

-- eSubpackages := self.eSubpackages;
eClassifiers := self.eClassifiers[ECORE::EClass]->map
class2Class()->asOrderedSet();
}

mapping ECORE::EClass::class2Class() : ECORE::EClass {
name := 'Wild' + self.name.substringAfter('Nice');

-- TODO copy all data here. Can this be done generic?
}

------------------------------------------------------------ ----------

Maybe someone can comment on this and give some hints if there is a
better / cleaner way of doing it?

An explanation why my first attempt did not work is appreciated.
(eClassifiers := self.eClassifiers;)

Kind Regards,
Mahdi


Mahdi D-Manesh schrieb:
> Hello everyone,
>
> this is my first shot on QVTO and I am just trying to get a very basic
> transformation working. The code is as follows and takes in an ecore
> file with a single package, containing a single class and should write a
> second ecore file, basically a copy of it but with changed names.
>
> First here is the code:
>
> ------------------------------------------------------------ ----------
>
> -- The metametamodel is ecore.
> modeltype ECORE uses "http://www.eclipse.org/emf/2002/Ecore";
>
> -- Transform nice animals to wild animals.
> transformation NewTransformation(in nice : ECORE, out ECORE);
>
> main() {
> nice.rootObjects()[ECORE::EPackage]->map package2Package();
> }
>
> /*
> Setup the package so that the postfix is wild.
> Also add the nsPrefix and nsURI accordingly.
> */
> mapping ECORE::EPackage::package2Package() : ECORE::EPackage {
> name := self.name.substringBefore('nice') + 'wild';
> nsPrefix := self.name.substringBefore('nice') + 'wild';
> nsURI := self.nsURI;
>
> -- Is it legal to perform the next two lines like this?
> eSubpackages := self.eSubpackages;
> eClassifiers := self.eClassifiers;
> }
>
> ------------------------------------------------------------ ----------
>
> The main issue arrises in the following line:
>
> eClassifiers := self.eClassifiers;
>
> Eclipse compains:
>
> org.eclipse.m2m.internal.qvt.oml.evaluator.QvtRuntimeExcepti on: Input
> model parameter 'nice : NewTransformation::ECORE' is read-only!
> at EPackage.package2Package(NewTransformation.qvto:21)
> at NewTransformation.main(NewTransformation.qvto:8)
> at NewTransformation.<init>(NewTransformation.qvto:7)
>
> Is my assignment of a collection / OrderedSet like this not a valid
> transformation?
>
> Kind Regards,
> Mahdi
Re: [QVTO] Input model parameter '...' is read-only! [message #90970 is a reply to message #90928] Wed, 01 October 2008 12:22 Go to previous messageGo to next message
Eclipse UserFriend
Hi Mahdi,

In your original QVT code you tried to assign objects having its contain=
er =

object in the [in] model
which is by definition read-only.
Actually, by this step you have attempted to modify the input model,
as you would change the container of the child objects by the assignment=
=

to containment reference.
Finally, you would also modify the parent, by cutting off his children.
Anyway, I can see I got the point.

To avoid copying manually by creating mappings that assign property by =

property,
you can use deepClone() on you model elements and provide only mappings =
=

that
would do your custom changes.
See example bellow, base on you code sinppet:


-- The metametamodel is ecore.
modeltype ECORE uses "http://www.eclipse.org/emf/2002/Ecore";

-- Transform nice animals to wild animals.
transformation NewTransformation(in nice : ECORE, out ECORE);
=

main() {
nice.rootObjects()[ECORE::EPackage]->map package2Package();
}

/*
Setup the package so that the postfix is wild.
Also add the nsPrefix and nsURI accordingly.
*/
mapping ECORE::EPackage::package2Package() : ECORE::EPackage {
init {
result :=3D self.deepclone().oclAsType(EPackage);
}
=

name :=3D self.name/*.substringBefore('nice')*/ + 'wild';
nsPrefix :=3D self.name/*.substringBefore('nice')*/ + 'wild';
nsURI :=3D self.nsURI;
}

Regards,
/Radek



On Wed, 01 Oct 2008 16:56:30 +0200, Mahdi D-Manesh =

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

> PS:
>
> I changed some of the code and the EClass gets copied now using an =

> explicit mapping rule.
>
> My code looks like follows:
>
> ------------------------------------------------------------ ----------=

>
> mapping ECORE::EPackage::package2Package() : ECORE::EPackage {
> name :=3D self.name.substringBefore('nice') + 'wild';
> nsPrefix :=3D self.name.substringBefore('nice') + 'wild';
> nsURI :=3D self.nsURI;
> =

> -- eSubpackages :=3D self.eSubpackages;
> eClassifiers :=3D self.eClassifiers[ECORE::EClass]->map =

> class2Class()->asOrderedSet();
> }
>
> mapping ECORE::EClass::class2Class() : ECORE::EClass {
> name :=3D 'Wild' + self.name.substringAfter('Nice');
> =

> -- TODO copy all data here. Can this be done generic?
> }
>
> ------------------------------------------------------------ ----------=

>
> Maybe someone can comment on this and give some hints if there is a =

> better / cleaner way of doing it?
>
> An explanation why my first attempt did not work is appreciated.
> (eClassifiers :=3D self.eClassifiers;)
>
> Kind Regards,
> Mahdi
>
>
> Mahdi D-Manesh schrieb:
>> Hello everyone,
>> this is my first shot on QVTO and I am just trying to get a very bas=
ic =

>> transformation working. The code is as follows and takes in an ecore =
=

>> file with a single package, containing a single class and should writ=
e =

>> a second ecore file, basically a copy of it but with changed names.
>> First here is the code:
>> ------------------------------------------------------------ --------=
--
>> -- The metametamodel is ecore.
>> modeltype ECORE uses "http://www.eclipse.org/emf/2002/Ecore";
>> -- Transform nice animals to wild animals.
>> transformation NewTransformation(in nice : ECORE, out ECORE);
>> main() {
>> nice.rootObjects()[ECORE::EPackage]->map package2Package();
>> }
>> /*
>> Setup the package so that the postfix is wild.
>> Also add the nsPrefix and nsURI accordingly.
>> */
>> mapping ECORE::EPackage::package2Package() : ECORE::EPackage {
>> name :=3D self.name.substringBefore('nice') + 'wild';
>> nsPrefix :=3D self.name.substringBefore('nice') + 'wild';
>> nsURI :=3D self.nsURI;
>> -- Is it legal to perform the next two lines like this?
>> eSubpackages :=3D self.eSubpackages;
>> eClassifiers :=3D self.eClassifiers;
>> }
>> ------------------------------------------------------------ --------=
--
>> The main issue arrises in the following line:
>> eClassifiers :=3D self.eClassifiers;
>> Eclipse compains:
>> org.eclipse.m2m.internal.qvt.oml.evaluator.QvtRuntimeExcepti on: Inpu=
t =

>> model parameter 'nice : NewTransformation::ECORE' is read-only!
>> at EPackage.package2Package(NewTransformation.qvto:21)
>> at NewTransformation.main(NewTransformation.qvto:8)
>> at NewTransformation.<init>(NewTransformation.qvto:7)
>> Is my assignment of a collection / OrderedSet like this not a valid =
=

>> transformation?
>> Kind Regards,
>> Mahdi



-- =

Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Re: [QVTO] Input model parameter '...' is read-only! [message #91074 is a reply to message #90970] Thu, 02 October 2008 06:46 Go to previous message
Eclipse UserFriend
Originally posted by: mahdider.students.uni-mainz.de

Hi Radek,

now this was a fast answer thank you a lot!

Of course since I am assigning references, it would make the source
model indirectly "modifyable". I did not think about this at all, too
much concentrating on the syntax I guess... :)

copy() and deepCopy() look like what I need. I found them after I posted
here (in the QVT Specs) but did not try them at that point.

I did now and they work as expected. Very nice.

Kind Regards,
Mahdi


Radek Dvorak schrieb:
> Hi Mahdi,
>
> In your original QVT code you tried to assign objects having its
> container object in the [in] model
> which is by definition read-only.
> Actually, by this step you have attempted to modify the input model,
> as you would change the container of the child objects by the assignment
> to containment reference.
> Finally, you would also modify the parent, by cutting off his children.
> Anyway, I can see I got the point.
>
> To avoid copying manually by creating mappings that assign property by
> property,
> you can use deepClone() on you model elements and provide only mappings
> that
> would do your custom changes.
> See example bellow, base on you code sinppet:
>
>
> -- The metametamodel is ecore.
> modeltype ECORE uses "http://www.eclipse.org/emf/2002/Ecore";
>
> -- Transform nice animals to wild animals.
> transformation NewTransformation(in nice : ECORE, out ECORE);
>
> main() {
> nice.rootObjects()[ECORE::EPackage]->map package2Package();
> }
>
> /*
> Setup the package so that the postfix is wild.
> Also add the nsPrefix and nsURI accordingly.
> */
> mapping ECORE::EPackage::package2Package() : ECORE::EPackage {
> init {
> result := self.deepclone().oclAsType(EPackage);
> }
>
> name := self.name/*.substringBefore('nice')*/ + 'wild';
> nsPrefix := self.name/*.substringBefore('nice')*/ + 'wild';
> nsURI := self.nsURI;
> }
>
> Regards,
> /Radek
>
>
>
> On Wed, 01 Oct 2008 16:56:30 +0200, Mahdi D-Manesh
> <mahdider@students.uni-mainz.de> wrote:
>
>> PS:
>>
>> I changed some of the code and the EClass gets copied now using an
>> explicit mapping rule.
>>
>> My code looks like follows:
>>
>> ------------------------------------------------------------ ----------
>>
>> mapping ECORE::EPackage::package2Package() : ECORE::EPackage {
>> name := self.name.substringBefore('nice') + 'wild';
>> nsPrefix := self.name.substringBefore('nice') + 'wild';
>> nsURI := self.nsURI;
>>
>> -- eSubpackages := self.eSubpackages;
>> eClassifiers := self.eClassifiers[ECORE::EClass]->map
>> class2Class()->asOrderedSet();
>> }
>>
>> mapping ECORE::EClass::class2Class() : ECORE::EClass {
>> name := 'Wild' + self.name.substringAfter('Nice');
>>
>> -- TODO copy all data here. Can this be done generic?
>> }
>>
>> ------------------------------------------------------------ ----------
>>
>> Maybe someone can comment on this and give some hints if there is a
>> better / cleaner way of doing it?
>>
>> An explanation why my first attempt did not work is appreciated.
>> (eClassifiers := self.eClassifiers;)
>>
>> Kind Regards,
>> Mahdi
>>
>>
>> Mahdi D-Manesh schrieb:
>>> Hello everyone,
>>> this is my first shot on QVTO and I am just trying to get a very
>>> basic transformation working. The code is as follows and takes in an
>>> ecore file with a single package, containing a single class and
>>> should write a second ecore file, basically a copy of it but with
>>> changed names.
>>> First here is the code:
>>> ------------------------------------------------------------ ----------
>>> -- The metametamodel is ecore.
>>> modeltype ECORE uses "http://www.eclipse.org/emf/2002/Ecore";
>>> -- Transform nice animals to wild animals.
>>> transformation NewTransformation(in nice : ECORE, out ECORE);
>>> main() {
>>> nice.rootObjects()[ECORE::EPackage]->map package2Package();
>>> }
>>> /*
>>> Setup the package so that the postfix is wild.
>>> Also add the nsPrefix and nsURI accordingly.
>>> */
>>> mapping ECORE::EPackage::package2Package() : ECORE::EPackage {
>>> name := self.name.substringBefore('nice') + 'wild';
>>> nsPrefix := self.name.substringBefore('nice') + 'wild';
>>> nsURI := self.nsURI;
>>> -- Is it legal to perform the next two lines like this?
>>> eSubpackages := self.eSubpackages;
>>> eClassifiers := self.eClassifiers;
>>> }
>>> ------------------------------------------------------------ ----------
>>> The main issue arrises in the following line:
>>> eClassifiers := self.eClassifiers;
>>> Eclipse compains:
>>> org.eclipse.m2m.internal.qvt.oml.evaluator.QvtRuntimeExcepti on:
>>> Input model parameter 'nice : NewTransformation::ECORE' is read-only!
>>> at EPackage.package2Package(NewTransformation.qvto:21)
>>> at NewTransformation.main(NewTransformation.qvto:8)
>>> at NewTransformation.<init>(NewTransformation.qvto:7)
>>> Is my assignment of a collection / OrderedSet like this not a valid
>>> transformation?
>>> Kind Regards,
>>> Mahdi
>
>
>
Previous Topic:Using a Generic MetaClass Name ?!
Next Topic:ATL-self reference into foreach statement
Goto Forum:
  


Current Time: Fri May 09 02:31:58 EDT 2025

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

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

Back to the top