Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » [QVTo] Transformation from one to N models
[QVTo] Transformation from one to N models [message #523154] Thu, 25 March 2010 11:40 Go to next message
Pablo Parra is currently offline Pablo ParraFriend
Messages: 1
Registered: March 2010
Junior Member
Hi all,

I'm facing a problem regarding model transformation with QVTo and I don't know how to face it. The problem is as follows:

I have one input model that has an "a priori" undetermined number of elements of a certain type. This is:

<rootElement>
<nodeList>
<node1>
<node2>
...
<noden>
</nodeList>

The thing is that I have to create one output model from each of the nodeN elements. The first solution that came into my mind has been to create a transformation from the original input model to the output model. That transformation contains a mapping between the nodeN element type to the output model root type. With the TransformationExecutor class, I call it for each of the elements of the node list, like this:

Resource inputRes = ...
NodeList nodeList = ...
...
ExecutionContextImpl context = new ExecutionContextImpl();
TransformationExecutor executor = new TransformationExecutor(transformationURI);

for (Iterator<NodeElement> i = nodeList.iterator; i.hasNext(); )
{
Node node = i.next();
Resource outputRes = ...
BasicModelExtent input = new BasicModelExtent();
input.add(node);

ModelExtent output = new BasicModelExtent();

ExecutionDiagnostic diagnostic = executor.execute(context, input, output);

if(diagnostic.getSeverity() == Diagnostic.OK) {
...
}
}

The problem with this solution is that the transformation does not work unless I put input and output parameters to the main mapping entry operation. My first approach was not to put them and to call the mapping in a way similar to this one:

main()
{
inModel.rootObjects()[model::NodeElementType]->map NodeElement2OutputModel;
}

But it does not work (or at least it didn't work for me): it does not detect any input element. What I did then was to put parameters to the main mapping entry:

main(in node : inputModel::NodeElementType, out outModel : outputModel)
{
outModel := node.map NodeElement2OutputModel;
}

This works, but it outputs a warning message saying that using parameters in the main entry is deprecated Sad so i don't know if it will work in the future...

I don't know if there is another way to approach the problem or if I'm missing something.. any help would be very much appreciated Smile

Thank you very much in advance.

Pablo Parra.
Re: [QVTo] Transformation from one to N models [message #524642 is a reply to message #523154] Thu, 01 April 2010 16:26 Go to previous message
Sergey Boyko is currently offline Sergey BoykoFriend
Messages: 171
Registered: July 2009
Senior Member
Hi Pablo ,

Which version of QVTo do you use?

There was bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=287711 that
led to empty result of
inModel.rootObjects()[model::SomeType]

in case objects of that type had eContainer()!=null (like in your case).

As that bug was fixed usual parameterless main() should work.

Regards,
Sergey

Pablo Parra wrote:
> Hi all,
>
> I'm facing a problem regarding model transformation with QVTo and I
> don't know how to face it. The problem is as follows:
>
> I have one input model that has an "a priori" undetermined number of
> elements of a certain type. This is:
>
> <rootElement>
> <nodeList>
> <node1>
> <node2>
> ...
> <noden>
> </nodeList>
>
> The thing is that I have to create one output model from each of the
> nodeN elements. The first solution that came into my mind has been to
> create a transformation from the original input model to the output
> model. That transformation contains a mapping between the nodeN element
> type to the output model root type. With the TransformationExecutor
> class, I call it for each of the elements of the node list, like this:
>
> Resource inputRes = ...
> NodeList nodeList = ...
> ..
> ExecutionContextImpl context = new ExecutionContextImpl();
> TransformationExecutor executor = new
> TransformationExecutor(transformationURI);
>
> for (Iterator<NodeElement> i = nodeList.iterator; i.hasNext(); )
> {
> Node node = i.next();
> Resource outputRes = ...
> BasicModelExtent input = new BasicModelExtent();
> input.add(node);
>
> ModelExtent output = new BasicModelExtent();
>
> ExecutionDiagnostic diagnostic = executor.execute(context, input,
> output);
>
> if(diagnostic.getSeverity() == Diagnostic.OK) {
> ...
> }
> }
>
> The problem with this solution is that the transformation does not work
> unless I put input and output parameters to the main mapping entry
> operation. My first approach was not to put them and to call the mapping
> in a way similar to this one:
>
> main()
> {
> inModel.rootObjects()[model::NodeElementType]->map
> NodeElement2OutputModel;
> }
>
> But it does not work (or at least it didn't work for me): it does not
> detect any input element. What I did then was to put parameters to the
> main mapping entry:
>
> main(in node : inputModel::NodeElementType, out outModel : outputModel)
> {
> outModel := node.map NodeElement2OutputModel;
> }
>
> This works, but it outputs a warning message saying that using
> parameters in the main entry is deprecated :( so i don't know if it
> will work in the future...
>
> I don't know if there is another way to approach the problem or if I'm
> missing something.. any help would be very much appreciated :)
>
> Thank you very much in advance.
>
> Pablo Parra.
Previous Topic:[QVTo] Recursive extension of targetelement's parent element
Next Topic:[QVTO] Mapping a enumeration
Goto Forum:
  


Current Time: Wed Oct 23 22:03:39 GMT 2019

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

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

Back to the top