Home » Archived » M2M (model-to-model transformation) » [QVTO] Iteration over collection
[QVTO] Iteration over collection [message #82474] |
Wed, 28 May 2008 10:59 |
Eclipse User |
|
|
|
Hello,
I am evaluating QVTO. I want to transform a UML model with different
elements (Class,Subclass, Activity, Statemachine elements) into another
UML model.
The hierarchical structure of the source model should be remained.
Therefore I want to iterate over "ownedElement" Collection of UML::Model.
Unfortunately I don't know how to iterate correctly.
The command "forEach" seems to be unimplemented,yet.
So I tried with "iterate". But it has some syntax errors I can't resolve.
The error message is "")" misplaced construct(s)" which points to the
first if condition.
This is my code snippet :
modeltype UML uses "http://www.eclipse.org/uml2/2.1.0/UML";
transformation uml2uml(in model : UML, out model1 : UML);
main() {
var models := model.objects()[Model];
models.map umlmodel();
}
mapping UML::Model::umlmodel(): UML::Model {
ownedElement:=self.ownedElement->iterate (el; ini: Set(UML::Element){}|
if (el.oclIsTypeOf(UML::Class))
then
{select(oclIsTypeOf(UML::Class))->collect(oclAsType(UML::Class))- >map
Class2ClassTrans()->asSet();
}--end of then
endif;
if (el.oclIsTypeOf(UML::UML::Activity)).....
endif;
);--end of iterate
Thanks in advance for any suggestions !
Cheers,
Deepak
|
|
|
Re: [QVTO] Iteration over collection [message #82488 is a reply to message #82474] |
Wed, 28 May 2008 12:12 |
Radomil Dvorak Messages: 249 Registered: July 2009 |
Senior Member |
|
|
Hi Deepak,
You are right forEach is not implemented yet.
Also, it would not help you much as it executes a block of expressions b=
ut =
returns null.
There is a couple of issues I can see in your code snippet.
1)
iterate (el; ini: Set(UML::Element){}| --> self.ownedElement->iterate =
(el; ini: Set(UML::Element) =3D Set{} |
=
2) missing source object of the call to select
select(oclIsTypeOf(UML::Class))->collect(oclAsType(UML::Class))- >map =
Class2ClassTrans()->asSet();
3) 'ownedElement' property is not changeable, derived
4) as in iterate a block of expressions is not supported, you may exctra=
ct =
them into a helper operation
However, I suggest you to follow the style like bellow and guess it woul=
d =
satisfy your
usecase.
mapping UML::Model::umlmodel(): UML::Model {
nestedPackage +=3D self.ownedElement[Package]->map toPackage();
ownedType :=3D self.ownedElement[Class]->map toClass()->asSet();
...
}
If you need any further help do not hesitate to post a question.
Regards,
/Radek
On Wed, 28 May 2008 12:59:49 +0200, Deepak <dee_n@gmx.de> wrote:
> Hello,
>
> I am evaluating QVTO. I want to transform a UML model with different =
> elements (Class,Subclass, Activity, Statemachine elements) into anothe=
r =
> UML model.
>
> The hierarchical structure of the source model should be remained.
>
> Therefore I want to iterate over "ownedElement" Collection of UML::Mod=
el.
>
> Unfortunately I don't know how to iterate correctly.
>
> The command "forEach" seems to be unimplemented,yet.
>
> So I tried with "iterate". But it has some syntax errors I can't resol=
ve.
>
> The error message is "")" misplaced construct(s)" which points to the=
=
> first if condition.
>
>
> This is my code snippet :
>
>
> modeltype UML uses "http://www.eclipse.org/uml2/2.1.0/UML";
>
> transformation uml2uml(in model : UML, out model1 : UML);
>
> main() {
> var models :=3D model.objects()[Model];
> models.map umlmodel();
> }
>
>
> mapping UML::Model::umlmodel(): UML::Model {
>
> ownedElement:=3Dself.ownedElement->iterate (el; ini: Set(UML::Element)=
{}|
>
> if (el.oclIsTypeOf(UML::Class))
>
> then
>
> {select(oclIsTypeOf(UML::Class))->collect(oclAsType(UML::Class))- >map =
=
> Class2ClassTrans()->asSet();
>
> }--end of then
>
> endif;
>
> if (el.oclIsTypeOf(UML::UML::Activity)).....
>
> endif;
>
> );--end of iterate
>
>
>
> Thanks in advance for any suggestions !
>
>
>
> Cheers,
>
> Deepak
>
>
-- =
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
|
|
|
Re: [QVTO] Iteration over collection [message #82519 is a reply to message #82488] |
Wed, 28 May 2008 12:35 |
Sergey Boyko Messages: 171 Registered: July 2009 |
Senior Member |
|
|
Hello,
Just as suggestion for the starting example - QVTO provides virtual
behavior for the mappings.
So instead of 'if()' testing of element's type the following code can be
used:
mapping UML::Model::umlmodel(): UML::Model {
packagedElement := self.ownedElement->collect(map ElementToNew())->asSet();
}
mapping Element::ElementToNew() : PackageableElement {
init {
result := object Class{name:='fake'};
}
}
mapping Class::ElementToNew() : PackageableElement {
init {
result := object Class{name:='real'};
}
}
mapping Activity::ElementToNew() : PackageableElement {
init {
result := object Activity{};
}
}
Radek Dvorak wrote:
> Hi Deepak,
>
> You are right forEach is not implemented yet.
> Also, it would not help you much as it executes a block of expressions
> but returns null.
>
> There is a couple of issues I can see in your code snippet.
> 1)
> iterate (el; ini: Set(UML::Element){}| -->
> self.ownedElement->iterate (el; ini: Set(UML::Element) = Set{} |
>
> 2) missing source object of the call to select
> select(oclIsTypeOf(UML::Class))->collect(oclAsType(UML::Class))- >map
> Class2ClassTrans()->asSet();
>
> 3) 'ownedElement' property is not changeable, derived
>
> 4) as in iterate a block of expressions is not supported, you may
> exctract them into a helper operation
>
>
> However, I suggest you to follow the style like bellow and guess it
> would satisfy your
> usecase.
>
> mapping UML::Model::umlmodel(): UML::Model {
> nestedPackage += self.ownedElement[Package]->map toPackage();
> ownedType := self.ownedElement[Class]->map toClass()->asSet();
> ...
> }
>
> If you need any further help do not hesitate to post a question.
>
> Regards,
> /Radek
>
>
>
> On Wed, 28 May 2008 12:59:49 +0200, Deepak <dee_n@gmx.de> wrote:
>
>> Hello,
>>
>> I am evaluating QVTO. I want to transform a UML model with different
>> elements (Class,Subclass, Activity, Statemachine elements) into
>> another UML model.
>>
>> The hierarchical structure of the source model should be remained.
>>
>> Therefore I want to iterate over "ownedElement" Collection of UML::Model.
>>
>> Unfortunately I don't know how to iterate correctly.
>>
>> The command "forEach" seems to be unimplemented,yet.
>>
>> So I tried with "iterate". But it has some syntax errors I can't resolve.
>>
>> The error message is "")" misplaced construct(s)" which points to the
>> first if condition.
>>
>>
>> This is my code snippet :
>>
>>
>> modeltype UML uses "http://www.eclipse.org/uml2/2.1.0/UML";
>>
>> transformation uml2uml(in model : UML, out model1 : UML);
>>
>> main() {
>> var models := model.objects()[Model];
>> models.map umlmodel();
>> }
>>
>>
>> mapping UML::Model::umlmodel(): UML::Model {
>>
>> ownedElement:=self.ownedElement->iterate (el; ini: Set(UML::Element){}|
>>
>> if (el.oclIsTypeOf(UML::Class))
>>
>> then
>>
>> {select(oclIsTypeOf(UML::Class))->collect(oclAsType(UML::Class))- >map
>> Class2ClassTrans()->asSet();
>>
>> }--end of then
>>
>> endif;
>>
>> if (el.oclIsTypeOf(UML::UML::Activity)).....
>>
>> endif;
>>
>> );--end of iterate
>>
>>
>>
>> Thanks in advance for any suggestions !
>>
>>
>>
>> Cheers,
>>
>> Deepak
>>
>>
>
>
>
|
|
|
Re: [QVTO] Iteration over collection [message #83001 is a reply to message #82519] |
Fri, 30 May 2008 14:17 |
Eclipse User |
|
|
|
Thanks Radek for your correction.
Sergey your solution is really elegant ! I am using it.
Thanks again !
Che
Sergey Boyko schrieb:
> Hello,
>
> Just as suggestion for the starting example - QVTO provides virtual
> behavior for the mappings.
> So instead of 'if()' testing of element's type the following code can be
> used:
>
> mapping UML::Model::umlmodel(): UML::Model {
> packagedElement := self.ownedElement->collect(map
> ElementToNew())->asSet();
> }
>
> mapping Element::ElementToNew() : PackageableElement {
> init {
> result := object Class{name:='fake'};
> }
> }
>
> mapping Class::ElementToNew() : PackageableElement {
> init {
> result := object Class{name:='real'};
> }
> }
>
> mapping Activity::ElementToNew() : PackageableElement {
> init {
> result := object Activity{};
> }
> }
>
>
>
> Radek Dvorak wrote:
>> Hi Deepak,
>>
>> You are right forEach is not implemented yet.
>> Also, it would not help you much as it executes a block of expressions
>> but returns null.
>>
>> There is a couple of issues I can see in your code snippet.
>> 1)
>> iterate (el; ini: Set(UML::Element){}| -->
>> self.ownedElement->iterate (el; ini: Set(UML::Element) = Set{} |
>> 2) missing source object of the call to select
>>
>> select(oclIsTypeOf(UML::Class))->collect(oclAsType(UML::Class))- >map
>> Class2ClassTrans()->asSet();
>>
>> 3) 'ownedElement' property is not changeable, derived
>>
>> 4) as in iterate a block of expressions is not supported, you may
>> exctract them into a helper operation
>>
>>
>> However, I suggest you to follow the style like bellow and guess it
>> would satisfy your
>> usecase.
>>
>> mapping UML::Model::umlmodel(): UML::Model {
>> nestedPackage += self.ownedElement[Package]->map toPackage();
>> ownedType := self.ownedElement[Class]->map toClass()->asSet();
>> ...
>> }
>>
>> If you need any further help do not hesitate to post a question.
>>
>> Regards,
>> /Radek
>>
>>
>>
>> On Wed, 28 May 2008 12:59:49 +0200, Deepak <dee_n@gmx.de> wrote:
>>
>>> Hello,
>>>
>>> I am evaluating QVTO. I want to transform a UML model with different
>>> elements (Class,Subclass, Activity, Statemachine elements) into
>>> another UML model.
>>>
>>> The hierarchical structure of the source model should be remained.
>>>
>>> Therefore I want to iterate over "ownedElement" Collection of
>>> UML::Model.
>>>
>>> Unfortunately I don't know how to iterate correctly.
>>>
>>> The command "forEach" seems to be unimplemented,yet.
>>>
>>> So I tried with "iterate". But it has some syntax errors I can't
>>> resolve.
>>>
>>> The error message is "")" misplaced construct(s)" which points to
>>> the first if condition.
>>>
>>>
>>> This is my code snippet :
>>>
>>>
>>> modeltype UML uses "http://www.eclipse.org/uml2/2.1.0/UML";
>>>
>>> transformation uml2uml(in model : UML, out model1 : UML);
>>>
>>> main() {
>>> var models := model.objects()[Model];
>>> models.map umlmodel();
>>> }
>>>
>>>
>>> mapping UML::Model::umlmodel(): UML::Model {
>>>
>>> ownedElement:=self.ownedElement->iterate (el; ini: Set(UML::Element){}|
>>>
>>> if (el.oclIsTypeOf(UML::Class))
>>>
>>> then
>>>
>>> {select(oclIsTypeOf(UML::Class))->collect(oclAsType(UML::Class))- >map
>>> Class2ClassTrans()->asSet();
>>>
>>> }--end of then
>>>
>>> endif;
>>>
>>> if (el.oclIsTypeOf(UML::UML::Activity)).....
>>>
>>> endif;
>>>
>>> );--end of iterate
>>>
>>>
>>>
>>> Thanks in advance for any suggestions !
>>>
>>>
>>>
>>> Cheers,
>>>
>>> Deepak
>>>
>>>
>>
>>
>>
|
|
|
Re: [QVTO] Iteration over collection [message #83031 is a reply to message #83001] |
Fri, 30 May 2008 15:04 |
Radomil Dvorak Messages: 249 Registered: July 2009 |
Senior Member |
|
|
Hi,
Just a remark, you can use mapping 'disjucts' to achieve the same behavi=
or =
with
the advantage of having specific concrete return types.
This allows you to utilize the implicit population section and eliminate=
s
the need for explicit assignment of the result in the init section.
In addition, from the caller perspective, the individual mappings return=
appropriate types and no cast is needed.
Also, no fake result for the abstract super type mapping is really neede=
d
as the 'disjucting' mapping returns null if no appropriate 'disjuncted' =
one
can be selected for a given call.
Everything depends on you needs ;-), check the QVT spec for 'disjuncts',=
=
if interested.
Cheers,
/Radek
On Fri, 30 May 2008 16:17:25 +0200, Deepak <dee_n@gmx.de> wrote:
> Thanks Radek for your correction.
>
> Sergey your solution is really elegant ! I am using it.
>
> Thanks again !
>
> Che
>
>
>
>
> Sergey Boyko schrieb:
>> Hello,
>> Just as suggestion for the starting example - QVTO provides virtual =
=
>> behavior for the mappings.
>> So instead of 'if()' testing of element's type the following code can=
=
>> be used:
>> mapping UML::Model::umlmodel(): UML::Model {
>> packagedElement :=3D self.ownedElement->collect(map =
>> ElementToNew())->asSet();
>> }
>> mapping Element::ElementToNew() : PackageableElement {
>> init {
>> result :=3D object Class{name:=3D'fake'};
>> }
>> }
>> mapping Class::ElementToNew() : PackageableElement {
>> init {
>> result :=3D object Class{name:=3D'real'};
>> }
>> }
>> mapping Activity::ElementToNew() : PackageableElement {
>> init {
>> result :=3D object Activity{};
>> }
>> }
>> Radek Dvorak wrote:
>>> Hi Deepak,
>>>
>>> You are right forEach is not implemented yet.
>>> Also, it would not help you much as it executes a block of expressio=
ns =
>>> but returns null.
>>>
>>> There is a couple of issues I can see in your code snippet.
>>> 1)
>>> iterate (el; ini: Set(UML::Element){}| --> =
>>> self.ownedElement->iterate (el; ini: Set(UML::Element) =3D Set{} |
>>> 2) missing source object of the call to select
>>> =
>>> select(oclIsTypeOf(UML::Class))->collect(oclAsType(UML::Class))- >map=
=
>>> Class2ClassTrans()->asSet();
>>>
>>> 3) 'ownedElement' property is not changeable, derived
>>>
>>> 4) as in iterate a block of expressions is not supported, you may =
>>> exctract them into a helper operation
>>>
>>>
>>> However, I suggest you to follow the style like bellow and guess it =
=
>>> would satisfy your
>>> usecase.
>>>
>>> mapping UML::Model::umlmodel(): UML::Model {
>>> nestedPackage +=3D self.ownedElement[Package]->map toPackage();
>>> ownedType :=3D self.ownedElement[Class]->map toClass()->asSet();=
>>> ...
>>> }
>>>
>>> If you need any further help do not hesitate to post a question.
>>>
>>> Regards,
>>> /Radek
>>>
>>>
>>>
>>> On Wed, 28 May 2008 12:59:49 +0200, Deepak <dee_n@gmx.de> wrote:
>>>
>>>> Hello,
>>>>
>>>> I am evaluating QVTO. I want to transform a UML model with differen=
t =
>>>> elements (Class,Subclass, Activity, Statemachine elements) into =
>>>> another UML model.
>>>>
>>>> The hierarchical structure of the source model should be remained.
>>>>
>>>> Therefore I want to iterate over "ownedElement" Collection of =
>>>> UML::Model.
>>>>
>>>> Unfortunately I don't know how to iterate correctly.
>>>>
>>>> The command "forEach" seems to be unimplemented,yet.
>>>>
>>>> So I tried with "iterate". But it has some syntax errors I can't =
>>>> resolve.
>>>>
>>>> The error message is "")" misplaced construct(s)" which points to =
=
>>>> the first if condition.
>>>>
>>>>
>>>> This is my code snippet :
>>>>
>>>>
>>>> modeltype UML uses "http://www.eclipse.org/uml2/2.1.0/UML";
>>>>
>>>> transformation uml2uml(in model : UML, out model1 : UML);
>>>>
>>>> main() {
>>>> var models :=3D model.objects()[Model];
>>>> models.map umlmodel();
>>>> }
>>>>
>>>>
>>>> mapping UML::Model::umlmodel(): UML::Model {
>>>>
>>>> ownedElement:=3Dself.ownedElement->iterate (el; ini: =
>>>> Set(UML::Element){}|
>>>>
>>>> if (el.oclIsTypeOf(UML::Class))
>>>>
>>>> then
>>>>
>>>> {select(oclIsTypeOf(UML::Class))->collect(oclAsType(UML::Class))- >m=
ap =
>>>> Class2ClassTrans()->asSet();
>>>>
>>>> }--end of then
>>>>
>>>> endif;
>>>>
>>>> if (el.oclIsTypeOf(UML::UML::Activity)).....
>>>>
>>>> endif;
>>>>
>>>> );--end of iterate
>>>>
>>>>
>>>>
>>>> Thanks in advance for any suggestions !
>>>>
>>>>
>>>>
>>>> Cheers,
>>>>
>>>> Deepak
>>>>
>>>>
>>>
>>>
>>>
-- =
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
|
|
|
Goto Forum:
Current Time: Tue Apr 23 16:45:19 GMT 2024
Powered by FUDForum. Page generated in 0.03884 seconds
|