Home » Archived » M2M (model-to-model transformation) » [ATL] ordered transformations
[ATL] ordered transformations [message #19276] |
Tue, 27 February 2007 13:29  |
Eclipse User |
|
|
|
Originally posted by: irbull.cs.uvic.ca
I have two questions about the ordering of transformations:
1) Is it possibly to specify transformations to happen in the same order
that the elements exist in the source model. That is, if I have list of
elements [a,b,c,d] and I transform these to nodes, can I ensure the
transformations matches a,b,c,d in that order?
2) How does the sortedBy work? I have the following transformation (below):
In the imperative section I add the Item to my list of items, and then I
try to sort my entire list by the value. This doesn't seem to work. The
documentation says that sortedBy returns a list, so I have also tried:
thisModule.root.items <- thisModule.root.items->sortedBy( e | e.value );
Still no luck
<snip>
module ExampleTransformation; -- Module Header
create OUT : barchartviewer from IN : viewshaper;
rule MappRule1 {
from s : viewshaper!Node
to t : barchartviewer!Item (
label <- s.attributes-> ...
value <- s.attributes-> ...
)
do {
thisModule.root.items<-t;
thisModule.root.items->sortedBy( e | e.value );
}
}
helper def: root: barchartviewer!BarChartViewer=OclAny;
entrypoint rule ModelRule() {
to t : barchartviewer!BarChartViewer
do {
thisModule.root <- t;
}
}
</snip>
Thanks,
Ian
|
|
| |
Re: [ATL] ordered transformations [message #25575 is a reply to message #19276] |
Fri, 23 March 2007 19:32  |
Eclipse User |
|
|
|
Hello Ian,
> 1) Is it possibly to specify transformations to happen in the same order
> that the elements exist in the source model. That is, if I have list of
> elements [a,b,c,d] and I transform these to nodes, can I ensure the
> transformations matches a,b,c,d in that order?
No it is not possible to specify the execution order of declarative
rules (with respect to each other, and to the elements they match).
Declarative transformations are still deterministic because this order
does not matter.
However, you may have problems when you insert imperative statements in
your declarative rules.
When you use imperative constructs, you have to make sure that the part
of the target model you are modifying is in a known state. For the
action block (i.e., the "do" part) of declarative rules, you can achieve
this by only working on the elements generated by this very same rule
for the current source.
If you need to perform something on a larger part of the model, you may
put the corresponding code in an endpoint rule.
> 2) How does the sortedBy work?
Yes.
> I have the following transformation
> (below):
>
> In the imperative section I add the Item to my list of items, and then I
> try to sort my entire list by the value. This doesn't seem to work. The
> documentation says that sortedBy returns a list, so I have also tried:
> thisModule.root.items <- thisModule.root.items->sortedBy( e | e.value );
You are right that this version is more likely to work than the one in
your code snippet, which does not store the value returned by sortedBy.
> Still no luck
However, you are trying to modify the root from a declarative rule, when
you know little about the state of the whole model.
You should do this in an endpoint rule (see above).
Additionally, you are assigning the elements to root.items several
times. You should only assign them once, in the correct order.
One way to do this is the following:
rule MappRule1 {
from s : viewshaper!Node
to t : barchartviewer!Item (
label <- s.attributes-> ...
value <- s.attributes-> ...
)
do {
thisModule.items <- thisModule.items->including(t);
}
}
helper def: item: Sequence(barchartviewer!Item)=Sequence{};
endpoint rule ModelRule() {
to t : barchartviewer!BarChartViewer
do {
t.items <- thisModule.items->sortedBy( e | e.value );
}
}
Note that we store the items in a temporary collection, and that we only
sort the whole collection once after the declarative part has finished
its execution.
If you need the root to be created before the execution of the
declarative part for some other reason, you may still create it in an
entrypoint. However, because it did not seem necessary to have both an
entrypoint and an endpoint here, I simplified the transformation.
Note that if you have a root element in your source model, it should
also be possible to have a declarative-only solution. You could indeed
sort the sequence of viewshaper!Node, which would resolve into a sorted
sequence of barchartviewer!Item.
To avoid recomputing the value, you could use an attribute helper.
Best regards,
Frédéric Jouault
|
|
|
Goto Forum:
Current Time: Thu May 08 02:14:37 EDT 2025
Powered by FUDForum. Page generated in 0.08627 seconds
|