[ATL] Launching (EMF) ATL programmatically and allow inter model references [message #486069] |
Wed, 16 September 2009 08:47 |
Eclipse User |
|
|
|
Originally posted by: loic.fejoz.realtimeatwork.com
Hi,
I'am trying to make a plugin that contains an ATL transformation. By now
I am able to get the resulting file but it does not contains intermodel
references. Obviously I tried the option allowInterModelReferences but
I cannot get it working...
First, is the name of the option contained somewhere in a static field?
org.eclipse.m2m.atl.adt.launching.AtlLauncherTools is not in Galileo,
does it?
Second, is it the same option name if I am calling method
(EMF)Resource.save?
Do you need to pass it to the ATL Launcher (also it's not working)?
Do you need to put a Boolean or a string value (neither work)?
Here is what I think is the interesting code. Note that normally I use
the EMF ATL VM hence I always get an EMFModel as a result.
public static Resource toXxResource(final IResource yyModelResource)
throws ATLCoreException, IOException {
// This is the basic call
IModel outputModel = toXxModel(yyModelResource);
// Now try to serialize the result
URI outputURI = URI.createURI(yyModelResource.getLocationURI()
.toString().concat(".xmi"));
final Map<String, Object> options = new HashMap<String, Object>();
options.put("allowInterModelReferences", Boolean.TRUE);
options.put("AllowInterModelReferences", Boolean.TRUE);
if (outputModel instanceof EMFModel) {
EMFModel emfModel = (EMFModel) outputModel;
Resource res = emfModel.getResource();
assert res != null;
ResourceSet set = res.getResourceSet();
assert set != null
OutputStream outputStream = set.getURIConverter()
.createOutputStream(outputURI);
res.save(outputStream, options);
res.setURI(outputURI);
assert res.getURI().equals(outputURI);
return res;
} else {
IExtractor extractor = CoreService.getExtractor("EMF");
extractor.extract(outputModel, outputURI.toString(), options);
return null;
}
}
--
regards,
Loïc Fejoz
|
|
|
Re: [ATL] Launching (EMF) ATL programmatically and allow inter model references [message #486078 is a reply to message #486069] |
Wed, 16 September 2009 09:27 |
Eclipse User |
|
|
|
Originally posted by: loic.fejoz.realtimeatwork.com
By luck, I found the following thread [1]. It tells that the options
should be pass to the ILauncher.launch call! The option must be a String
(and not a Boolean). The option's name starts with a lower-case 'a'.
options.put("allowInterModelReferences", "true");
final Object result = launcher.launch(ILauncher.RUN_MODE, new
NullProgressMonitor(), options, asmURL.openStream());
[1]
< http://www.eclipse.org/forums/index.php?t=msg&goto=10345 1&S=7469d14bf19de722271dc05f93e4cdac>
--
regards,
Loïc Fejoz
Loïc Fejoz a écrit :
> Hi,
>
> I'am trying to make a plugin that contains an ATL transformation. By now
> I am able to get the resulting file but it does not contains intermodel
> references. Obviously I tried the option allowInterModelReferences but
> I cannot get it working...
>
> First, is the name of the option contained somewhere in a static field?
> org.eclipse.m2m.atl.adt.launching.AtlLauncherTools is not in Galileo,
> does it?
>
> Second, is it the same option name if I am calling method
> (EMF)Resource.save?
>
> Do you need to pass it to the ATL Launcher (also it's not working)?
>
> Do you need to put a Boolean or a string value (neither work)?
>
> Here is what I think is the interesting code. Note that normally I use
> the EMF ATL VM hence I always get an EMFModel as a result.
>
> public static Resource toXxResource(final IResource yyModelResource)
> throws ATLCoreException, IOException {
> // This is the basic call
> IModel outputModel = toXxModel(yyModelResource);
> // Now try to serialize the result
> URI outputURI = URI.createURI(yyModelResource.getLocationURI()
> .toString().concat(".xmi"));
> final Map<String, Object> options = new HashMap<String, Object>();
> options.put("allowInterModelReferences", Boolean.TRUE);
> options.put("AllowInterModelReferences", Boolean.TRUE);
> if (outputModel instanceof EMFModel) {
> EMFModel emfModel = (EMFModel) outputModel;
> Resource res = emfModel.getResource();
> assert res != null;
> ResourceSet set = res.getResourceSet();
> assert set != null
> OutputStream outputStream = set.getURIConverter()
> .createOutputStream(outputURI);
> res.save(outputStream, options);
> res.setURI(outputURI);
> assert res.getURI().equals(outputURI);
> return res;
> } else {
> IExtractor extractor = CoreService.getExtractor("EMF");
> extractor.extract(outputModel, outputURI.toString(), options);
> return null;
> }
> }
>
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03674 seconds