Home » Modeling » ATL » Troubles with ATL API
Troubles with ATL API [message #909183] |
Thu, 06 September 2012 17:32 |
El Arbi Aboussoror Messages: 90 Registered: June 2010 |
Member |
|
|
Hello,
I'm trying to use the ATL API to launch my transformations, but the result is a null resource !
import java.io.InputStream;
import java.util.Collections;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.m2m.atl.core.emf.EMFInjector;
import org.eclipse.m2m.atl.core.emf.EMFModel;
import org.eclipse.m2m.atl.core.emf.EMFModelFactory;
import org.eclipse.m2m.atl.core.emf.EMFReferenceModel;
import org.eclipse.m2m.atl.core.launch.ILauncher;
import org.eclipse.m2m.atl.engine.emfvm.launch.EMFVMLauncher;
public class AtlFacade {
private AtlExecutionContext context;
public AtlFacade(AtlExecutionContext context) {
this.context = context;
}
public Resource evaluate(InputStream ASMInputStream, Resource sourceM) {
EMFInjector injector = new EMFInjector();
EMFVMLauncher emfVmLauncher = new EMFVMLauncher();
emfVmLauncher.initialize(Collections.<String, Object> emptyMap());
EMFModelFactory emfModelFactory = new EMFModelFactory();
// inject source MM
EMFReferenceModel sourceEmfMM = (EMFReferenceModel) emfModelFactory
.newReferenceModel();
injector.inject(sourceEmfMM, context.sourceMM);
// inject target MM
EMFReferenceModel targetEmfMM = (EMFReferenceModel) emfModelFactory
.newReferenceModel();
injector.inject(targetEmfMM, context.targetMM);
// inject source M
EMFModel sourceEmfM = (EMFModel) emfModelFactory.newModel(sourceEmfMM);
injector.inject(sourceEmfM, sourceM);
// load source M
emfVmLauncher.addInModel(sourceEmfM, "IN", context.sourceMetamodelName);
// create & load target M
EMFModel targetM = (EMFModel) emfModelFactory.newModel(targetEmfMM);
emfVmLauncher.addOutModel(targetM, "OUT", context.targetMetamodelName);
Object asm = emfVmLauncher.loadModule(ASMInputStream);
emfVmLauncher.launch(ILauncher.RUN_MODE, new NullProgressMonitor(),
Collections.<String, Object> emptyMap(), asm);
return targetM.getResource();
}
}
This method is used as following
private Resource xml2Scenario2(final Resource sourceXMLRes) {
Resource result = null;
ResourceSet resourceSet = new ResourceSetImpl();
EPackage.Registry.INSTANCE.put(ScenarioPackage.eNS_URI, ScenarioPackage.eINSTANCE);
Resource sourceMM = resourceSet.getResource(XML_NS_URI, true);
Resource targetMM = resourceSet.getResource(scenario_NS_URI, true);
AtlExecutionContext context = new AtlExecutionContext(sourceMM,
targetMM, "XML", "Scenario");
AtlFacade atlFacade = new AtlFacade(context);
try {
result = atlFacade.evaluate(XML2Scenario_PATH.openStream(), sourceXMLRes);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return result;
}
And the sourceXMLRes is an XML model loaded from a file.
I've launched my test in debugging mode and I found that in the run method of the ASM class (from org.eclipse.m2m.atl.engine.emfvm) in the line :
ret = mainOperation.exec(frame.enter(), monitor);
ret is null !?
Is something missing ?
[Updated on: Thu, 06 September 2012 17:42] Report message to a moderator
|
|
| |
Re: Troubles with ATL API [message #909472 is a reply to message #909183] |
Fri, 07 September 2012 07:47 |
William Piers Messages: 301 Registered: July 2009 |
Senior Member |
|
|
Hello,
The injector api role is to inject real-world models (e.g. EMF resource)
into an IModel, usable by ATL.
The extractor has the inverse behaviour, as it allows to persist the
model managed by the transformation (targetM) into the EMF resource.
In your transformation you are missing the last step, which consists on
extracting the result model into the resource, using the EMFExtractor.
A complete example of use of this API is available as an example, in the
public 2 private example.
Also generating an atl plugin (new ATL plugin, the follow the wizard)
from your transformation will create a standalone java app which
launches your transformation.
Some useful links:
http://wiki.eclipse.org/ATL_Developer_Doc#Core_API
http://wiki.eclipse.org/ATL/User_Guide_-_The_ATL_Tools#ATL_Plugins
http://wiki.eclipse.org/ATL_Developer_Doc#Examples_of_use_.28run_ATL_transformations_in_Java.29
http://wiki.eclipse.org/ATL_Developer_Doc#Core_API
Best regards,
William
Le 06/09/2012 19:32, ElArbi Mising name a écrit :
> Hello,
>
> I'm trying to use the ATL API to launch my transformations, but the
> result is a null resource !
>
> import java.io.InputStream;
> import java.util.Collections;
>
> import org.eclipse.core.runtime.NullProgressMonitor;
> import org.eclipse.emf.ecore.resource.Resource;
> import org.eclipse.m2m.atl.core.emf.EMFInjector;
> import org.eclipse.m2m.atl.core.emf.EMFModel;
> import org.eclipse.m2m.atl.core.emf.EMFModelFactory;
> import org.eclipse.m2m.atl.core.emf.EMFReferenceModel;
> import org.eclipse.m2m.atl.core.launch.ILauncher;
> import org.eclipse.m2m.atl.engine.emfvm.launch.EMFVMLauncher;
>
>
> public class AtlFacade {
>
> private AtlExecutionContext context;
>
> public AtlFacade(AtlExecutionContext context) {
> this.context = context;
> }
>
> public Resource evaluate(InputStream ASMInputStream, Resource
> sourceM) {
> EMFInjector injector = new EMFInjector();
> EMFVMLauncher emfVmLauncher = new EMFVMLauncher();
> emfVmLauncher.initialize(Collections.<String, Object> emptyMap());
> EMFModelFactory emfModelFactory = new EMFModelFactory();
> // inject source MM
> EMFReferenceModel sourceEmfMM = (EMFReferenceModel)
> emfModelFactory
> .newReferenceModel();
> injector.inject(sourceEmfMM, context.sourceMM);
>
> // inject target MM
> EMFReferenceModel targetEmfMM = (EMFReferenceModel)
> emfModelFactory
> .newReferenceModel();
> injector.inject(targetEmfMM, context.targetMM);
>
> // inject source M
> EMFModel sourceEmfM = (EMFModel)
> emfModelFactory.newModel(sourceEmfMM);
> injector.inject(sourceEmfM, sourceM);
>
> // load source M
> emfVmLauncher.addInModel(sourceEmfM, "IN",
> context.sourceMetamodelName);
>
> // create & load target M
> EMFModel targetM = (EMFModel)
> emfModelFactory.newModel(targetEmfMM);
> emfVmLauncher.addOutModel(targetM, "OUT",
> context.targetMetamodelName);
>
> Object asm = emfVmLauncher.loadModule(ASMInputStream);
> emfVmLauncher.launch(ILauncher.RUN_MODE, new
> NullProgressMonitor(),
> Collections.<String, Object> emptyMap(), asm);
>
> return targetM.getResource();
> }
> }
>
> This method is used as following
>
> private Resource xml2Scenario2(final Resource sourceXMLRes) {
> Resource result = null;
> ResourceSet resourceSet = new ResourceSetImpl();
>
>
> EPackage.Registry.INSTANCE.put(ScenarioPackage.eNS_URI,
> ScenarioPackage.eINSTANCE);
>
> Resource sourceMM = resourceSet.getResource(XML_NS_URI, true);
> Resource targetMM = resourceSet.getResource(scenario_NS_URI,
> true);
> AtlExecutionContext context = new AtlExecutionContext(sourceMM,
> targetMM, "XML", "Scenario");
> AtlFacade atlFacade = new AtlFacade(context);
> try {
> result = atlFacade.evaluate(XML2Scenario_PATH.openStream(),
> sourceXMLRes);
> } catch (IOException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
> return result;
>
> }
>
> And the sourceXMLRes is an XML model loaded from a file.
> Is something missing ?
>
>
|
|
| |
Goto Forum:
Current Time: Tue Apr 23 06:45:06 GMT 2024
Powered by FUDForum. Page generated in 0.03385 seconds
|