Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » [ATL] can we "cast" an EMFModel to an ASMModel?
[ATL] can we "cast" an EMFModel to an ASMModel? [message #103169] Thu, 09 April 2009 10:09 Go to next message
Skander TURKI is currently offline Skander TURKIFriend
Messages: 130
Registered: July 2009
Senior Member
hi,
i am trying to develop a High Order Transformation as a first step of a
transformation chain, for this, i need to compile the result of the High
Order Transformation (ATL .ecore) before using it in the second simple
transformation.
I wanted to avoid saving the result to an .ecore file then re-inject it
and then compile, so i modified a little bit the LauncherServie.launch
method so that to get a Map<String, IModel> that contains the output
models, these are EMFModels in my case. But the compiler only accepts
ASMModels, so the problem is to "cast" an EMFModel to an ASMModel. Is this
possible?

I wanted to avoid saving to .ecore then re-injecting to reduce errors,
because after re-injection, the compilation of the ATL model is not
working. I tried to manually extract the .ecore model with AM3 to .atl
file and to compile it and this worked well. So i suppose that maybe the
injection from the atl.ecore file caused this problem.

So is it possible to convert an EMFModel to an ASMModel?
thanks
Re: [ATL] can we "cast" an EMFModel to an ASMModel? [message #103278 is a reply to message #103169] Fri, 10 April 2009 09:25 Go to previous messageGo to next message
William Piers is currently offline William PiersFriend
Messages: 301
Registered: July 2009
Senior Member
Hello,

At this time, the best way to do that is:
- to extract the EMFModel as an OutputStream
- to reload it using the EMFModelLoader.loadModel(String name, ASMModel
metamodel, InputStream in) method

Note that at least, the compiler will be rewrited to conform to the new
IModel/EMFModel API.

Best regards

William

Skander a écrit :
> hi,
> i am trying to develop a High Order Transformation as a first step of a
> transformation chain, for this, i need to compile the result of the High
> Order Transformation (ATL .ecore) before using it in the second simple
> transformation.
> I wanted to avoid saving the result to an .ecore file then re-inject it
> and then compile, so i modified a little bit the LauncherServie.launch
> method so that to get a Map<String, IModel> that contains the output
> models, these are EMFModels in my case. But the compiler only accepts
> ASMModels, so the problem is to "cast" an EMFModel to an ASMModel. Is
> this possible?
>
> I wanted to avoid saving to .ecore then re-injecting to reduce errors,
> because after re-injection, the compilation of the ATL model is not
> working. I tried to manually extract the .ecore model with AM3 to .atl
> file and to compile it and this worked well. So i suppose that maybe the
> injection from the atl.ecore file caused this problem.
>
> So is it possible to convert an EMFModel to an ASMModel?
> thanks
Re: [ATL] can we "cast" an EMFModel to an ASMModel? [message #103323 is a reply to message #103278] Fri, 10 April 2009 13:53 Go to previous messageGo to next message
Skander TURKI is currently offline Skander TURKIFriend
Messages: 130
Registered: July 2009
Senior Member
ok thanks william
Re: [ATL] can we "cast" an EMFModel to an ASMModel? [message #103438 is a reply to message #103278] Tue, 14 April 2009 09:26 Go to previous messageGo to next message
Skander TURKI is currently offline Skander TURKIFriend
Messages: 130
Registered: July 2009
Senior Member
Hi William, i tried to use pipes to convert the OutputStream to
InputStream, but i have an error before that in the extract method, here
is my code, i hope you can help me out, it seems the EMF extractor is not
the one i need:

public ASMModel injectATLModelFileToATLModel (IModel atlEMFModel){

System.out.println("Model Loading Started!");
ASMModel atlASMModel = null;

try
{
// initialisation
AtlModelHandler amh = AtlModelHandler.getDefault(AtlModelHandler.AMH_EMF);
ASMModel atlMM = amh.createModelLoader().getATL();

//Maybe the IExtractor is not the one i need?!!!
IExtractor extractor = CoreService.getExtractor("EMF");
OutputStream streamOut = new ByteArrayOutputStream();

// extraction from file to outputstream (crushes down)
extractor.extract(atlEMFModel, streamOut, null);

// connecting outputstream pipe to inputstream pipe
PipedOutputStream pipedOut = (PipedOutputStream)streamOut;
PipedInputStream streamIn = new PipedInputStream(pipedOut);

// reload the model from the inputstream pipe
atlASMModel = amh.createModelLoader().loadModel("MarteToAAXL", atlMM,
streamIn);

System.out.println("Model Loading Started!");
}
catch (Exception e)
{
e.printStackTrace();
}

return atlASMModel;
}


/////
Thanks .
Re: [ATL] can we "cast" an EMFModel to an ASMModel? [message #103465 is a reply to message #103278] Tue, 14 April 2009 14:22 Go to previous messageGo to next message
Skander TURKI is currently offline Skander TURKIFriend
Messages: 130
Registered: July 2009
Senior Member
hi, i changed the code, it was an error in the method call, not in the
extraction itself, now i extract the model to an Outputstream but,
apparently, the Inputstream tries to read it with a different coding, in
fact the file is encoded with encoding="ISO-8859-1":
<?xml version="1.0" encoding="ISO-8859-1"?>
<xmi:XMI xmi:version="2.0"

And the error message i get is : Invalid byte 2 of 3-byte UTF-8 sequence.
it seems more like a Java problem than an ATL problem, i'll look in the
Java forums for a solution, here is the new code causing the coding error :
try
{

AtlModelHandler amh = AtlModelHandler.getDefault(AtlModelHandler.AMH_EMF);
ASMModel atlMM = amh.createModelLoader().getATL();

// extract the EMFModel as an OutputStream
final OutputStream streamOut = new PipedOutputStream();
PipedInputStream streamIn = new
PipedInputStream((PipedOutputStream)streamOut);

new Thread(
new Runnable(){
public void run(){
IExtractor extractor;
try {
extractor = CoreService.getExtractor("EMF");
Map<String, Object> options = new HashMap<String, Object>();
extractor.extract(atlEMFModel, streamOut, options);
} catch (ATLCoreException e) {
e.printStackTrace();
}
}
).start();

// reload it using the EMFModelLoader.loadModel method
atlASMModel = amh.createModelLoader().loadModel("MarteToAAXL", atlMM,
streamIn);

System.out.println("Model Loading Started!");

thanks..
Re: [ATL] Is this a bug in ATL ? [message #103502 is a reply to message #103465] Wed, 15 April 2009 09:11 Go to previous messageGo to next message
Skander TURKI is currently offline Skander TURKIFriend
Messages: 130
Registered: July 2009
Senior Member
i don't know if this is a bug in the ATL API but the problem is :

in the package org.eclipse.m2m.atl.drivers.emf4atl in the EMFModelLoader
class, the encoding is set to "ISO-8859-1", so the EMFModelLoader.save
method will always store the model with the "ISO-8859-1" encoding. In the
other hand the EMFModelLoader.load method tries to load it with the UTF-8
encoding, what causes the load method to crash for me with the message :

com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequ enceException:
Invalid byte 2 of 3-byte UTF-8 sequence.

Is this a bug, or is it possible to force the load methos to use the
"ISO-8859-1" encoding? Or maybe the use of pipes to convert from an
Outputstream to an Inputstream causes this problem?

thanks in advance!
Skander.
Re: [ATL] Is this a bug in ATL ? [message #103525 is a reply to message #103502] Wed, 15 April 2009 09:23 Go to previous messageGo to next message
William Piers is currently offline William PiersFriend
Messages: 301
Registered: July 2009
Senior Member
Hello,

I don't know how to change the emf4atl driver loading encoding, but here
is how to change the EMFModel extraction encoding:

By default, the EMFExtractor saves the EMF Resource using the option:

extractOptions.put(XMLResource.OPTION_ENCODING, "ISO-8859-1");

But you can override that option:

Map<String, Object> options = new HashMap<String, Object>();
options .put(XMLResource.OPTION_ENCODING, "UTF-8"); // (I guess)
extractor.extract(atlEMFModel, streamOut, options);

Best regards,

William

Skander a écrit :
> i don't know if this is a bug in the ATL API but the problem is :
>
> in the package org.eclipse.m2m.atl.drivers.emf4atl in the EMFModelLoader
> class, the encoding is set to "ISO-8859-1", so the EMFModelLoader.save
> method will always store the model with the "ISO-8859-1" encoding. In
> the other hand the EMFModelLoader.load method tries to load it with the
> UTF-8 encoding, what causes the load method to crash for me with the
> message :
> com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequ enceException:
> Invalid byte 2 of 3-byte UTF-8 sequence.
>
> Is this a bug, or is it possible to force the load methos to use the
> "ISO-8859-1" encoding? Or maybe the use of pipes to convert from an
> Outputstream to an Inputstream causes this problem?
>
> thanks in advance!
> Skander.
>
ATL model do not have a root element?!! [message #103568 is a reply to message #103525] Thu, 16 April 2009 09:31 Go to previous message
Skander TURKI is currently offline Skander TURKIFriend
Messages: 130
Registered: July 2009
Senior Member
thanks william for your reply, it worked for me to add the options.put
instruction.

I also added two instructions that close the pipes otherwise i get an
error.

Now the EMFModelLoader.loadModel from the inputstream only populates the
"extent" field (i explore the ASMEMFModel in the debugger after the
loading) , so in the extent field of the ASMEMFModel i find all the data
that comes from the model, but the ModelElements field is completely
empty, i noticed that this is sometimes the case in other model loadings
so i don't think this is a problem.

The problem is that the compiling method now causes this error:
OclUndefined has no property
ATL VM Stack:
J.process() : ??#8 null
local variables = {self=OclUndefined}
local stack = ['Error: could not find matching node for Void at ']

I don't know where the problem comes from. But i wonder if it is normal
that a model conforming to the ATL metamodel do not have a root element,
in fact there are many elements in the first level of its hierarchy, only
the module element contains other elements. Here is an example of an the
ATL model:

<a href="http://www.flickr.com/photos/skanderturki/3447267160/"
title="ATLModel de skanderturki, sur Flickr"><img
src=" http://farm4.static.flickr.com/3344/3447267160_1a1f7fc611.jp g"
width="500" height="444" alt="ATLModel" /></a>
Previous Topic:[ATL] how to pass a parameter to a Query
Next Topic:[QVTO] Type problem in Ecore2UML transformation
Goto Forum:
  


Current Time: Thu Apr 25 15:38:55 GMT 2024

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

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

Back to the top