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 |
Skander TURKI 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 |
William Piers 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 #103438 is a reply to message #103278] |
Tue, 14 April 2009 09:26 |
Skander TURKI 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 |
Skander TURKI 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 #103525 is a reply to message #103502] |
Wed, 15 April 2009 09:23 |
William Piers 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.
>
|
|
| |
Goto Forum:
Current Time: Thu Apr 25 15:38:55 GMT 2024
Powered by FUDForum. Page generated in 0.04028 seconds
|